Skip to content

Commit ec56ad9

Browse files
committed
chore: use new parallel build feature of jsii
Improve build times by using the new "build-all-at-once" feature of jsii-pacmak. Goes together with aws/jsii#849.
1 parent 934d36f commit ec56ad9

File tree

3 files changed

+63
-8
lines changed

3 files changed

+63
-8
lines changed

pack.sh

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Runs "npm package" in all modules. This will produce a "dist/" directory in each module.
33
# Then, calls pack-collect.sh to merge all outputs into a root ./pack directory, which is
44
# later read by bundle-beta.sh.
5-
set -e
5+
set -eu
66
export PATH=$PWD/node_modules/.bin:$PATH
77
export NODE_OPTIONS="--max-old-space-size=4096 ${NODE_OPTIONS:-}"
88
root=$PWD
@@ -11,15 +11,33 @@ distdir="$PWD/dist"
1111
rm -fr ${distdir}
1212
mkdir -p ${distdir}
1313

14-
scopes=$(lerna ls 2>/dev/null | grep -v "(private)" | cut -d" " -f1 | xargs -n1 -I{} echo "--scope {}" | tr "\n" " ")
14+
# Split out jsii and non-jsii packages. Jsii packages will be built all at once.
15+
# Non-jsii packages will be run individually.
16+
echo "Collecting package list..." >&2
17+
scripts/list-packages $TMPDIR/jsii.txt $TMPDIR/nonjsii.txt
1518

16-
# Run the "cdk-package" script in all modules. For jsii modules, this invokes jsii-pacmak which generates and builds multi-language
17-
# outputs. For non-jsii module, it will just run "npm pack" and place the output in dist/npm
18-
# (which is similar to how pacmak outputs it).
19-
lerna run ${scopes} --sort --concurrency=1 --stream package
19+
# Return lerna scopes from a package list
20+
function lerna_scopes() {
21+
while [[ "${1:-}" != "" ]]; do
22+
echo "--scope $1 "
23+
shift
24+
done
25+
}
26+
27+
echo "Packaging jsii modules" >&2
28+
29+
# Jsii packaging (all at once using jsii-pacmak)
30+
jsii-pacmak \
31+
--verbose \
32+
--outdir $distdir/ \
33+
$(cat $TMPDIR/jsii.txt)
34+
35+
# Non-jsii packaging, which means running 'package' in every individual
36+
# module and rsync'ing the result to the shared dist directory.
37+
echo "Packaging non-jsii modules" >&2
38+
lerna run $(lerna_scopes $(cat $TMPDIR/nonjsii.txt)) --sort --concurrency=1 --stream package
2039

21-
# Collect dist/ from all modules into the root dist/
22-
for dir in $(find packages -name dist | grep -v node_modules); do
40+
for dir in $(find packages -name dist | grep -v node_modules | grep -v run-wrappers); do
2341
echo "Merging ${dir} into ${distdir}"
2442
rsync -av $dir/ ${distdir}/
2543
done

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"fs-extra": "^8.1.0",
1616
"jest": "^24.9.0",
1717
"jsii-diff": "^0.17.1",
18+
"jsii-pacmak": "^0.17.1",
1819
"lerna": "^3.16.4",
1920
"nodeunit": "^0.11.3",
2021
"nyc": "^14.1.1",

scripts/list-packages

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Collects all packages in the repository in a way that makes it
4+
* easy to process for packaging.
5+
*/
6+
const child_process = require('child_process');
7+
const fs = require('fs-extra');
8+
const path = require('path');
9+
10+
if (process.argv.length < 4) {
11+
process.stderr.write('Usage: list-packages <jsii file> <nonjsii file>\n');
12+
process.exit(1);
13+
}
14+
15+
child_process.exec('lerna ls --json', { shell: true }, (error, stdout) => {
16+
if (error) {
17+
console.error('Error: ', error);
18+
process.exit(-1);
19+
}
20+
const modules = JSON.parse(stdout.toString('utf8'));
21+
22+
const jsiiDirectories = [];
23+
const nonJsiiNames = [];
24+
25+
for (const module of modules) {
26+
const pkgJson = require(path.join(module.location, 'package.json'));
27+
if (pkgJson.jsii) {
28+
jsiiDirectories.push(module.location);
29+
} else {
30+
nonJsiiNames.push(pkgJson.name);
31+
}
32+
}
33+
34+
fs.writeFileSync(process.argv[2], jsiiDirectories.join('\n'));
35+
fs.writeFileSync(process.argv[3], nonJsiiNames.join('\n'));
36+
});

0 commit comments

Comments
 (0)