Skip to content

Commit

Permalink
v0.6.5
Browse files Browse the repository at this point in the history
  * [enhancement] Versions to install may now be specified as major version numbers only, e.g. `22`
  * [enhancement] Interactive prompt is now less verbose in that opt-outs aren't explicitly mentioned.
  • Loading branch information
mklement0 committed Feb 10, 2025
1 parent eb8ed54 commit 9e4066e
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 46 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Versioning complies with [semantic versioning (semver)](http://semver.org/).

<!-- NOTE: An entry template for a new version is automatically added each time `make version` is called. Fill in changes afterwards. -->

* **[v0.6.5](https://github.com/mklement0/n-install/compare/v0.6.4...v0.6.5)** (2025-02-09):
* [enhancement] Versions to install may now be specified as major version numbers only, e.g. `22`
* [enhancement] Interactive prompt is now less verbose in that opt-outs aren't explicitly mentioned.

* **[v0.6.4](https://github.com/mklement0/n-install/compare/v0.6.3...v0.6.4)** (2025-01-23):
* [fix] SHA-256 checksum-utility command-line construction code updated for new macOS version.

Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ curl -sL https://bit.ly/n-install | bash -s -- -q
```

* Automated installation to the default location, with subsequent installation of the latest LTS
(Long Term Support) version, and the latest 0.10.x release:
(Long Term Support) version, and the latest v22 release:

```shell
curl -L https://bit.ly/n-install | bash -s -- -y lts 0.10
curl -L https://bit.ly/n-install | bash -s -- -y lts 22
```

* Automated installation to custom location `~/util/n`, with subsequent installation of the latest LTS Node.js version:
Expand Down Expand Up @@ -180,7 +180,7 @@ DESCRIPTION
* lts ... the LTS (long-term stability) version
* latest ... the latest version available overall
* otherwise, specify an explicit version number, such as '0.12' or '0.10.35'
* otherwise, specify an explicit version number, such as '22' or '22.13'
If multiple versions are specified, the first one will be made active.
Expand Down Expand Up @@ -310,6 +310,10 @@ Versioning complies with [semantic versioning (semver)](http://semver.org/).
<!-- NOTE: An entry template for a new version is automatically added each time `make version` is called. Fill in changes afterwards. -->
* **[v0.6.5](https://github.com/mklement0/n-install/compare/v0.6.4...v0.6.5)** (2025-02-09):
* [enhancement] Versions to install may now be specified as major version numbers only, e.g. `22`
* [enhancement] Interactive prompt is now less verbose in that opt-outs aren't explicitly mentioned.
* **[v0.6.4](https://github.com/mklement0/n-install/compare/v0.6.3...v0.6.4)** (2025-01-23):
* [fix] SHA-256 checksum-utility command-line construction code updated for new macOS version.
Expand Down
80 changes: 42 additions & 38 deletions bin/n-install
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ kMIN_BASH_VERSION='3.2' # due to use of =~, we require at least 3.2
##### IMPORTANT: These names must, at least in part, be kept in sync with their counterparts in 'n-update' and 'n-uninstall'.
kINSTALLER_NAME=n-install # This script's name; note that since we'll typically be running via curl directly from GitHub, using $(basename "$BASH_SOURCE") to determine the name is not an option.
# Note: The actual *installation* URL is https://bit.ly/n-install which redirects to https://raw.githubusercontent.com/mklement0/n-install/stable/bin/n-install
kTHIS_REPO_URL='https://bit.ly/n-install-repo' # This script's source repository - SHORT, git.io-based form.
kTHIS_REPO_URL='https://bit.ly/n-install-repo' # This script's source repository - SHORTENED form.
kTHIS_REPO_URL_LONG='https://github.com/mklement0/n-install' # This script's source repository in LONG form - needed for deriving raw.githubusercontent.com URLs from it.
kPREFIX_DIR=${N_PREFIX:-$HOME/n} # The target prefix directory, inside which both a dir. for n itself and the active node version's dirs. will be located.
## For updating the relevant shell initialization file: The string that identifies the line added by us.
## !! IMPORTANT:
## !! Now that this project has been published, we HARD-CODE this ID string to ensure that old installations are found.
## !! Notably, we've changed from:
## !! http:// to https:// URLs later
## !! http://git.io/n-install-repo to https://bit.ly/n-install-repo after retirment of git.io
## !! http://git.io/n-install-repo to https://bit.ly/n-install-repo after *retirement of git.io* (though existings URLs seemingly still work)
## !! but the ID STRING MUST CONTINUE TO USE "http://git.io/n-install-repo" to avoid breaking later uninstalls / reinstalls.
kINIT_FILE_LINE_ID=" # Added by n-install (see http://git.io/n-install-repo)."
kREGEX_CONFLICTING_LINE='^[^#]*\bN_PREFIX=' # Regex that identifies relevant existing lines.
Expand Down Expand Up @@ -56,8 +56,8 @@ kHELPER_SCRIPT_URLS=(
# !! DO NOT MODIFY THE *FORMAT* OF THIS ARRAY LITERAL - `util/update-checksums`
# !! and a test rely on it.
kSHA256_SUMS=(
"80378b7def620aeaae3cbf268906ce123b69648668b283d0dcb44c10938e123b $kUPDATE_SCRIPT"
"6c1ba6e9563f7a0efd1ba821d3a5dc889a0b86c08bb0f4dd2ad2ea9d673d8df0 $kUNINSTALL_SCRIPT"
"e2a9c78ad63ce59104ec3b6331b2a63dfdba8b25cb3edc4dc0bb9d4fddb72a2a $kUPDATE_SCRIPT"
"f046f2d5c278ff8e2279a8915218c83e6ab601d3c5d28473dc2b94ffc242153e $kUNINSTALL_SCRIPT"
)
##

Expand Down Expand Up @@ -425,10 +425,10 @@ EOF
}

# SYNOPSIS
# parseSemVer [-2] version
# parseSemVer [-1] version
# DESCRIPTION
# Parses the specified semver-2.0-compatible version into its components (see http://semver.org/).
# If you specify option -2, only the <major>.<minor> part must be present.
# If you specify option -1, only the <major> part must be present.
# Nothing is output if the version is not semver-compatible, and the return value is set to 1.
# Each component is returned on its own line, up to and including the last component found:
# Line 1 == major, line 2 == minor, line 3 == patch, line 4 == pre-release ID, line 5 == build metadata
Expand All @@ -441,19 +441,19 @@ EOF
# parseSemVer 0.5.12-pre+build7 # -> $'0\n5\n12\npre\nbuild7'
# parseSemVer 0.5.12+build7 # -> $'0\n5\n12\n\nbuild7'
parseSemVer() {
local onlyMajorMinorRequired=0
[[ $1 == '-2' ]] && { onlyMajorMinorRequired=1; shift; }
local onlyMajorRequired=0
[[ $1 == '-1' ]] && { onlyMajorRequired=1; shift; }
(( $# == 1 )) || return 2

# Parse into major, minor, patch, and *roughly* into pre-release identifiers and metadata.
local num='([0-9]|[1-9][0-9]+)' # a decimal integer, but leading zeros are not allowed
local idList='([0-9A-Za-z.-]+)' # looser-than-required expression for the sub-identifiers making up the pre-release and metada parts; additional validation required
# [[ $1 =~ ^$num\.$num(\.$num(-$idList(\+$idList)?)?)?$ ]] || return 1
[[ $1 =~ ^$num\.$num(\.$num(-$idList)?(\+$idList)?)?$ ]] || return 1
[[ $1 =~ ^$num(\.$num(\.$num(-$idList)?(\+$idList)?)?)?$ ]] || return 1

# See if we have at least major, minor, patch, or, if -2 was specified, major and minor.
# See if we have at least major, minor, patch, or, if -1 was specified, major.
local n major=${BASH_REMATCH[1]} minor=${BASH_REMATCH[2]} patch=${BASH_REMATCH[4]} prId=${BASH_REMATCH[6]} buildMd=${BASH_REMATCH[8]}
[[ -n $patch ]] || (( onlyMajorMinorRequired )) || return 1
[[ -n $patch ]] || (( onlyMajorRequired )) || return 1

# Validate the optional pre-release part and the metadata part, each composed of
# a list of non-empty, dot-separated sub-identifiers that are either decimal integers without
Expand Down Expand Up @@ -497,7 +497,7 @@ unset CDPATH # to prevent unpredictable `cd` behavior
# Output version number and exit, if requested.
# [!! SEEMINGLY NO LONGER UPDATED AUTOMATICALLY - TO BE INVESTIGATED]
# Note that the `ver='...'` statement is automatically updated by `make version VER=<newVer>` - DO keep the 'v' prefix in the variable _definition_.
[[ $1 == '--version' ]] && { ver='v0.6.4'; echo "$kTHIS_NAME ${ver#v}"$'\nFor license information and more, visit https://bit.ly/n-install-repo'; exit 0; }
[[ $1 == '--version' ]] && { ver='v0.6.5'; echo "$kTHIS_NAME ${ver#v}"$'\nFor license information and more, visit https://bit.ly/n-install-repo'; exit 0; }

# !! AS OF n 1.3.0, n ITSELF ONLY WORKS WITH curl, NOT ALSO WITH wget.
# !! Once n also supports wget, mention wget as an alternative in the help text.
Expand All @@ -522,7 +522,7 @@ DESCRIPTION
* lts ... the LTS (long-term stability) version
* latest ... the latest version available overall
* otherwise, specify an explicit version number, such as '0.12' or '0.10.35'
* otherwise, specify an explicit version number, such as '22' or '22.13'
If multiple versions are specified, the first one will be made active.
Expand Down Expand Up @@ -680,16 +680,16 @@ else # operands specified: interpret them as Node.js versions to install
# we expect that to be the *only* operand, since an explicit list
# of operands always overrides the default, but we don't enforce this.
;;
lts|stable|latest|io:stable|io:latest) # symbolic names for latest LTS / in-development versions; 'stable' is obsolescent
lts|stable|latest) # symbolic names for latest LTS / in-development versions; 'stable' is obsolescent and is now synonmyous with 'latest'
versionsToInstall+=( "$ver" )
;;
current) # !! See comments above.
versionsToInstall+=( 'latest' )
;;
*) # must be a version number in the form <major>.<minor>[.<patch>]
componentCount=$(parseSemVer -2 "${ver#io:}" | wc -l)
(( componentCount == 2 || componentCount == 3 )) ||
dieSyntax - <<<"'$ver' is not a valid Node.js version specifier."$'\n'"(Must be 'lts', 'latest', or <major>.<minor>[.<patch>].)" # , optionally prefixed with 'io:'
componentCount=$(parseSemVer -1 "$ver" | wc -l)
(( componentCount >= 1 && componentCount <= 3 )) ||
dieSyntax - <<<"'$ver' is not a valid Node.js version specifier."$'\n'"(Must be 'lts', 'latest', or <major>[.<minor>[.<patch>]].)"
versionsToInstall+=( "$ver" )
;;
esac
Expand Down Expand Up @@ -774,39 +774,43 @@ if (( ! (skipPrompts || quiet) )); then
You are ABOUT TO INSTALL n, the Node.js VERSION MANAGER, in:
$(green $N_PREFIX)
$(
if (( ${#versionsToInstall[@]} > 0 )); then
cat <<EOFinst
Afterwards, THE FOLLOWING Node.js VERSION(S) WILL BE INSTALLED,
and the first one listed will be made active;
'lts' refers to the LTS (long-term support) version,
'latest' to the latest available version.
'-' means that *no* version will be installed:
$( (( ${#versionsToInstall[@]} > 0 )) && green "${versionsToInstall[*]}" || yellow NOTE: Skipping Node.js installation, as requested.)
$(green "${versionsToInstall[*]}")
EOFinst
fi
)
$(
if (( ! skipInitFileUpdate )); then
cat <<EOFifu
If your shell is bash, bsh, zsh, fish, or pwsh (PowerShell), the relevant
initialization file will be modified in order to:
- export environment variable \$N_PREFIX.
- ensure that \$N_PREFIX/bin is in the \$PATH
$(
if (( skipInitFileUpdate )); then
echo " $(yellow NOTE: Skipping initialization-file update, as requested.)"
elif (( shellIsSupported )); then
cat <<EOF4
EOFifu
if (( shellIsSupported )); then
cat <<EOFifus
$(green Your shell, $userDefaultShell, IS supported), and the following initialization
file will be updated:
$initFile
EOF4
else
cat <<EOF5
EOFifus
else
cat <<EOFifns
$(red Your shell, $userDefaultShell, is NOT supported for automatic initialization-file modification.)
You will have to make these modifications yourself - details to follow.
EOF5
fi
EOFifns
fi
fi
)
For more information, see $kTHIS_REPO_URL
Expand All @@ -816,7 +820,7 @@ EOF
# Determine where to read user input from:
# If -f ${BASH_SOURCE} is true, we're running from a local script file, such as during testing, so we respect whatever stdin is set to, so that user input can be *simulated*.
# Otherwise, the assumption is that we're running via curl ... | bash, in which case we always want to read from /dev/tty - giving us a chance to
# to pipe the script contents via stdin, while soliciting user input from the terminal (unless -y was specified to skipt he confirmation prompt).
# to pipe the script contents via stdin, while soliciting user input from the terminal (unless -y was specified to skip he confirmation prompt).
[[ -f ${BASH_SOURCE} ]] && src='/dev/stdin' || src='/dev/tty'

# Prompt the user:
Expand Down Expand Up @@ -961,7 +965,7 @@ if (( toInstallCount > 0 )); then
(( quiet )) || echo " $(( ++i )) of ${toInstallCount}: ${ver}..."
(( quiet )) && args=( '-q' ) || args=()
[[ $archOverride ]] && args+=( '-a' "$archOverride" )
[[ $ver == 'io:'* ]] && args+=( io "${ver#io:}" ) || args+=( "$ver" )
args+=( "$ver" )
# Note: To be safe, we place $nBinDir FIRST in the path for this invocation.
if PATH="$nBinDir:$PATH" N_PREFIX="$N_PREFIX" n "${args[@]}"; then
(( ++installedCount == 1 )) && firstInstalledVerArgs=( "${args[@]}" )
Expand Down Expand Up @@ -994,13 +998,13 @@ $( (( installedCount > 0 )) &&
To update n later, run \`$kUPDATE_SCRIPT\`.
To uninstall, run \`$kUNINSTALL_SCRIPT\`.
$( [[ -n $initFile ]] && cat <<EOF2 || cat <<EOF3
$( [[ -n $initFile ]] && cat <<EOFns || cat <<EOFmif
IMPORTANT: OPEN A NEW TERMINAL TAB/WINDOW or run \`. ${initFile/#$HOME/~}\`
before using n and Node.js.
EOF2
EOFns
IMPORTANT: Modify your shell initialization file as described above
before using n and Node.js.
EOF3
EOFmif
)
===
EOF
Expand Down
2 changes: 1 addition & 1 deletion bin/n-uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ unset CDPATH # to prevent unpredictable `cd` behavior
[[ -t 1 ]] || kNO_COLOR=1 # turn off colored output if stdout is not connected to a terminal

# Output version number and exit, if requested. Note that the `ver='...'` statement is automatically updated by `make version VER=<newVer>` - DO keep the 'v' prefix in the variable _definition_.
[ "$1" = '--version' ] && { ver='v0.6.4'; echo "$kTHIS_NAME ${ver#v}"$'\nFor license information and more, visit https://bit.ly/n-install-repo'; exit 0; }
[ "$1" = '--version' ] && { ver='v0.6.5'; echo "$kTHIS_NAME ${ver#v}"$'\nFor license information and more, visit https://bit.ly/n-install-repo'; exit 0; }

# Command-line help.
if [ "$1" = '--help' ] || [ "$1" = '-h' ]; then
Expand Down
2 changes: 1 addition & 1 deletion bin/n-update
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ unset CDPATH # to prevent unpredictable `cd` behavior
[[ -t 1 ]] || kNO_COLOR=1 # turn off colored output if stdout is not connected to a terminal

# Output version number and exit, if requested. Note that the `ver='...'` statement is automatically updated by `make version VER=<newVer>` - DO keep the 'v' prefix in the variable _definition_.
[ "$1" = '--version' ] && { ver='v0.6.4'; echo "$kTHIS_NAME ${ver#v}"$'\nFor license information and more, visit https://bit.ly/n-install-repo'; exit 0; }
[ "$1" = '--version' ] && { ver='v0.6.5'; echo "$kTHIS_NAME ${ver#v}"$'\nFor license information and more, visit https://bit.ly/n-install-repo'; exit 0; }

# Command-line help.
if [ "$1" = '--help' ] || [ "$1" = '-h' ]; then
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "n-install",
"description": "installs n, the Node.js version manager, without needing to install Node.js first",
"private": true,
"version": "0.6.4",
"version": "0.6.5",
"os": [
"darwin",
"linux"
Expand Down
Empty file removed test/.urchin_stdout
Empty file.

0 comments on commit 9e4066e

Please sign in to comment.