Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[edge] enable edge compiler source maps by default #38365

Merged
6 changes: 0 additions & 6 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1449,12 +1449,6 @@ export default async function getBaseWebpackConfig(
].filter(Boolean),
},
plugins: [
...(!dev &&
isEdgeServer &&
!!config.experimental.middlewareSourceMaps &&
!config.productionBrowserSourceMaps
? require('./webpack/plugins/middleware-source-maps-plugin').getMiddlewareSourceMapPlugins()
: []),
dev && isClient && new ReactRefreshWebpackPlugin(webpack),
// Makes sure `Buffer` and `process` are polyfilled in client and flight bundles (same behavior as webpack 4)
(isClient || isEdgeServer) &&
Expand Down
7 changes: 5 additions & 2 deletions packages/next/build/webpack/config/blocks/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ export const base = curry(function base(
config.devtool = 'eval-source-map'
}
} else {
// Enable browser sourcemaps:
if (ctx.productionBrowserSourceMaps && ctx.isClient) {
if (
ctx.isEdgeRuntime ||
// Enable browser sourcemaps:
(ctx.productionBrowserSourceMaps && ctx.isClient)
) {
config.devtool = 'source-map'
} else {
config.devtool = false
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions packages/next/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export interface ExperimentalConfig {
unoptimized?: boolean
allowFutureImage?: boolean
}
middlewareSourceMaps?: boolean
modularizeImports?: Record<
string,
{
Expand Down Expand Up @@ -549,7 +548,6 @@ export const defaultConfig: NextConfig = {
disablePostcssPresetEnv: undefined,
amp: undefined,
urlImports: undefined,
middlewareSourceMaps: undefined,
modularizeImports: undefined,
},
}
Expand Down
5 changes: 4 additions & 1 deletion test/.stats-app/stats-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ const clientGlobs = [
},
{
name: 'Middleware size',
globs: ['.next/server/middleware*', '.next/server/edge-runtime-webpack.js'],
globs: [
'.next/server/middleware*.js',
'.next/server/edge-runtime-webpack.js',
],
},
]

Expand Down
77 changes: 28 additions & 49 deletions test/production/generate-middleware-source-maps/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,47 @@ import { NextInstance } from 'test/lib/next-modes/base'
import fs from 'fs-extra'
import path from 'path'

const files = {
'pages/index.js': `
export default function () { return <div>Hello, world!</div> }
`,
'middleware.js': `
import { NextResponse } from "next/server";
export default function middleware() {
return NextResponse.next();
}
`,
}

describe('experimental.middlewareSourceMaps: true', () => {
describe('Middleware source maps', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion(blocker): could we also test this for Edge API routes?

The path I've followed in #38234 was to have the same test suite for middleware and edge-api-route, named edge-runtime-XYZ. There's another PR that will turn more of the middleware integration tests so they also cover edge route.

Could you please do the same here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 👍

let next: NextInstance

const nextConfig = { experimental: { middlewareSourceMaps: true } }

afterEach(() => next.destroy())

it('generates a source map', async () => {
next = await createNext({ nextConfig, files })

const middlewarePath = path.resolve(
next.testDir,
'.next/server/middleware.js'
)
expect(await fs.pathExists(middlewarePath)).toEqual(true)
expect(await fs.pathExists(`${middlewarePath}.map`)).toEqual(true)
})

it('generates a source map from src', async () => {
beforeAll(async () => {
next = await createNext({
nextConfig,
files: Object.fromEntries(
Object.entries(files).map(([filename, content]) => [
`src/${filename}`,
content,
])
),
files: {
'pages/index.js': `
export default function () { return <div>Hello, world!</div> }
`,
'pages/api/edge.js': `
export const config = { runtime: 'experimental-edge' };
export default function (req) {
return new Response("Hello from " + req.url);
}
`,
'middleware.js': `
import { NextResponse } from "next/server";
export default function middleware() {
return NextResponse.next();
}
`,
},
})
})
afterAll(() => next.destroy())

it('generates a source map for Middleware', async () => {
const middlewarePath = path.resolve(
next.testDir,
'.next/server/src/middleware.js'
'.next/server/middleware.js'
)
expect(await fs.pathExists(middlewarePath)).toEqual(true)
expect(await fs.pathExists(`${middlewarePath}.map`)).toEqual(true)
})
})

describe('experimental.middlewareSourceMaps: false', () => {
let next: NextInstance

afterEach(() => next.destroy())

it('does not generate a source map', async () => {
next = await createNext({ files })
const middlewarePath = path.resolve(
it('generates a source map for Edge API', async () => {
const edgePath = path.resolve(
next.testDir,
'.next/server/middleware.js'
'.next/server/pages/api/edge.js'
)
expect(await fs.pathExists(middlewarePath)).toEqual(true)
expect(await fs.pathExists(`${middlewarePath}.map`)).toEqual(false)
expect(await fs.pathExists(edgePath)).toEqual(true)
expect(await fs.pathExists(`${edgePath}.map`)).toEqual(true)
})
})