From 64d5b94597f81c262f6bfb77e8d0e682ced3729f Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 15 Apr 2021 10:18:49 +0200 Subject: [PATCH 1/2] allow to opt-out from webpack 5 --- packages/next/next-server/server/config-utils.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/next/next-server/server/config-utils.ts b/packages/next/next-server/server/config-utils.ts index a3dea184bc667..373c81199a172 100644 --- a/packages/next/next-server/server/config-utils.ts +++ b/packages/next/next-server/server/config-utils.ts @@ -78,6 +78,14 @@ export async function shouldLoadWithWebpack5( } } + // Opted-out manually + if (userConfig.future?.webpack5 === false) { + return { + enabled: false, + reason: 'no-future-flag', + } + } + // Uncomment to add auto-enable when there is no custom webpack config // The user isn't configuring webpack if (!userConfig.webpack) { @@ -98,7 +106,7 @@ function reasonMessage(reason: CheckReasons) { case 'future-flag': return 'future.webpack5 option enabled' case 'no-future-flag': - return 'future.webpack5 option not enabled' + return 'future.webpack5 option disabled' case 'no-config': return 'no next.config.js' case 'webpack-config': From 1f8693fd94415b984d714f34affefc07a2e47279 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 15 Apr 2021 09:47:25 +0200 Subject: [PATCH 2/2] improve pr stats action --- .../next-stats-action/src/add-comment.js | 2 +- .../next-stats-action/src/run/index.js | 48 +++++++++------ test/.stats-app/stats-config.js | 58 +++++++++---------- 3 files changed, 59 insertions(+), 49 deletions(-) diff --git a/.github/actions/next-stats-action/src/add-comment.js b/.github/actions/next-stats-action/src/add-comment.js index e483ffcfe64ba..2f2d9afc15785 100644 --- a/.github/actions/next-stats-action/src/add-comment.js +++ b/.github/actions/next-stats-action/src/add-comment.js @@ -83,7 +83,7 @@ module.exports = async function addComment( else if (!isGzipItem && !groupKey.match(gzipIgnoreRegex)) return if ( - itemKey !== 'buildDuration' || + !itemKey.startsWith('buildDuration') || (isBenchmark && itemKey.match(/req\/sec/)) ) { if (typeof mainItemVal === 'number') mainRepoTotal += mainItemVal diff --git a/.github/actions/next-stats-action/src/run/index.js b/.github/actions/next-stats-action/src/run/index.js index e8ddf32dea70f..e2159e9a89bf2 100644 --- a/.github/actions/next-stats-action/src/run/index.js +++ b/.github/actions/next-stats-action/src/run/index.js @@ -26,6 +26,7 @@ async function runConfigs( let curStats = { General: { buildDuration: null, + buildDurationCached: null, nodeModulesSize: null, }, } @@ -55,20 +56,25 @@ async function runConfigs( ) } - const buildStart = new Date().getTime() + const buildStart = Date.now() await exec(`cd ${statsAppDir} && ${statsConfig.appBuildCommand}`, false, { env: yarnEnvValues, }) - curStats.General.buildDuration = new Date().getTime() - buildStart + curStats.General.buildDuration = Date.now() - buildStart // apply renames to get deterministic output names for (const rename of config.renames) { const results = await glob(rename.srcGlob, { cwd: statsAppDir }) - if (results.length === 0 || results[0] === rename.dest) continue - await fs.move( - path.join(statsAppDir, results[0]), - path.join(statsAppDir, rename.dest) - ) + for (const result of results) { + let dest = rename.removeHash + ? result.replace(/(\.|-)[0-9a-f]{20}(\.|-)/g, '$1HASH$2') + : rename.dest + if (result === dest) continue + await fs.move( + path.join(statsAppDir, result), + path.join(statsAppDir, dest) + ) + } } const collectedStats = await collectStats(config, statsConfig) @@ -80,19 +86,17 @@ async function runConfigs( const applyRenames = (renames, stats) => { if (renames) { for (const rename of renames) { + let { cur, prev } = rename + cur = path.basename(cur) + prev = path.basename(prev) + Object.keys(stats).forEach((group) => { - Object.keys(stats[group]).forEach((item) => { - let { cur, prev } = rename - cur = path.basename(cur) - prev = path.basename(prev) - - if (cur === item) { - stats[group][prev] = stats[group][item] - stats[group][prev + ' gzip'] = stats[group][item + ' gzip'] - delete stats[group][item] - delete stats[group][item + ' gzip'] - } - }) + if (stats[group][cur]) { + stats[group][prev] = stats[group][cur] + stats[group][prev + ' gzip'] = stats[group][cur + ' gzip'] + delete stats[group][cur] + delete stats[group][cur + ' gzip'] + } }) } } @@ -146,6 +150,12 @@ async function runConfigs( /* eslint-disable-next-line */ mainRepoStats = curStats } + + const secondBuildStart = Date.now() + await exec(`cd ${statsAppDir} && ${statsConfig.appBuildCommand}`, false, { + env: yarnEnvValues, + }) + curStats.General.buildDurationCached = Date.now() - secondBuildStart } logger(`Finished running: ${config.title}`) diff --git a/test/.stats-app/stats-config.js b/test/.stats-app/stats-config.js index f5a2c08440b59..00eb4a3860ed1 100644 --- a/test/.stats-app/stats-config.js +++ b/test/.stats-app/stats-config.js @@ -30,38 +30,17 @@ const renames = [ dest: '.next/static/BUILD_ID/pages', }, { - srcGlob: '.next/static/runtime/main-*', - dest: '.next/static/runtime/main-HASH.js', + srcGlob: '.next/static/*/pages/**/*', + removeHash: true, }, { - srcGlob: '.next/static/chunks/main-*', - dest: '.next/static/chunks/main-HASH.js', + srcGlob: '.next/static/runtime/*', + removeHash: true, }, { - srcGlob: '.next/static/runtime/webpack-*', - dest: '.next/static/runtime/webpack-HASH.js', + srcGlob: '.next/static/chunks/*', + removeHash: true, }, - { - srcGlob: '.next/static/chunks/webpack-*', - dest: '.next/static/chunks/webpack-HASH.js', - }, - { - srcGlob: '.next/static/runtime/polyfills-*', - dest: '.next/static/runtime/polyfills-HASH.js', - }, - { - srcGlob: '.next/static/chunks/polyfills-*', - dest: '.next/static/chunks/polyfills-HASH.js', - }, - { - srcGlob: '.next/static/chunks/commons*', - dest: '.next/static/chunks/commons.HASH.js', - }, - { - srcGlob: '.next/static/chunks/framework*', - dest: '.next/static/chunks/framework.HASH.js', - }, - // misc { srcGlob: '.next/static/*/_buildManifest.js', dest: '.next/static/BUILD_ID/_buildManifest.js', @@ -86,6 +65,9 @@ module.exports = { content: ` module.exports = { generateBuildId: () => 'BUILD_ID', + future: { + webpack5: true + }, webpack(config) { config.optimization.minimize = false config.optimization.minimizer = undefined @@ -148,8 +130,26 @@ module.exports = { ], }, { - title: 'Webpack 5 Mode', + title: 'Webpack 4 Mode', diff: 'onOutputChange', + diffConfigFiles: [ + { + path: 'next.config.js', + content: ` + module.exports = { + generateBuildId: () => 'BUILD_ID', + future: { + webpack5: false + }, + webpack(config) { + config.optimization.minimize = false + config.optimization.minimizer = undefined + return config + } + } + `, + }, + ], renames, configFiles: [ { @@ -158,7 +158,7 @@ module.exports = { module.exports = { generateBuildId: () => 'BUILD_ID', future: { - webpack5: true + webpack5: false } } `,