fix(babel): emit forward slashes in generated import paths on Windows - #5054
Open
KallinikosMil wants to merge 1 commit into
Open
fix(babel): emit forward slashes in generated import paths on Windows#5054KallinikosMil wants to merge 1 commit into
KallinikosMil wants to merge 1 commit into
Conversation
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.
Motivation
scripts/generate-mappings.tsbuilds each mapping'spathwithpath.relative, which returns platform-native separators. On Windows that writes backslashes intolib/mappings.json:The babel plugin then interpolates that value straight into an import specifier (
`${name}/${mapping.path}`insrc/babel/index.js), so the rewritten imports come out as:Import specifiers always use forward slashes regardless of platform, so these paths don't resolve — the plugin's output is broken for anyone generating the mappings on Windows.
This normalises the separator to
/at the point where the path is produced.indexis taken frompackage.json'smain, which is already POSIX, so only therelative()result needed fixing.Related issue
No existing issue — I ran into it while running the test suite on Windows, where
src/babel/__tests__/index.jsfails onmainfor this reason.Test plan
yarn jest src/babelfails onmainon Windows and passes with this change:The regenerated
lib/mappings.jsonnow contains"lib/module/theme/tokens"on Windows, matching what the existing__fixtures__/generate-mappings/output.jssnapshot expects.The change is a no-op on Linux/macOS, where
path.sepis already/, so the existing CI result is unaffected. Full suite locally: 55 suites / 735 tests passing, lint and typecheck clean.