From 800e244e784999fd80c66d72babf4bcc8112a5b3 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Tue, 23 Nov 2021 21:23:30 -0300 Subject: [PATCH 01/15] feat: add commands for managing an internal node-build installation --- .gitignore | 2 ++ lib/commands/command-nodebuild.bash | 32 ++++++++++++++++++++++ lib/commands/command-update-nodebuild.bash | 28 +++++++++++++++++++ lib/utils.sh | 10 ++++--- 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 lib/commands/command-nodebuild.bash create mode 100755 lib/commands/command-update-nodebuild.bash diff --git a/.gitignore b/.gitignore index f38630c..3ac0283 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,5 @@ $RECYCLE.BIN/ *.lnk # End of https://www.toptal.com/developers/gitignore/api/linux,macos,windows + +.node-build diff --git a/lib/commands/command-nodebuild.bash b/lib/commands/command-nodebuild.bash new file mode 100644 index 0000000..aa46936 --- /dev/null +++ b/lib/commands/command-nodebuild.bash @@ -0,0 +1,32 @@ +#! /usr/bin/env bash + +set -eu -o pipefail + +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../utils.sh" + +: "${ASDF_NODEJS_NODEBUILD_HOME=$ASDF_NODEJS_PLUGIN_DIR/.node-build}" + +# node-build environment variables being overriden by asdf-nodejs +export NODE_BUILD_CACHE_PATH="${NODE_BUILD_CACHE_PATH:-$ASDF_NODEJS_CACHE_DIR/node-build}" + +if [ "$NODEJS_ORG_MIRROR" ]; then + export NODE_BUILD_MIRROR_URL="$NODEJS_ORG_MIRROR" +fi + +if [ "${ASDF_CONCURRENCY-}" ]; then + export MAKE_OPTS="${MAKE_OPTS:-} -j \"$ASDF_CONCURRENCY\"" +fi + +nodebuild="${ASDF_NODEJS_NODEBUILD:-$ASDF_NODEJS_NODEBUILD_HOME/bin/node-build}" + +if ! [ -x "$nodebuild" ]; then + printf "Binary for node-build not found\n" + + if ! [ "$ASDF_NODEJS_NODEBUILD" ]; then + printf "Are you sure it was installed? Try running \`asdf %s update-nodebuild\` to do a local update or install\n" "$(plugin_name)" + fi + + exit 1 +fi + +exec "$nodebuild" "$@" diff --git a/lib/commands/command-update-nodebuild.bash b/lib/commands/command-update-nodebuild.bash new file mode 100755 index 0000000..e1137a0 --- /dev/null +++ b/lib/commands/command-update-nodebuild.bash @@ -0,0 +1,28 @@ +#! /usr/bin/env bash + +set -eu -o pipefail + +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../utils.sh" + +: "${ASDF_NODEJS_NODEBUILD_HOME=$ASDF_NODEJS_PLUGIN_DIR/.node-build}" +: "${ASDF_NODEJS_NODEBUILD_REPOSITORY=https://github.com/nodenv/node-build.git}" + +ensure_updated_project() { + local pull_exit_code= + + if ! [ -d "$ASDF_NODEJS_NODEBUILD_HOME" ]; then + printf "Cloning node-build...\n" + git clone "$ASDF_NODEJS_NODEBUILD_REPOSITORY" "$ASDF_NODEJS_NODEBUILD_HOME" + else + printf "Trying to update node-build...\n" + git -C "$ASDF_NODEJS_NODEBUILD_HOME" pull origin master || pull_exit_code=$? + + if [ "$pull_exit_code" ]; then + printf "ERROR: Updating the node-build repository exited with code %s\n" "$pull_exit_code" + printf "Please check if the git repository at %s doesn't have any changes or anything that might not allow a git pull\n" "$ASDF_NODEJS_NODEBUILD_REPOSITORY" + exit 1 + fi + fi +} + +ensure_updated_project diff --git a/lib/utils.sh b/lib/utils.sh index 4540575..5b3dd46 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -10,15 +10,17 @@ fi ASDF_NODEJS_KEYRING=asdf-nodejs.gpg -ASDF_NODEJS_PLUGIN_NAME="$(basename "$(dirname "$(dirname "$0")")")" +export ASDF_NODEJS_PLUGIN_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) + # TODO: Replace with an asdf variable once asdf starts providing the plugin name # as a variable +export ASDF_NODEJS_PLUGIN_NAME=$(basename "$ASDF_NODEJS_PLUGIN_DIR") plugin_name() { printf "%s\n" "$ASDF_NODEJS_PLUGIN_NAME" } -ASDF_DIR="${ASDF_DIR:-$HOME/.asdf}" -export ASDF_NODEJS_PLUGIN_NAME ASDF_DIR +export ASDF_NODEJS_CACHE_DIR="${ASDF_DATA_DIR:-${ASDF_DIR:-$HOME/.asdf}}/tmp/$ASDF_NODEJS_PLUGIN_NAME/cache" +export ASDF_DIR="${ASDF_DIR:-$HOME/.asdf}" die() { >&2 echo "$@" @@ -61,7 +63,7 @@ filter_version_candidates() { done } -versions_cache_dir="${ASDF_DATA_DIR:-${ASDF_HOME:-$HOME/.asdf}}/tmp/$(plugin_name)/cache" +versions_cache_dir="$ASDF_NODEJS_CACHE_DIR/versions-tab" mkdir -p "$versions_cache_dir" etag_file="$versions_cache_dir/etag" From c4e335f872b248b6578cdc56bfdeeafb831c7721 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Tue, 23 Nov 2021 23:08:14 -0300 Subject: [PATCH 02/15] feat: modify install to use node-build behind the scenes --- bin/install | 304 +++------------------------- lib/commands/command-nodebuild.bash | 14 +- 2 files changed, 37 insertions(+), 281 deletions(-) mode change 100644 => 100755 lib/commands/command-nodebuild.bash diff --git a/bin/install b/bin/install index b7cd160..078ca26 100755 --- a/bin/install +++ b/bin/install @@ -1,85 +1,48 @@ #!/usr/bin/env bash -set -o nounset -o pipefail -o errexit +set -eu -o pipefail # shellcheck source=../lib/utils.sh -source "$(dirname "$0")/../lib/utils.sh" - -NODEJS_CHECK_SIGNATURES="${NODEJS_CHECK_SIGNATURES:-strict}" - +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../lib/utils.sh" install_nodejs() { - local install_type="$1" - local version_query="$2" - local install_path="$3" - local tmp_download_dir="$4" + local install_type="$1" version_query="$2" install_path="$3" + local version= - local version="$(resolve_version_query "$version_query")" + version="$(resolve_version_query "$version_query")" if [ "$version" != "$version_query" ]; then - install_aliased_version "$version" "$version_query" "$install_path" + install_aliased_version "$version" "$version_query" "$install_path" else - install_canon_version "$1" "$version" "$3" "$4" + install_canon_version "$install_type" "$version" "$install_path" fi } +ensure_nodebuild_updated() { + "$ASDF_NODEJS_PLUGIN_DIR/lib/commands/command-update-nodebuild.bash" +} + + +nodebuild_wrapped() { + "$ASDF_NODEJS_PLUGIN_DIR/lib/commands/command-nodebuild.bash" "$@" +} + + install_canon_version() { - local install_type="$1" - local version="$2" - local install_path="$3" - local tmp_download_dir="$4" - local make_flags="-j${ASDF_CONCURRENCY-1}" + local install_type="$1" version="$2" install_path="$3" + local nodebuild_args=() - ## Do this first as it is fast but could fail. - download_and_verify_checksums "$install_type" "$version" "$tmp_download_dir" - - local archive_path - archive_path="${tmp_download_dir}/$(get_archive_file_name "$install_type" "$version")" - - local download_result=0 - download_file "$(get_download_url "$install_type" "$version")" "${archive_path}" \ - || download_result=$? - - if [ $download_result != 0 ]; then - if [ "$install_type" = "ref" ]; then - die "Source code not found for version $version" - fi - - echo "Binary not found for version $version. Falling back to source code" - install_type="ref" - - download_file "$(get_download_url "$install_type" "$version")" "${archive_path}" \ - || die "Source code not found for version $version" - else - verify_archive "$tmp_download_dir" + if [ "$install_type" = ref ]; then + nodebuild_args+=(-c) fi - # running this in a subshell - # we don't want to disturb current working dir - ( - if [ "$install_type" != "version" ]; then - tar zxf "$archive_path" -C "$install_path" --strip-components=1 || exit 1 - cd "$install_path" || exit 1 - - local configure_options - configure_options="$(construct_configure_options "$install_path")" - - # shellcheck disable=SC2086 - ./configure $configure_options || exit 1 - make $make_flags || exit 1 - make $make_flags install || exit 1 - - if [ $? -ne 0 ]; then - rm -rf "$install_path" - exit 1 - fi - else - tar zxf "$archive_path" -C "$install_path" --strip-components=1 || exit 1 - fi - ) + ensure_nodebuild_updated + NODE_BUILD_BUILD_PATH="$ASDF_DOWNLOAD_PATH" \ + nodebuild_wrapped -v "${nodebuild_args[@]}" "$version" "$install_path" } + install_aliased_version() { local version=$1 local version_query=$2 @@ -118,216 +81,6 @@ resolve_version_query() { } -construct_configure_options() { - local install_path="$1" - - if [ -z "${NODEJS_CONFIGURE_OPTIONS:-}" ]; then - local configure_options - configure_options="--dest-cpu=$(get_nodejs_machine_hardware_name)" - - if [ "${NODEJS_EXTRA_CONFIGURE_OPTIONS:-}" != "" ]; then - configure_options="$configure_options ${NODEJS_EXTRA_CONFIGURE_OPTIONS:-}" - fi - else - local configure_options="${NODEJS_CONFIGURE_OPTIONS:-}" - fi - - configure_options="$configure_options --prefix=$install_path" - - echo "$configure_options" -} - - -get_nodejs_machine_hardware_name() { - local machine_hardware_name - machine_hardware_name="$(uname -m)" - - case "$machine_hardware_name" in - 'x86_64') local cpu_type="x64";; - # For FreeBSD - 'amd64') local cpu_type="x64";; - 'i686') local cpu_type="x86";; - 'aarch64') local cpu_type="arm64";; - *) local cpu_type="$machine_hardware_name";; - esac - - echo "$cpu_type" -} - - -download_file() { - local download_url="$1" - local download_path="$2" - - STATUSCODE=$(curl --write-out "%{http_code}" -Lo "$download_path" "$download_url") - - if test $STATUSCODE -eq 404; then - return 1 - fi -} - - -get_archive_file_name() { - local install_type="$1" - local version="$2" - - local pkg_name - - if [ "$install_type" = "version" ]; then - pkg_name="node-v${version}-$(uname -s | tr '[:upper:]' '[:lower:]')-$(get_nodejs_machine_hardware_name)" - else - pkg_name="v${version}" - fi - - echo "${pkg_name}.tar.gz" -} - - -get_download_url() { - local install_type="$1" - local version="$2" - - if [ "$install_type" = "version" ]; then - local download_url_base="${NODEJS_ORG_MIRROR}v${version}" - else - local download_url_base="https://github.com/nodejs/node/archive" - fi - - echo "${download_url_base}/$(get_archive_file_name "$install_type" "$version")" -} - - -get_signed_checksum_download_url() { - local install_type=$1 - local version=$2 - - if [ "$install_type" = "version" ]; then - echo "${NODEJS_ORG_MIRROR}v${version}/SHASUMS256.txt.asc" - else - # Not implemented. - exit 1 - fi -} - - -download_and_verify_checksums() { - local install_type="$1" - local version="$2" - local tmp_download_dir="$3" - - if [ "${NODEJS_CHECK_SIGNATURES}" == "no" ]; then - return 0 - fi - - ## Seems nodejs.org started with around 0.10.0 to release properly signed SHA2-256 checksum files. - if verlte "0.10.0" "$version" - then - local signed_checksum_file="$tmp_download_dir/SHASUMS256.txt.asc" - local signed_checksum_download_url - signed_checksum_download_url="$(get_signed_checksum_download_url "$install_type" "$version")" - if [ -z "${signed_checksum_download_url}" ]; then - if [ "${NODEJS_CHECK_SIGNATURES}" == "strict" ]; then - echo "$version did not provide signed checksums or support for them has not been implemented and NODEJS_CHECK_SIGNATURES=strict is set. Exiting." >&2 - exit 1 - else - echo "$version did not provide signed checksums or support for them has not been implemented. Continue without signature checking." >&2 - return 0 - fi - fi - - download_file "${signed_checksum_download_url}" "$signed_checksum_file" \ - || die "Checksum not found for version $version" - - local gnugp_verify_command_name - gnugp_verify_command_name="$(command -v gpg gpg2 | head -n 1 || :)" - if [ -z "${gnugp_verify_command_name}" ]; then - echo "You must install GnuPG to verify the authenticity of the downloaded archives before continuing with the install: https://www.gnupg.org/" >&2 - exit 1 - fi - - ( - if [ -z "${GNUPGHOME:-}" ] && [ -d "${ASDF_DIR:-$HOME/.asdf}/keyrings/nodejs" ]; then - export GNUPGHOME="${ASDF_DIR:-$HOME/.asdf}/keyrings/nodejs" - fi - - # Automatically add needed PGP keys - "$(dirname "$0")/import-release-team-keyring" - - if ! $gnugp_verify_command_name --no-default-keyring --keyring "${ASDF_NODEJS_KEYRING}" --display-charset utf-8 --verify "$signed_checksum_file" 2>/dev/null; then - # Try default keyring - if ! $gnugp_verify_command_name --display-charset utf-8 --verify "$signed_checksum_file" 2>/dev/null; then - echo "Authenticity of checksum file can not be assured! Please be sure to check the README of asdf-nodejs in case you did not yet import the needed PGP keys. Also, make sure the plugin is up-to-date by running \`asdf plugin update $(plugin_name)\`. If you already did that then that is the point to become SUSPICIOUS! There must be a reason why this is failing. If you are installing an older NodeJS version you might need to import OpenPGP keys of previous release managers. Exiting." >&2 - exit 1 - fi - fi - ## Mitigates: https://github.com/nodejs/node/issues/6821 - local authentic_checksum_file="$tmp_download_dir/authentic_SHASUMS256.txt" - $gnugp_verify_command_name --no-default-keyring --keyring "${ASDF_NODEJS_KEYRING}" --yes --output "${authentic_checksum_file}" --decrypt "$signed_checksum_file" 2>/dev/null || - $gnugp_verify_command_name --yes --output "${authentic_checksum_file}" --decrypt "$signed_checksum_file" 2>/dev/null - ) - elif [ "${NODEJS_CHECK_SIGNATURES}" == "strict" ]; then - echo "$version did not provide signed checksums or support for them has not been implemented and NODEJS_CHECK_SIGNATURES=strict is set. Exiting." >&2 - exit 1 - fi -} - -checkShasum () -{ - local archive_file_name="${1}" - local authentic_checksum_file="${2}" - - if $(command -v sha256sum >/dev/null 2>&1); then - sha256sum \ - -c <(grep "\s${archive_file_name}$" "${authentic_checksum_file}") - elif $(command -v shasum >/dev/null 2>&1); then - shasum \ - -a 256 \ - -c <(grep "\s${archive_file_name}$" "${authentic_checksum_file}") - else - echo "sha256sum or shasum is not available for use" >&2 - return 1 - fi -} - -verify_archive() { - local tmp_download_dir="$1" - - local authentic_checksum_file="$tmp_download_dir/authentic_SHASUMS256.txt" - - if [ "${NODEJS_CHECK_SIGNATURES}" == "no" ]; then - return 0 - fi - - if [ "${NODEJS_CHECK_SIGNATURES}" == "yes" ] && [ ! -e "${authentic_checksum_file}" ]; then - return 0 - fi - - if verlte "0.10.0" "$version" - then - local archive_file_name - archive_file_name="$(basename "$(get_download_url "$install_type" "$version")")" - - ( - cd "${tmp_download_dir}" - if ! checkShasum "$archive_file_name" "$authentic_checksum_file"; then - echo "Authenticity of package archive can not be assured. Exiting." >&2 - exit 1 - fi - ) - fi -} - -# stolen from https://github.com/rbenv/ruby-build/pull/631/files#diff-fdcfb8a18714b33b07529b7d02b54f1dR942 -function sort_versions() { - sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | \ - LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}' -} - -verlte() { - ## https://stackoverflow.com/questions/4023830/how-compare-two-strings-in-dot-separated-version-format-in-bash/4024263#4024263 - [ "$1" = "$(echo -e "$1\n$2" | sort_versions | head -n1)" ] -} - install_default_npm_packages() { local default_npm_packages="${ASDF_NPM_DEFAULT_PACKAGES_FILE:=$HOME/.default-npm-packages}" @@ -345,10 +98,7 @@ install_default_npm_packages() { done } -tmp_download_dir="$(mktemp -d -t 'asdf_nodejs_XXXXXX')" -trap 'rm -rf "${tmp_download_dir}"' EXIT - -install_nodejs "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH" "$tmp_download_dir" -ASDF_SKIP_RESHIM=1 install_default_npm_packages +install_nodejs "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH" +install_default_npm_packages asdf reshim "$(plugin_name)" "$ASDF_INSTALL_VERSION" diff --git a/lib/commands/command-nodebuild.bash b/lib/commands/command-nodebuild.bash old mode 100644 new mode 100755 index aa46936..b1299e5 --- a/lib/commands/command-nodebuild.bash +++ b/lib/commands/command-nodebuild.bash @@ -13,20 +13,26 @@ if [ "$NODEJS_ORG_MIRROR" ]; then export NODE_BUILD_MIRROR_URL="$NODEJS_ORG_MIRROR" fi -if [ "${ASDF_CONCURRENCY-}" ]; then - export MAKE_OPTS="${MAKE_OPTS:-} -j \"$ASDF_CONCURRENCY\"" +if [[ $ASDF_NODEJS_CONCURRENCY =~ ^[0-9]+$ ]]; then + export MAKE_OPTS="${MAKE_OPTS:-} -j$ASDF_NODEJS_CONCURRENCY" + export NODE_MAKE_OPTS="${NODE_MAKE_OPTS:-} -j$ASDF_NODEJS_CONCURRENCY" fi nodebuild="${ASDF_NODEJS_NODEBUILD:-$ASDF_NODEJS_NODEBUILD_HOME/bin/node-build}" +nodebuild_args=() if ! [ -x "$nodebuild" ]; then printf "Binary for node-build not found\n" - if ! [ "$ASDF_NODEJS_NODEBUILD" ]; then + if ! [ "${ASDF_NODEJS_NODEBUILD-}" ]; then printf "Are you sure it was installed? Try running \`asdf %s update-nodebuild\` to do a local update or install\n" "$(plugin_name)" fi exit 1 fi -exec "$nodebuild" "$@" +if [ "${ASDF_NODEJS_VERBOSE_INSTALL-}" ]; then + nodebuild_args+=(-v) +fi + +exec "$nodebuild" "${nodebuild_args[@]}" "$@" From ee8daa2b75ce1746c19ec46931c698fb25721257 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Tue, 23 Nov 2021 23:35:25 -0300 Subject: [PATCH 03/15] feat: remove previous integrity check logic --- bin/import-previous-release-team-keyring | 38 --------------------- bin/import-release-team-keyring | 43 ------------------------ bin/install | 3 +- lib/commands/command-nodebuild.bash | 2 +- 4 files changed, 3 insertions(+), 83 deletions(-) delete mode 100755 bin/import-previous-release-team-keyring delete mode 100755 bin/import-release-team-keyring diff --git a/bin/import-previous-release-team-keyring b/bin/import-previous-release-team-keyring deleted file mode 100755 index 79302ef..0000000 --- a/bin/import-previous-release-team-keyring +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash - -set -o nounset -o pipefail -o errexit - -## Previous Keys from https://github.com/nodejs/node/#release-keys -KEYS="9554F04D7259F04124DE6B476D5A82AC7E37093B \ - B9AE9905FFD7803F25714661B63B535A4C206CA9 \ - 77984A986EBC2AA786BC0F66B01FBB92821C587A \ - 93C7E9E91B49E432C2F75674B0A78B0A6C481CF6 \ - 56730D5401028683275BD23C23EFEFE93C4CFFFE \ - FD3A5288F042B6850C66B31F09FE44734EB7990E \ - 114F43EE0176B71C7BC219DD50A3051F888C628D \ - 7937DFD2AB06298B2293C3187D33FF9D0246406D \ - 1C050899334244A8AF75E53792EF661D867B9DFA" - -SERVERS="keyserver.ubuntu.com - keyserver.ubuntu.com:80 \ - pgp.mit.edu - pgp.mit.edu:80" - -OPTIONS="" -if [ -v http_proxy ]; -then OPTIONS="--keyserver-options http-proxy=$http_proxy"; -fi - -gnugp_verify_command_name="$(command -v gpg gpg2 | head -n 1 || :)" - -if [ -z "${gnugp_verify_command_name}" ]; then - echo 'gpg or gpg2 command not found!' >&2 - echo "You must install GnuPG to import release team keys: https://www.gnupg.org/" >&2 - exit 1 -fi - -for key in $KEYS; do - for server in $SERVERS; do - $gnugp_verify_command_name --no-tty --keyserver "hkp://$server" $OPTIONS --display-charset utf-8 --recv-keys "$key" && break - done -done diff --git a/bin/import-release-team-keyring b/bin/import-release-team-keyring deleted file mode 100755 index 9da8f74..0000000 --- a/bin/import-release-team-keyring +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash - -set -o nounset -o pipefail -o errexit - -source "$(dirname "$0")/../lib/utils.sh" - -## Keys from https://github.com/nodejs/node/#release-keys -KEYS="4ED778F539E3634C779C87C6D7062848A1AB005C \ - 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \ - 74F12602B6F1C4E913FAA37AD3A89613643B6201 \ - 71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \ - 8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \ - C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \ - C82FA3AE1CBEDC6BE46B9360C43CEC45C17AB93C \ - DD8F2338BAE7501E3DD5AC78C273792F7D83545D \ - A48C2BEE680E841632CD4E44F07496B3EB3C1762 \ - 108F52B48DB57BB0CC439B2997B01419BD92F80A \ - B9E2F5981AA6E0CD28160D9FF13993A75599653C" - -SERVERS="keyserver.ubuntu.com - keyserver.ubuntu.com:80 \ - pgp.mit.edu - pgp.mit.edu:80" - -OPTIONS="" -if [ -n "${http_proxy:-}" ]; - then OPTIONS="--keyserver-options http-proxy=$http_proxy"; -fi - -gnugp_verify_command_name="$(command -v gpg gpg2 | head -n 1 || :)" - -if [ -z "${gnugp_verify_command_name}" ]; then - echo 'gpg or gpg2 command not found!' >&2 - echo "You must install GnuPG to import release team keys: https://www.gnupg.org/" >&2 - exit 1 -fi - -for key in $KEYS; do - for server in $SERVERS; do - $gnugp_verify_command_name --with-colons --no-default-keyring --keyring ${ASDF_NODEJS_KEYRING} -k $key > /dev/null 2>&1 || \ - $gnugp_verify_command_name --no-default-keyring --keyring ${ASDF_NODEJS_KEYRING} --no-tty --keyserver "hkp://$server" $OPTIONS --display-charset utf-8 --recv-keys "$key" && break - done -done diff --git a/bin/install b/bin/install index 078ca26..fe88e53 100755 --- a/bin/install +++ b/bin/install @@ -38,7 +38,8 @@ install_canon_version() { fi ensure_nodebuild_updated - NODE_BUILD_BUILD_PATH="$ASDF_DOWNLOAD_PATH" \ + + NODE_BUILD_BUILD_PATH="$ASDF_DOWNLOAD_PATH" NODE_BUILD_CACHE_PATH="$ASDF_DOWNLOAD_PATH" \ nodebuild_wrapped -v "${nodebuild_args[@]}" "$version" "$install_path" } diff --git a/lib/commands/command-nodebuild.bash b/lib/commands/command-nodebuild.bash index b1299e5..feae7ff 100755 --- a/lib/commands/command-nodebuild.bash +++ b/lib/commands/command-nodebuild.bash @@ -13,7 +13,7 @@ if [ "$NODEJS_ORG_MIRROR" ]; then export NODE_BUILD_MIRROR_URL="$NODEJS_ORG_MIRROR" fi -if [[ $ASDF_NODEJS_CONCURRENCY =~ ^[0-9]+$ ]]; then +if [[ "${ASDF_NODEJS_CONCURRENCY-}" =~ ^[0-9]+$ ]]; then export MAKE_OPTS="${MAKE_OPTS:-} -j$ASDF_NODEJS_CONCURRENCY" export NODE_MAKE_OPTS="${NODE_MAKE_OPTS:-} -j$ASDF_NODEJS_CONCURRENCY" fi From 67c382b8a28a18f5fcccff11243faef311b50a81 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Wed, 24 Nov 2021 00:20:25 -0300 Subject: [PATCH 04/15] docs: update README com new information about installation --- README.md | 87 +++++++---------------------- bin/install | 2 +- lib/commands/command-nodebuild.bash | 1 + 3 files changed, 23 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index e94ae80..ef96405 100644 --- a/README.md +++ b/README.md @@ -4,23 +4,6 @@ Node.js plugin for [asdf](https://github.com/asdf-vm/asdf) version manager -*The plugin properly validates OpenPGP signatures to check the authenticity of the package. Requires `gpg` to be available during package installs* - -## Requirements - - -### macOS -* [GnuPG](http://www.gnupg.org) - `brew install gpg` -* awk - any posix compliant implementation (tested on gawk `brew install gawk`) - -### Linux (Debian) - -* [dirmngr](https://packages.debian.org/sid/dirmngr) - `apt-get install - dirmngr` -* [GnuPG](http://www.gnupg.org) - `apt-get install gpg` -* [curl](https://curl.haxx.se) - `apt-get install curl` -* awk - any posix compliant implementation (tested on gawk `apt-get install gawk`) - ## Install After installing [asdf](https://github.com/asdf-vm/asdf), install the plugin by running: @@ -31,16 +14,29 @@ asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git ## Use -Check [asdf](https://github.com/asdf-vm/asdf) readme for instructions on how to install & manage versions of Node.js. +Check [asdf](https://github.com/asdf-vm/asdf) readme for instructions on how to install & manage versions of Node.js at a system and project level. -When installing Node.js using `asdf install`, you can pass custom configure options with the following env vars: +Behind the scenes, `asdf-nodejs` utilizes [`node-build`](https://github.com/nodenv/node-build) to install pre-compiled binaries and compile from source if necessary. You can check its [README](https://github.com/nodenv/node-build/blob/master/README.md) for more compile settings and troubleshooting. -* `NODEJS_CONFIGURE_OPTIONS` - use only your configure options -* `NODEJS_EXTRA_CONFIGURE_OPTIONS` - append these configure options along with ones that this plugin already uses -* `NODEJS_CHECK_SIGNATURES` - `strict` is default. Other values are `no` and `yes`. Checks downloads against OpenPGP signatures from the Node.js release team. -* `NODEJS_ORG_MIRROR` - official mirror `https://nodejs.org/dist/` is default. If you are in China, you can set it to `https://npm.taobao.org/mirrors/node/`. +When compiling a version from source, you are going to need to install [all requirements for compiling Node.js](https://github.com/nodejs/node/blob/master/BUILDING.md#building-nodejs-on-supported-platforms) (be advised that different versions might require different configurations). That being said, `node-build` does a great job at handling edge cases and compilations rarely need a deep investigation. -### `.nvmrc` and `.node-version` files +### Configuration + +Aside from the [common configuration with `node-build`](https://github.com/nodenv/node-build#custom-build-configuration), `asdf-nodejs` has a few extra environment variables for configuration. + +| Variable | Function | +| --------| ---| +- `ASDF_NODEJS_NODEBUILD_HOME`: Home for the node-build installation, defaults to `$ASDF_DIR/plugins/nodejs/.node-build`, you can install it in another place or share it with your system +- `ASDF_NODEJS_NODEBUILD`: Path to the node-build executable, defaults to `$NODE_BUILD_MIRROR_URL/bin/node-build` +- `ASDF_NODEJS_CONCURRENCY`: How many jobs should be used in compilation. Defaults to half the computer cores +- `ASDF_NODEJS_VERBOSE_INSTALL`: Enables verbose output for downloading and building. Any value different from empty is treated as enabled. +- `NODEJS_ORG_MIRROR`: (Legacy) overrides the default mirror used for downloading the distibutions, alternative to the `NODE_BUILD_MIRROR_URL` node-build env var + +### Integrity/signature check + +In the past `asdf-nodejs` checked for signatures and integrity on our own. `node-build` checks integrity by precomputing checksums ahead of time and versioning them together with the instructions for building them. + +### `.nvmrc` and `.node-version` support asdf uses the `.tool-versions` for auto-switching between software versions. To ease migration, you can have it read an existing `.nvmrc` or `.node-version` file to find out what version of Node.js should be used. To do this, add the following to `$HOME/.asdfrc`: @@ -50,7 +46,7 @@ legacy_version_file = yes ## Default npm Packages -asdf-nodejs can automatically install a set of default set of npm package right after installing a Node.js version. To enable this feature, provide a `$HOME/.default-npm-packages` file that lists one package per line, for example: +`asdf-nodejs` can automatically install a set of default set of npm package right after installing a Node.js version. To enable this feature, provide a `$HOME/.default-npm-packages` file that lists one package per line, for example: ``` lodash @@ -59,44 +55,3 @@ express ``` You can specify a non-default location of this file by setting a `ASDF_NPM_DEFAULT_PACKAGES_FILE` variable. - -## Problems with OpenPGP signatures in older versions - -The plugin automatically imports the NodeJS release team's OpenPGP keys. If you are trying to install a previous release and facing any issue about verification, import the Node.js previous release team's OpenPGP keys to main keyring: - -```bash -bash -c '${ASDF_DATA_DIR:=$HOME/.asdf}/plugins/nodejs/bin/import-previous-release-team-keyring' -``` - -## Using a dedicated OpenPGP keyring - -The `bash` script mentioned in [the installation instructions](#install) (`import-release-team-keyring`) imports the OpenPGP public keys in your main OpenPGP keyring. However, you can also use a dedicated keyring in order to mitigate [this issue](https://github.com/nodejs/node/issues/9859). - -To use a dedicated keyring, prepare the dedicated keyring and set it as the default keyring in the current shell: - -```bash -export GNUPGHOME="${ASDF_DIR:-$HOME/.asdf}/keyrings/nodejs" && mkdir -p "$GNUPGHOME" && chmod 0700 "$GNUPGHOME" - -# Imports Node.js release team's OpenPGP keys to the keyring -bash ~/.asdf/plugins/nodejs/bin/import-release-team-keyring -``` - -Again, if you used `brew` to manage the `asdf` installation use the following bash commands: - -```bash -export GNUPGHOME="bash /usr/local/opt/asdf/keyrings/nodejs" && mkdir -p "$GNUPGHOME" && chmod 0700 "$GNUPGHOME" - -# Imports Node.js release team's OpenPGP keys to the keyring -bash /usr/local/opt/asdf/plugins/nodejs/bin/import-release-team-keyring -``` - -#### Related notes - -* [Verifying Node.js Binaries](https://github.com/nodejs/node#verifying-binaries). -* Only versions `>=0.10.0` are checked. Before that version, signatures for SHA2-256 hashes might not be provided (and can not be installed with the `strict` setting for that reason). - -This behavior can be influenced by the `NODEJS_CHECK_SIGNATURES` env var which supports the following options: - -* `strict` - (default): Check signatures/checksums and don’t operate on package versions which did not provide signatures/checksums properly (< 0.10.0). -* `no` - Do not check signatures/checksums -* `yes`- Check signatures/checksums if they should be present (enforced for >= 0.10.0) diff --git a/bin/install b/bin/install index fe88e53..d9eb2de 100755 --- a/bin/install +++ b/bin/install @@ -40,7 +40,7 @@ install_canon_version() { ensure_nodebuild_updated NODE_BUILD_BUILD_PATH="$ASDF_DOWNLOAD_PATH" NODE_BUILD_CACHE_PATH="$ASDF_DOWNLOAD_PATH" \ - nodebuild_wrapped -v "${nodebuild_args[@]}" "$version" "$install_path" + nodebuild_wrapped "${nodebuild_args[@]}" "$version" "$install_path" } diff --git a/lib/commands/command-nodebuild.bash b/lib/commands/command-nodebuild.bash index feae7ff..a353c2d 100755 --- a/lib/commands/command-nodebuild.bash +++ b/lib/commands/command-nodebuild.bash @@ -5,6 +5,7 @@ set -eu -o pipefail source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../utils.sh" : "${ASDF_NODEJS_NODEBUILD_HOME=$ASDF_NODEJS_PLUGIN_DIR/.node-build}" +: "${ASDF_NODEJS_CONCURRENCY=$(($ASDF_CONCURRENCY / 2))}" # node-build environment variables being overriden by asdf-nodejs export NODE_BUILD_CACHE_PATH="${NODE_BUILD_CACHE_PATH:-$ASDF_NODEJS_CACHE_DIR/node-build}" From 94bd796e023b2fd6f3edf5f94df777077ab84181 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Mon, 29 Nov 2021 12:48:06 -0300 Subject: [PATCH 05/15] docs: add information on nodebuild commands --- README.md | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ef96405..6952908 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,6 @@ When compiling a version from source, you are going to need to install [all requ Aside from the [common configuration with `node-build`](https://github.com/nodenv/node-build#custom-build-configuration), `asdf-nodejs` has a few extra environment variables for configuration. -| Variable | Function | -| --------| ---| - `ASDF_NODEJS_NODEBUILD_HOME`: Home for the node-build installation, defaults to `$ASDF_DIR/plugins/nodejs/.node-build`, you can install it in another place or share it with your system - `ASDF_NODEJS_NODEBUILD`: Path to the node-build executable, defaults to `$NODE_BUILD_MIRROR_URL/bin/node-build` - `ASDF_NODEJS_CONCURRENCY`: How many jobs should be used in compilation. Defaults to half the computer cores @@ -44,6 +42,28 @@ asdf uses the `.tool-versions` for auto-switching between software versions. To legacy_version_file = yes ``` +### Updating node-build defitions + +Every new node version needs to have a definition file in the `node-build` repository. Because of that, `asdf-nodejs` tries to update the local `node-build` repository at every install command to download definitions for newly added versions. + +We provide a command for manually updating `node-build` at your own time: + +```bash +asdf nodejs update-nodebuild +``` + +### node-build advanced variations + +`node-build` has some additional variations aside from the versions listed in `asdf list-all nodejs` (chakracore/graalvm branches and some others). As of now, we weakly support these variations because they are available for install and can be used in a `.tool-versions` file, but we don't list them as installation candidates nor give full support. Some of them will work out of the box, and some others will need a bit of investigation to get them built. We are planning in providing better support for these variations in the future. + +To list all the available variations run: + +``` bash +asdf nodejs nodebuild --definitions +``` + +*Note that this command only lists the current `node-build` definitions. You might want to [update the local `node-build` repository](#updating-node-build-definitions) before listing them.* + ## Default npm Packages `asdf-nodejs` can automatically install a set of default set of npm package right after installing a Node.js version. To enable this feature, provide a `$HOME/.default-npm-packages` file that lists one package per line, for example: From 1a70296fdc9eb399db3e75d256de4bbd1366a711 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Mon, 29 Nov 2021 12:48:30 -0300 Subject: [PATCH 06/15] fix: add correct default for concurrency --- lib/commands/command-nodebuild.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/commands/command-nodebuild.bash b/lib/commands/command-nodebuild.bash index a353c2d..2b1b8bb 100755 --- a/lib/commands/command-nodebuild.bash +++ b/lib/commands/command-nodebuild.bash @@ -4,8 +4,10 @@ set -eu -o pipefail source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../utils.sh" +DEFAULT_CONCURRENCY=$(bc <<< "scale=0; (${ASDF_CONCURRENCY-1} + 1) / 2") + : "${ASDF_NODEJS_NODEBUILD_HOME=$ASDF_NODEJS_PLUGIN_DIR/.node-build}" -: "${ASDF_NODEJS_CONCURRENCY=$(($ASDF_CONCURRENCY / 2))}" +: "${ASDF_NODEJS_CONCURRENCY=$DEFAULT_CONCURRENCY}" # node-build environment variables being overriden by asdf-nodejs export NODE_BUILD_CACHE_PATH="${NODE_BUILD_CACHE_PATH:-$ASDF_NODEJS_CACHE_DIR/node-build}" From 1dd98c407c73578f9cd596a376885321d5309814 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Mon, 29 Nov 2021 12:49:58 -0300 Subject: [PATCH 07/15] typo: change defitions to definitions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6952908..78fa589 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ asdf uses the `.tool-versions` for auto-switching between software versions. To legacy_version_file = yes ``` -### Updating node-build defitions +### Updating node-build definitions Every new node version needs to have a definition file in the `node-build` repository. Because of that, `asdf-nodejs` tries to update the local `node-build` repository at every install command to download definitions for newly added versions. From 07fe573c33bce118698e2ed4219e811eefa6749b Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Mon, 29 Nov 2021 12:53:18 -0300 Subject: [PATCH 08/15] docs: add section for running the wrapped node-build command also some minor text adjustments --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 78fa589..874ad73 100644 --- a/README.md +++ b/README.md @@ -52,9 +52,19 @@ We provide a command for manually updating `node-build` at your own time: asdf nodejs update-nodebuild ``` +### Running the wrapped node-build command + +We provide a command for running the installed `node-build` command: + +```bash +asdf nodejs nodebuild --version +``` + ### node-build advanced variations -`node-build` has some additional variations aside from the versions listed in `asdf list-all nodejs` (chakracore/graalvm branches and some others). As of now, we weakly support these variations because they are available for install and can be used in a `.tool-versions` file, but we don't list them as installation candidates nor give full support. Some of them will work out of the box, and some others will need a bit of investigation to get them built. We are planning in providing better support for these variations in the future. +`node-build` has some additional variations aside from the versions listed in `asdf list-all nodejs` (chakracore/graalvm branches and some others). As of now, we weakly support these variations. In the sense that they are available for install and can be used in a `.tool-versions` file, but we don't list them as installation candidates nor give them full attention. + +Some of them will work out of the box, and some will need a bit of investigation to get them built. We are planning in providing better support for these variations in the future. To list all the available variations run: From e2e0db2aad173c29bbb6fe82cd052b7ac8cfefb8 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Mon, 29 Nov 2021 15:00:39 -0300 Subject: [PATCH 09/15] chore: add better error messages --- bin/install | 39 ++++++++++++++-------- lib/commands/command-update-nodebuild.bash | 15 +++++---- lib/utils.sh | 10 ++++-- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/bin/install b/bin/install index d9eb2de..8f51ab4 100755 --- a/bin/install +++ b/bin/install @@ -19,8 +19,18 @@ install_nodejs() { } -ensure_nodebuild_updated() { - "$ASDF_NODEJS_PLUGIN_DIR/lib/commands/command-update-nodebuild.bash" +try_to_update_nodebuild() { + local exit_code=0 + + "$ASDF_NODEJS_PLUGIN_DIR/lib/commands/command-update-nodebuild.bash" 2> /dev/null || exit_code=$? + + if [ "$exit_code" != 0 ]; then + printf " +%s: Updating node-build failed with exit code %s. The installation will +try to continue with already installed local defintions. To debug what went +wrong try to manually updating node-build by running: \`asdf %s update nodebuild\` +\n" "$(colored $YELLOW WARNING)" "$exit_code" "$ASDF_NODEJS_PLUGIN_NAME" + fi } @@ -37,7 +47,7 @@ install_canon_version() { nodebuild_args+=(-c) fi - ensure_nodebuild_updated + try_to_update_nodebuild NODE_BUILD_BUILD_PATH="$ASDF_DOWNLOAD_PATH" NODE_BUILD_CACHE_PATH="$ASDF_DOWNLOAD_PATH" \ nodebuild_wrapped "${nodebuild_args[@]}" "$version" "$install_path" @@ -84,19 +94,22 @@ resolve_version_query() { install_default_npm_packages() { local default_npm_packages="${ASDF_NPM_DEFAULT_PACKAGES_FILE:=$HOME/.default-npm-packages}" + local name if [ ! -f "$default_npm_packages" ]; then return; fi - cat "$default_npm_packages" | while read -r name; do - echo -ne "\nInstalling \033[33m${name}\033[39m npm package... " - source "$(dirname "$0")/exec-env" - PATH="$ASDF_INSTALL_PATH/bin:$PATH" npm install -g "$name" > /dev/null 2>&1 && rc=$? || rc=$? - if [[ $rc -eq 0 ]]; then - echo -e "\033[32mSUCCESS\033[39m" - else - echo -e "\033[31mFAIL\033[39m" - fi - done + while read -r name; do + ( + printf "Installing $(colord $YELLOW %s) npm package...\n" "$name" + source "$(dirname "$0")/exec-env" + PATH="$ASDF_INSTALL_PATH/bin:$PATH" npm install -g "$name" > /dev/null 2>&1 && rc=$? || rc=$? + if [[ $rc -eq 0 ]]; then + printf "$(colored $GREEN SUCCESS)\n" + else + printf "$(colored $RED FAIL)\n" + fi + ) + done < "$default_npm_packages" } install_nodejs "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH" diff --git a/lib/commands/command-update-nodebuild.bash b/lib/commands/command-update-nodebuild.bash index e1137a0..5bd799b 100755 --- a/lib/commands/command-update-nodebuild.bash +++ b/lib/commands/command-update-nodebuild.bash @@ -8,20 +8,23 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../utils.sh" : "${ASDF_NODEJS_NODEBUILD_REPOSITORY=https://github.com/nodenv/node-build.git}" ensure_updated_project() { - local pull_exit_code= + local pull_exit_code=0 output= if ! [ -d "$ASDF_NODEJS_NODEBUILD_HOME" ]; then printf "Cloning node-build...\n" git clone "$ASDF_NODEJS_NODEBUILD_REPOSITORY" "$ASDF_NODEJS_NODEBUILD_HOME" else printf "Trying to update node-build...\n" - git -C "$ASDF_NODEJS_NODEBUILD_HOME" pull origin master || pull_exit_code=$? + output=$(git -C "$ASDF_NODEJS_NODEBUILD_HOME" pull origin master 2>&1) || pull_exit_code=$? - if [ "$pull_exit_code" ]; then - printf "ERROR: Updating the node-build repository exited with code %s\n" "$pull_exit_code" - printf "Please check if the git repository at %s doesn't have any changes or anything that might not allow a git pull\n" "$ASDF_NODEJS_NODEBUILD_REPOSITORY" - exit 1 + if [ "$pull_exit_code" != 0 ]; then + printf "\n%s\n\n" "$output" >&2 + printf "$(colored $RED ERROR): Pulling the node-build repository exited with code %s\n" "$pull_exit_code" >&2 + printf "Please check if the git repository at %s doesn't have any changes or anything\nthat might not allow a git pull\n" "$ASDF_NODEJS_NODEBUILD_HOME" >&2 + exit $pull_exit_code fi + + printf "node-build updated!\n" fi } diff --git a/lib/utils.sh b/lib/utils.sh index 5b3dd46..72c050f 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -8,8 +8,6 @@ then NODEJS_ORG_MIRROR=$NODEJS_ORG_MIRROR/ fi -ASDF_NODEJS_KEYRING=asdf-nodejs.gpg - export ASDF_NODEJS_PLUGIN_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) # TODO: Replace with an asdf variable once asdf starts providing the plugin name @@ -22,6 +20,14 @@ plugin_name() { export ASDF_NODEJS_CACHE_DIR="${ASDF_DATA_DIR:-${ASDF_DIR:-$HOME/.asdf}}/tmp/$ASDF_NODEJS_PLUGIN_NAME/cache" export ASDF_DIR="${ASDF_DIR:-$HOME/.asdf}" +# Colors +colored() { + local color="$1" text="$2" + printf "\033[%sm%s\033[39;49m\n" "$color" "$text" +} + +export RED=31 GREEN=32 YELLOW=33 BLUE=34 MAGENTA=35 CYAN=36 + die() { >&2 echo "$@" exit 1 From 58859abcd55e690f6c6237cff0bbb55d78fe32ed Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Tue, 7 Dec 2021 00:03:28 -0300 Subject: [PATCH 10/15] chore: better messages --- bin/install | 4 ++-- lib/commands/command-update-nodebuild.bash | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/install b/bin/install index 8f51ab4..23761ed 100755 --- a/bin/install +++ b/bin/install @@ -26,10 +26,10 @@ try_to_update_nodebuild() { if [ "$exit_code" != 0 ]; then printf " -%s: Updating node-build failed with exit code %s. The installation will +$(colored $YELLOW WARNING): Updating node-build failed with exit code %s. The installation will try to continue with already installed local defintions. To debug what went wrong try to manually updating node-build by running: \`asdf %s update nodebuild\` -\n" "$(colored $YELLOW WARNING)" "$exit_code" "$ASDF_NODEJS_PLUGIN_NAME" +\n" "$exit_code" "$ASDF_NODEJS_PLUGIN_NAME" fi } diff --git a/lib/commands/command-update-nodebuild.bash b/lib/commands/command-update-nodebuild.bash index 5bd799b..a3ae8a4 100755 --- a/lib/commands/command-update-nodebuild.bash +++ b/lib/commands/command-update-nodebuild.bash @@ -14,7 +14,7 @@ ensure_updated_project() { printf "Cloning node-build...\n" git clone "$ASDF_NODEJS_NODEBUILD_REPOSITORY" "$ASDF_NODEJS_NODEBUILD_HOME" else - printf "Trying to update node-build...\n" + printf "Trying to update node-build..." output=$(git -C "$ASDF_NODEJS_NODEBUILD_HOME" pull origin master 2>&1) || pull_exit_code=$? if [ "$pull_exit_code" != 0 ]; then @@ -24,7 +24,7 @@ ensure_updated_project() { exit $pull_exit_code fi - printf "node-build updated!\n" + printf " ok\n" fi } From 3e44540e9ac113d8543c3571d4aef93981943813 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Tue, 7 Dec 2021 00:15:06 -0300 Subject: [PATCH 11/15] docs: better wording for the README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 874ad73..dd8c36b 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,13 @@ asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git Check [asdf](https://github.com/asdf-vm/asdf) readme for instructions on how to install & manage versions of Node.js at a system and project level. -Behind the scenes, `asdf-nodejs` utilizes [`node-build`](https://github.com/nodenv/node-build) to install pre-compiled binaries and compile from source if necessary. You can check its [README](https://github.com/nodenv/node-build/blob/master/README.md) for more compile settings and troubleshooting. +Behind the scenes, `asdf-nodejs` utilizes [`node-build`](https://github.com/nodenv/node-build) to install pre-compiled binaries and compile from source if necessary. You can check its [README](https://github.com/nodenv/node-build/blob/master/README.md) for additional settings and some troubleshooting. When compiling a version from source, you are going to need to install [all requirements for compiling Node.js](https://github.com/nodejs/node/blob/master/BUILDING.md#building-nodejs-on-supported-platforms) (be advised that different versions might require different configurations). That being said, `node-build` does a great job at handling edge cases and compilations rarely need a deep investigation. ### Configuration -Aside from the [common configuration with `node-build`](https://github.com/nodenv/node-build#custom-build-configuration), `asdf-nodejs` has a few extra environment variables for configuration. +`node-build` already has a [handful of settings](https://github.com/nodenv/node-build#custom-build-configuration), in additional to that `asdf-nodejs` has a few extra configuration variables: - `ASDF_NODEJS_NODEBUILD_HOME`: Home for the node-build installation, defaults to `$ASDF_DIR/plugins/nodejs/.node-build`, you can install it in another place or share it with your system - `ASDF_NODEJS_NODEBUILD`: Path to the node-build executable, defaults to `$NODE_BUILD_MIRROR_URL/bin/node-build` @@ -32,11 +32,11 @@ Aside from the [common configuration with `node-build`](https://github.com/noden ### Integrity/signature check -In the past `asdf-nodejs` checked for signatures and integrity on our own. `node-build` checks integrity by precomputing checksums ahead of time and versioning them together with the instructions for building them. +In the past `asdf-nodejs` checked for signatures and integrity by querying live keyservers. `node-build`, on the other hand, checks integrity by precomputing checksums ahead of time and versioning them together with the instructions for building them, making the process a lot more streamlined. ### `.nvmrc` and `.node-version` support -asdf uses the `.tool-versions` for auto-switching between software versions. To ease migration, you can have it read an existing `.nvmrc` or `.node-version` file to find out what version of Node.js should be used. To do this, add the following to `$HOME/.asdfrc`: +asdf uses a `.tool-versions` file for auto-switching between software versions. To ease migration, you can have it read an existing `.nvmrc` or `.node-version` file to find out what version of Node.js should be used. To do this, add the following to `$HOME/.asdfrc`: ``` legacy_version_file = yes From dcc73aea0e7af5cda4f70f78de7319a61a49623c Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Mon, 13 Dec 2021 22:50:58 -0300 Subject: [PATCH 12/15] fix: fix typos & revert import of utils.sh --- bin/install | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/install b/bin/install index 23761ed..f70aae1 100755 --- a/bin/install +++ b/bin/install @@ -3,7 +3,7 @@ set -eu -o pipefail # shellcheck source=../lib/utils.sh -source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../lib/utils.sh" +source "$(dirname "$0")/../lib/utils.sh" install_nodejs() { local install_type="$1" version_query="$2" install_path="$3" @@ -100,7 +100,7 @@ install_default_npm_packages() { while read -r name; do ( - printf "Installing $(colord $YELLOW %s) npm package...\n" "$name" + printf "Installing $(colored $YELLOW %s) npm package...\n" "$name" source "$(dirname "$0")/exec-env" PATH="$ASDF_INSTALL_PATH/bin:$PATH" npm install -g "$name" > /dev/null 2>&1 && rc=$? || rc=$? if [[ $rc -eq 0 ]]; then From 363c0d1d9f2e86796b7fa96fadd5b050929bb0c0 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Wed, 15 Dec 2021 14:07:51 -0300 Subject: [PATCH 13/15] fix: add fallback for empty arrays in bash3 --- bin/install | 2 +- lib/commands/command-nodebuild.bash | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/install b/bin/install index f70aae1..ceae17c 100755 --- a/bin/install +++ b/bin/install @@ -50,7 +50,7 @@ install_canon_version() { try_to_update_nodebuild NODE_BUILD_BUILD_PATH="$ASDF_DOWNLOAD_PATH" NODE_BUILD_CACHE_PATH="$ASDF_DOWNLOAD_PATH" \ - nodebuild_wrapped "${nodebuild_args[@]}" "$version" "$install_path" + nodebuild_wrapped "${nodebuild_args[@]-}" "$version" "$install_path" } diff --git a/lib/commands/command-nodebuild.bash b/lib/commands/command-nodebuild.bash index 2b1b8bb..1c169c7 100755 --- a/lib/commands/command-nodebuild.bash +++ b/lib/commands/command-nodebuild.bash @@ -38,4 +38,4 @@ if [ "${ASDF_NODEJS_VERBOSE_INSTALL-}" ]; then nodebuild_args+=(-v) fi -exec "$nodebuild" "${nodebuild_args[@]}" "$@" +exec "$nodebuild" "${nodebuild_args[@]-}" "$@" From e0d3804a5514f1e6c30ead79636105e897a72e0a Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Wed, 15 Dec 2021 14:17:39 -0300 Subject: [PATCH 14/15] docs: better explanation of manually updating node-build --- README.md | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index dd8c36b..b5cfa3a 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,12 @@ Node.js plugin for [asdf](https://github.com/asdf-vm/asdf) version manager After installing [asdf](https://github.com/asdf-vm/asdf), install the plugin by running: ```bash -asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git +asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git ``` ## Use -Check [asdf](https://github.com/asdf-vm/asdf) readme for instructions on how to install & manage versions of Node.js at a system and project level. +Check [asdf](https://github.com/asdf-vm/asdf) readme for instructions on how to install & manage versions of Node.js at a system and project level. Behind the scenes, `asdf-nodejs` utilizes [`node-build`](https://github.com/nodenv/node-build) to install pre-compiled binaries and compile from source if necessary. You can check its [README](https://github.com/nodenv/node-build/blob/master/README.md) for additional settings and some troubleshooting. @@ -42,16 +42,6 @@ asdf uses a `.tool-versions` file for auto-switching between software versions. legacy_version_file = yes ``` -### Updating node-build definitions - -Every new node version needs to have a definition file in the `node-build` repository. Because of that, `asdf-nodejs` tries to update the local `node-build` repository at every install command to download definitions for newly added versions. - -We provide a command for manually updating `node-build` at your own time: - -```bash -asdf nodejs update-nodebuild -``` - ### Running the wrapped node-build command We provide a command for running the installed `node-build` command: @@ -68,11 +58,19 @@ Some of them will work out of the box, and some will need a bit of investigation To list all the available variations run: -``` bash +```bash asdf nodejs nodebuild --definitions ``` -*Note that this command only lists the current `node-build` definitions. You might want to [update the local `node-build` repository](#updating-node-build-definitions) before listing them.* +_Note that this command only lists the current `node-build` definitions. You might want to [update the local `node-build` repository](#updating-node-build-definitions) before listing them._ + +### Manually updating node-build definitions + +Every new node version needs to have a definition file in the `node-build` repository. `asdf-nodejs` already tries to update `node-build` on every new version installation, but if you want to update `node-build` manually for some reason we provide a command just for that: + +```bash +asdf nodejs update-nodebuild +``` ## Default npm Packages From b58ae2359f2bf604aaaa3139357fee82a713cdf0 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Thu, 16 Dec 2021 21:10:58 -0300 Subject: [PATCH 15/15] fix: add fallback for unbound variables in bash3 --- bin/install | 6 +++--- lib/commands/command-nodebuild.bash | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/install b/bin/install index ceae17c..4e85935 100755 --- a/bin/install +++ b/bin/install @@ -41,16 +41,16 @@ nodebuild_wrapped() { install_canon_version() { local install_type="$1" version="$2" install_path="$3" - local nodebuild_args=() + local args=() if [ "$install_type" = ref ]; then - nodebuild_args+=(-c) + args+=(-c) fi try_to_update_nodebuild NODE_BUILD_BUILD_PATH="$ASDF_DOWNLOAD_PATH" NODE_BUILD_CACHE_PATH="$ASDF_DOWNLOAD_PATH" \ - nodebuild_wrapped "${nodebuild_args[@]-}" "$version" "$install_path" + nodebuild_wrapped ${args+"${args[@]}"} "$version" "$install_path" } diff --git a/lib/commands/command-nodebuild.bash b/lib/commands/command-nodebuild.bash index 1c169c7..ea5a54d 100755 --- a/lib/commands/command-nodebuild.bash +++ b/lib/commands/command-nodebuild.bash @@ -22,7 +22,7 @@ if [[ "${ASDF_NODEJS_CONCURRENCY-}" =~ ^[0-9]+$ ]]; then fi nodebuild="${ASDF_NODEJS_NODEBUILD:-$ASDF_NODEJS_NODEBUILD_HOME/bin/node-build}" -nodebuild_args=() +args=() if ! [ -x "$nodebuild" ]; then printf "Binary for node-build not found\n" @@ -35,7 +35,7 @@ if ! [ -x "$nodebuild" ]; then fi if [ "${ASDF_NODEJS_VERBOSE_INSTALL-}" ]; then - nodebuild_args+=(-v) + args+=(-v) fi -exec "$nodebuild" "${nodebuild_args[@]-}" "$@" +exec "$nodebuild" ${args+"${args[@]}"} "$@"