fix(js): use TypeScript readConfigFile instead of JSON.parse in resolvePathsBaseUrl#35539
Open
aqeelat wants to merge 1 commit intonrwl:masterfrom
Open
fix(js): use TypeScript readConfigFile instead of JSON.parse in resolvePathsBaseUrl#35539aqeelat wants to merge 1 commit intonrwl:masterfrom
aqeelat wants to merge 1 commit intonrwl:masterfrom
Conversation
…vePathsBaseUrl resolvePathsBaseUrl walked the tsconfig extends chain using JSON.parse, which cannot handle // or /* */ comments (JSONC). When a tsconfig in the chain contained comments, parsing failed silently and broke the extends walk, causing workspace path mappings to resolve relative to the project directory instead of the workspace root. Use ts.readConfigFile (which handles JSONC) — the same approach already used by readTsConfig in the same file. Fixes nrwl#35537
👷 Deploy request for nx-docs pending review.Visit the deploys page to approve it
|
👷 Deploy request for nx-dev pending review.Visit the deploys page to approve it
|
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.
Current Behavior
resolvePathsBaseUrlinpackages/js/src/utils/typescript/ts-config.tswalks the tsconfigextendschain usingJSON.parse(readFileSync(...))to find wherepathsis defined.JSON.parsecannot handle//or/* */comments (JSONC), which are extremely common in tsconfig files. When parsing fails, thecatchblock silently skips the file, breaking the extends chain walk. The function never reachestsconfig.base.json(wherepathsandbaseUrlare defined), so it falls back to the project's own directory as the resolution base, producing incorrect path mappings like{workspaceRoot}/libs/my-lib/dist/libs/data-layerinstead of{workspaceRoot}/dist/libs/data-layer.This is a regression introduced in v22.7.0 by PR #34965.
Expected Behavior
Buildable library builds should resolve workspace dependencies correctly, even when tsconfig files in the extends chain contain JSONC comments (
//or/* */). The fix uses TypeScript'sreadConfigFile(which handles JSONC) — the same approach already used byreadTsConfigin the same file.Related Issue(s)
Fixes #35537