-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(common): work around nvm being a function on linux, mac
On Linux, macOS, nvm is only provided as a bash function, which means it is not available to the script unless nvm.sh is `source`d. Unfortunately, this is fragile -- variable usage, function names, etc. can all interfere with each other between build.sh and nvm.sh (for example, the `$VERSION` variable). So we have a wrapper script on those platforms to do our nvm invocation. Relates-to: nvm-sh/nvm#3257
- Loading branch information
Showing
2 changed files
with
39 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
set -u | ||
|
||
if [[ $# -lt 1 ]]; then | ||
echo "This script is called by shellHelperFunctions.sh, _select_node_version_with_nvm()" | ||
echo "during build.sh configure steps. It is not intended to be called directly, as it" | ||
echo "is a wrapper for nvm." | ||
exit 99 | ||
fi | ||
|
||
REQUIRED_NODE_VERSION="$1" | ||
|
||
# | ||
# nvm on macos and linux is a shell function. `source`ing it into our scripts is | ||
# fragile because it uses some of the same variable names that we do. Safest way | ||
# to work around this is to load it in a clean subshell and run it there. | ||
# | ||
# See also https://github.com/nvm-sh/nvm/issues/3257 (among others) | ||
# | ||
|
||
type -t nvm >/dev/null || { | ||
source "$NVM_DIR/nvm.sh" | ||
type -t nvm >/dev/null || { | ||
echo "Failed to find nvm" | ||
exit 1 | ||
} | ||
} | ||
|
||
nvm install "$REQUIRED_NODE_VERSION" | ||
nvm use "$REQUIRED_NODE_VERSION" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters