build: add check for lib size

This commit is contained in:
Steven 2018-06-05 20:30:07 -04:00
parent 3822e3e4ed
commit bceb08b36f
2 changed files with 41 additions and 1 deletions

View File

@ -12,6 +12,7 @@ const clone = require("gulp-clone");
const newer = require("gulp-newer");
const tsc = require("gulp-typescript");
const tsc_oop = require("./scripts/build/gulp-typescript-oop");
const { getDirSize } = require("./scripts/build/get-dir-size");
const insert = require("gulp-insert");
const sourcemaps = require("gulp-sourcemaps");
const Q = require("q");
@ -588,7 +589,14 @@ gulp.task("VerifyLKG", /*help*/ false, [], () => {
gulp.task("LKGInternal", /*help*/ false, ["lib", "local"]);
gulp.task("LKG", "Makes a new LKG out of the built js files", ["clean", "dontUseDebugMode"], () => {
return runSequence("LKGInternal", "VerifyLKG");
const lib = "./lib";
const sizeBefore = getDirSize(lib);
const seq = runSequence("LKGInternal", "VerifyLKG");
const sizeAfter = getDirSize(lib);
if (sizeAfter > (sizeBefore * 1.10)) {
throw new Error("The lib folder increased by 10% or more. This likely indicates a bug.");
}
return seq;
});

View File

@ -0,0 +1,32 @@
// @ts-check
const { lstatSync, readdirSync } = require("fs");
const { join } = require("path");
const { promisify } = require("util");
const execFile = promisify(require("child_process").execFile);
/**
* Find the size of a directory recursively.
* Symbolic links are counted once (same inode).
* @param {string} root
* @param {Set} seen
* @returns {number} bytes
*/
function getDirSize(root, seen = new Set()) {
const stats = lstatSync(root);
if (seen.has(stats.ino)) {
return 0;
}
seen.add(stats.ino);
if (!stats.isDirectory()) {
return stats.size;
}
return readdirSync(root)
.map(file => getDirSize(join(root, file), seen))
.reduce((acc, num) => acc + num, 0);
}
exports.getDirSize = getDirSize;