| 1 |
import { createRequire } from "module"; |
| 2 |
import { resolvescip-typescript npm @babel/core 7.20.12 src/vendor/`import-meta-resolve.d.ts`/resolve(). as polyfillscip-typescript npm @babel/core 7.20.12 src/vendor/`import-meta-resolve.d.ts`/resolve(). } from "../../vendor/import-meta-resolve"scip-typescript npm @babel/core 7.20.12 src/vendor/`import-meta-resolve.d.ts`/; |
| 3 |
|
| 4 |
const requirescip-typescript npm @babel/core 7.20.12 src/config/files/`import-meta-resolve.ts`/require. = createRequire(import.meta.urlscip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/ImportMeta#url.); |
| 5 |
|
| 6 |
let import_scip-typescript npm @babel/core 7.20.12 src/config/files/`import-meta-resolve.ts`/import_.; |
| 7 |
try { |
| 8 |
// Node < 13.3 doesn't support import() syntax. |
| 9 |
import_scip-typescript npm @babel/core 7.20.12 src/config/files/`import-meta-resolve.ts`/import_. = requirescip-typescript npm @babel/core 7.20.12 src/config/files/`import-meta-resolve.ts`/require.("./import.cjs"); |
| 10 |
} catch {} |
| 11 |
|
| 12 |
// import.meta.resolve is only available in ESM, but this file is compiled to CJS. |
| 13 |
// We can extract it using dynamic import. |
| •14 |
// @ts-ignore |
| 15 |
const importMetaResolvePscip-typescript npm @babel/core 7.20.12 src/config/files/`import-meta-resolve.ts`/importMetaResolveP.: Promisescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Promise#<ImportMetascip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ImportMeta#["resolve"scip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/ImportMeta#resolve().]> = |
| 16 |
import_scip-typescript npm @babel/core 7.20.12 src/config/files/`import-meta-resolve.ts`/import_. && |
| 17 |
// Due to a Node.js/V8 bug (https://github.com/nodejs/node/issues/35889), we cannot |
| 18 |
// use always dynamic import because it segfaults when running in a Node.js `vm` context, |
| 19 |
// which is used by the default Jest environment and by webpack-cli. |
| 20 |
// |
| 21 |
// However, import.meta.resolve is experimental and only enabled when Node.js is run |
| 22 |
// with the `--experimental-import-meta-resolve` flag: we can avoid calling import() |
| 23 |
// when that flag is not enabled, so that the default behavior never segfaults. |
| 24 |
// |
| 25 |
// Hopefully, before Node.js unflags import.meta.resolve, either: |
| 26 |
// - we will move to ESM, so that we have direct access to import.meta.resolve, or |
| 27 |
// - the V8 bug will be fixed so that we can safely use dynamic import by default. |
| 28 |
// |
| 29 |
// I (@nicolo-ribaudo) am really anoyed by this bug, because there is no known |
| 30 |
// work-around other than "don't use dynamic import if you are running in a `vm` context", |
| 31 |
// but there is no reliable way to detect it (you cannot try/catch segfaults). |
| 32 |
// |
| 33 |
// This is the only place where we *need* to use dynamic import because we need to access |
| 34 |
// an ES module. All the other places will first try using require() and *then*, if |
| 35 |
// it throws because it's a module, will fallback to import(). |
| 36 |
process.execArgv.includes("--experimental-import-meta-resolve") |
| 37 |
? import_scip-typescript npm @babel/core 7.20.12 src/config/files/`import-meta-resolve.ts`/import_.("data:text/javascript,export default import.meta.resolve").then( |
| 38 |
(m: { default: ImportMetascip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ImportMeta#["resolve"scip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/ImportMeta#resolve().] | undefined }) => |
| 39 |
m.default || polyfillscip-typescript npm @babel/core 7.20.12 src/vendor/`import-meta-resolve.d.ts`/resolve()., |
| 40 |
() => polyfillscip-typescript npm @babel/core 7.20.12 src/vendor/`import-meta-resolve.d.ts`/resolve()., |
| 41 |
) |
| 42 |
: Promisescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Promise#.resolvescip-typescript npm typescript 5.9.3 lib/`lib.es2015.promise.d.ts`/PromiseConstructor#resolve().(polyfillscip-typescript npm @babel/core 7.20.12 src/vendor/`import-meta-resolve.d.ts`/resolve().); |
| 43 |
|
| 44 |
export default async function resolvescip-typescript npm @babel/core 7.20.12 src/config/files/`import-meta-resolve.ts`/resolve().( |
| •45 |
// @ts-ignore |
| 46 |
specifierscip-typescript npm @babel/core 7.20.12 src/config/files/`import-meta-resolve.ts`/resolve().(specifier): Parametersscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Parameters#<ImportMetascip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ImportMeta#["resolve"scip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/ImportMeta#resolve().]>[0], |
| •47 |
// @ts-ignore |
| 48 |
parentscip-typescript npm @babel/core 7.20.12 src/config/files/`import-meta-resolve.ts`/resolve().(parent)?: Parametersscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Parameters#<ImportMetascip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ImportMeta#["resolve"scip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/ImportMeta#resolve().]>[1], |
| •49 |
// @ts-ignore |
| 50 |
): ReturnTypescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ReturnType#<ImportMetascip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ImportMeta#["resolve"scip-typescript npm typescript 5.9.3 lib/`lib.dom.d.ts`/ImportMeta#resolve().]> { |
| 51 |
return (await importMetaResolvePscip-typescript npm @babel/core 7.20.12 src/config/files/`import-meta-resolve.ts`/importMetaResolveP.)(specifierscip-typescript npm @babel/core 7.20.12 src/config/files/`import-meta-resolve.ts`/resolve().(specifier), parentscip-typescript npm @babel/core 7.20.12 src/config/files/`import-meta-resolve.ts`/resolve().(parent)); |
| 52 |
} |