vendor: update cordis / loader
This commit is contained in:
24
vendor/loader/src/internal.ts
vendored
24
vendor/loader/src/internal.ts
vendored
@@ -105,18 +105,28 @@ export type ModuleLoader = ModuleLoaderV1 | ModuleLoaderV2
|
||||
export namespace ModuleLoader {
|
||||
let _cachedLoader: ModuleLoader | undefined
|
||||
|
||||
export function fromInternal(): ModuleLoader | undefined {
|
||||
if (!process.execArgv.includes('--expose-internals')) return
|
||||
if (_cachedLoader) return _cachedLoader
|
||||
function requireInternal(id: string): any {
|
||||
const require = createRequire(import.meta.url)
|
||||
if (process.execArgv.includes('--expose-internals')) {
|
||||
try {
|
||||
return require(id)
|
||||
} catch {}
|
||||
}
|
||||
try {
|
||||
return require('node-addon-require-builtin').requireBuiltin(id)
|
||||
} catch {}
|
||||
}
|
||||
|
||||
export function fromInternal(): ModuleLoader | undefined {
|
||||
if (_cachedLoader) return _cachedLoader
|
||||
const [major] = process.versions.node.split('.').map(Number)
|
||||
|
||||
if (major >= 24) {
|
||||
const raw = require('internal/modules/esm/loader').getOrInitializeCascadedLoader()
|
||||
return _cachedLoader = Object.assign(raw, { version: 'v2' })
|
||||
const raw = requireInternal('internal/modules/esm/loader')?.getOrInitializeCascadedLoader()
|
||||
if (raw) return _cachedLoader = Object.assign(raw, { version: 'v2' })
|
||||
} else if (major >= 22) {
|
||||
const raw = require('internal/modules/esm/loader').getOrInitializeCascadedLoader()
|
||||
return _cachedLoader = Object.assign(raw, { version: 'v1' })
|
||||
const raw = requireInternal('internal/modules/esm/loader')?.getOrInitializeCascadedLoader()
|
||||
if (raw) return _cachedLoader = Object.assign(raw, { version: 'v1' })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user