Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for auto enabling corepack #396

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ When compiling a version from source, you are going to need to install [all requ
- `ASDF_NODEJS_LEGACY_FILE_DYNAMIC_STRATEGY`: Enable and choose the strategy for
dynamic/partial versions in legacy version files. Either `latest_installed` or
`latest_available`. For more info check the [Partial and codename versions](#partial-and-codename-versions) section
- `ASDF_NODEJS_AUTO_ENABLE_COREPACK`: Enable corepack for new installations. Defaults to empty
- `ASDF_NODEJS_VERBOSE_INSTALL`: Enables verbose output for downloading and building. Any value different from empty is treated as enabled.
- `ASDF_NODEJS_FORCE_COMPILE`: Forces compilation from source instead of preferring pre-compiled binaries
- `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
Expand Down
25 changes: 19 additions & 6 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ install_nodejs() {
nodebuild_wrapped ${args+"${args[@]}"} "$version" "$install_path"
}

_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" "$@"
)
}


install_default_npm_packages() {
local default_npm_packages_file="${ASDF_NPM_DEFAULT_PACKAGES_FILE:=$HOME/.default-npm-packages}" filtered_packages=
Expand All @@ -36,13 +46,13 @@ install_default_npm_packages() {
xargs printf "%s, " <<< "$filtered_packages"
printf "\x8\x8 \n" # Cleanup last comma

(
if [ -r "$ASDF_NODEJS_PLUGIN_DIR/bin/exec-env" ]; then
. "$ASDF_NODEJS_PLUGIN_DIR/bin/exec-env"
fi
_run_for_installation xargs npm install -g <<< "$filtered_packages"
fi
}

xargs env PATH="$ASDF_INSTALL_PATH/bin:$PATH" npm install -g <<< "$filtered_packages"
)
enable_corepack() {
if [ "${ASDF_NODEJS_AUTO_ENABLE_COREPACK-}" ]; then
_run_for_installation corepack enable
fi
}

Expand All @@ -51,4 +61,7 @@ install_nodejs "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
install_default_npm_packages \
|| printf "\n$(colored $YELLOW WARNING:) An error occurred when installing the default npm packages, but Node's installation succeeded\n"

enable_corepack \
|| printf "\n$(colored $YELLOW WARNING:) An error occurred while enabling corepack for this version\n"

asdf reshim "$(plugin_name)" "$ASDF_INSTALL_VERSION"
Loading