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

[docs] Page size tracking fixes #20199

Merged
merged 3 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
34 changes: 32 additions & 2 deletions scripts/sizeSnapshot/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ async function getNextPagesSize() {
});
const pageRegex = /(?<treeViewPresentation>┌|├|└)\s+((?<fileType>λ|○|●)\s+)?(?<pageUrl>[^\s]+)\s+(?<sizeFormatted>[0-9.]+)\s+(?<sizeUnit>\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}`;
Expand All @@ -104,15 +106,43 @@ 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,
{
parsed: prettyBytesInverse(sizeFormatted, sizeUnit),
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() {
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down