Skip to content

Commit

Permalink
script/postinstall.sh: Fix endless loop with npm 7
Browse files Browse the repository at this point in the history
`npm rebuild` started running the postinstall script after completing.
This calls npm rebuild again, triggering the postinstall script again,
in an endless, recursive loop.

So set an environment variable "APM_ALREADY_REBUILDING"
before doing npm rebuild the first time,
and exit the postinstall script early if that is set,
and the endless loop will be broken.
  • Loading branch information
DeeDeeG committed Feb 11, 2021
1 parent 9afa93c commit eaed703
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions script/postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

set -e

# Skip the postinstall script if we're already rebuilding,
# to avoid an endless, recursive postinstall loop.
if [ -n "${APM_ALREADY_REBUILDING}" ]; then
echo ">> Postinstall script is already being run. Skipping recursive call."
exit 0
fi

echo ">> Downloading bundled Node"
node script/download-node.js

echo
echo ">> Rebuilding apm dependencies with bundled Node $(./bin/node -p "process.version + ' ' + process.arch")"
export APM_ALREADY_REBUILDING="true"
./bin/npm rebuild

echo
Expand Down

0 comments on commit eaed703

Please sign in to comment.