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

Copy system cert configs when installing new versions #2118

Open
wants to merge 1 commit into
base: master
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -16,6 +16,7 @@
- [Long-term support](#long-term-support)
- [Migrating global packages while installing](#migrating-global-packages-while-installing)
- [Default global packages from file while installing](#default-global-packages-from-file-while-installing)
- [Copy system certificate preferences when installing](#copy-system-certificate-preferences-when-installing)
- [io.js](#iojs)
- [System version of node](#system-version-of-node)
- [Listing versions](#listing-versions)
@@ -310,6 +311,10 @@ object-inspect@1.0.2
stevemao/left-pad
```

### Copy system certificate preferences when installing

If you have any of `ca`, `cafile`, or `cert` present in your npm config when installing a new version, those keys will be copied into the newly-installed version's global config file. If you don't want this behavior, pass the `--skip-system-certs` flag when installing a new version

This comment has been minimized.

Copy link
@ljharb

ljharb Nov 5, 2019

Member

Can you explain more about why this complexity is desired or needed?

I don't think having these present is a common case, and looking these up from the current node version (which might be "the system node") will slow things down for the majority that would never need it.

It seems simpler for the user to manually rerun their npm config commands, or better, for each project to define its own .npmrc file.


### io.js

If you want to install [io.js](https://github.com/iojs/io.js/):
25 nvm.sh
@@ -2368,6 +2368,7 @@ nvm() {
nvm_echo ' --lts When installing, only select from LTS (long-term support) versions'
nvm_echo ' --lts=<LTS name> When installing, only select from versions for a specific LTS line'
nvm_echo ' --skip-default-packages When installing, skip the default-packages file if it exists'
nvm_echo ' --skip-system-certs When installing, skip copying certificate configuration from system npm'
nvm_echo ' --latest-npm After installing, attempt to upgrade to the latest working npm on the given node version'
nvm_echo ' --no-progress Disable the progress bar on any downloads'
nvm_echo ' nvm uninstall <version> Uninstall a version'
@@ -2640,6 +2641,8 @@ nvm() {
local REINSTALL_PACKAGES_FROM
local SKIP_DEFAULT_PACKAGES
local DEFAULT_PACKAGES
local SKIP_CERTS
local CERT_CONFIGS

while [ $# -ne 0 ]; do
case "$1" in
@@ -2662,6 +2665,9 @@ nvm() {
--skip-default-packages)
SKIP_DEFAULT_PACKAGES=true
;;
--skip-system-certs)
SKIP_CERTS=true
;;
*)
ADDITIONAL_PARAMETERS="${ADDITIONAL_PARAMETERS} $1"
;;
@@ -2677,6 +2683,10 @@ nvm() {
fi
fi

if [ -z "${SKIP_CERTS-}" ]; then
CERT_CONFIGS="$(nvm exec system npm config ls | sed -n 's/^\(ca\|cafile\|cert\)[ \t]*=[ \t]*\(.*\)$/\1 \2/p')"
fi

if [ -n "${PROVIDED_REINSTALL_PACKAGES_FROM-}" ] && [ "$(nvm_ensure_version_prefix "${PROVIDED_REINSTALL_PACKAGES_FROM}")" = "${VERSION}" ]; then
nvm_err "You can't reinstall global packages from the same version of node you're installing."
return 4
@@ -2704,6 +2714,9 @@ nvm() {
if [ -n "${REINSTALL_PACKAGES_FROM-}" ] && [ "_${REINSTALL_PACKAGES_FROM}" != "_N/A" ]; then
nvm reinstall-packages "${REINSTALL_PACKAGES_FROM}"
fi
if [ -n "${CERT_CONFIGS}" ]; then
nvm_copy_cert_configs "${CERT_CONFIGS}"
fi
fi
if [ -n "${LTS-}" ]; then
LTS="$(echo "${LTS}" | tr '[:upper:]' '[:lower:]')"
@@ -2782,6 +2795,9 @@ nvm() {
nvm reinstall-packages "${REINSTALL_PACKAGES_FROM}"
EXIT_CODE=$?
fi
if [ -n "${CERT_CONFIGS}" ]; then
nvm_copy_cert_configs "${CERT_CONFIGS}"
fi
else
EXIT_CODE=$?
fi
@@ -3530,6 +3546,7 @@ nvm() {
nvm_sanitize_path nvm_has_colors nvm_process_parameters \
node_version_has_solaris_binary iojs_version_has_solaris_binary \
nvm_curl_libz_support nvm_command_info nvm_is_zsh nvm_stdout_is_terminal \
nvm_copy_cert_configs \
>/dev/null 2>&1
unset NVM_RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_IOJS_ORG_MIRROR NVM_DIR \
NVM_CD_FLAGS NVM_BIN NVM_MAKE_JOBS \
@@ -3587,6 +3604,14 @@ nvm_install_default_packages() {
fi
}

nvm_copy_cert_configs() {
nvm_echo "Copying certificate information from system npm (if present)..."
if ! nvm_echo "$1" | command xargs -L1 npm config set -g; then
nvm_err "Failed to copy certificate configuration from system npm."
return 1
fi
}

nvm_supports_source_options() {
# shellcheck disable=SC1091,SC2240
[ "_$( . /dev/stdin yes 2> /dev/null <<'EOF'
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.