mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-23 10:29:01 -06:00
build: add check for lib size
This commit is contained in:
parent
3822e3e4ed
commit
bceb08b36f
10
Gulpfile.js
10
Gulpfile.js
@ -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;
|
||||
});
|
||||
|
||||
|
||||
|
||||
32
scripts/build/get-dir-size.js
Normal file
32
scripts/build/get-dir-size.js
Normal 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;
|
||||
Loading…
x
Reference in New Issue
Block a user