-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support
module_resolution: "nodenext"
(vercel/turborepo#8748)
### 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
- Loading branch information
Showing
11 changed files
with
180 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import foo from "./src/foo.js"; | ||
import bar from "./src/bar.js"; | ||
import fooEsm from "./src/foo-esm.mjs"; | ||
import fooCjs from "./src/foo-cjs.cjs"; | ||
|
||
it("should correctly resolve explicit extensions with nodenext", () => { | ||
expect(foo).toBe("foo"); | ||
expect(bar).toBe("bar"); | ||
expect(fooEsm).toBe("fooEsm"); | ||
expect(fooCjs).toBe("fooCjs"); | ||
}); |
1 change: 1 addition & 0 deletions
1
...s/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/bar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "bar"; |
1 change: 1 addition & 0 deletions
1
...rbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo-cjs.cts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = "fooCjs"; |
1 change: 1 addition & 0 deletions
1
...rbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo-esm.mts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "fooEsm"; |
1 change: 1 addition & 0 deletions
1
...es/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
throw new Error("Should have a lower precedence than foo.ts"); |
1 change: 1 addition & 0 deletions
1
...es/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/src/foo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "foo"; |
6 changes: 6 additions & 0 deletions
6
...turbopack-tests/tests/execution/turbopack/resolving/tsconfig-nodenext/input/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext" | ||
} | ||
} |