2015-05-24 12:26:04 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-11-24 10:08:14 +08:00
|
|
|
set -eu -o pipefail
|
2017-02-13 03:44:21 +08:00
|
|
|
|
2020-01-14 22:54:24 +08:00
|
|
|
# shellcheck source=../lib/utils.sh
|
2021-12-14 09:50:58 +08:00
|
|
|
source "$(dirname "$0")/../lib/utils.sh"
|
2020-10-02 23:33:24 +08:00
|
|
|
|
2015-05-24 12:26:04 +08:00
|
|
|
install_nodejs() {
|
2021-11-24 10:08:14 +08:00
|
|
|
local install_type="$1" version="$2" install_path="$3"
|
2021-12-17 08:10:58 +08:00
|
|
|
local args=()
|
2021-10-30 09:40:13 +08:00
|
|
|
|
2023-04-20 01:24:34 +08:00
|
|
|
version=$(resolve_version "$version")
|
|
|
|
|
2022-02-10 07:12:37 +08:00
|
|
|
if [ "$install_type" = ref ] || [ "${ASDF_NODEJS_FORCE_COMPILE-}" ]; then
|
2021-12-17 08:10:58 +08:00
|
|
|
args+=(-c)
|
2021-10-30 09:40:13 +08:00
|
|
|
fi
|
2020-10-03 00:11:26 +08:00
|
|
|
|
2023-05-19 00:35:05 +08:00
|
|
|
try_to_update_nodebuild
|
2021-11-24 10:35:25 +08:00
|
|
|
|
Don't set `NODE_BUILD_BUILD_PATH`
If not set, [node-build defaults to a timestamped subdirectory of
`TMPDIR`](https://github.com/nodenv/node-build#custom-build-configuration),
which is exactly what we need.
This fixes https://github.com/asdf-vm/asdf-nodejs/issues/289
With this change, I see repeated builds fail in the exact same way (see
https://github.com/asdf-vm/asdf-nodejs/issues/289 for a detailed
explanation of what used to happen):
$ PATH="$PWD:$PATH" ASDF_NODEJS_FORCE_COMPILE=1 asdf install nodejs 14.18.1
Trying to update node-build... ok
WARNING: node-v14.18.1 is in LTS Maintenance mode and nearing its end of life.
It only receives *critical* security updates, *critical* bug fixes and documentation updates.
Installing node-v14.18.1...
BUILD FAILED (Arch rolling using node-build 4.9.69)
Inspect or clean up the working tree at /tmp/node-build.20220216023317.178521.tZF5cV
Results logged to /tmp/node-build.20220216023317.178521.log
Last 10 log lines:
/tmp/node-build.20220216023317.178521.tZF5cV ~/tmp/demoing
/tmp/node-build.20220216023317.178521.tZF5cV/node-v14.18.1 /tmp/node-build.20220216023317.178521.tZF5cV ~/tmp/demoing
Node.js configure: Found Python 3.9.6...
WARNING: C compiler (CC=gcc, 0.0.0) too old, need gcc 4.2 or clang 3.2
WARNING: Could not recognize `gas`:
ERROR: Did not find a new enough assembler, install one or build with
--openssl-no-asm.
Please refer to BUILDING.md
$ PATH="$PWD:$PATH" ASDF_NODEJS_FORCE_COMPILE=1 asdf install nodejs 14.18.1
Trying to update node-build... ok
WARNING: node-v14.18.1 is in LTS Maintenance mode and nearing its end of life.
It only receives *critical* security updates, *critical* bug fixes and documentation updates.
Installing node-v14.18.1...
BUILD FAILED (Arch rolling using node-build 4.9.69)
Inspect or clean up the working tree at /tmp/node-build.20220216023335.178790.u0kcPV
Results logged to /tmp/node-build.20220216023335.178790.log
Last 10 log lines:
/tmp/node-build.20220216023335.178790.u0kcPV ~/tmp/demoing
/tmp/node-build.20220216023335.178790.u0kcPV/node-v14.18.1 /tmp/node-build.20220216023335.178790.u0kcPV ~/tmp/demoing
Node.js configure: Found Python 3.9.6...
WARNING: C compiler (CC=gcc, 0.0.0) too old, need gcc 4.2 or clang 3.2
WARNING: Could not recognize `gas`:
ERROR: Did not find a new enough assembler, install one or build with
--openssl-no-asm.
Please refer to BUILDING.md
2022-02-16 18:34:24 +08:00
|
|
|
NODE_BUILD_CACHE_PATH="${NODE_BUILD_CACHE_PATH:-$ASDF_DOWNLOAD_PATH}" \
|
2021-12-17 08:10:58 +08:00
|
|
|
nodebuild_wrapped ${args+"${args[@]}"} "$version" "$install_path"
|
2020-10-03 00:11:26 +08:00
|
|
|
}
|
|
|
|
|
2024-07-30 23:17:56 +08:00
|
|
|
_run_for_installation() {
|
|
|
|
(
|
|
|
|
if [ -r "$ASDF_NODEJS_PLUGIN_DIR/bin/exec-env" ]; then
|
|
|
|
. "$ASDF_NODEJS_PLUGIN_DIR/bin/exec-env"
|
|
|
|
fi
|
|
|
|
|
|
|
|
env PATH="$ASDF_INSTALL_PATH/bin:$PATH" "$@"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-11-24 10:08:14 +08:00
|
|
|
|
2017-07-31 12:37:03 +08:00
|
|
|
install_default_npm_packages() {
|
2022-02-10 09:29:34 +08:00
|
|
|
local default_npm_packages_file="${ASDF_NPM_DEFAULT_PACKAGES_FILE:=$HOME/.default-npm-packages}" filtered_packages=
|
2017-07-31 12:37:03 +08:00
|
|
|
|
2022-02-10 09:29:34 +08:00
|
|
|
if ! [ -f "$default_npm_packages_file" ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
filtered_packages=$(grep -vE "^\s*#" < "$default_npm_packages_file")
|
|
|
|
|
2022-03-11 22:25:24 +08:00
|
|
|
if [ "${filtered_packages-}" ]; then
|
2022-02-10 09:29:34 +08:00
|
|
|
printf "$(colored $CYAN "Installing the following default packages globally: ")"
|
|
|
|
xargs printf "%s, " <<< "$filtered_packages"
|
|
|
|
printf "\x8\x8 \n" # Cleanup last comma
|
2017-07-31 12:37:03 +08:00
|
|
|
|
2024-07-30 23:17:56 +08:00
|
|
|
_run_for_installation xargs npm install -g <<< "$filtered_packages"
|
|
|
|
fi
|
|
|
|
}
|
2022-02-10 09:29:34 +08:00
|
|
|
|
2024-07-30 23:17:56 +08:00
|
|
|
enable_corepack() {
|
|
|
|
if [ "${ASDF_NODEJS_AUTO_ENABLE_COREPACK-}" ]; then
|
|
|
|
_run_for_installation corepack enable
|
2022-02-10 09:29:34 +08:00
|
|
|
fi
|
2017-07-31 12:37:03 +08:00
|
|
|
}
|
2017-02-13 03:44:21 +08:00
|
|
|
|
2021-11-24 10:08:14 +08:00
|
|
|
install_nodejs "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
|
2022-02-10 09:29:34 +08:00
|
|
|
|
|
|
|
install_default_npm_packages \
|
|
|
|
|| printf "\n$(colored $YELLOW WARNING:) An error occurred when installing the default npm packages, but Node's installation succeeded\n"
|
2020-01-14 22:54:24 +08:00
|
|
|
|
2024-07-30 23:17:56 +08:00
|
|
|
enable_corepack \
|
|
|
|
|| printf "\n$(colored $YELLOW WARNING:) An error occurred while enabling corepack for this version\n"
|
|
|
|
|
2020-01-14 22:54:24 +08:00
|
|
|
asdf reshim "$(plugin_name)" "$ASDF_INSTALL_VERSION"
|