-
Notifications
You must be signed in to change notification settings - Fork 0
TURBOPACK: Fix subpath imports resolving to dependencies #150
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 all commits
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 |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| import foo from '#foo' | ||
| import dep from '#dep' | ||
| import depInNm from '#dep-in-nm' | ||
| import pattern from '#pattern/pat.js' | ||
| import conditionalImport from '#conditional' | ||
| const conditionalRequire = require('#conditional') | ||
|
|
||
| console.log(foo, dep, pattern, conditionalImport, conditionalRequire) | ||
| console.log(foo, dep, depInNm, pattern, conditionalImport, conditionalRequire) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| (globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([ | ||
| "output/0rv8_turbopack-tests_tests_snapshot_imports_subpath-imports_input_index_1jr1_4n.js", | ||
| {"otherChunks":["output/1do3_crates_turbopack-tests_tests_snapshot_imports_subpath-imports_input_14v1xaq._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/imports/subpath-imports/input/index.js [test] (ecmascript)"]} | ||
| "output/0rv8_turbopack-tests_tests_snapshot_imports_subpath-imports_input_index_01i6qyk.js", | ||
| {"otherChunks":["output/1do3_crates_turbopack-tests_tests_snapshot_imports_subpath-imports_input_1p6gt_f._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/imports/subpath-imports/input/index.js [test] (ecmascript)"]} | ||
| ]); | ||
| // Dummy runtime |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
Pattern::alternativesto try both a relative path (prefixed with./) and the original path for subpath imports can lead to ambiguous resolution. According to the Node.js specification, subpath import targets are either relative (starting with./or../) or bare package specifiers. Trying both might cause a bare specifier like"#dep": "my-pkg"to accidentally resolve to a local file./my-pkgif it exists, which deviates from standard Node.js behavior.If the intention is to strictly follow the spec,
result_path.clone()should be sufficient forExportImport::Import, asRequest::parsewill correctly handle the relativeness based on the prefix. If backward compatibility for missing./prefixes is required, the current approach is a safe fallback, but the code can be simplified to avoid redundant shadowing and improve readability.