-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
fix: force the use of posix path separators for ts module graphs #8149
Conversation
When resolving the name of the main module for use in TS module graphs, ensure we force the usage of posix paths as this is what `typescript` uses and returns. This fixes an issue when running on Windows, where an assert would be thrown as a result of two identical paths using different path seperators being compared for equality.
There are some existing utils we have for this operation:
Could you add a test case to this file? We do run a CI job on Windows so that would cover this bug
|
Thanks @mischnic I'll pick up those tasks tomorrow. Can you shed any light into why this code path is only triggered in the presence of a |
Updated with the above comments:
|
Test failure with:
Will investigate. Edit: ✅ |
↪️ Pull Request
When resolving the name of the main module for use in TS module graphs, ensure we force the usage of posix paths as this is what
typescript
uses and returns.This fixes an issue when running on Windows, where an assert would be thrown as a result of two identical paths using different path separators being compared for equality.
For some reason I'm unaware of, this only occurs if a
tsconfig.json
file with apaths
entry is present in the root folder.💻 Examples
The main module name for ts module graphs is resolved here:
parcel/packages/transformers/typescript-types/src/TSTypesTransformer.js
Lines 54 to 57 in f2d0a3a
On windows, this returns a path with dos path separators
\
.Subsequently in
collect.js
when we usetypescript
to visit a node, it returns the node's name using posix separators/
, when we add that node to the module graph:parcel/packages/transformers/typescript-types/src/collect.js
Line 26 in f2d0a3a
It then attempts to compare it to the main module name resolved in
TSTypesTransformer
earlier:parcel/packages/transformers/typescript-types/src/TSModuleGraph.js
Lines 19 to 24 in f2d0a3a
Which fails due to the path separator mismatch.
Fast forward a bit, and
getAllExports
is called, and the assert is thrown due tonullthrows(this.mainModule),
still being undefined/ null.🚨 Test instructions
tsconfig.json
file in the same directory as your package.json. This file can contain anything, as long as it contains an arbitrary entry forcompilerOptions.paths
parcel build
✔️ PR Todo