react/scripts/rollup/consolidateBundleSizes.js
Andrew Clark 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.
2019-05-29 21:30:16 -07:00

26 lines
773 B
JavaScript

'use strict';
// Script that combines bundle size information for each build into a single
// JSON file for easier storage and processing.
const fs = require('fs');
const path = require('path');
const BUILD_DIR = path.join(__dirname, '../../build');
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('.json')) {
const json = fs.readFileSync(path.join(BUILD_DIR, 'sizes', filename));
bundleSizes.push(...JSON.parse(json).bundleSizes);
}
}
const outputFilename = path.join(BUILD_DIR, 'bundle-sizes.json');
const outputContents = JSON.stringify({bundleSizes}, null, 2);
fs.writeFileSync(outputFilename, outputContents);