Fix import path completions for wildcard patterns with extensions #62764
+167
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #62706
Problem
Import path completions were missing for package.json exports using wildcard patterns with file extensions.
Example:
{ "exports": { "./glob/path/*.js": "./build/*.js" } }Typing
import {} from "@local/a/glob/path/"should suggestbar.js,baz.jsbut completions were missing.Root Cause
Two bugs in
src/services/stringCompletions.ts:Line 1234: Wildcard detection used
endsWith(pattern, "/*")which only matched patterns ending with"/*", missing patterns like"./path/*.js"Line 1166-1168: Completion generation didn't append file extension suffixes from patterns
Solution
Change 1: Broaden wildcard detection (Line 1234)
This correctly detects all Node.js wildcard patterns containing
"/*"regardless of trailing characters.Change 2: Append file extension suffixes (Line 1166-1168)
This adds file extension suffixes (
.js,.css,.d.ts, etc.) to completions while correctly ignoring path components (like"/suffix").Testing
New Test Case
Added
tests/cases/fourslash/completionForPackageExportsGlobWithExtension.tsto verify wildcard patterns with extensions work correctly.Validation Results
Before fix:
"Error: completion 'bar.js' not found")After fix:
Patterns Fixed
"./glob/path/*.js"✅"./styles/*.css"✅"./dist/*.d.ts"✅"./esm/*.mjs"✅"./cjs/*.cjs"✅Compliance
Aligns with Node.js Package Entry Points specification which supports wildcard patterns like:
{ "exports": { "./features/*.js": "./src/features/*.js", "./lib/*/index.js": "./src/*/index.js" } }All valid patterns contain
"/*"substring.Files Changed
src/services/stringCompletions.ts(2 lines modified)tests/cases/fourslash/completionForPackageExportsGlobWithExtension.ts(new test)