Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev-packages/browser-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@
"@sentry/rrweb-types": "^2.45.0",
"@sentry/wasm": "11.10.0",
"@types/node": "^20.19.0",
"glob": "^13.0.6"
"glob": "^14.0.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,12 @@ for (const chunk of chunks) {
assert.ok(crossCheckedChunks > 0, 'Expected at least one uploaded chunk to cross-check debug IDs against');
console.log(`${crossCheckedChunks} chunk(s) ship a debug ID that was uploaded\n`);

const remainingClientMaps = fs
.readdirSync(CLIENT_ASSETS_DIR, { recursive: true })
.filter(file => file.endsWith('.map'));
assert.deepEqual(remainingClientMaps, [], 'Expected client source maps to be deleted after upload');

const remainingServerMaps = fs.readdirSync('build/server', { recursive: true }).filter(file => file.endsWith('.map'));
assert.ok(remainingServerMaps.length > 0, 'Expected server source maps outside the deletion pattern to be preserved');

console.log('All react-router source map assertions passed!');
2 changes: 1 addition & 1 deletion packages/bundler-plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"dependencies": {
"@sentry/core": "11.10.0",
"dotenv": "^17.4.2",
"glob": "^13.0.6",
"glob": "^14.0.3",
"magic-string": "~0.30.8 || ^1.0.0",
"oxc-parser": "^0.152.0",
"sentry": "^0.45.0",
Expand Down
9 changes: 9 additions & 0 deletions packages/bundler-plugins/test/core/glob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ describe('globFiles', () => {
expect(result).toEqual([]);
});

it.skipIf(process.platform === 'win32')('matches files with a query or hash suffix', async () => {
const files = await Promise.all([touch('a.js?v=1'), touch('a.js.map#hash'), touch('b.mjs?v=1#hash')]);
await touch('c.css?v=1');

const result = await globFiles(JS_AND_MAP_PATTERNS, { root: tmpDir });
result.sort();
expect(result).toEqual(files.sort());
});

it('works in nested subdirectories', async () => {
const files = await Promise.all([touch('src', 'deep', 'a.js'), touch('src', 'deep', 'a.js.map')]);

Expand Down
1 change: 0 additions & 1 deletion packages/react-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"@sentry/server-runtime-injection": "11.10.0",
"@sentry/server-utils": "11.10.0",
"@sentry/bundler-plugins": "11.10.0",
"glob": "^13.0.6",
"sentry": "^0.44.0"
},
"devDependencies": {
Expand Down
15 changes: 9 additions & 6 deletions packages/react-router/src/vite/buildEnd/handleOnBuildEnd.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { rm } from 'node:fs/promises';
import * as path from 'node:path';
import type { Config } from '@react-router/dev/config';
import { createSentrySDK } from 'sentry';
import { globFiles } from '@sentry/bundler-plugins/core';
import type { SentryVitePluginOptions } from '@sentry/bundler-plugins/vite';
import { glob } from 'glob';
import type { SentryReactRouterBuildOptions } from '../types';

type BuildEndHook = NonNullable<Config['buildEnd']>;
Expand All @@ -24,6 +25,11 @@ function getSentryConfig(viteConfig: unknown): SentryReactRouterBuildOptions {
return (viteConfig as { sentryConfig: SentryReactRouterBuildOptions }).sentryConfig;
}

/** Glob patterns need forward slashes, but React Router resolves `buildDirectory` with the platform separator. */
function toGlobPath(directory: string): string {
return directory.split(path.sep).join('/');
}

/**
* A build end hook that handles Sentry release creation and source map uploads.
* It creates a new Sentry release if configured, uploads source maps to Sentry,
Expand Down Expand Up @@ -123,7 +129,7 @@ export const sentryOnBuildEnd: BuildEndHook = async ({ reactRouterConfig, viteCo

// set a default value no option was set
if (typeof updatedFilesToDeleteAfterUpload === 'undefined') {
updatedFilesToDeleteAfterUpload = [`${reactRouterConfig.buildDirectory}/**/*.map`];
updatedFilesToDeleteAfterUpload = [`${toGlobPath(reactRouterConfig.buildDirectory)}/**/*.map`];
debug &&
// eslint-disable-next-line no-console
console.info(
Expand All @@ -134,10 +140,7 @@ export const sentryOnBuildEnd: BuildEndHook = async ({ reactRouterConfig, viteCo
}
if (updatedFilesToDeleteAfterUpload) {
try {
const filePathsToDelete = await glob(updatedFilesToDeleteAfterUpload, {
absolute: true,
nodir: true,
});
const filePathsToDelete = await globFiles(updatedFilesToDeleteAfterUpload);
if (debug) {
filePathsToDelete.forEach(filePathToDelete => {
// eslint-disable-next-line no-console
Expand Down
51 changes: 38 additions & 13 deletions packages/react-router/test/vite/buildEnd/handleOnBuildEnd.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createSentrySDK } from 'sentry';
import { rm } from 'node:fs/promises';
import { glob } from 'glob';
import type * as path from 'node:path';
import { globFiles } from '@sentry/bundler-plugins/core';
import type { ResolvedConfig } from 'vite';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { sentryOnBuildEnd } from '../../../src/vite/buildEnd/handleOnBuildEnd';
Expand All @@ -11,7 +12,7 @@ vi.mock('node:fs/promises', () => {
const rm = vi.fn().mockResolvedValue(undefined);
return { rm, default: { rm } };
});
vi.mock('glob');
vi.mock('@sentry/bundler-plugins/core', () => ({ globFiles: vi.fn() }));

type TestConfig = ResolvedConfig & {
sentryConfig: SentryReactRouterBuildOptions;
Expand Down Expand Up @@ -62,7 +63,7 @@ describe('sentryOnBuildEnd', () => {
vi.mocked(createSentrySDK)
.mockReset()
.mockReturnValue(mockSentrySdkInstance as unknown as ReturnType<typeof createSentrySDK>);
vi.mocked(glob).mockResolvedValue(['/build/file1.map', '/build/file2.map']);
vi.mocked(globFiles).mockResolvedValue(['/build/file1.map', '/build/file2.map']);
vi.mocked(rm).mockResolvedValue(undefined);
});

Expand Down Expand Up @@ -126,10 +127,7 @@ describe('sentryOnBuildEnd', () => {
directory: '/build',
release: '1.2.3',
});
expect(glob).toHaveBeenCalledWith(['./build/custom/**/*.map'], {
absolute: true,
nodir: true,
});
expect(globFiles).toHaveBeenCalledWith(['./build/custom/**/*.map']);
});

it('should upload source maps when enabled', async () => {
Expand Down Expand Up @@ -196,7 +194,7 @@ describe('sentryOnBuildEnd', () => {

expect(mockSentrySdkInstance.sourcemap.inject).not.toHaveBeenCalled();
expect(mockSentrySdkInstance.sourcemap.upload).not.toHaveBeenCalled();
expect(glob).not.toHaveBeenCalled();
expect(globFiles).not.toHaveBeenCalled();
expect(rm).not.toHaveBeenCalled();
});

Expand All @@ -219,7 +217,37 @@ describe('sentryOnBuildEnd', () => {

expect(mockSentrySdkInstance.sourcemap.inject).toHaveBeenCalledWith({ directory: '/build' });
expect(mockSentrySdkInstance.sourcemap.upload).not.toHaveBeenCalled();
expect(glob).not.toHaveBeenCalled();
expect(globFiles).not.toHaveBeenCalled();
});

it('deletes the source maps in the build directory by default', async () => {
// @ts-expect-error - mocking the React config
await sentryOnBuildEnd(defaultConfig);

expect(globFiles).toHaveBeenCalledWith(['/build/**/*.map']);
expect(rm).toHaveBeenCalledWith('/build/file1.map', { force: true });
expect(rm).toHaveBeenCalledWith('/build/file2.map', { force: true });
});

it('builds the default deletion pattern with forward slashes on Windows', async () => {
vi.doMock('node:path', async importOriginal => ({
...(await importOriginal<typeof path>()),
sep: '\\',
}));
const { sentryOnBuildEnd: sentryOnBuildEndWin32 } = await import('../../../src/vite/buildEnd/handleOnBuildEnd');
const { globFiles: globFilesWin32 } = await import('@sentry/bundler-plugins/core');
vi.mocked(globFilesWin32).mockResolvedValue([]);

const config = {
...defaultConfig,
reactRouterConfig: { ...defaultConfig.reactRouterConfig, buildDirectory: 'C:\\app\\build' },
};

// @ts-expect-error - mocking the React config
await sentryOnBuildEndWin32(config);

expect(globFilesWin32).toHaveBeenCalledWith(['C:/app/build/**/*.map']);
vi.doUnmock('node:path');
});

it('should delete custom files after upload when specified', async () => {
Expand All @@ -239,10 +267,7 @@ describe('sentryOnBuildEnd', () => {
// @ts-expect-error - mocking the React config
await sentryOnBuildEnd(config);

expect(glob).toHaveBeenCalledWith('/custom/**/*.map', {
absolute: true,
nodir: true,
});
expect(globFiles).toHaveBeenCalledWith('/custom/**/*.map');
});

it('should handle errors during release creation gracefully', async () => {
Expand Down
52 changes: 45 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading