Skip to content

Commit 3b33542

Browse files
chargomeclaude
andcommitted
fix(remix): Normalise Windows separators in the deletion glob
`glob` reads a backslash as an escape, so a Windows `outDir` produced a pattern that matched nothing and left the generated source maps on disk. Both path flavours are now checked for absoluteness, since `path.isAbsolute` only recognises the host platform's form. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 9f30a0e commit 3b33542

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

‎packages/remix/src/vite/sourceMaps.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,13 @@ export function makeAddSentryVitePlugin(options: SentryRemixVitePluginOptions):
5454
// Derived from the configured `outDir` rather than hardcoding `build`, so a custom Remix
5555
// `buildDirectory` still gets cleaned up. Remix runs a client and an SSR build, each with
5656
// its own `outDir`, so each pass deletes only what it emitted.
57-
// Vite resolves `outDir` to an absolute path, so only a relative one may be prefixed with
58-
// `./` - `.//abs/path/**/*.map` matches nothing and silently leaves the maps on disk.
59-
const outDir = config.build?.outDir?.replace(/\/+$/, '') || 'build';
60-
const outDirGlob = path.isAbsolute(outDir) ? outDir : `./${outDir.replace(/^\.\//, '')}`;
57+
//
58+
// Separators are normalised because `glob` reads a backslash as an escape, and both path
59+
// flavours are checked because `path.isAbsolute` only recognises the host platform's form.
60+
// Only a relative path may take the `./` prefix: `.//abs/path/**/*.map` matches nothing.
61+
const outDir = (config.build?.outDir || 'build').replace(/\\/g, '/').replace(/\/+$/, '');
62+
const isAbsoluteOutDir = path.posix.isAbsolute(outDir) || path.win32.isAbsolute(outDir);
63+
const outDirGlob = isAbsoluteOutDir ? outDir : `./${outDir.replace(/^\.\//, '')}`;
6164
const filesToDelete = [`${outDirGlob}/**/*.map`];
6265

6366
if (debug) {

‎packages/remix/test/vite/sourceMaps.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,19 @@ describe('makeAddSentryVitePlugin', () => {
164164
]);
165165
});
166166

167+
// `glob` reads a backslash as an escape, so an unnormalised Windows `outDir` matches nothing and
168+
// leaves the maps on disk. Both path flavours are checked, so this holds on POSIX runners too.
169+
it('normalises a Windows absolute outDir', async () => {
170+
const plugins = makeAddSentryVitePlugin({});
171+
const configPlugin = plugins.find(plugin => plugin.name === 'sentry-remix-files-to-delete-after-upload');
172+
173+
(configPlugin?.config as (config: UserConfig) => void)({ build: { outDir: 'C:\\proj\\build\\client' } });
174+
175+
await expect(capturedOptions?.sourcemaps?.filesToDeleteAfterUpload).resolves.toEqual([
176+
'C:/proj/build/client/**/*.map',
177+
]);
178+
});
179+
167180
it('keeps the source maps when the user set their own build.sourcemap', async () => {
168181
const plugins = makeAddSentryVitePlugin({});
169182
const configPlugin = plugins.find(plugin => plugin.name === 'sentry-remix-files-to-delete-after-upload');

0 commit comments

Comments
 (0)