-
Notifications
You must be signed in to change notification settings - Fork 940
Fix module resolver bug exposed by malformed package.json import patterns #2680
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
df286f8
a4781f7
7dee5c1
0edcafc
2b730dc
90aa27c
ab2810c
77a5486
934d7c5
eb80f5f
c3031cc
91ff619
60d385b
85d2d5e
ef63974
1c72bd8
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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // @noEmit: true | ||
| // @noTypesAndSymbols: true | ||
| // @module: nodenext | ||
| // @moduleResolution: nodenext | ||
| // @filename: src/a.ts | ||
|
Comment on lines
+1
to
+5
|
||
| import * as b from "#/b."; | ||
|
|
||
| b.foo(); | ||
|
|
||
| // @filename: src/b.ts | ||
| export function foo() {} | ||
|
|
||
| // @filename: package.json | ||
| { | ||
| "imports": { | ||
| "#/*": { | ||
| "types": "./src/*ts", | ||
| "default": "./dist/*js" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // @filename: tsconfig.json | ||
| { | ||
| "compilerOptions": { | ||
| "module": "nodenext", | ||
| "moduleResolution": "nodenext", | ||
| "rootDir": "src", | ||
| "outDir": "dist" | ||
| }, | ||
| "include": ["src"] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // @noEmit: true | ||
| // @noTypesAndSymbols: true | ||
| // @module: nodenext | ||
| // @moduleResolution: nodenext | ||
| // Test verifies that when a module specifier contains ".ts" that gets matched by a | ||
| // wildcard pattern, resolvedUsingTsExtension is correctly set to true. | ||
| // Example: import "#/foo.ts.omg" with pattern "#/*.omg": "./src/*" | ||
| // The * matches "foo.ts", and when expanded becomes "./src/foo.ts" | ||
| // Since the wildcard matched ".ts" from the specifier, an error should be reported. | ||
|
|
||
| // @filename: src/foo.ts | ||
| export function hello() { | ||
| return "world"; | ||
| } | ||
|
|
||
| // @filename: src/index.ts | ||
| import { hello } from "#/foo.ts.omg"; | ||
|
|
||
| hello(); | ||
|
|
||
| // @filename: package.json | ||
| { | ||
| "type": "module", | ||
| "imports": { | ||
| "#/*.omg": "./src/*" | ||
| } | ||
| } | ||
|
|
||
| // @filename: tsconfig.json | ||
| { | ||
| "compilerOptions": { | ||
| "module": "nodenext", | ||
| "moduleResolution": "nodenext", | ||
| "rootDir": "src", | ||
| "outDir": "dist" | ||
| }, | ||
| "include": ["src"] | ||
| } |
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.
The fallback TS extension extraction uses
strings.Contains(moduleReference, ext)while iteratingtspath.SupportedTSExtensionsFlat(which lists.tsbefore.tsxand.d.ts). This can pick the wrong extension (e.g."foo.tsx.omg"matches.tsfirst,"foo.d.ts.omg"matches.tsinstead of.d.ts), producing incorrect TS5097 diagnostics. Prefer a boundary-aware match (e.g. look for an extension that is followed by/,.,?,#, or end-of-string) and/or prefer the longest matching extension.