Skip to content

Commit

Permalink
[core] Disable page size tracking (#24932)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Feb 14, 2021
1 parent 64823e0 commit 56d344a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 110 deletions.
14 changes: 0 additions & 14 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,6 @@ jobs:
artifactName: 'canaries'
targetPath: 'material-ui-core.tgz'

- task: Cache@2
inputs:
key: 'nextjs-build | yarn.lock'
path: $(DOCS_NEXT_CACHE_FOLDER)
displayName: Cache nextjs build

- script: |
set -o pipefail
mkdir -p scripts/sizeSnapshot/build
yarn docs:build | tee scripts/sizeSnapshot/build/docs.next
displayName: 'build docs for size snapshot'
env:
NODE_OPTIONS: '--max_old_space_size=4096'
- script: |
yarn size:snapshot
displayName: 'create a size snapshot'
Expand Down
96 changes: 0 additions & 96 deletions scripts/sizeSnapshot/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,109 +66,13 @@ async function getWebpackSizes(webpackEnvironment) {
return sizes;
}

// waiting for String.prototype.matchAll in node 10
function* matchAll(string, regex) {
let match = null;
do {
match = regex.exec(string);
if (match !== null) {
yield match;
}
} while (match !== null);
}

/**
* Inverse to `pretty-bytes`
* @param {string} n
* @param {'B', 'kB' | 'MB' | 'GB' | 'TB' | 'PB'} unit
* @returns {number}
*/

function prettyBytesInverse(n, unit) {
const metrixPrefix = unit.length < 2 ? '' : unit[0];
const metricPrefixes = ['', 'k', 'M', 'G', 'T', 'P'];
const metrixPrefixIndex = metricPrefixes.indexOf(metrixPrefix);
if (metrixPrefixIndex === -1) {
throw new TypeError(
`unrecognized metric prefix '${metrixPrefix}' in unit '${unit}'. only '${metricPrefixes.join(
"', '",
)}' are allowed`,
);
}

const power = metrixPrefixIndex * 3;
return n * 10 ** power;
}

/**
* parses output from next build to size snapshot format
* @returns {[string, { gzip: number, files: number, packages: number }][]}
*/

async function getNextPagesSize() {
const consoleOutput = await fse.readFile(path.join(__dirname, 'build/docs.next'), {
encoding: 'utf8',
});
const pageRegex = /(?<treeViewPresentation>┌|├|└)\s+((?<fileType>λ|○|●)\s+)?(?<pageUrl>[^\s]+)\s+(?<sizeFormatted>[0-9.]+)\s+(?<sizeUnit>\w+)/gm;

const sharedChunks = [];

const entries = Array.from(matchAll(consoleOutput, pageRegex), (match) => {
const { pageUrl, sizeFormatted, sizeUnit } = match.groups;

let snapshotId = `docs:${pageUrl}`;
// used to be tracked with custom logic hence the different ids
if (pageUrl === '/') {
snapshotId = 'docs.landing';
// chunks contain a content hash that makes the names
// unsuitable for tracking. Using stable name instead:
} else if (/^chunks\/pages\/_app\.(.+)\.js$/.test(pageUrl)) {
snapshotId = 'docs.main';
} else if (/^chunks\/main\.(.+)\.js$/.test(pageUrl)) {
snapshotId = 'docs:shared:runtime/main';
} else if (/^chunks\/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(argv) {
const { analyze, accurateBundles } = argv;

const rollupBundles = [path.join(workspaceRoot, 'packages/material-ui/size-snapshot.json')];
const bundleSizes = lodash.fromPairs([
...(await getWebpackSizes({ analyze, accurateBundles })),
...lodash.flatten(await Promise.all(rollupBundles.map(getRollupSize))),
...(await getNextPagesSize()),
]);

await fse.writeJSON(snapshotDestPath, bundleSizes, { spaces: 2 });
Expand Down

0 comments on commit 56d344a

Please sign in to comment.