-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(bundle): boot a bundled tegg app (cnpmcore) end to end #5987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
5bf4854
5997a06
86503a6
ffbee4b
a356760
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,7 +62,13 @@ try { | |
| // state persists across test files. | ||
| const detectedIsESM = isESM; | ||
| const nodeMajorVersion = parseInt(process.versions.node.split('.', 1)[0], 10); | ||
| const supportImportMetaResolve = nodeMajorVersion >= 18; | ||
| // Feature-detect instead of gating on the Node version: when the code is shipped | ||
| // inside a bundle (e.g. @utoo/pack rewrites `import.meta` to a runtime shim that | ||
| // lacks `.resolve`), `import.meta.resolve` is not a function even on Node >= 18, so | ||
| // calling it throws. Detecting the actual capability lets us fall back to | ||
| // `require.resolve` in the bundled CommonJS runtime. | ||
| const supportImportMetaResolve = | ||
| nodeMajorVersion >= 18 && typeof (import.meta as { resolve?: unknown }).resolve === 'function'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If const supportImportMetaResolve =
nodeMajorVersion >= 18 &&
typeof import.meta !== 'undefined' &&
!!import.meta &&
typeof (import.meta as { resolve?: unknown }).resolve === 'function';
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch — fixed in 5997a06 (guarded the undefined case; no-op when defined). |
||
|
|
||
| let _customRequire: NodeRequire; | ||
| export function getRequire(): NodeRequire { | ||
|
|
@@ -407,7 +413,10 @@ export function importResolve(filepath: string, options?: ImportResolveOptions): | |
| throw new TypeError(`Cannot find module ${filepath}, because ${moduleFilePath} does not exists`); | ||
| } | ||
| } else { | ||
| moduleFilePath = getRequire().resolve(filepath); | ||
| // Fallback when `import.meta.resolve` is unavailable (e.g. inside a bundle). | ||
| // Forward `paths` so package resolution still honours the caller's lookup | ||
| // dirs (the app baseDir / framework dirs), matching the on-disk attempts above. | ||
| moduleFilePath = getRequire().resolve(filepath, paths ? { paths } : undefined); | ||
| } | ||
| } | ||
| debug('[importResolve:success] %o, options: %o => %o, isESM: %s', filepath, options, moduleFilePath, isESM); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.