Skip to content

Commit 12fe60e

Browse files
authoredJun 12, 2023
chore: Remove npm bin from scripts (aws#25913)
This change removes the expression `export PATH=$(npm bin):$PATH`, which had formerly been used in scripts to ensure `node_modules` is in `PATH`. `npm bin` was [removed in npm 9](npm/cli#5459). `npm exec` or `npx` should be used instead. `build.sh` already uses `npx`. This change revises `scripts/gen.sh` to use `npx` as well. Prior to this change, within shells executing `build.sh` or `scripts/gen.sh`, `PATH` actually contains error text if npm 9+ is used. ``` ~/repos/aws-cdk $ docker run --rm -v $PWD:$PWD -w $PWD node:hydrogen-alpine sh -c 'node --version && npm --version && export PATH=$(npm bin):$PATH && echo $PATH' # output when npm bin is unavailable v18.16.0 9.5.1 Unknown command: "bin" To see a list of supported npm commands, run: npm help:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ~/repos/aws-cdk $ docker run --rm -v $PWD:$PWD -w $PWD node:gallium-alpine sh -c 'node --version && npm --version && export PATH=$(npm bin):$PATH && echo $PATH' # output when npm bin is available v16.20.0 8.19.4 /Users/douglasnaphas/repos/aws-cdk/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ``` It didn't make `build.sh` fail, because `lerna` has been run via `npx` since aws#24217, and `build.sh` doesn't need anything from `node_modules` to be added to `PATH`. `export PATH=$(npm bin):$PATH` succeeds even though `npm bin` fails, per `export`'s normal behavior. Prior to this change, `scripts/gen.sh` failed with ``` ./scripts/gen.sh: line 18: lerna: command not found ``` when I ran it. After this change, `scripts/gen.sh` ran successfully. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 23a84d3 commit 12fe60e

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed
 

‎build.sh

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ while [[ "${1:-}" != "" ]]; do
4545
shift
4646
done
4747

48-
export PATH=$(npm bin):$PATH
4948
export NODE_OPTIONS="--max-old-space-size=8196 --experimental-worker ${NODE_OPTIONS:-}"
5049

5150
# Temporary log memory for long builds (this may mess with tests that check stderr)

‎scripts/gen.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
export PATH=$(npm bin):$PATH
54
export NODE_OPTIONS="--max-old-space-size=8196 ${NODE_OPTIONS:-}"
65

76
echo "============================================================================================="
@@ -15,8 +14,8 @@ fail() {
1514

1615
echo "============================================================================================="
1716
echo "building required build tools..."
18-
time lerna run --stream build --scope @aws-cdk/cfn2ts --scope @aws-cdk/ubergen --include-dependencies || fail
17+
time npx lerna run --stream build --scope @aws-cdk/cfn2ts --scope @aws-cdk/ubergen --include-dependencies || fail
1918

2019
echo "============================================================================================="
2120
echo "executing gen..."
22-
time lerna run --stream gen || fail
21+
time npx lerna run --stream gen || fail

0 commit comments

Comments
 (0)