Skip to content

Commit

Permalink
feat: using new Function create dynamic import
Browse files Browse the repository at this point in the history
  • Loading branch information
nonzzz committed Jul 24, 2023
1 parent bafe9b0 commit b869de2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
7 changes: 0 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@
},
"./*": "./*"
},
"typesVersions": {
"*": {
"*": [
"./dist/*"
]
}
},
"author": "Kanno",
"license": "MIT",
"homepage": "https://github.com/nonzzz/vite-plugin-cdn",
Expand Down
4 changes: 2 additions & 2 deletions src/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fsp from 'fs/promises'
import worker_threads from 'worker_threads'
import type { MessagePort } from 'worker_threads'
import { MAX_CONCURRENT, createConcurrentQueue, createVM } from './vm'
import { is, len, lookup } from './shared'
import { _import, is, len, lookup } from './shared'
import type { IIFEModuleInfo, IModule, ModuleInfo, ResolverFunction, TrackModule } from './interface'

// This file is a simply dependencies scanner.
Expand Down Expand Up @@ -83,7 +83,7 @@ async function tryResolveModule(
const code = await fsp.readFile(iifeFilePath, 'utf8')
Object.assign(meta, { name, version, code, relativeModule: iifeRelativePath, ...rest })
}
const pkg = await import(moduleName)
const pkg = await _import(moduleName)
const keys = Object.keys(pkg)
// If it's only exports by default
if (keys.includes('default') && len(keys) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ export function is(condit: boolean, message: string) {
throw new Error(message)
}
}

// https://github.com/TypeStrong/ts-node/discussions/1290
// TODO
// It should be removed until dynamic import can be prcoess by right syntax.
export const _import = new Function('specifier', 'return import(specifier)')

0 comments on commit b869de2

Please sign in to comment.