Skip to content

Commit

Permalink
Add support for auto enabling corepack (#396)
Browse files Browse the repository at this point in the history
* Add variable for enabling corepack automatically

* Add docs to corepack variable
  • Loading branch information
augustobmoura authored Jul 30, 2024
1 parent c5b7c40 commit fb44c90
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
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"

0 comments on commit fb44c90

Please sign in to comment.