From 99f9dd814c808879a260cfb8d18d663fa40dbde6 Mon Sep 17 00:00:00 2001 From: Yevhenii Date: Sun, 11 Oct 2026 18:54:22 +0300 Subject: [PATCH] fix(babel): normalize resolved paths to POSIX so Windows rewrites work path.resolve separates with backslashes on Windows, so a relative import resolved against the file never matched the forward-slash package paths the handlers split on, and was left unrewritten. --- src/babel/helpers.ts | 7 +++++++ src/babel/react-native-web.ts | 5 ++--- src/babel/react-native.ts | 5 ++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/babel/helpers.ts b/src/babel/helpers.ts index c66f630c..afa5cba4 100644 --- a/src/babel/helpers.ts +++ b/src/babel/helpers.ts @@ -1,3 +1,5 @@ +import { dirname, resolve, sep } from "path"; + import tBabelTypes, { type CallExpression } from "@babel/types"; export type BabelTypes = typeof tBabelTypes; @@ -38,3 +40,8 @@ export function getInteropRequireDefaultSource( return requireArg.value; } + +// The handlers match "/"-separated package paths, and path.resolve separates with "\" on Windows +export function resolveImportSource(filename: string, source: string): string { + return resolve(dirname(filename), source).split(sep).join("/"); +} diff --git a/src/babel/react-native-web.ts b/src/babel/react-native-web.ts index 2b1d77a5..7e1b142c 100644 --- a/src/babel/react-native-web.ts +++ b/src/babel/react-native-web.ts @@ -1,5 +1,3 @@ -import { dirname, resolve } from "path"; - import { type NodePath } from "@babel/traverse"; import tBabelTypes, { type CallExpression, @@ -10,12 +8,13 @@ import tBabelTypes, { } from "@babel/types"; import { allowedModules } from "./allowedModules"; +import { resolveImportSource } from "./helpers"; type BabelTypes = typeof tBabelTypes; function parseReactNativeWebSource(source: string, filename: string) { if (source.startsWith(".")) { - source = resolve(dirname(filename), source); + source = resolveImportSource(filename, source); const internalPath = source.split("react-native-web/dist")[1]; if (!internalPath) { diff --git a/src/babel/react-native.ts b/src/babel/react-native.ts index e035fec1..b285e0cd 100644 --- a/src/babel/react-native.ts +++ b/src/babel/react-native.ts @@ -1,5 +1,3 @@ -import { dirname, resolve } from "path"; - import { type NodePath } from "@babel/traverse"; import tBabelTypes, { type ImportDeclaration, @@ -9,12 +7,13 @@ import tBabelTypes, { } from "@babel/types"; import { allowedModules } from "./allowedModules"; +import { resolveImportSource } from "./helpers"; type BabelTypes = typeof tBabelTypes; function parseReactNativeSource(source: string, filename: string) { if (source.startsWith(".")) { - source = resolve(dirname(filename), source); + source = resolveImportSource(filename, source); const internalPath = source.split("react-native/Libraries/Components/")[1]; if (!internalPath) {