Skip to content

Commit 7c382b5

Browse files
committed
Fix Windows path handling in module-details-from-path
On Windows, module-details-from-path only works with backslash-separated paths. Bundlers (esbuild, vite, rollup) normalize paths to forward slashes on all platforms, causing module-details-from-path to return null on Windows. This fix normalizes bundler paths to use the platform-native separator before passing to module-details-from-path, ensuring it works correctly on Windows. Fixes path matching issues that prevented instrumentation on Windows builds.
1 parent 2e4a083 commit 7c382b5

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/plugin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ const unplugin = createUnplugin<CodeTransformerPluginOptions>((options) => {
5353
}
5454

5555
// Try to get module details from the file path
56-
const moduleDetails = moduleDetailsFromPath(id);
56+
// IMPORTANT: On Windows, module-details-from-path only works with backslash paths.
57+
// Bundlers typically normalize to forward slashes, so we convert back to the
58+
// platform-native separator.
59+
const normalizedId = process.platform === 'win32' ? id.replace(/\//g, '\\') : id;
60+
const moduleDetails = moduleDetailsFromPath(normalizedId);
5761

5862
// If no module details found, the file is not part of a module
5963
if (!moduleDetails) {

0 commit comments

Comments
 (0)