Unverified Commit a33bb5be authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Fix app-document-import-order test for webpack 5 (#15224)

parent 56d62a52
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
"publish-stable": "lerna version --force-publish", "publish-stable": "lerna version --force-publish",
"lint-staged": "lint-staged", "lint-staged": "lint-staged",
"next": "node packages/next/dist/bin/next", "next": "node packages/next/dist/bin/next",
"debug": "node --inspect-brk packages/next/dist/bin/next" "debug": "node --inspect packages/next/dist/bin/next"
}, },
"pre-commit": "lint-staged", "pre-commit": "lint-staged",
"devDependencies": { "devDependencies": {
......
...@@ -103,7 +103,7 @@ export function createEntrypoints( ...@@ -103,7 +103,7 @@ export function createEntrypoints(
const bundleFile = normalizePagePath(page) const bundleFile = normalizePagePath(page)
const isApiRoute = page.match(API_ROUTE) const isApiRoute = page.match(API_ROUTE)
const clientBundlePath = posix.join('static', 'pages', bundleFile) const clientBundlePath = posix.join('pages', bundleFile)
const serverBundlePath = posix.join('pages', bundleFile) const serverBundlePath = posix.join('pages', bundleFile)
const isLikeServerless = isTargetLikeServerless(target) const isLikeServerless = isTargetLikeServerless(target)
......
...@@ -134,9 +134,7 @@ function getOptimizedAliases(isServer: boolean): { [pkg: string]: string } { ...@@ -134,9 +134,7 @@ function getOptimizedAliases(isServer: boolean): { [pkg: string]: string } {
} }
type ClientEntries = { type ClientEntries = {
'main.js': string[] [key: string]: string | string[]
} & {
[key: string]: string
} }
export default async function getBaseWebpackConfig( export default async function getBaseWebpackConfig(
...@@ -432,7 +430,6 @@ export default async function getBaseWebpackConfig( ...@@ -432,7 +430,6 @@ export default async function getBaseWebpackConfig(
shared: { shared: {
name(module, chunks) { name(module, chunks) {
return ( return (
(isWebpack5 ? 'static/chunks/' : '') +
crypto crypto
.createHash('sha1') .createHash('sha1')
.update( .update(
...@@ -443,8 +440,7 @@ export default async function getBaseWebpackConfig( ...@@ -443,8 +440,7 @@ export default async function getBaseWebpackConfig(
'' ''
) )
) )
.digest('hex') + .digest('hex') + (isModuleCSS(module) ? '_CSS' : '')
(isModuleCSS(module) ? '_CSS' : '')
) )
}, },
priority: 10, priority: 10,
...@@ -713,7 +709,9 @@ export default async function getBaseWebpackConfig( ...@@ -713,7 +709,9 @@ export default async function getBaseWebpackConfig(
output: { output: {
path: outputPath, path: outputPath,
// On the server we don't use the chunkhash // On the server we don't use the chunkhash
filename: dev || isServer ? '[name].js' : '[name]-[chunkhash].js', filename: isServer
? '[name].js'
: `static/chunks/[name]${dev ? '' : '-[chunkhash]'}.js`,
library: isServer ? undefined : '_N_E', library: isServer ? undefined : '_N_E',
libraryTarget: isServer ? 'commonjs2' : 'assign', libraryTarget: isServer ? 'commonjs2' : 'assign',
hotUpdateChunkFilename: isWebpack5 hotUpdateChunkFilename: isWebpack5
...@@ -1277,11 +1275,10 @@ export default async function getBaseWebpackConfig( ...@@ -1277,11 +1275,10 @@ export default async function getBaseWebpackConfig(
: originalEntry : originalEntry
// Server compilation doesn't have main.js // Server compilation doesn't have main.js
if (clientEntries && entry['main.js'] && entry['main.js'].length > 0) { if (clientEntries && entry['main.js'] && entry['main.js'].length > 0) {
const originalFile = clientEntries[CLIENT_STATIC_FILES_RUNTIME_MAIN] const originalFile = clientEntries[
entry[CLIENT_STATIC_FILES_RUNTIME_MAIN] = [ CLIENT_STATIC_FILES_RUNTIME_MAIN
...entry['main.js'], ] as string
originalFile, entry[CLIENT_STATIC_FILES_RUNTIME_MAIN] = [...['main.js'], originalFile]
]
} }
delete entry['main.js'] delete entry['main.js']
......
...@@ -252,7 +252,7 @@ export default class PageLoader { ...@@ -252,7 +252,7 @@ export default class PageLoader {
route = normalizeRoute(route) route = normalizeRoute(route)
let scriptRoute = getAssetPathFromRoute(route, '.js') let scriptRoute = getAssetPathFromRoute(route, '.js')
const url = `${this.assetPrefix}/_next/static/pages${encodeURI( const url = `${this.assetPrefix}/_next/static/chunks/pages${encodeURI(
scriptRoute scriptRoute
)}` )}`
this.loadScript(url, route) this.loadScript(url, route)
......
...@@ -19,17 +19,16 @@ export const CLIENT_STATIC_FILES_PATH = 'static' ...@@ -19,17 +19,16 @@ export const CLIENT_STATIC_FILES_PATH = 'static'
export const CLIENT_STATIC_FILES_RUNTIME = 'runtime' export const CLIENT_STATIC_FILES_RUNTIME = 'runtime'
export const AMP_RENDER_TARGET = '__NEXT_AMP_RENDER_TARGET__' export const AMP_RENDER_TARGET = '__NEXT_AMP_RENDER_TARGET__'
export const STRING_LITERAL_DROP_BUNDLE = '__NEXT_DROP_CLIENT_FILE__' export const STRING_LITERAL_DROP_BUNDLE = '__NEXT_DROP_CLIENT_FILE__'
export const CLIENT_STATIC_FILES_RUNTIME_PATH = `${CLIENT_STATIC_FILES_PATH}/${CLIENT_STATIC_FILES_RUNTIME}`
// static/runtime/main.js // static/runtime/main.js
export const CLIENT_STATIC_FILES_RUNTIME_MAIN = `${CLIENT_STATIC_FILES_RUNTIME_PATH}/main` export const CLIENT_STATIC_FILES_RUNTIME_MAIN = `main`
// static/runtime/react-refresh.js // static/runtime/react-refresh.js
export const CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH = `${CLIENT_STATIC_FILES_RUNTIME_PATH}/react-refresh` export const CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH = `react-refresh`
// static/runtime/amp.js // static/runtime/amp.js
export const CLIENT_STATIC_FILES_RUNTIME_AMP = `${CLIENT_STATIC_FILES_RUNTIME_PATH}/amp` export const CLIENT_STATIC_FILES_RUNTIME_AMP = `amp`
// static/runtime/webpack.js // static/runtime/webpack.js
export const CLIENT_STATIC_FILES_RUNTIME_WEBPACK = `${CLIENT_STATIC_FILES_RUNTIME_PATH}/webpack` export const CLIENT_STATIC_FILES_RUNTIME_WEBPACK = `webpack`
// static/runtime/polyfills.js // static/runtime/polyfills.js
export const CLIENT_STATIC_FILES_RUNTIME_POLYFILLS = `${CLIENT_STATIC_FILES_RUNTIME_PATH}/polyfills` export const CLIENT_STATIC_FILES_RUNTIME_POLYFILLS = `polyfills`
export const TEMPORARY_REDIRECT_STATUS = 307 export const TEMPORARY_REDIRECT_STATUS = 307
export const PERMANENT_REDIRECT_STATUS = 308 export const PERMANENT_REDIRECT_STATUS = 308
export const STATIC_PROPS_ID = '__N_SSG' export const STATIC_PROPS_ID = '__N_SSG'
......
import getRouteFromAssetPath from '../lib/router/utils/get-route-from-asset-path' import getRouteFromAssetPath from '../lib/router/utils/get-route-from-asset-path'
// matches static/<buildid>/pages/:page*.js
// const SERVER_ROUTE_NAME_REGEX = /^static[/\\][^/\\]+[/\\]pages[/\\](.*)$/
// matches pages/:page*.js // matches pages/:page*.js
const SERVER_ROUTE_NAME_REGEX = /^pages[/\\](.*)$/ const SERVER_ROUTE_NAME_REGEX = /^pages[/\\](.*)$/
// matches static/pages/:page*.js // matches static/pages/:page*.js
......
...@@ -84,7 +84,7 @@ function addCorsSupport(req: IncomingMessage, res: ServerResponse) { ...@@ -84,7 +84,7 @@ function addCorsSupport(req: IncomingMessage, res: ServerResponse) {
} }
const matchNextPageBundleRequest = route( const matchNextPageBundleRequest = route(
'/_next/static/pages/:path*.js(\\.map|)' '/_next/static/chunks/pages/:path*.js(\\.map|)'
) )
// Recursively look up the issuer till it ends up at the root // Recursively look up the issuer till it ends up at the root
......
...@@ -168,7 +168,7 @@ export default function onDemandEntryHandler( ...@@ -168,7 +168,7 @@ export default function onDemandEntryHandler(
const bundleFile = normalizePagePath(pageUrl) const bundleFile = normalizePagePath(pageUrl)
const serverBundlePath = posix.join('pages', bundleFile) const serverBundlePath = posix.join('pages', bundleFile)
const clientBundlePath = posix.join('static', 'pages', bundleFile) const clientBundlePath = posix.join('pages', bundleFile)
const absolutePagePath = pagePath.startsWith('next/dist/pages') const absolutePagePath = pagePath.startsWith('next/dist/pages')
? require.resolve(pagePath) ? require.resolve(pagePath)
: join(pagesDir, pagePath) : join(pagesDir, pagePath)
......
...@@ -699,6 +699,7 @@ declare module 'webpack' { ...@@ -699,6 +699,7 @@ declare module 'webpack' {
reuseExistingChunk?: boolean reuseExistingChunk?: boolean
/** Give chunks created a name (chunks with equal name are merged) */ /** Give chunks created a name (chunks with equal name are merged) */
name?: boolean | string | ((...args: any[]) => any) name?: boolean | string | ((...args: any[]) => any)
filename?: string
} }
interface SplitChunksOptions { interface SplitChunksOptions {
/** Select chunks for determining shared modules (defaults to \"async\", \"initial\" and \"all\" requires adding these chunks to the HTML) */ /** Select chunks for determining shared modules (defaults to \"async\", \"initial\" and \"all\" requires adding these chunks to the HTML) */
......
...@@ -17,6 +17,7 @@ module.exports = { ...@@ -17,6 +17,7 @@ module.exports = {
enforce: true, enforce: true,
priority: 10, priority: 10,
chunks: 'all', chunks: 'all',
filename: 'static/chunks/[name].[chunkhash].js',
}, },
requiredByPage: { requiredByPage: {
test: /requiredByPage.js/, test: /requiredByPage.js/,
...@@ -24,6 +25,7 @@ module.exports = { ...@@ -24,6 +25,7 @@ module.exports = {
enforce: true, enforce: true,
priority: 10, priority: 10,
chunks: 'all', chunks: 'all',
filename: 'static/chunks/[name].[chunkhash].js',
}, },
}, },
}, },
......
...@@ -26,7 +26,7 @@ describe('Build Output', () => { ...@@ -26,7 +26,7 @@ describe('Build Output', () => {
expect(stdout).toMatch(/\/ [ ]* \d{1,} B/) expect(stdout).toMatch(/\/ [ ]* \d{1,} B/)
expect(stdout).toMatch(/\+ First Load JS shared by all [ 0-9.]* kB/) expect(stdout).toMatch(/\+ First Load JS shared by all [ 0-9.]* kB/)
expect(stdout).toMatch(/ runtime\/main\.[0-9a-z]{6}\.js [ 0-9.]* kB/) expect(stdout).toMatch(/ chunks\/main\.[0-9a-z]{6}\.js [ 0-9.]* kB/)
expect(stdout).toMatch(/ chunks\/framework\.[0-9a-z]{6}\.js [ 0-9. ]* kB/) expect(stdout).toMatch(/ chunks\/framework\.[0-9a-z]{6}\.js [ 0-9. ]* kB/)
expect(stdout).not.toContain(' /_document') expect(stdout).not.toContain(' /_document')
...@@ -149,7 +149,7 @@ describe('Build Output', () => { ...@@ -149,7 +149,7 @@ describe('Build Output', () => {
expect(stdout).toMatch(/\/ [ ]* \d{1,} B/) expect(stdout).toMatch(/\/ [ ]* \d{1,} B/)
expect(stdout).toMatch(/\/_app [ ]* \d{1,} B/) expect(stdout).toMatch(/\/_app [ ]* \d{1,} B/)
expect(stdout).toMatch(/\+ First Load JS shared by all [ 0-9.]* kB/) expect(stdout).toMatch(/\+ First Load JS shared by all [ 0-9.]* kB/)
expect(stdout).toMatch(/ runtime\/main\.[0-9a-z]{6}\.js [ 0-9.]* kB/) expect(stdout).toMatch(/ chunks\/main\.[0-9a-z]{6}\.js [ 0-9.]* kB/)
expect(stdout).toMatch(/ chunks\/framework\.[0-9a-z]{6}\.js [ 0-9. ]* kB/) expect(stdout).toMatch(/ chunks\/framework\.[0-9a-z]{6}\.js [ 0-9. ]* kB/)
expect(stdout).not.toContain(' /_document') expect(stdout).not.toContain(' /_document')
...@@ -177,7 +177,7 @@ describe('Build Output', () => { ...@@ -177,7 +177,7 @@ describe('Build Output', () => {
expect(stdout).toMatch(/\/amp .* AMP/) expect(stdout).toMatch(/\/amp .* AMP/)
expect(stdout).toMatch(/\/hybrid [ 0-9.]* B/) expect(stdout).toMatch(/\/hybrid [ 0-9.]* B/)
expect(stdout).toMatch(/\+ First Load JS shared by all [ 0-9.]* kB/) expect(stdout).toMatch(/\+ First Load JS shared by all [ 0-9.]* kB/)
expect(stdout).toMatch(/ runtime\/main\.[0-9a-z]{6}\.js [ 0-9.]* kB/) expect(stdout).toMatch(/ chunks\/main\.[0-9a-z]{6}\.js [ 0-9.]* kB/)
expect(stdout).toMatch(/ chunks\/framework\.[0-9a-z]{6}\.js [ 0-9. ]* kB/) expect(stdout).toMatch(/ chunks\/framework\.[0-9a-z]{6}\.js [ 0-9. ]* kB/)
expect(stdout).not.toContain(' /_document') expect(stdout).not.toContain(' /_document')
...@@ -203,7 +203,7 @@ describe('Build Output', () => { ...@@ -203,7 +203,7 @@ describe('Build Output', () => {
expect(stdout).toMatch(/\/ [ ]* \d{1,} B/) expect(stdout).toMatch(/\/ [ ]* \d{1,} B/)
expect(stdout).toMatch(/λ \/404 [ ]* \d{1,} B/) expect(stdout).toMatch(/λ \/404 [ ]* \d{1,} B/)
expect(stdout).toMatch(/\+ First Load JS shared by all [ 0-9.]* kB/) expect(stdout).toMatch(/\+ First Load JS shared by all [ 0-9.]* kB/)
expect(stdout).toMatch(/ runtime\/main\.[0-9a-z]{6}\.js [ 0-9.]* kB/) expect(stdout).toMatch(/ chunks\/main\.[0-9a-z]{6}\.js [ 0-9.]* kB/)
expect(stdout).toMatch(/ chunks\/framework\.[0-9a-z]{6}\.js [ 0-9. ]* kB/) expect(stdout).toMatch(/ chunks\/framework\.[0-9a-z]{6}\.js [ 0-9. ]* kB/)
expect(stdout).not.toContain(' /_document') expect(stdout).not.toContain(' /_document')
......
...@@ -17,7 +17,7 @@ const nextConfig = join(appDir, 'next.config.js') ...@@ -17,7 +17,7 @@ const nextConfig = join(appDir, 'next.config.js')
let appPort let appPort
let app let app
describe('Production Usage', () => { describe('distDir', () => {
describe('With basic usage', () => { describe('With basic usage', () => {
beforeAll(async () => { beforeAll(async () => {
await nextBuild(appDir) await nextBuild(appDir)
......
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