forked from bazel-contrib/rules_nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-deleted-packages.js
31 lines (29 loc) · 1.1 KB
/
update-deleted-packages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Called from package.json script to re-write the .bazelrc file with a setting that
// treats directories under e2e and examples as plain files, not Bazel packages.
const {readFileSync, writeFileSync, readdirSync, lstatSync} = require('fs');
const {join, basename, dirname} = require('path');
const pattern = /((build|query) --deleted_packages=).*/;
const content = readFileSync('.bazelrc', 'utf-8').split('\n');
function collectNested(dir, result) {
readdirSync(dir).filter(
f => f !== 'node_modules'
).map(
f => join(dir, f)
).forEach(f => {
if (lstatSync(f).isDirectory()) {
collectNested(f, result)
} else if (dir.includes('/') && (basename(f) === 'BUILD' || basename(f) === 'BUILD.bazel')) {
result.push(dirname(f))
}
});
}
const deleted_packages = []
collectNested('e2e', deleted_packages);
collectNested('examples', deleted_packages);
writeFileSync('.bazelrc', content.map(line => {
const match = line.match(pattern);
if (match) {
return match[1] + deleted_packages.sort().join(',');
}
return line;
}).join('\n'));