Commit af8a686e authored by Jimmy Lai's avatar Jimmy Lai

fix: improve source map path normalization and monorepo support

- Add normalizeSourceUrl function to handle file:/ URL concatenation
- Fix bug where file:/ URLs at position 0 weren't handled (>= 0 instead of > 0)
- Add packages/next/dist to shouldIgnorePath for monorepo development
- Export shouldIgnorePath for reuse by webpack source map implementation
- Add unit tests for normalizeSourceUrl
parent 1f6179b4
...@@ -6,13 +6,14 @@ import DevToolsIgnorePlugin from '../../plugins/devtools-ignore-list-plugin' ...@@ -6,13 +6,14 @@ import DevToolsIgnorePlugin from '../../plugins/devtools-ignore-list-plugin'
import EvalSourceMapDevToolPlugin from '../../plugins/eval-source-map-dev-tool-plugin' import EvalSourceMapDevToolPlugin from '../../plugins/eval-source-map-dev-tool-plugin'
import { getRspackCore } from '../../../../shared/lib/get-rspack' import { getRspackCore } from '../../../../shared/lib/get-rspack'
function shouldIgnorePath(modulePath: string): boolean { export function shouldIgnorePath(modulePath: string): boolean {
return ( return (
modulePath.includes('node_modules') || modulePath.includes('node_modules') ||
modulePath.endsWith('__nextjs-internal-proxy.cjs') || modulePath.endsWith('__nextjs-internal-proxy.cjs') ||
modulePath.endsWith('__nextjs-internal-proxy.mjs') || modulePath.endsWith('__nextjs-internal-proxy.mjs') ||
// Only relevant for when Next.js is symlinked e.g. in the Next.js monorepo // Only relevant for when Next.js is symlinked e.g. in the Next.js monorepo
modulePath.includes('next/dist') modulePath.includes('next/dist') ||
modulePath.includes('packages/next/dist')
) )
} }
......
...@@ -4,11 +4,16 @@ import { ...@@ -4,11 +4,16 @@ import {
decorateServerError, decorateServerError,
type ErrorSourceType, type ErrorSourceType,
} from '../../shared/lib/error-source' } from '../../shared/lib/error-source'
import { normalizeSourceUrl } from '../lib/source-map-utils'
function getFilesystemFrame(frame: StackFrame): StackFrame { function getFilesystemFrame(frame: StackFrame): StackFrame {
const f: StackFrame = { ...frame } const f: StackFrame = { ...frame }
if (typeof f.file === 'string') { if (typeof f.file === 'string') {
// Normalize paths that may have been malformed by source-map library
// (e.g., duplicate path segments from Turbopack)
f.file = normalizeSourceUrl(f.file)
if ( if (
// Posix: // Posix:
f.file.startsWith('/') || f.file.startsWith('/') ||
......
/**
* Pure string utilities for source map path normalization.
* No Node.js dependencies - safe to import in browser bundles.
*/
/**
* Normalize source URLs that were incorrectly formed by source-map resolution.
*
* Fixes two issues:
*
* 1. **file:/ URL concatenation bug in source-map library**
* The source-map library (v0.6.1) doesn't recognize `file:/` (single slash) as an
* absolute URL, so when a source map has `sourceRoot: "../../../"` and
* `sources: ["file:/Users/foo/app/page.js"]`, the library incorrectly concatenates
* them into `../../../file:/Users/foo/app/page.js`.
* We extract the last `file:/` occurrence and normalize it to `file:///`.
* See: https://github.com/nicolo-ribaudo/source-map/issues/1
*
* 2. **Duplicate path segments**
* Some bundler/compiler combinations can produce paths with duplicate directory
* sequences like `app/components/app/components/Button.js`. We detect and remove
* the first occurrence of repeated segments.
*/
export function normalizeSourceUrl(source: string): string {
let result = source
// Fix 1: Handle file:/ URL that was incorrectly concatenated with sourceRoot.
// Find the last occurrence of file:/ since that's the actual source path.
const lastFileUrlIndex = result.lastIndexOf('file:/')
if (lastFileUrlIndex > 0) {
// Only extract if file:/ is NOT at the beginning (meaning it was concatenated)
let fileUrl = result.slice(lastFileUrlIndex)
// Normalize file:/ (single slash) to file:/// (canonical form with empty host)
if (!fileUrl.startsWith('file://')) {
fileUrl = 'file://' + fileUrl.slice(5) // 'file:/' is 5 chars, replace with 'file://'
}
result = fileUrl
} else if (lastFileUrlIndex === 0 && !result.startsWith('file://')) {
// Handle file:/ at the beginning that needs normalization to file://
result = 'file://' + result.slice(5)
}
// Fix 2: Handle duplicate path segments (e.g., test/foo/test/foo/file.js -> test/foo/file.js)
// This also applies to file:// URLs with duplicate paths
// Algorithm: Find the shortest repeated sequence of path segments and remove the duplicate.
const parts = result.split('/')
for (let len = 1; len <= parts.length / 2; len++) {
for (let i = 0; i <= parts.length - len * 2; i++) {
// Check if parts[i..i+len] equals parts[i+len..i+len*2]
let match = true
for (let j = 0; j < len; j++) {
if (parts[i + j] !== parts[i + len + j]) {
match = false
break
}
}
// Don't treat '..' or '.' or empty string as duplicates (e.g., ../../foo is valid)
// Empty string can appear in file:// URLs (file:///Users -> ['file:', '', '', 'Users'])
if (match && parts[i] !== '..' && parts[i] !== '.' && parts[i] !== '') {
// Remove the duplicate segment by keeping [0..i+len] and [i+len*2..end]
const newParts = [
...parts.slice(0, i + len),
...parts.slice(i + len * 2),
]
return newParts.join('/')
}
}
}
return result
}
import { ignoreListAnonymousStackFramesIfSandwiched } from './source-maps' import {
ignoreListAnonymousStackFramesIfSandwiched,
normalizeSourceUrl,
} from './source-maps'
type StackFrame = null | { type StackFrame = null | {
file: string file: string
...@@ -226,3 +229,119 @@ test('does not ignore list anonymous frames that are not likely JS native method ...@@ -226,3 +229,119 @@ test('does not ignore list anonymous frames that are not likely JS native method
{ ignored: true, file: 'file2.js', methodName: 'render' }, { ignored: true, file: 'file2.js', methodName: 'render' },
]) ])
}) })
describe('normalizeSourceUrl', () => {
// Import the source-map library to demonstrate its actual behavior
const { SourceMapConsumer } = (require('next/dist/compiled/source-map') as typeof import('next/dist/compiled/source-map'))
describe('file URL concatenation (source-map library bug)', () => {
// The source-map library doesn't recognize file:/ (single slash) as an absolute URL,
// so it concatenates sourceRoot with the file:/ source, producing malformed paths.
// This test demonstrates the actual library behavior and verifies our fix.
it('fixes malformed paths produced by source-map library with sourceRoot', () => {
// Create a source map that triggers the bug:
// - sourceRoot is a relative path
// - source is a file:/ URL (single slash, which is technically valid but uncommon)
const rawSourceMap = {
version: 3,
file: 'output.js',
sourceRoot: '../../../',
sources: ['file:/Users/foo/app/page.js'],
names: [],
mappings: 'AAAA', // Maps position (0,0) -> (0,0)
}
const consumer = new SourceMapConsumer(rawSourceMap)
// Get the source URL as the library reports it
const malformedSource = consumer.sources[0]
// The library incorrectly concatenates sourceRoot with the file:/ URL
expect(malformedSource).toBe('../../../file:/Users/foo/app/page.js')
// Our normalizeSourceUrl fixes this malformed path
expect(normalizeSourceUrl(malformedSource)).toBe(
'file:///Users/foo/app/page.js'
)
})
it('normalizes file:/ to file:// even without sourceRoot', () => {
const rawSourceMap = {
version: 3,
file: 'output.js',
sources: ['file:/Users/foo/app/page.js'],
names: [],
mappings: 'AAAA',
}
const consumer = new SourceMapConsumer(rawSourceMap)
const source = consumer.sources[0]
// Without sourceRoot, file:/ comes through as-is (still malformed)
expect(source).toBe('file:/Users/foo/app/page.js')
// Our fix normalizes it to the canonical file:// format
expect(normalizeSourceUrl(source)).toBe('file:///Users/foo/app/page.js')
})
it('handles file:/// URLs correctly (no change needed)', () => {
expect(normalizeSourceUrl('file:///Users/foo/app/page.js')).toBe(
'file:///Users/foo/app/page.js'
)
})
it('extracts last file:/ when multiple occurrences exist', () => {
// Edge case: nested source maps could produce multiple file: occurrences
expect(
normalizeSourceUrl('file:/wrong/path/file:/correct/path/page.js')
).toBe('file:///correct/path/page.js')
})
})
describe('duplicate path segments', () => {
it('removes single duplicate segment', () => {
expect(normalizeSourceUrl('app/app/page.tsx')).toBe('app/page.tsx')
})
it('removes multi-directory duplicate segment', () => {
expect(normalizeSourceUrl('test/fixtures/test/fixtures/app.js')).toBe(
'test/fixtures/app.js'
)
})
it('removes duplicate with relative prefix preserved', () => {
expect(
normalizeSourceUrl('../../../app/components/app/components/Button.js')
).toBe('../../../app/components/Button.js')
})
})
describe('paths that should not be modified', () => {
it('does not modify consecutive .. segments', () => {
expect(normalizeSourceUrl('../../page.js')).toBe('../../page.js')
})
it('does not modify paths with . in them', () => {
expect(normalizeSourceUrl('./src/./page.js')).toBe('./src/./page.js')
})
it('does not modify normal relative paths', () => {
expect(normalizeSourceUrl('src/components/page.js')).toBe(
'src/components/page.js'
)
})
it('does not modify webpack:// URLs', () => {
expect(normalizeSourceUrl('webpack://app/./src/page.js')).toBe(
'webpack://app/./src/page.js'
)
})
it('does not modify turbopack:// URLs', () => {
expect(normalizeSourceUrl('turbopack://[project]/src/page.js')).toBe(
'turbopack://[project]/src/page.js'
)
})
})
})
import type { SourceMap } from 'module' import type { SourceMap } from 'module'
import { LRUCache } from './lru-cache' import { LRUCache } from './lru-cache'
export { normalizeSourceUrl } from './source-map-utils'
function noSourceMap(): SourceMap | undefined { function noSourceMap(): SourceMap | undefined {
return undefined return undefined
......
...@@ -8,6 +8,7 @@ import { ...@@ -8,6 +8,7 @@ import {
findApplicableSourceMapPayload, findApplicableSourceMapPayload,
ignoreListAnonymousStackFramesIfSandwiched as ignoreListAnonymousStackFramesIfSandwichedGeneric, ignoreListAnonymousStackFramesIfSandwiched as ignoreListAnonymousStackFramesIfSandwichedGeneric,
sourceMapIgnoreListsEverything, sourceMapIgnoreListsEverything,
normalizeSourceUrl,
} from './lib/source-maps' } from './lib/source-maps'
import { parseStack, type StackFrame } from './lib/parse-stack' import { parseStack, type StackFrame } from './lib/parse-stack'
import { getOriginalCodeFrame } from '../next-devtools/server/shared' import { getOriginalCodeFrame } from '../next-devtools/server/shared'
...@@ -59,13 +60,30 @@ function frameToString( ...@@ -59,13 +60,30 @@ function frameToString(
// In a multi-app repo, this leads to potentially larger file names but will make clicking snappy. // In a multi-app repo, this leads to potentially larger file names but will make clicking snappy.
// There's no tradeoff for the cases where `dir` in `next dev [dir]` is omitted // There's no tradeoff for the cases where `dir` in `next dev [dir]` is omitted
// since relative to cwd is both the shortest and snappiest. // since relative to cwd is both the shortest and snappiest.
fileLocation = path.relative(process.cwd(), url.fileURLToPath(sourceURL)) try {
fileLocation = path.relative(process.cwd(), url.fileURLToPath(sourceURL))
} catch {
// fileURLToPath throws for file URLs with non-localhost hosts (e.g., file://remote/path)
// This can happen with malformed source map URLs. Fall back to using the URL as-is.
fileLocation = sourceURL
}
} else if (sourceURL !== null && sourceURL.startsWith('/')) { } else if (sourceURL !== null && sourceURL.startsWith('/')) {
fileLocation = path.relative(process.cwd(), sourceURL) fileLocation = path.relative(process.cwd(), sourceURL)
} else { } else {
fileLocation = sourceURL fileLocation = sourceURL
} }
// Decode URL-encoded characters in the path.
// Dynamic routes like [slug] get encoded as %5Bslug%5D in source map URLs.
// Decode them back so stack traces show readable paths: pages/blog/[slug].js
if (fileLocation !== null) {
try {
fileLocation = decodeURIComponent(fileLocation)
} catch {
// Keep original if decoding fails (e.g., malformed percent encoding)
}
}
return methodName return methodName
? ` at ${methodName} (${fileLocation}${sourceLocation})` ? ` at ${methodName} (${fileLocation}${sourceLocation})`
: ` at ${fileLocation}${sourceLocation}` : ` at ${fileLocation}${sourceLocation}`
...@@ -112,14 +130,22 @@ interface SourceMappedFrame { ...@@ -112,14 +130,22 @@ interface SourceMappedFrame {
function createUnsourcemappedFrame( function createUnsourcemappedFrame(
frame: SourcemappableStackFrame frame: SourcemappableStackFrame
): SourceMappedFrame { ): SourceMappedFrame {
// Normalize the file path even for unsourcemapped frames.
// This handles cases where V8's built-in source map support already resolved the path
// but introduced duplicate path segments (e.g., from Turbopack's source maps).
const normalizedFile = normalizeSourceUrl(frame.file)
return { return {
stack: { stack: {
file: frame.file, file: normalizedFile,
line1: frame.line1, line1: frame.line1,
column1: frame.column1, column1: frame.column1,
methodName: frame.methodName, // Webpack's eval devtool wraps code in eval() which produces ugly method names like:
// "Timeout.eval [as _onTimeout]" instead of "Timeout._onTimeout"
// This regex extracts the actual method name from the "[as X]" wrapper.
methodName: frame.methodName?.replace(/\.eval \[as ([^\]]+)\]/, '.$1'),
arguments: frame.arguments, arguments: frame.arguments,
ignored: shouldIgnoreListGeneratedFrame(frame.file), ignored: shouldIgnoreListGeneratedFrame(normalizedFile),
}, },
code: null, code: null,
} }
...@@ -250,14 +276,16 @@ function getSourcemappedFrameIfPossible( ...@@ -250,14 +276,16 @@ function getSourcemappedFrameIfPossible(
applicableSourceMap !== undefined && applicableSourceMap !== undefined &&
sourceMapIgnoreListsEverything(applicableSourceMap) sourceMapIgnoreListsEverything(applicableSourceMap)
if (sourcePosition.source === null) { if (sourcePosition.source === null) {
// Normalize the file path in case V8's source maps already resolved it with duplicates
const normalizedFile = normalizeSourceUrl(frame.file)
return { return {
stack: { stack: {
arguments: frame.arguments, arguments: frame.arguments,
file: frame.file, file: normalizedFile,
line1: frame.line1, line1: frame.line1,
column1: frame.column1, column1: frame.column1,
methodName: frame.methodName, methodName: frame.methodName,
ignored: ignored || shouldIgnoreListGeneratedFrame(frame.file), ignored: ignored || shouldIgnoreListGeneratedFrame(normalizedFile),
}, },
code: null, code: null,
} }
...@@ -282,6 +310,11 @@ function getSourcemappedFrameIfPossible( ...@@ -282,6 +310,11 @@ function getSourcemappedFrameIfPossible(
ignored = applicableSourceMap.ignoreList?.includes(sourceIndex) ?? false ignored = applicableSourceMap.ignoreList?.includes(sourceIndex) ?? false
} }
// Normalize the source URL to fix issues from source-map library:
// 1. Duplicate path segments from Turbopack (test/foo/test/foo/file.js)
// 2. Malformed file:/ URLs from sourceRoot concatenation
const normalizedSource = normalizeSourceUrl(sourcePosition.source)
const originalFrame: IgnorableStackFrame = { const originalFrame: IgnorableStackFrame = {
// We ignore the sourcemapped name since it won't be the correct name. // We ignore the sourcemapped name since it won't be the correct name.
// The callsite will point to the column of the variable name instead of the // The callsite will point to the column of the variable name instead of the
...@@ -289,8 +322,11 @@ function getSourcemappedFrameIfPossible( ...@@ -289,8 +322,11 @@ function getSourcemappedFrameIfPossible(
// TODO(NDX-531): Spy on prepareStackTrace to get the enclosing line number for method name mapping. // TODO(NDX-531): Spy on prepareStackTrace to get the enclosing line number for method name mapping.
methodName: frame.methodName methodName: frame.methodName
?.replace('__WEBPACK_DEFAULT_EXPORT__', 'default') ?.replace('__WEBPACK_DEFAULT_EXPORT__', 'default')
?.replace('__webpack_exports__.', ''), ?.replace('__webpack_exports__.', '')
file: sourcePosition.source, // Webpack's eval devtool wraps code in eval() which produces ugly method names.
// Extract actual method name: "Timeout.eval [as _onTimeout]" -> "Timeout._onTimeout"
?.replace(/\.eval \[as ([^\]]+)\]/, '.$1'),
file: normalizedSource,
line1: sourcePosition.line, line1: sourcePosition.line,
column1: sourcePosition.column + 1, column1: sourcePosition.column + 1,
// TODO: c&p from async createOriginalStackFrame but why not frame.arguments? // TODO: c&p from async createOriginalStackFrame but why not frame.arguments?
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Edge route usage of dynamic code evaluation development mode shows a warning when running WebAssembly.compile: wasm-compile-Edge route-turbopack 1`] = `
"DynamicWasmCodeGenerationWarning: Dynamic WASM code generation (e. g. 'WebAssembly.compile') not allowed in Edge Runtime.
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
at usingWebAssemblyCompile (../../test/integration/edge-runtime-dynamic-code/lib/wasm.js:22:18)
at handler (../../test/integration/edge-runtime-dynamic-code/pages/api/route.js:20:55)
20 |
21 | export async function usingWebAssemblyCompile(x) {
> 22 | const module = await WebAssembly.compile(SQUARE_WASM_BUFFER)
| ^"
`;
exports[`Edge route usage of dynamic code evaluation development mode shows a warning when running WebAssembly.compile: wasm-compile-Edge route-webpack 1`] = `
"DynamicWasmCodeGenerationWarning: Dynamic WASM code generation (e. g. 'WebAssembly.compile') not allowed in Edge Runtime.
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
at usingWebAssemblyCompile (../../test/integration/edge-runtime-dynamic-code/lib/wasm.js:22:24)
at handler (../../test/integration/edge-runtime-dynamic-code/pages/api/route.js:20:55)
20 |
21 | export async function usingWebAssemblyCompile(x) {
> 22 | const module = await WebAssembly.compile(SQUARE_WASM_BUFFER)
| ^"
`;
exports[`Edge route usage of dynamic code evaluation development mode shows a warning when running WebAssembly.instantiate with a buffer parameter: wasm-instantiate-Edge route-turbopack 1`] = `
"DynamicWasmCodeGenerationWarning: Dynamic WASM code generation ('WebAssembly.instantiate' with a buffer parameter) not allowed in Edge Runtime.
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
at async usingWebAssemblyInstantiateWithBuffer (../../test/integration/edge-runtime-dynamic-code/lib/wasm.js:28:24)
at async handler (../../test/integration/edge-runtime-dynamic-code/pages/api/route.js:28:26)
26 |
27 | export async function usingWebAssemblyInstantiateWithBuffer(x) {
> 28 | const { instance } = await WebAssembly.instantiate(SQUARE_WASM_BUFFER, {})
| ^"
`;
exports[`Edge route usage of dynamic code evaluation development mode shows a warning when running WebAssembly.instantiate with a buffer parameter: wasm-instantiate-Edge route-webpack 1`] = `
"DynamicWasmCodeGenerationWarning: Dynamic WASM code generation ('WebAssembly.instantiate' with a buffer parameter) not allowed in Edge Runtime.
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
at async usingWebAssemblyInstantiateWithBuffer (../../test/integration/edge-runtime-dynamic-code/lib/wasm.js:28:24)
at async handler (../../test/integration/edge-runtime-dynamic-code/pages/api/route.js:28:26)
26 |
27 | export async function usingWebAssemblyInstantiateWithBuffer(x) {
> 28 | const { instance } = await WebAssembly.instantiate(SQUARE_WASM_BUFFER, {})
| ^"
`;
exports[`Edge route usage of dynamic code evaluation development mode shows a warning when running code with eval: eval-Edge route-turbopack 1`] = `
"DynamicCodeEvaluationWarning: Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
at usingEval (../../test/integration/edge-runtime-dynamic-code/lib/utils.js:3:17)
at handler (../../test/integration/edge-runtime-dynamic-code/pages/api/route.js:12:41)
1 | export async function usingEval() {
2 | // eslint-disable-next-line no-eval
> 3 | return { value: eval('100') }
| ^"
`;
exports[`Edge route usage of dynamic code evaluation development mode shows a warning when running code with eval: eval-Edge route-webpack 1`] = `
"DynamicCodeEvaluationWarning: Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
at usingEval (../../test/integration/edge-runtime-dynamic-code/lib/utils.js:3:19)
at handler (../../test/integration/edge-runtime-dynamic-code/pages/api/route.js:12:41)
1 | export async function usingEval() {
2 | // eslint-disable-next-line no-eval
> 3 | return { value: eval('100') }
| ^"
`;
exports[`Middleware usage of dynamic code evaluation development mode shows a warning when running WebAssembly.compile: wasm-compile-Middleware-turbopack 1`] = `
"DynamicWasmCodeGenerationWarning: Dynamic WASM code generation (e. g. 'WebAssembly.compile') not allowed in Edge Runtime.
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
at usingWebAssemblyCompile (../../test/integration/edge-runtime-dynamic-code/lib/wasm.js:22:18)
at middleware (../../test/integration/edge-runtime-dynamic-code/middleware.js:24:68)
20 |
21 | export async function usingWebAssemblyCompile(x) {
> 22 | const module = await WebAssembly.compile(SQUARE_WASM_BUFFER)
| ^"
`;
exports[`Middleware usage of dynamic code evaluation development mode shows a warning when running WebAssembly.compile: wasm-compile-Middleware-webpack 1`] = `
"DynamicWasmCodeGenerationWarning: Dynamic WASM code generation (e. g. 'WebAssembly.compile') not allowed in Edge Runtime.
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
at usingWebAssemblyCompile (../../test/integration/edge-runtime-dynamic-code/lib/wasm.js:22:24)
at middleware (../../test/integration/edge-runtime-dynamic-code/middleware.js:24:68)
20 |
21 | export async function usingWebAssemblyCompile(x) {
> 22 | const module = await WebAssembly.compile(SQUARE_WASM_BUFFER)
| ^"
`;
exports[`Middleware usage of dynamic code evaluation development mode shows a warning when running WebAssembly.instantiate with a buffer parameter: wasm-instantiate-Middleware-turbopack 1`] = `
"DynamicWasmCodeGenerationWarning: Dynamic WASM code generation ('WebAssembly.instantiate' with a buffer parameter) not allowed in Edge Runtime.
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
at async usingWebAssemblyInstantiateWithBuffer (../../test/integration/edge-runtime-dynamic-code/lib/wasm.js:28:24)
at async middleware (../../test/integration/edge-runtime-dynamic-code/middleware.js:39:30)
26 |
27 | export async function usingWebAssemblyInstantiateWithBuffer(x) {
> 28 | const { instance } = await WebAssembly.instantiate(SQUARE_WASM_BUFFER, {})
| ^"
`;
exports[`Middleware usage of dynamic code evaluation development mode shows a warning when running WebAssembly.instantiate with a buffer parameter: wasm-instantiate-Middleware-webpack 1`] = `
"DynamicWasmCodeGenerationWarning: Dynamic WASM code generation ('WebAssembly.instantiate' with a buffer parameter) not allowed in Edge Runtime.
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
at async usingWebAssemblyInstantiateWithBuffer (../../test/integration/edge-runtime-dynamic-code/lib/wasm.js:28:24)
at async middleware (../../test/integration/edge-runtime-dynamic-code/middleware.js:39:30)
at async eval (dist/build/webpack/loaders/next-middleware-loader.js?absolutePagePath=/Users/feedthejim/Projects/next.js/test/integration/edge-runtime-dynamic-code/middleware.js&page=/middleware&rootDir=/Users/feedthejim/Projects/next.js/test/integration/edge-runtime-dynamic-code&matchers=&preferredRegion=&middlewareConfig=e30=!:30:1)
26 |
27 | export async function usingWebAssemblyInstantiateWithBuffer(x) {
> 28 | const { instance } = await WebAssembly.instantiate(SQUARE_WASM_BUFFER, {})
| ^"
`;
exports[`Middleware usage of dynamic code evaluation development mode shows a warning when running code with eval: eval-Middleware-turbopack 1`] = `
"DynamicCodeEvaluationWarning: Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
at usingEval (../../test/integration/edge-runtime-dynamic-code/lib/utils.js:3:17)
at middleware (../../test/integration/edge-runtime-dynamic-code/middleware.js:12:54)
1 | export async function usingEval() {
2 | // eslint-disable-next-line no-eval
> 3 | return { value: eval('100') }
| ^"
`;
exports[`Middleware usage of dynamic code evaluation development mode shows a warning when running code with eval: eval-Middleware-webpack 1`] = `
"DynamicCodeEvaluationWarning: Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
at usingEval (../../test/integration/edge-runtime-dynamic-code/lib/utils.js:3:19)
at middleware (../../test/integration/edge-runtime-dynamic-code/middleware.js:12:54)
1 | export async function usingEval() {
2 | // eslint-disable-next-line no-eval
> 3 | return { value: eval('100') }
| ^"
`;
#!/bin/bash
# Update snapshots for both Turbopack and Webpack, then merge them.
# Usage: ./update-snapshots.sh
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
SNAP_FILE="$SCRIPT_DIR/test/__snapshots__/index.test.ts.snap"
TMP_DIR=$(mktemp -d)
echo "Generating Turbopack snapshots..."
IS_TURBOPACK_TEST=1 TURBOPACK_DEV=1 NEXT_TEST_MODE=dev pnpm jest test/integration/edge-runtime-dynamic-code/test/index.test.ts -u --silent
cp "$SNAP_FILE" "$TMP_DIR/turbopack.snap"
echo "Generating Webpack snapshots..."
IS_WEBPACK_TEST=1 NEXT_TEST_MODE=dev pnpm jest test/integration/edge-runtime-dynamic-code/test/index.test.ts -u --silent
cp "$SNAP_FILE" "$TMP_DIR/webpack.snap"
echo "Merging snapshots..."
{
echo '// Jest Snapshot v1, https://goo.gl/fbAQLP'
echo ''
tail -n +3 "$TMP_DIR/turbopack.snap"
tail -n +3 "$TMP_DIR/webpack.snap"
} > "$SNAP_FILE"
rm -rf "$TMP_DIR"
COUNT=$(grep -c 'exports\[' "$SNAP_FILE")
echo "Done! Merged $COUNT snapshots."
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment