Skip to content

Commit 48691e2

Browse files
committed
fix(nextjs): Ensure sourcemaps upload ignore patterns are relative
Closes: #18108
1 parent 1a7189d commit 48691e2

File tree

2 files changed

+54
-49
lines changed

2 files changed

+54
-49
lines changed

packages/nextjs/src/config/getBuildPluginOptions.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,24 +124,22 @@ function createSourcemapUploadAssetPatterns(
124124

125125
/**
126126
* Creates ignore patterns for source map uploads
127+
* Note: These patterns are relative to the upload path, not absolute paths
127128
*/
128-
function createSourcemapUploadIgnorePattern(
129-
normalizedDistPath: string,
130-
widenClientFileUpload: boolean = false,
131-
): string[] {
129+
function createSourcemapUploadIgnorePattern(widenClientFileUpload: boolean = false): string[] {
132130
const ignore: string[] = [];
133131

134132
// We only add main-* files if the user has not opted into it
135133
if (!widenClientFileUpload) {
136-
ignore.push(path.posix.join(normalizedDistPath, FILE_PATTERNS.MAIN_CHUNKS));
134+
ignore.push(FILE_PATTERNS.MAIN_CHUNKS);
137135
}
138136

139137
// Always ignore these patterns
140138
ignore.push(
141-
path.posix.join(normalizedDistPath, FILE_PATTERNS.FRAMEWORK_CHUNKS),
142-
path.posix.join(normalizedDistPath, FILE_PATTERNS.FRAMEWORK_CHUNKS_DOT),
143-
path.posix.join(normalizedDistPath, FILE_PATTERNS.POLYFILLS_CHUNKS),
144-
path.posix.join(normalizedDistPath, FILE_PATTERNS.WEBPACK_CHUNKS),
139+
FILE_PATTERNS.FRAMEWORK_CHUNKS,
140+
FILE_PATTERNS.FRAMEWORK_CHUNKS_DOT,
141+
FILE_PATTERNS.POLYFILLS_CHUNKS,
142+
FILE_PATTERNS.WEBPACK_CHUNKS,
145143
);
146144

147145
return ignore;
@@ -250,7 +248,7 @@ export function getBuildPluginOptions({
250248
widenClientFileUpload,
251249
);
252250

253-
const sourcemapUploadIgnore = createSourcemapUploadIgnorePattern(normalizedDistDirAbsPath, widenClientFileUpload);
251+
const sourcemapUploadIgnore = createSourcemapUploadIgnorePattern(widenClientFileUpload);
254252

255253
const filesToDeleteAfterUpload = createFilesToDeleteAfterUploadPattern(
256254
normalizedDistDirAbsPath,

packages/nextjs/test/config/getBuildPluginOptions.test.ts

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ describe('getBuildPluginOptions', () => {
2828
sourcemaps: {
2929
assets: ['/path/to/.next/server', '/path/to/.next/static/chunks/pages', '/path/to/.next/static/chunks/app'],
3030
ignore: [
31-
'/path/to/.next/static/chunks/main-*',
32-
'/path/to/.next/static/chunks/framework-*',
33-
'/path/to/.next/static/chunks/framework.*',
34-
'/path/to/.next/static/chunks/polyfills-*',
35-
'/path/to/.next/static/chunks/webpack-*',
31+
'static/chunks/main-*',
32+
'static/chunks/framework-*',
33+
'static/chunks/framework.*',
34+
'static/chunks/polyfills-*',
35+
'static/chunks/webpack-*',
3636
],
3737
filesToDeleteAfterUpload: undefined,
3838
rewriteSources: expect.any(Function),
@@ -93,6 +93,13 @@ describe('getBuildPluginOptions', () => {
9393
'C:/Users/test/.next/static/chunks/pages/**',
9494
'C:/Users/test/.next/static/chunks/app/**',
9595
]);
96+
expect(result.sourcemaps?.ignore).toEqual([
97+
'static/chunks/main-*',
98+
'static/chunks/framework-*',
99+
'static/chunks/framework.*',
100+
'static/chunks/polyfills-*',
101+
'static/chunks/webpack-*',
102+
]);
96103
});
97104
});
98105

@@ -116,11 +123,11 @@ describe('getBuildPluginOptions', () => {
116123
'/path/to/.next/static/chunks/app/**',
117124
]);
118125
expect(result.sourcemaps?.ignore).toEqual([
119-
'/path/to/.next/static/chunks/main-*',
120-
'/path/to/.next/static/chunks/framework-*',
121-
'/path/to/.next/static/chunks/framework.*',
122-
'/path/to/.next/static/chunks/polyfills-*',
123-
'/path/to/.next/static/chunks/webpack-*',
126+
'static/chunks/main-*',
127+
'static/chunks/framework-*',
128+
'static/chunks/framework.*',
129+
'static/chunks/polyfills-*',
130+
'static/chunks/webpack-*',
124131
]);
125132
expect(result.reactComponentAnnotation).toBeDefined();
126133
});
@@ -138,10 +145,10 @@ describe('getBuildPluginOptions', () => {
138145

139146
expect(result.sourcemaps?.assets).toEqual(['/path/to/.next/static/chunks/**']);
140147
expect(result.sourcemaps?.ignore).toEqual([
141-
'/path/to/.next/static/chunks/framework-*',
142-
'/path/to/.next/static/chunks/framework.*',
143-
'/path/to/.next/static/chunks/polyfills-*',
144-
'/path/to/.next/static/chunks/webpack-*',
148+
'static/chunks/framework-*',
149+
'static/chunks/framework.*',
150+
'static/chunks/polyfills-*',
151+
'static/chunks/webpack-*',
145152
]);
146153
});
147154

@@ -156,11 +163,11 @@ describe('getBuildPluginOptions', () => {
156163
expect(result._metaOptions?.loggerPrefixOverride).toBe('[@sentry/nextjs - Node.js]');
157164
expect(result.sourcemaps?.assets).toEqual(['/path/to/.next/server/**', '/path/to/.next/serverless/**']);
158165
expect(result.sourcemaps?.ignore).toEqual([
159-
'/path/to/.next/static/chunks/main-*',
160-
'/path/to/.next/static/chunks/framework-*',
161-
'/path/to/.next/static/chunks/framework.*',
162-
'/path/to/.next/static/chunks/polyfills-*',
163-
'/path/to/.next/static/chunks/webpack-*',
166+
'static/chunks/main-*',
167+
'static/chunks/framework-*',
168+
'static/chunks/framework.*',
169+
'static/chunks/polyfills-*',
170+
'static/chunks/webpack-*',
164171
]);
165172
expect(result.reactComponentAnnotation).toBeDefined();
166173
});
@@ -176,11 +183,11 @@ describe('getBuildPluginOptions', () => {
176183
expect(result._metaOptions?.loggerPrefixOverride).toBe('[@sentry/nextjs - Edge]');
177184
expect(result.sourcemaps?.assets).toEqual(['/path/to/.next/server/**', '/path/to/.next/serverless/**']);
178185
expect(result.sourcemaps?.ignore).toEqual([
179-
'/path/to/.next/static/chunks/main-*',
180-
'/path/to/.next/static/chunks/framework-*',
181-
'/path/to/.next/static/chunks/framework.*',
182-
'/path/to/.next/static/chunks/polyfills-*',
183-
'/path/to/.next/static/chunks/webpack-*',
186+
'static/chunks/main-*',
187+
'static/chunks/framework-*',
188+
'static/chunks/framework.*',
189+
'static/chunks/polyfills-*',
190+
'static/chunks/webpack-*',
184191
]);
185192
expect(result.reactComponentAnnotation).toBeDefined();
186193
});
@@ -200,11 +207,11 @@ describe('getBuildPluginOptions', () => {
200207
'/path/to/.next/static/chunks/app',
201208
]);
202209
expect(result.sourcemaps?.ignore).toEqual([
203-
'/path/to/.next/static/chunks/main-*',
204-
'/path/to/.next/static/chunks/framework-*',
205-
'/path/to/.next/static/chunks/framework.*',
206-
'/path/to/.next/static/chunks/polyfills-*',
207-
'/path/to/.next/static/chunks/webpack-*',
210+
'static/chunks/main-*',
211+
'static/chunks/framework-*',
212+
'static/chunks/framework.*',
213+
'static/chunks/polyfills-*',
214+
'static/chunks/webpack-*',
208215
]);
209216
expect(result.reactComponentAnnotation).toBeUndefined();
210217
});
@@ -223,11 +230,11 @@ describe('getBuildPluginOptions', () => {
223230
'/path/to/.next/static/chunks', // Turbopack uses broader pattern
224231
]);
225232
expect(result.sourcemaps?.ignore).toEqual([
226-
'/path/to/.next/static/chunks/main-*',
227-
'/path/to/.next/static/chunks/framework-*',
228-
'/path/to/.next/static/chunks/framework.*',
229-
'/path/to/.next/static/chunks/polyfills-*',
230-
'/path/to/.next/static/chunks/webpack-*',
233+
'static/chunks/main-*',
234+
'static/chunks/framework-*',
235+
'static/chunks/framework.*',
236+
'static/chunks/polyfills-*',
237+
'static/chunks/webpack-*',
231238
]);
232239
expect(result.reactComponentAnnotation).toBeUndefined();
233240
});
@@ -755,11 +762,11 @@ describe('getBuildPluginOptions', () => {
755762
disable: false,
756763
assets: ['/path/to/.next/server', '/path/to/.next/static/chunks/pages', '/path/to/.next/static/chunks/app'],
757764
ignore: [
758-
'/path/to/.next/static/chunks/main-*',
759-
'/path/to/.next/static/chunks/framework-*',
760-
'/path/to/.next/static/chunks/framework.*',
761-
'/path/to/.next/static/chunks/polyfills-*',
762-
'/path/to/.next/static/chunks/webpack-*',
765+
'static/chunks/main-*',
766+
'static/chunks/framework-*',
767+
'static/chunks/framework.*',
768+
'static/chunks/polyfills-*',
769+
'static/chunks/webpack-*',
763770
],
764771
filesToDeleteAfterUpload: undefined,
765772
rewriteSources: expect.any(Function),

0 commit comments

Comments
 (0)