Skip to content

Commit a6e209a

Browse files
committed
Fix build script: npm removed bin command
Background ========== The build script used `npm bin` to fetch the local bin path for running `cdk` commands. See https://docs.npmjs.com/cli/v8/commands/npm-bin npm version 9 removed the `bin` command so it no longer works. See npm/cli#5459 Change ====== Changed the way the script gets the npm execution environment. Added some clean-up to the script to remove the CloudFormation template staging directory. Updated the "Copy Dist to S3" guard code so it does not try to copy to any of the reference buckets.
1 parent c68e9f6 commit a6e209a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

deployment/build-s3-dist.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ cleanup_and_die() {
5151
}
5252

5353
cleanup() {
54-
trap - SIGINT SIGTERM ERR EXIT
54+
trap - SIGINT SIGTERM EXIT
5555
# Deactivate and remove the temporary python virtualenv used to run this script
5656
if [[ "$VIRTUAL_ENV" != "" ]];
5757
then
@@ -198,7 +198,7 @@ echo "Using virtual python environment:"
198198
VENV=$(mktemp -d) && echo "$VENV"
199199
python3 -m venv "$VENV" || die "ERROR: Couldn't create virtual python environment" 1
200200

201-
trap cleanup_and_die SIGINT SIGTERM ERR EXIT
201+
trap cleanup_and_die SIGINT SIGTERM EXIT
202202

203203
source "$VENV"/bin/activate
204204
pip3 install wheel
@@ -760,7 +760,7 @@ do_cmd cd "$cdk_dir"
760760
do_cmd npm install
761761

762762
# Add local install to PATH
763-
export PATH=$(npm bin):$PATH
763+
export PATH=$(npm exec -c 'echo $PATH')
764764
# Check cdk version to verify installation
765765
current_cdkver=`cdk --version | grep -Eo '^[0-9]{1,2}\.[0-9]+\.[0-9]+'`
766766
echo CDK version $current_cdkver
@@ -782,7 +782,7 @@ do_cmd cdk synth -q --output="$staging_dist_dir"
782782

783783
# Remove unnecessary output files
784784
do_cmd cd "$staging_dist_dir"
785-
rm -f tree.json manifest.json cdk.out
785+
rm -f tree.json manifest.json cdk.out *.csv
786786

787787
echo "Preparing template files:"
788788
root_template=`basename *.assets.json .assets.json`
@@ -831,9 +831,13 @@ new_version="s/%%VERSION%%/$version/g"
831831
sed -i.orig -e "$new_global_bucket" -e "$new_regional_bucket" -e "$new_version" "${global_dist_dir}"/*.template
832832
rm -f "${global_dist_dir}"/*.orig
833833

834+
# Remove temporary staging directory if it is empty. Ignore failure to delete if it is not empty.
835+
cd "$build_dir"
836+
rmdir "$staging_dist_dir" || true
837+
834838
# Skip copy dist to S3 if building for solution builder because
835839
# that pipeline takes care of copying the dist in another script.
836-
if [ "$global_bucket" != "solutions-reference" ] && [ "$global_bucket" != "solutions-test-reference" ]; then
840+
if [[ ! "$global_bucket" =~ solutions(-[a-z]+)?-reference ]]; then
837841
echo "------------------------------------------------------------------------------"
838842
echo "Copy dist to S3"
839843
echo "------------------------------------------------------------------------------"

0 commit comments

Comments
 (0)