Skip to content

Commit

Permalink
Fix app-document-import-order test for webpack 5 (#15224)
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens authored Jul 17, 2020
1 parent 56d62a5 commit a33bb5b
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"publish-stable": "lerna version --force-publish",
"lint-staged": "lint-staged",
"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",
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function createEntrypoints(
const bundleFile = normalizePagePath(page)
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 isLikeServerless = isTargetLikeServerless(target)
Expand Down
21 changes: 9 additions & 12 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ function getOptimizedAliases(isServer: boolean): { [pkg: string]: string } {
}

type ClientEntries = {
'main.js': string[]
} & {
[key: string]: string
[key: string]: string | string[]
}

export default async function getBaseWebpackConfig(
Expand Down Expand Up @@ -432,7 +430,6 @@ export default async function getBaseWebpackConfig(
shared: {
name(module, chunks) {
return (
(isWebpack5 ? 'static/chunks/' : '') +
crypto
.createHash('sha1')
.update(
Expand All @@ -443,8 +440,7 @@ export default async function getBaseWebpackConfig(
''
)
)
.digest('hex') +
(isModuleCSS(module) ? '_CSS' : '')
.digest('hex') + (isModuleCSS(module) ? '_CSS' : '')
)
},
priority: 10,
Expand Down Expand Up @@ -713,7 +709,9 @@ export default async function getBaseWebpackConfig(
output: {
path: outputPath,
// 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',
libraryTarget: isServer ? 'commonjs2' : 'assign',
hotUpdateChunkFilename: isWebpack5
Expand Down Expand Up @@ -1277,11 +1275,10 @@ export default async function getBaseWebpackConfig(
: originalEntry
// Server compilation doesn't have main.js
if (clientEntries && entry['main.js'] && entry['main.js'].length > 0) {
const originalFile = clientEntries[CLIENT_STATIC_FILES_RUNTIME_MAIN]
entry[CLIENT_STATIC_FILES_RUNTIME_MAIN] = [
...entry['main.js'],
originalFile,
]
const originalFile = clientEntries[
CLIENT_STATIC_FILES_RUNTIME_MAIN
] as string
entry[CLIENT_STATIC_FILES_RUNTIME_MAIN] = [...['main.js'], originalFile]
}
delete entry['main.js']

Expand Down
2 changes: 1 addition & 1 deletion packages/next/client/page-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export default class PageLoader {
route = normalizeRoute(route)
let scriptRoute = getAssetPathFromRoute(route, '.js')

const url = `${this.assetPrefix}/_next/static/pages${encodeURI(
const url = `${this.assetPrefix}/_next/static/chunks/pages${encodeURI(
scriptRoute
)}`
this.loadScript(url, route)
Expand Down
11 changes: 5 additions & 6 deletions packages/next/next-server/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ export const CLIENT_STATIC_FILES_PATH = 'static'
export const CLIENT_STATIC_FILES_RUNTIME = 'runtime'
export const AMP_RENDER_TARGET = '__NEXT_AMP_RENDER_TARGET__'
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
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
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
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
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
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 PERMANENT_REDIRECT_STATUS = 308
export const STATIC_PROPS_ID = '__N_SSG'
Expand Down
2 changes: 0 additions & 2 deletions packages/next/next-server/server/get-route-from-entrypoint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
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
const SERVER_ROUTE_NAME_REGEX = /^pages[/\\](.*)$/
// matches static/pages/:page*.js
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/hot-reloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function addCorsSupport(req: IncomingMessage, res: ServerResponse) {
}

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
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/on-demand-entry-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default function onDemandEntryHandler(

const bundleFile = normalizePagePath(pageUrl)
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')
? require.resolve(pagePath)
: join(pagesDir, pagePath)
Expand Down
1 change: 1 addition & 0 deletions packages/next/types/webpack.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ declare module 'webpack' {
reuseExistingChunk?: boolean
/** Give chunks created a name (chunks with equal name are merged) */
name?: boolean | string | ((...args: any[]) => any)
filename?: string
}
interface SplitChunksOptions {
/** Select chunks for determining shared modules (defaults to \"async\", \"initial\" and \"all\" requires adding these chunks to the HTML) */
Expand Down
2 changes: 2 additions & 0 deletions test/integration/app-document-import-order/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ module.exports = {
enforce: true,
priority: 10,
chunks: 'all',
filename: 'static/chunks/[name].[chunkhash].js',
},
requiredByPage: {
test: /requiredByPage.js/,
name: 'requiredByPage',
enforce: true,
priority: 10,
chunks: 'all',
filename: 'static/chunks/[name].[chunkhash].js',
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions test/integration/build-output/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Build Output', () => {

expect(stdout).toMatch(/\/ [ ]* \d{1,} B/)
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).not.toContain(' /_document')
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('Build Output', () => {
expect(stdout).toMatch(/\/ [ ]* \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(/ 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).not.toContain(' /_document')
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('Build Output', () => {
expect(stdout).toMatch(/\/amp .* AMP/)
expect(stdout).toMatch(/\/hybrid [ 0-9.]* B/)
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).not.toContain(' /_document')
Expand All @@ -203,7 +203,7 @@ describe('Build Output', () => {
expect(stdout).toMatch(/\/ [ ]* \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(/ 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).not.toContain(' /_document')
Expand Down
2 changes: 1 addition & 1 deletion test/integration/dist-dir/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const nextConfig = join(appDir, 'next.config.js')
let appPort
let app

describe('Production Usage', () => {
describe('distDir', () => {
describe('With basic usage', () => {
beforeAll(async () => {
await nextBuild(appDir)
Expand Down

0 comments on commit a33bb5b

Please sign in to comment.