Skip to content

Commit 0e66691

Browse files
committed
ignore-list published sources if they have have a sourcemap
This shouldn't affect most users since in those case these files would be inside node_modules/ and therefore ignore-listed by default. The only exception I can think of is setups where modules are not inside node_modules/ but inside another folder (Yarn Berry has such on option). It's mostly targetted at our own testing where the Next.js installation may be symlinked and therefore not point into node_modules. Webpack-bundled code may not be affected due to https://linear.app/vercel/issue/NDX-464.
1 parent 94ef480 commit 0e66691

File tree

4 files changed

+153
-328
lines changed

4 files changed

+153
-328
lines changed

packages/next/taskfile-swc.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,24 @@ if ((typeof exports.default === 'function' || (typeof exports.default === 'objec
166166

167167
output.code += Buffer.from(`\n//# sourceMappingURL=${map}`)
168168

169+
const sourceMapPayload = JSON.parse(output.map)
170+
if ('ignoreList' in sourceMapPayload) {
171+
throw new Error(
172+
'SWC already sets an ignoreList. We may no longer need to manually set ignoreList.'
173+
)
174+
}
175+
// ignore-list everything
176+
sourceMapPayload.ignoreList = sourceMapPayload.sources.map(
177+
(source, sourceIndex) => {
178+
return sourceIndex
179+
}
180+
)
181+
169182
// add sourcemap to `files` array
170183
this._.files.push({
171184
base: map,
172185
dir: file.dir,
173-
data: Buffer.from(output.map),
186+
data: Buffer.from(JSON.stringify(sourceMapPayload)),
174187
})
175188
}
176189

test/integration/edge-runtime-dynamic-code/test/index.test.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,10 @@ describe.each([
109109
expect(output).toContain(
110110
isTurbopack
111111
? '' +
112+
// TODO(veil): Turbopack duplicates project pa
112113
'\n at usingEval (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/lib/utils.js:11:16)' +
113114
'\n at middleware (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/middleware.js:12:52)' +
114-
// Next.js internal frame. Feel free to adjust.
115-
// Not ignore-listed because we're not in an isolated app and Next.js is symlinked so it's not in node_modules
116-
'\n at'
115+
'\n 9 | export async function usingEval() {'
117116
: '\n at usingEval (../../test/integration/edge-runtime-dynamic-code/lib/utils.js:11:18)' +
118117
'\n at middleware (../../test/integration/edge-runtime-dynamic-code/middleware.js:12:53)' +
119118
// Next.js internal frame. Feel free to adjust.
@@ -124,9 +123,10 @@ describe.each([
124123
expect(output).toContain(
125124
isTurbopack
126125
? '' +
126+
// TODO(veil): Turbopack duplicates project path
127127
'\n at usingEval (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/lib/utils.js:11:16)' +
128128
'\n at handler (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/pages/api/route.js:13:22)' +
129-
// Next.js internal frame. Feel free to adjust.
129+
// @opentelemetry/api internal frame. Feel free to adjust.
130130
// Not ignore-listed because we're not in an isolated app and Next.js is symlinked so it's not in node_modules
131131
'\n at'
132132
: '\n at usingEval (../../test/integration/edge-runtime-dynamic-code/lib/utils.js:11:18)' +
@@ -175,9 +175,10 @@ describe.each([
175175
? '' +
176176
'\n at usingWebAssemblyCompile (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/lib/wasm.js:22:17)' +
177177
'\n at middleware (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/middleware.js:24:68)' +
178-
// Next.js internal frame. Feel free to adjust.
179-
// Not ignore-listed because we're not in an isolated app and Next.js is symlinked so it's not in node_modules
180-
'\n at'
178+
'\n 20 |' +
179+
'\n 21 | export async function usingWebAssemblyCompile(x) {' +
180+
'\n> 22 | const module = await WebAssembly.compile(SQUARE_WASM_BUFFER)' +
181+
'\n | ^'
181182
: '\n at usingWebAssemblyCompile (../../test/integration/edge-runtime-dynamic-code/lib/wasm.js:22:23)' +
182183
'\n at middleware (../../test/integration/edge-runtime-dynamic-code/middleware.js:24:68)' +
183184
// Next.js internal frame. Feel free to adjust.
@@ -188,6 +189,7 @@ describe.each([
188189
expect(output).toContain(
189190
isTurbopack
190191
? '' +
192+
// TODO(veil): Turbopack duplicates project path
191193
'\n at usingWebAssemblyCompile (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/lib/wasm.js:22:17)' +
192194
'\n at handler (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/pages/api/route.js:17:42)' +
193195
// Next.js internal frame. Feel free to adjust.
@@ -232,14 +234,12 @@ describe.each([
232234
? '' +
233235
'\n at async usingWebAssemblyInstantiateWithBuffer (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/lib/wasm.js:28:23)' +
234236
'\n at async middleware (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/middleware.js:37:29)' +
235-
// Next.js internal frame. Feel free to adjust.
236-
// Not ignore-listed because we're not in an isolated app and Next.js is symlinked so it's not in node_modules
237-
'\n at'
237+
'\n 26 |\n'
238238
: '' +
239239
'\n at async usingWebAssemblyInstantiateWithBuffer (../../test/integration/edge-runtime-dynamic-code/lib/wasm.js:28:23)' +
240240
'\n at async middleware (../../test/integration/edge-runtime-dynamic-code/middleware.js:37:29)' +
241241
// Next.js internal frame. Feel free to adjust.
242-
// Not ignore-listed because we're not in an isolated app and Next.js is symlinked so it's not in node_modules
242+
// TODO(veil): https://linear.app/vercel/issue/NDX-464
243243
'\n at '
244244
)
245245
expect(stripAnsi(output)).toContain(
@@ -254,9 +254,7 @@ describe.each([
254254
// TODO(veil): Turbopack duplicates project path
255255
'\n at async usingWebAssemblyInstantiateWithBuffer (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/lib/wasm.js:28:23)' +
256256
'\n at async handler (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/pages/api/route.js:21:16)' +
257-
// Next.js internal frame. Feel free to adjust.
258-
// Not ignore-listed because we're not in an isolated app and Next.js is symlinked so it's not in node_modules
259-
'\n at'
257+
'\n 26 |'
260258
: '' +
261259
'\n at async usingWebAssemblyInstantiateWithBuffer (../../test/integration/edge-runtime-dynamic-code/lib/wasm.js:28:23)' +
262260
'\n at async handler (../../test/integration/edge-runtime-dynamic-code/pages/api/route.js:21:16)' +

test/integration/edge-runtime-with-node.js-apis/test/index.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ const unsupportedClasses = [
4444
'WritableStreamDefaultController',
4545
]
4646

47-
const isTurbopack = process.env.IS_TURBOPACK_TEST
48-
4947
describe.each([
5048
{
5149
title: 'Middleware',
@@ -113,12 +111,7 @@ describe.each([
113111
expect(output)
114112
.toInclude(`A Node.js API is used (${api}) which is not supported in the Edge Runtime.
115113
Learn more: https://nextjs.org/docs/api-reference/edge-runtime`)
116-
if (isTurbopack) {
117-
expect(stripAnsi(output)).toInclude(errorHighlight)
118-
} else {
119-
// TODO(veil): Use codeframe froma stackframe that's not ignore-listed
120-
expect(stripAnsi(output)).not.toInclude(errorHighlight)
121-
}
114+
expect(stripAnsi(output)).toInclude(errorHighlight)
122115
})
123116
}
124117
)

0 commit comments

Comments
 (0)