Skip to content

Commit aee537a

Browse files
authoredApr 27, 2023
chore(aws-cdk-lib): Run pre and post package steps for aws-cdk-lib from pack.sh (aws#25239)
Until this PR, the pre and post package steps defined in `aws-cdk-lib`'s `package.json` were not actually executed during the pack step of the pipeline. The ultimate purpose of this change is to make sure that the `.js` source files are minified in the release pipeline, resulting in a smaller overall package size. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 2935b92 commit aee537a

File tree

5 files changed

+49
-10
lines changed

5 files changed

+49
-10
lines changed
 

‎pack.sh

+9-1
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,24 @@ function lerna_scopes() {
3838

3939
scripts/run-rosetta.sh --infuse --pkgs-from $TMPDIR/jsii.txt
4040

41+
# Execute any pre-package steps for the jsii modules here:
42+
echo "Running aws-cdk-lib pre-package"
43+
npx lerna run --scope aws-cdk-lib package -- --pre-only
44+
4145
# Jsii packaging (all at once using jsii-pacmak)
4246
echo "Packaging jsii modules" >&2
4347
$PACMAK \
4448
--verbose \
4549
$(cat $TMPDIR/jsii.txt)
4650

51+
# Execute any post-package steps for the jsii modules here:
52+
echo "Running aws-cdk-lib post-package"
53+
npx lerna run --scope aws-cdk-lib package -- --post-only
54+
4755
# Non-jsii packaging, which means running 'package' in every individual
4856
# module
4957
echo "Packaging non-jsii modules" >&2
50-
lerna run $(lerna_scopes $(cat $TMPDIR/nonjsii.txt)) --sort --concurrency=1 --stream package
58+
npx lerna run $(lerna_scopes $(cat $TMPDIR/nonjsii.txt)) --sort --concurrency=1 --stream package
5159

5260
# Finally rsync all 'dist' directories together into a global 'dist' directory
5361
for dir in $(find packages -name dist | grep -v node_modules | grep -v run-wrappers); do

‎packages/aws-cdk-lib/package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@
5656
]
5757
},
5858
"cdk-package": {
59-
"pre": "/bin/bash ./scripts/minify-sources.sh",
60-
"post": "node ./scripts/verify-stripped-exp.js"
59+
"pre": [
60+
"/bin/bash ./scripts/minify-sources.sh"
61+
],
62+
"post": [
63+
"ts-node ./scripts/verify-stripped-exp.ts"
64+
]
6165
},
6266
"pkglint": {
6367
"exclude": [

‎scripts/check-pack-prerequisites.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ app_min="1.8.0"
5252
check_which $app $app_min
5353
app_v=$(${app} -version 2>&1)
5454
echo -e "Checking javac version... \c"
55-
# 1.8
56-
if [ $(echo $app_v | grep -c -E "1\.8\.[0-9].*") -eq 1 ]
55+
# javac >= 1.8
56+
if [ $(echo $app_v | grep -c -E "1\.[89]\.[0-9].*") -eq 1 ] || [ $(echo $app_v | grep -c -E "[2-9]\.[0-9]+\.[0-9]+.*") -eq 1 ] || [ $(echo $app_v | grep -c -E "[1-9][0-9]+\.[0-9]+\.[0-9]+.*") -eq 1 ]
5757
then
5858
echo "Ok"
5959
else

‎tools/@aws-cdk/cdk-build-tools/bin/cdk-package.ts

+24-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,24 @@ async function main() {
2222
default: require.resolve('jsii-pacmak/bin/jsii-pacmak'),
2323
defaultDescription: 'jsii-pacmak provided by node dependencies',
2424
})
25+
.option('pre-only', { type: 'boolean', default: false, desc: 'run pre package steps only' })
26+
.option('post-only', { type: 'boolean', default: false, desc: 'run post package steps only' })
2527
.argv;
2628

29+
if (args['pre-only'] && args['post-only']) {
30+
throw new Error('You can set a maxiumum of one of --pre-only and --post-only flags to true. Pick one.');
31+
}
32+
2733
const options = cdkPackageOptions();
2834

35+
if (args['post-only']) {
36+
if (options.post) {
37+
const commands = options.post.join(' && ');
38+
await shell([commands], { timers });
39+
}
40+
return;
41+
}
42+
2943
const outdir = 'dist';
3044

3145
// if this is a private module, don't package
@@ -34,6 +48,14 @@ async function main() {
3448
return;
3549
}
3650

51+
if (options.pre ) {
52+
const commands = options.pre.join(' && ');
53+
await shell([commands], { timers });
54+
}
55+
if (args['pre-only']) {
56+
return;
57+
}
58+
3759
// If we need to shrinkwrap this, do so now.
3860
if (options.shrinkWrap) {
3961
await yarnCling.generateShrinkwrap({
@@ -65,11 +87,11 @@ async function main() {
6587
}
6688

6789
if (options.post) {
68-
await shell(options.post, { timers });
90+
const commands = options.post.join(' && ');
91+
await shell([commands], { timers });
6992
}
7093
}
7194

72-
7395
main().then(() => {
7496
buildTimer.end();
7597
process.stdout.write(`Package complete. ${timers.display()}\n`);

‎tools/@aws-cdk/cdk-build-tools/lib/package-info.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ export interface CDKBuildOptions {
142142
};
143143

144144
/**
145-
* An optional command (formatted as a list of strings) to run before building
145+
* Optional commands (formatted as a list of strings, which will be joined together with the && operator) to run before building
146146
*
147147
* (Typically a code generator)
148148
*/
149149
pre?: string[];
150150

151151
/**
152-
* An optional command (formatted as a list of strings) to run after building
152+
* Optional commands (formatted as a list of strings, which will be joined together with the && operator) to run after building
153153
*
154154
* (Schema generator for example)
155155
*/
@@ -190,8 +190,13 @@ export interface CDKPackageOptions {
190190
*/
191191
shrinkWrap?: boolean;
192192

193+
/**
194+
* Optional commands (formatted as a list of strings, which will be joined together with the && operator) to run before packaging
195+
*/
196+
pre?: string[];
197+
193198
/*
194-
* An optional command (formatted as a list of strings) to run after packaging
199+
* Optional commands (formatted as a list of strings, which will be joined together with the && operator) to run after packaging
195200
*/
196201
post?: string[];
197202

0 commit comments

Comments
 (0)
Please sign in to comment.