UNPKG

@codechecks/build-size-watcher

Version:

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

36 lines 1.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const client_1 = require("@codechecks/client"); const glob = require("glob"); const getSize_1 = require("./getSize"); const path_1 = require("path"); const getArtifactDiff_1 = require("./getArtifactDiff"); const getReportFromDiff_1 = require("./getReportFromDiff"); const normalization_1 = require("./normalization"); async function buildSizeWatcher(_options) { const options = normalization_1.normalizeOptions(_options); const cwd = client_1.codechecks.context.workspaceRoot; const fullArtifact = {}; for (const file of options.files) { const matches = glob.sync(file.path, { cwd }); const sizes = await Promise.all(matches.map(match => getSize_1.getSize(path_1.join(cwd, match), options.gzip))); const overallSize = sizes.reduce((a, b) => a + b, 0); const artifact = { path: file.path, files: matches.length, overallSize, }; fullArtifact[file.path] = artifact; } await client_1.codechecks.saveValue(options.artifactName, fullArtifact); if (!client_1.codechecks.isPr()) { return; } const baseArtifact = await client_1.codechecks.getValue(options.artifactName); const diff = getArtifactDiff_1.getArtifactDiff(fullArtifact, baseArtifact); const report = getReportFromDiff_1.getReportFromDiff(diff, options.files, options); await client_1.codechecks.report(report); } exports.buildSizeWatcher = buildSizeWatcher; exports.default = buildSizeWatcher; //# sourceMappingURL=index.js.map