Skip to content

Commit 9f30a0e

Browse files
chargomeclaude
andcommitted
fix(remix): Do not prefix an absolute outDir in the deletion glob
Vite resolves `build.outDir` to an absolute path, so prefixing it with `./` produced `.//abs/path/**/*.map`, which matches nothing and left the generated source maps in the production output. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent b89699c commit 9f30a0e

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as path from 'path';
12
import { sentryVitePlugin } from '@sentry/bundler-plugins/vite';
23
import type { Plugin, UserConfig } from 'vite';
34
import type { SentryRemixVitePluginOptions } from './types';
@@ -53,8 +54,11 @@ export function makeAddSentryVitePlugin(options: SentryRemixVitePluginOptions):
5354
// Derived from the configured `outDir` rather than hardcoding `build`, so a custom Remix
5455
// `buildDirectory` still gets cleaned up. Remix runs a client and an SSR build, each with
5556
// its own `outDir`, so each pass deletes only what it emitted.
56-
const outDir = config.build?.outDir?.replace(/^\.\//, '').replace(/\/+$/, '') || 'build';
57-
const filesToDelete = [`./${outDir}/**/*.map`];
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(/^\.\//, '')}`;
61+
const filesToDelete = [`${outDirGlob}/**/*.map`];
5862

5963
if (debug) {
6064
// eslint-disable-next-line no-console

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,19 @@ describe('makeAddSentryVitePlugin', () => {
151151
await expect(capturedOptions?.sourcemaps?.filesToDeleteAfterUpload).resolves.toEqual(['./dist/client/**/*.map']);
152152
});
153153

154+
// Vite resolves `outDir` to an absolute path by the time this hook runs, and `.//abs/path` would
155+
// match nothing - leaving the maps in the production output.
156+
it('does not prefix an absolute outDir', async () => {
157+
const plugins = makeAddSentryVitePlugin({});
158+
const configPlugin = plugins.find(plugin => plugin.name === 'sentry-remix-files-to-delete-after-upload');
159+
160+
(configPlugin?.config as (config: UserConfig) => void)({ build: { outDir: '/tmp/app/build/client' } });
161+
162+
await expect(capturedOptions?.sourcemaps?.filesToDeleteAfterUpload).resolves.toEqual([
163+
'/tmp/app/build/client/**/*.map',
164+
]);
165+
});
166+
154167
it('keeps the source maps when the user set their own build.sourcemap', async () => {
155168
const plugins = makeAddSentryVitePlugin({});
156169
const configPlugin = plugins.find(plugin => plugin.name === 'sentry-remix-files-to-delete-after-upload');

0 commit comments

Comments
 (0)