Skip to content

Commit 3e8bf59

Browse files
author
Luca Forstner
authored
fix(core): Normalize id and releaseInjectionTargets in transformInclude (#132)
1 parent f34219f commit 3e8bf59

File tree

1 file changed

+12
-6
lines changed
  • packages/bundler-plugin-core/src

1 file changed

+12
-6
lines changed

packages/bundler-plugin-core/src/index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { createLogger, Logger } from "./sentry/logger";
2222
import { InternalOptions, normalizeUserOptions, validateOptions } from "./options-mapping";
2323
import { getSentryCli } from "./sentry/cli";
2424
import { Hub, makeMain } from "@sentry/node";
25+
import path from "path";
2526

2627
// We prefix the polyfill id with \0 to tell other plugins not to try to load or transform it.
2728
// This hack is taken straight from https://rollupjs.org/guide/en/#resolveid.
@@ -205,29 +206,34 @@ const unplugin = createUnplugin<Options>((options, unpluginMetaContext) => {
205206
transformInclude(id) {
206207
logger.debug('Called "transformInclude":', { id });
207208

209+
// We normalize the id because vite always passes `id` as a unix style path which causes problems when a user passes
210+
// a windows style path to `releaseInjectionTargets`
211+
const normalizedId = path.normalize(id);
212+
208213
// We don't want to transform our injected code.
209-
if (id === RELEASE_INJECTOR_ID) {
214+
if (normalizedId === RELEASE_INJECTOR_ID) {
210215
return false;
211216
}
212217

213218
if (internalOptions.releaseInjectionTargets) {
214219
// If there's an `releaseInjectionTargets` option transform (ie. inject the release varible) when the file path matches the option.
215220
if (typeof internalOptions.releaseInjectionTargets === "function") {
216-
return internalOptions.releaseInjectionTargets(id);
221+
return internalOptions.releaseInjectionTargets(normalizedId);
217222
}
218223

219224
return internalOptions.releaseInjectionTargets.some((entry) => {
220225
if (entry instanceof RegExp) {
221-
return entry.test(id);
226+
return entry.test(normalizedId);
222227
} else {
223-
return id === entry;
228+
const normalizedEntry = path.normalize(entry);
229+
return normalizedId === normalizedEntry;
224230
}
225231
});
226232
} else {
227-
const pathIsOrdinary = !id.includes("?") && !id.includes("#");
233+
const pathIsOrdinary = !normalizedId.includes("?") && !normalizedId.includes("#");
228234

229235
const pathHasAllowedFileEnding = ALLOWED_TRANSFORMATION_FILE_ENDINGS.some(
230-
(allowedFileEnding) => id.endsWith(allowedFileEnding)
236+
(allowedFileEnding) => normalizedId.endsWith(allowedFileEnding)
231237
);
232238

233239
return pathIsOrdinary && pathHasAllowedFileEnding;

0 commit comments

Comments
 (0)