Skip to content

fix(babel): emit forward slashes in generated import paths on Windows - #5054

Open
KallinikosMil wants to merge 1 commit into
callstack:mainfrom
KallinikosMil:fix/mappings-windows-path-separator
Open

fix(babel): emit forward slashes in generated import paths on Windows#5054
KallinikosMil wants to merge 1 commit into
callstack:mainfrom
KallinikosMil:fix/mappings-windows-path-separator

Conversation

@KallinikosMil

Copy link
Copy Markdown

Motivation

scripts/generate-mappings.ts builds each mapping's path with path.relative, which returns platform-native separators. On Windows that writes backslashes into lib/mappings.json:

"Palette": { "path": "lib\module\theme\tokens", "name": "Palette" }

The babel plugin then interpolates that value straight into an import specifier (`${name}/${mapping.path}` in src/babel/index.js), so the rewritten imports come out as:

import { Palette } from "react-native-paper/lib\module\theme\tokens";

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. index is taken from package.json's main, which is already POSIX, so only the relative() result needed fixing.

Related issue

No existing issue — I ran into it while running the test suite on Windows, where src/babel/__tests__/index.js fails on main for this reason.

Test plan

yarn jest src/babel fails on main on Windows and passes with this change:

- import { Palette } from "react-native-paper/lib/module/theme/tokens";
+ import { Palette } from "react-native-paper/lib\module\theme\tokens";

The regenerated lib/mappings.json now contains "lib/module/theme/tokens" on Windows, matching what the existing __fixtures__/generate-mappings/output.js snapshot expects.

The change is a no-op on Linux/macOS, where path.sep is already /, so the existing CI result is unaffected. Full suite locally: 55 suites / 735 tests passing, lint and typecheck clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant