Repository navigation
fix(module): set the package ID sub-module only for files in the package - #1038
Merged
camc314 merged 2 commits intoNov 19, 2026
Merged
Conversation
`get_package_id` took the sub-module name by slicing the resolved file name at the length of the package directory, without a check that the file is in that directory. A `types`, `typings`, or `main` field that leaves the package (for example `"types": "../pkg-x/index.d.ts"`) then gave a wrong sub-module name (`x/index.d.ts`), and a multi-byte character at the cut point (`../pkgé/index.d.ts`) panicked. Go `getPackageId` (`resolver.go:2035`) sets `subModuleName` only when `resolvedFileName.RelativeTo(packageDirectory)` succeeds. Port `RootedPath.RelativeTo` (the case-sensitive `trimContainedPath`, `rooted_path.go:575`) as `relative_to_directory` and use it in `get_package_id`. With the wrong sub-module name, two different packages could get the same package ID, so tsrs redirected one file to the other as a duplicate package and dropped a TS2322 that tsgo reports. Tests: the regression cases `package-id-outside-package-dedup` and `package-id-outside-package-utf8`, with expected output from tsgo. Their `node_modules` directories are added with `git add -f`, because the root `.gitignore` ignores `node_modules/`. AI assistance: written with Claude Code.
Contributor
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
camc314
approved these changes
Nov 19, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When the
typesfield ofnode_modules/pkg/package.jsonpoints outside the package,get_package_idstill cut the sub-module name at the length of the package directory:"types": "../pkgé/index.d.ts"panicked (start byte index ... is not a char boundary)."types": "../pkg-x/index.d.ts"gave the IDpkg/x/index.d.ts@1.0.0. A file of another package with the same ID was then redirected as a duplicate, and a TS2322 that tsgo reports was missing.Go
getPackageIdsets the sub-module name only whenRelativeTo(packageDirectory)succeeds. This PR portsRelativeTo(GotrimContainedPath) asrelative_to_directory.Tests: the
package-id-outside-package-utf8andpackage-id-outside-package-dedupregressions, with expected output from tsgo. Both fail without the fix.AI assistance: written with Claude Code.