-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Support module_resolution: "nodenext"
#8748
Support module_resolution: "nodenext"
#8748
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
🟢 Turbopack Benchmark CI successful 🟢Thanks |
✅ This change can build |
|
904e2f8
to
2e4ee59
Compare
1348426
to
8c02b98
Compare
if options_value.enable_js_ts_rewriting { | ||
let mut rewritten_path = path_pattern.clone(); | ||
let rewritten_path_modified = | ||
rewritten_path.replace_final_constants(&|c: &RcStr| -> Option<Pattern> { |
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.
Should modify new_path
Should be outside of the if !options_value.fully_specified
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.
One sideeffect of that approach is that is also replaces the js
that was appended via extensions
:
request with appended extensions:
Alternatives([
Constant("./src/foo.js"),
Constant("./src/foo.js.ts"),
Constant("./src/foo.js.js"),
Constant("./src/foo.js.json")])
request with extensions and then the new replacement
Alternatives([
Constant("./src/foo.ts"),
Constant("./src/foo.tsx"),
Constant("./src/foo.js"),
Constant("./src/foo.js.ts"), // <-
Constant("./src/foo.js.ts"), // <-
Constant("./src/foo.js.tsx"), // <-
Constant("./src/foo.js.js"),
Constant("./src/foo.js.json")])
But in practice, it probably doesn't make a difference
### Description Allow resolving for example `./foo.js` to `./foo.ts` `.js` can resolve to `.ts` and `.tsx` `.mjs` can resolve to `.mts` `.cjs` can resolve to `.cts` Closes PACK-3031 This is what `tsc --traceResolution` says about priority of the various possible resolution: ``` ======== Resolving module '../libs/f.js' from '/Users/niklas/Desktop/nodenext-app/app/page.tsx'. ======== Explicitly specified module resolution kind: 'NodeNext'. Resolving in CJS mode with conditions 'require', 'types', 'node'. Loading module as file / folder, candidate module location '/Users/niklas/Desktop/nodenext-app/libs/f.js', target file types: TypeScript, JavaScript, Declaration. File name '/Users/niklas/Desktop/nodenext-app/libs/f.js' has a '.js' extension - stripping it. File '/Users/niklas/Desktop/nodenext-app/libs/f.ts' does not exist. File '/Users/niklas/Desktop/nodenext-app/libs/f.tsx' does not exist. File '/Users/niklas/Desktop/nodenext-app/libs/f.d.ts' does not exist. File '/Users/niklas/Desktop/nodenext-app/libs/f.js' does not exist. File '/Users/niklas/Desktop/nodenext-app/libs/f.jsx' does not exist. File '/Users/niklas/Desktop/nodenext-app/libs/f.js.ts' does not exist. File '/Users/niklas/Desktop/nodenext-app/libs/f.js.tsx' does not exist. File '/Users/niklas/Desktop/nodenext-app/libs/f.js.d.ts' does not exist. ``` ### Testing Instructions I also added a test case
### Description Allow resolving for example `./foo.js` to `./foo.ts` `.js` can resolve to `.ts` and `.tsx` `.mjs` can resolve to `.mts` `.cjs` can resolve to `.cts` Closes PACK-3031 This is what `tsc --traceResolution` says about priority of the various possible resolution: ``` ======== Resolving module '../libs/f.js' from '/Users/niklas/Desktop/nodenext-app/app/page.tsx'. ======== Explicitly specified module resolution kind: 'NodeNext'. Resolving in CJS mode with conditions 'require', 'types', 'node'. Loading module as file / folder, candidate module location '/Users/niklas/Desktop/nodenext-app/libs/f.js', target file types: TypeScript, JavaScript, Declaration. File name '/Users/niklas/Desktop/nodenext-app/libs/f.js' has a '.js' extension - stripping it. File '/Users/niklas/Desktop/nodenext-app/libs/f.ts' does not exist. File '/Users/niklas/Desktop/nodenext-app/libs/f.tsx' does not exist. File '/Users/niklas/Desktop/nodenext-app/libs/f.d.ts' does not exist. File '/Users/niklas/Desktop/nodenext-app/libs/f.js' does not exist. File '/Users/niklas/Desktop/nodenext-app/libs/f.jsx' does not exist. File '/Users/niklas/Desktop/nodenext-app/libs/f.js.ts' does not exist. File '/Users/niklas/Desktop/nodenext-app/libs/f.js.tsx' does not exist. File '/Users/niklas/Desktop/nodenext-app/libs/f.js.d.ts' does not exist. ``` ### Testing Instructions I also added a test case
A regression from vercel/turborepo#8748 Closes PACK-3312 Previously, it treated imports to `something.mjs` as importing `something.mts` with a fallback to `something.js`. But it should obviously instead fallback to the original extension `mjs`, which is also what tsc does: ``` Found 'package.json' at 'input/package.json'. ======== Resolving module './src/foo.mjs' from 'input/index.js'. ======== Explicitly specified module resolution kind: 'NodeNext'. Resolving in CJS mode with conditions 'require', 'types', 'node'. Loading module as file / folder, candidate module location 'input/src/foo.mjs', target file types: TypeScript, JavaScript, Declaration. File name 'input/src/foo.mjs' has a '.mjs' extension - stripping it. File 'input/src/foo.mts' does not exist. File 'input/src/foo.d.mts' does not exist. File 'input/src/foo.mjs' does not exist. File 'input/src/foo.mjs.ts' does not exist. File 'input/src/foo.mjs.tsx' does not exist. File 'input/src/foo.mjs.d.ts' does not exist. File 'input/src/foo.mjs.js' does not exist. File 'input/src/foo.mjs.jsx' does not exist. Directory 'input/src/foo.mjs' does not exist, skipping all lookups in it. ======== Module name './src/foo.mjs' was not resolved. ======== ```
A regression from vercel/turborepo#8748 Closes PACK-3312 Previously, it treated imports to `something.mjs` as importing `something.mts` with a fallback to `something.js`. But it should obviously instead fallback to the original extension `mjs`, which is also what tsc does: ``` Found 'package.json' at 'input/package.json'. ======== Resolving module './src/foo.mjs' from 'input/index.js'. ======== Explicitly specified module resolution kind: 'NodeNext'. Resolving in CJS mode with conditions 'require', 'types', 'node'. Loading module as file / folder, candidate module location 'input/src/foo.mjs', target file types: TypeScript, JavaScript, Declaration. File name 'input/src/foo.mjs' has a '.mjs' extension - stripping it. File 'input/src/foo.mts' does not exist. File 'input/src/foo.d.mts' does not exist. File 'input/src/foo.mjs' does not exist. File 'input/src/foo.mjs.ts' does not exist. File 'input/src/foo.mjs.tsx' does not exist. File 'input/src/foo.mjs.d.ts' does not exist. File 'input/src/foo.mjs.js' does not exist. File 'input/src/foo.mjs.jsx' does not exist. Directory 'input/src/foo.mjs' does not exist, skipping all lookups in it. ======== Module name './src/foo.mjs' was not resolved. ======== ```
Description
Allow resolving for example
./foo.js
to./foo.ts
.js
can resolve to.ts
and.tsx
.mjs
can resolve to.mts
.cjs
can resolve to.cts
Closes PACK-3031
This is what
tsc --traceResolution
says about priority of the various possible resolution:Testing Instructions
I also added a test case