Skip to content

Commit b89699c

Browse files
chargomeclaude
andcommitted
fix(remix): Scope source map deletion to the configured outDir
A hardcoded `./build/**/*.map` left a custom Remix `buildDirectory` untouched, silently shipping its source maps. Deriving the glob from `build.outDir` also scopes Remix's client and SSR passes to the output each one actually emitted. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 677114b commit b89699c

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,21 @@ export function makeAddSentryVitePlugin(options: SentryRemixVitePluginOptions):
5050
typeof config.build?.sourcemap === 'undefined' &&
5151
!sourcemaps?.disable
5252
) {
53+
// Derived from the configured `outDir` rather than hardcoding `build`, so a custom Remix
54+
// `buildDirectory` still gets cleaned up. Remix runs a client and an SSR build, each with
55+
// 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`];
58+
5359
if (debug) {
5460
// eslint-disable-next-line no-console
5561
console.log(
56-
'[Sentry] Automatically setting `sourcemaps.filesToDeleteAfterUpload: ["./build/**/*.map"]` to delete generated source maps after they were uploaded to Sentry.',
62+
`[Sentry] Automatically setting \`sourcemaps.filesToDeleteAfterUpload: ${JSON.stringify(
63+
filesToDelete,
64+
)}\` to delete generated source maps after they were uploaded to Sentry.`,
5765
);
5866
}
59-
resolveFilesToDeleteAfterUpload?.(['./build/**/*.map']);
67+
resolveFilesToDeleteAfterUpload?.(filesToDelete);
6068
} else {
6169
resolveFilesToDeleteAfterUpload?.(userFilesToDelete);
6270
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ describe('makeAddSentryVitePlugin', () => {
140140
await expect(capturedOptions?.sourcemaps?.filesToDeleteAfterUpload).resolves.toEqual(['./build/**/*.map']);
141141
});
142142

143+
// Remix's `buildDirectory` is configurable, and it runs a client and an SSR build with their own
144+
// `outDir`s - a hardcoded `./build/**/*.map` would leave a custom output directory's maps on disk.
145+
it('scopes the deletion glob to the configured outDir', async () => {
146+
const plugins = makeAddSentryVitePlugin({});
147+
const configPlugin = plugins.find(plugin => plugin.name === 'sentry-remix-files-to-delete-after-upload');
148+
149+
(configPlugin?.config as (config: UserConfig) => void)({ build: { outDir: 'dist/client' } });
150+
151+
await expect(capturedOptions?.sourcemaps?.filesToDeleteAfterUpload).resolves.toEqual(['./dist/client/**/*.map']);
152+
});
153+
143154
it('keeps the source maps when the user set their own build.sourcemap', async () => {
144155
const plugins = makeAddSentryVitePlugin({});
145156
const configPlugin = plugins.find(plugin => plugin.name === 'sentry-remix-files-to-delete-after-upload');

0 commit comments

Comments
 (0)