UNPKG

@codechecks/build-size-watcher

Version:

Keep your build size in check and detect when it gets too big

50 lines 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const lodash_1 = require("lodash"); function getArtifactDiff(A, B = {}) { const totalSizeA = lodash_1.values(A) .map(f => f.overallSize) .reduce((a, b) => a + b, 0); const totalSizeB = lodash_1.values(B) .map(f => f.overallSize) .reduce((a, b) => a + b, 0); const totalSizeChange = totalSizeA - totalSizeB; const totalSizeChangeFraction = totalSizeB ? (totalSizeA - totalSizeB) / totalSizeB : 1; const files = {}; for (const aKey of [...Object.keys(A), ...Object.keys(B)]) { const a = A[aKey]; const b = B[aKey]; if (a && b) { files[aKey] = { type: "changed", overallSize: a.overallSize, sizeChange: a.overallSize - b.overallSize, sizeChangeFraction: (a.overallSize - b.overallSize) / b.overallSize, }; } else if (!b) { files[aKey] = { type: "new", overallSize: a.overallSize, sizeChange: a.overallSize, sizeChangeFraction: 1, }; } else { files[aKey] = { type: "deleted", overallSize: 0, sizeChange: -1 * b.overallSize, sizeChangeFraction: -1, }; } } return { totalSize: totalSizeA, totalSizeChange, totalSizeChangeFraction, files, }; } exports.getArtifactDiff = getArtifactDiff; //# sourceMappingURL=getArtifactDiff.js.map