@samitouri / QOS-React-2 / commits / 3b2302253f

Fix sizebot (#15771)

The previous naming scheme used the name of the resulting bundle file. However, there are cases where multiple bundles have the same filename. This meant whichever bundle finishes last overwrites the previous ones with the same name. The updated naming scheme is `bundle-sizes-<CI_NODE_INDEX>.json`. Instead of generating a separate info file per bundle, it now creates one per process.

Andrew Clark committed May 29, 2019 at 21:30 UTC 3b2302253f13c9cd049fac10784e10b6c582e3b6
3 files changed +20 -17
scripts/rollup/build.js
+3 -1
@@ -21,7 +21,7 @@ const useForks = require('./plugins/use-forks-plugin');
21 const stripUnusedImports = require('./plugins/strip-unused-imports');
22 const extractErrorCodes = require('../error-codes/extract-errors');
23 const Packaging = require('./packaging');
24 -const {asyncCopyTo} = require('./utils');
24 +const {asyncCopyTo, asyncRimRaf} = require('./utils');
25 const codeFrame = require('babel-code-frame');
26 const Wrappers = require('./wrappers');
27
@@ -634,6 +634,8 @@ function handleRollupError(error) {
634 }
635
636 async function buildEverything() {
637 + await asyncRimRaf('build');
638 +
639 // Run them serially for better console output
640 // and to avoid any potential race conditions.
641
scripts/rollup/consolidateBundleSizes.js
+2 -2
@@ -13,9 +13,9 @@ const filenames = fs.readdirSync(path.join(BUILD_DIR, 'sizes'));
13 let bundleSizes = [];
14 for (let i = 0; i < filenames.length; i++) {
15 const filename = filenames[i];
16 - if (filename.endsWith('.size.json')) {
16 + if (filename.endsWith('.json')) {
17 const json = fs.readFileSync(path.join(BUILD_DIR, 'sizes', filename));
18 - bundleSizes.push(JSON.parse(json));
18 + bundleSizes.push(...JSON.parse(json).bundleSizes);
19 }
20 }
21
scripts/rollup/stats.js
+15 -14
@@ -18,22 +18,23 @@ const currentBuildResults = {
18 };
19
20 function saveResults() {
21 - // Write all the bundle sizes to a single JSON file.
22 - fs.writeFileSync(
23 - BUNDLE_SIZES_FILE_NAME,
24 - JSON.stringify(currentBuildResults, null, 2)
25 - );
26 -
27 - // Also write each bundle size to a separate file. That way multiple build
28 - // processes can run in parallel and generate separate size artifacts.
29 - // A downstream job can combine them into a single JSON file.
30 - mkdirp.sync('build/sizes');
31 - currentBuildResults.bundleSizes.forEach(results => {
21 + if (process.env.CIRCLE_NODE_TOTAL) {
22 + // In CI, write the bundle sizes to a subdirectory and append the node index
23 + // to the filename. A downstream job will consolidate these into a
24 + // single file.
25 + const nodeIndex = process.env.CIRCLE_NODE_INDEX;
26 + mkdirp.sync('build/sizes');
27 fs.writeFileSync(
33 - join('build', 'sizes', `${results.filename}.size.json`),
34 - JSON.stringify(results, null, 2)
28 + join('build', 'sizes', `bundle-sizes-${nodeIndex}.json`),
29 + JSON.stringify(currentBuildResults, null, 2)
30 );
36 - });
31 + } else {
32 + // Write all the bundle sizes to a single JSON file.
33 + fs.writeFileSync(
34 + BUNDLE_SIZES_FILE_NAME,
35 + JSON.stringify(currentBuildResults, null, 2)
36 + );
37 + }
38 }
39
40 function fractionalChange(prev, current) {