Skip to content

Commit 7b2e092

Browse files
authored
Merge pull request microsoft#24712 from styfle/build-size
build: add check for lib size
2 parents b4dea5e + 8b034e6 commit 7b2e092

3 files changed

Lines changed: 47 additions & 11 deletions

File tree

Gulpfile.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const clone = require("gulp-clone");
1212
const newer = require("gulp-newer");
1313
const tsc = require("gulp-typescript");
1414
const tsc_oop = require("./scripts/build/gulp-typescript-oop");
15+
const getDirSize = require("./scripts/build/getDirSize");
1516
const insert = require("gulp-insert");
1617
const sourcemaps = require("gulp-sourcemaps");
1718
const Q = require("q");
@@ -588,7 +589,13 @@ gulp.task("VerifyLKG", /*help*/ false, [], () => {
588589
gulp.task("LKGInternal", /*help*/ false, ["lib", "local"]);
589590

590591
gulp.task("LKG", "Makes a new LKG out of the built js files", ["clean", "dontUseDebugMode"], () => {
591-
return runSequence("LKGInternal", "VerifyLKG");
592+
const sizeBefore = getDirSize(lkgDirectory);
593+
const seq = runSequence("LKGInternal", "VerifyLKG");
594+
const sizeAfter = getDirSize(lkgDirectory);
595+
if (sizeAfter > (sizeBefore * 1.10)) {
596+
throw new Error("The lib folder increased by 10% or more. This likely indicates a bug.");
597+
}
598+
return seq;
592599
});
593600

594601

Jakefile.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var path = require("path");
88
var child_process = require("child_process");
99
var fold = require("travis-fold");
1010
var ts = require("./lib/typescript");
11+
const getDirSize = require("./scripts/build/getDirSize");
1112

1213
// Variables
1314
var compilerDirectory = "src/compiler/";
@@ -642,26 +643,24 @@ task("generate-spec", [specMd]);
642643

643644
// Makes a new LKG. This target does not build anything, but errors if not all the outputs are present in the built/local directory
644645
desc("Makes a new LKG out of the built js files");
645-
task("LKG", ["clean", "release", "local"].concat(libraryTargets), function () {
646+
task("LKG", ["clean", "release", "local"].concat(libraryTargets), () => {
647+
const sizeBefore = getDirSize(LKGDirectory);
646648
var expectedFiles = [tscFile, servicesFile, serverFile, nodePackageFile, nodeDefinitionsFile, standaloneDefinitionsFile, tsserverLibraryFile, tsserverLibraryDefinitionFile, cancellationTokenFile, typingsInstallerFile, buildProtocolDts, watchGuardFile].
647649
concat(libraryTargets).
648650
concat(localizationTargets);
649-
var missingFiles = expectedFiles.filter(function (f) {
650-
return !fs.existsSync(f);
651-
});
651+
var missingFiles = expectedFiles.filter(f => !fs.existsSync(f));
652652
if (missingFiles.length > 0) {
653653
fail(new Error("Cannot replace the LKG unless all built targets are present in directory " + builtLocalDirectory +
654654
". The following files are missing:\n" + missingFiles.join("\n")));
655655
}
656656
// Copy all the targets into the LKG directory
657657
jake.mkdirP(LKGDirectory);
658-
for (i in expectedFiles) {
659-
jake.cpR(expectedFiles[i], LKGDirectory);
658+
expectedFiles.forEach(f => jake.cpR(f, LKGDirectory));
659+
660+
const sizeAfter = getDirSize(LKGDirectory);
661+
if (sizeAfter > (sizeBefore * 1.10)) {
662+
throw new Error("The lib folder increased by 10% or more. This likely indicates a bug.");
660663
}
661-
//var resourceDirectories = fs.readdirSync(builtLocalResourcesDirectory).map(function(p) { return path.join(builtLocalResourcesDirectory, p); });
662-
//resourceDirectories.map(function(d) {
663-
// jake.cpR(d, LKGResourcesDirectory);
664-
//});
665664
});
666665

667666
// Test directory

scripts/build/getDirSize.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @ts-check
2+
const { lstatSync, readdirSync } = require("fs");
3+
const { join } = require("path");
4+
5+
/**
6+
* Find the size of a directory recursively.
7+
* Symbolic links are counted once (same inode).
8+
* @param {string} root
9+
* @param {Set} seen
10+
* @returns {number} bytes
11+
*/
12+
function getDirSize(root, seen = new Set()) {
13+
const stats = lstatSync(root);
14+
15+
if (seen.has(stats.ino)) {
16+
return 0;
17+
}
18+
19+
seen.add(stats.ino);
20+
21+
if (!stats.isDirectory()) {
22+
return stats.size;
23+
}
24+
25+
return readdirSync(root)
26+
.map(file => getDirSize(join(root, file), seen))
27+
.reduce((acc, num) => acc + num, 0);
28+
}
29+
30+
module.exports = getDirSize;

0 commit comments

Comments
 (0)