diff --git a/azure-pipelines.yml b/azure-pipelines.yml index d43c38a168a1d5..7feb07a3afeef5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -67,10 +67,10 @@ steps: displayName: Cache nextjs build - script: | - set -o pipefail + set -e pipefail mkdir -p scripts/sizeSnapshot/build yarn docs:build | tee scripts/sizeSnapshot/build/docs.next - set +o pipefail + set +e pipefail displayName: 'build docs for size snapshot' - script: | diff --git a/scripts/sizeSnapshot/create.js b/scripts/sizeSnapshot/create.js index 02939f86478a6e..64768cf906ed8b 100644 --- a/scripts/sizeSnapshot/create.js +++ b/scripts/sizeSnapshot/create.js @@ -95,7 +95,9 @@ async function getNextPagesSize() { }); const pageRegex = /(?┌|├|└)\s+((?λ|○|●)\s+)?(?[^\s]+)\s+(?[0-9.]+)\s+(?\w+)/gm; - return Array.from(matchAll(consoleOutput, pageRegex), match => { + const sharedChunks = []; + + const entries = Array.from(matchAll(consoleOutput, pageRegex), match => { const { pageUrl, sizeFormatted, sizeUnit } = match.groups; let snapshotId = `docs:${pageUrl}`; @@ -104,7 +106,24 @@ async function getNextPagesSize() { snapshotId = 'docs.landing'; } else if (pageUrl === 'static/pages/_app.js') { snapshotId = 'docs.main'; + // chunks contain a content hash that makes the names + // unsuitable for tracking. Using stable name instead: + } else if (/^runtime\/main\.(.+)\.js$/.test(pageUrl)) { + snapshotId = 'docs:shared:runtime/main'; + } else if (/^runtime\/webpack\.(.+)\.js$/.test(pageUrl)) { + snapshotId = 'docs:shared:runtime/webpack'; + } else if (/^chunks\/commons\.(.+)\.js$/.test(pageUrl)) { + snapshotId = 'docs:shared:chunk/commons'; + } else if (/^chunks\/framework\.(.+)\.js$/.test(pageUrl)) { + snapshotId = 'docs:shared:chunk/framework'; + } else if (/^chunks\/(.*)\.js$/.test(pageUrl)) { + // shared chunks are unnamed and only have a hash + // we just track their tally and summed size + sharedChunks.push(prettyBytesInverse(sizeFormatted, sizeUnit)); + // and not each chunk individually + return null; } + return [ snapshotId, { @@ -112,7 +131,18 @@ async function getNextPagesSize() { gzip: -1, }, ]; - }); + }).filter(entry => entry !== null); + + entries.push([ + 'docs:chunk:shared', + { + parsed: sharedChunks.reduce((sum, size) => sum + size, 0), + gzip: -1, + tally: sharedChunks.length, + }, + ]); + + return entries; } async function run() { diff --git a/yarn.lock b/yarn.lock index 133c372650f8e9..ce64ddeb42c6dd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4273,9 +4273,9 @@ caniuse-api@^3.0.0: lodash.uniq "^4.5.0" caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001017, caniuse-lite@^1.0.30001020, caniuse-lite@^1.0.30001030: - version "1.0.30001031" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001031.tgz#76f1bdd39e19567b855302f65102d9a8aaad5930" - integrity sha512-DpAP5a1NGRLgYfaNCaXIRyGARi+3tJA2quZXNNA1Du26VyVkqvy2tznNu5ANyN1Y5aX44QDotZSVSUSi2uMGjg== + version "1.0.30001035" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001035.tgz#2bb53b8aa4716b2ed08e088d4dc816a5fe089a1e" + integrity sha512-C1ZxgkuA4/bUEdMbU5WrGY4+UhMFFiXrgNAfxiMIqWgFTWfv/xsZCS2xEHT2LMq7xAZfuAnu6mcqyDl0ZR6wLQ== case@1.6.2: version "1.6.2"