Skip to content

Commit

Permalink
Fix sizebot (#15771)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
acdlite authored May 30, 2019
1 parent 0f7cc2b commit 3b23022
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
4 changes: 3 additions & 1 deletion scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const useForks = require('./plugins/use-forks-plugin');
const stripUnusedImports = require('./plugins/strip-unused-imports');
const extractErrorCodes = require('../error-codes/extract-errors');
const Packaging = require('./packaging');
const {asyncCopyTo} = require('./utils');
const {asyncCopyTo, asyncRimRaf} = require('./utils');
const codeFrame = require('babel-code-frame');
const Wrappers = require('./wrappers');

Expand Down Expand Up @@ -634,6 +634,8 @@ function handleRollupError(error) {
}

async function buildEverything() {
await asyncRimRaf('build');

// Run them serially for better console output
// and to avoid any potential race conditions.

Expand Down
4 changes: 2 additions & 2 deletions scripts/rollup/consolidateBundleSizes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const filenames = fs.readdirSync(path.join(BUILD_DIR, 'sizes'));
let bundleSizes = [];
for (let i = 0; i < filenames.length; i++) {
const filename = filenames[i];
if (filename.endsWith('.size.json')) {
if (filename.endsWith('.json')) {
const json = fs.readFileSync(path.join(BUILD_DIR, 'sizes', filename));
bundleSizes.push(JSON.parse(json));
bundleSizes.push(...JSON.parse(json).bundleSizes);
}
}

Expand Down
29 changes: 15 additions & 14 deletions scripts/rollup/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@ const currentBuildResults = {
};

function saveResults() {
// Write all the bundle sizes to a single JSON file.
fs.writeFileSync(
BUNDLE_SIZES_FILE_NAME,
JSON.stringify(currentBuildResults, null, 2)
);

// Also write each bundle size to a separate file. That way multiple build
// processes can run in parallel and generate separate size artifacts.
// A downstream job can combine them into a single JSON file.
mkdirp.sync('build/sizes');
currentBuildResults.bundleSizes.forEach(results => {
if (process.env.CIRCLE_NODE_TOTAL) {
// In CI, write the bundle sizes to a subdirectory and append the node index
// to the filename. A downstream job will consolidate these into a
// single file.
const nodeIndex = process.env.CIRCLE_NODE_INDEX;
mkdirp.sync('build/sizes');
fs.writeFileSync(
join('build', 'sizes', `${results.filename}.size.json`),
JSON.stringify(results, null, 2)
join('build', 'sizes', `bundle-sizes-${nodeIndex}.json`),
JSON.stringify(currentBuildResults, null, 2)
);
});
} else {
// Write all the bundle sizes to a single JSON file.
fs.writeFileSync(
BUNDLE_SIZES_FILE_NAME,
JSON.stringify(currentBuildResults, null, 2)
);
}
}

function fractionalChange(prev, current) {
Expand Down

0 comments on commit 3b23022

Please sign in to comment.