CARVIEW |
Select Language
HTTP/2 200
date: Thu, 24 Jul 2025 16:39:11 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"5aed11bfbaf6d4bdea28a87a6bfebb81"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=2JuPH8XlZU3NSUycnI9uL5bo9JV1HFAtwmeZnrRqe0vC5rLmFVT7c5kTebpXCXRRgbu7%2F2vxYixbYRrn0qoTrWywx3%2B9HLeEfSknx2oS%2BHWbCJpnqJL9lK725oHbOPBrOY0DWhF6CcAGwzeQmkxo9fT9YWhsg7zaGEORJLoKRqRSUozoMolCxWLdU7k0901VM%2FGq2ObA0hTigY7uVyx1XI0n50rsUlwpRyCxXBjyPocU9N%2BVeoR60Tl7dY0JE0bz7XEd0oX8B0XE%2FllORd8ORQ%3D%3D--IdkVLYEXOv1TbAl%2F--pPyC%2F01mYeCl%2BIw67D7gtg%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1858472342.1753375151; Path=/; Domain=github.com; Expires=Fri, 24 Jul 2026 16:39:11 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Fri, 24 Jul 2026 16:39:11 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: D858:223761:5CE6:6E27:688261AF
nvm use <package.json> · GitHub
Show Gist options
Save assaf/ee377a186371e2e269a7 to your computer and use it in GitHub Desktop.
{{ message }}
Instantly share code, notes, and snippets.
-
Star
5
(5)
You must be signed in to star a gist -
Fork
1
(1)
You must be signed in to fork a gist
-
Save assaf/ee377a186371e2e269a7 to your computer and use it in GitHub Desktop.
nvm use <package.json>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Run nvmish in your current project directory to use the version of io.js/Node | |
# as specified in package.json. It will also install that version, if not | |
# already installed. | |
# | |
# If package.json specifies engines.iojs, uses the corresponding version of | |
# io.js, otherwise, if package.json specifies engines.node, uses the | |
# corresponding version of Node.js. | |
# | |
# You can specify an exact version number, or any semver-compatible range, in | |
# which case it will pick the most recent version available. | |
# | |
# $ source ./nvmish | |
# $ cd <project directory> | |
# $ cat package.json | jq --raw-output .engines.iojs | |
# > 1.6.2 | |
# $ nvmish | |
# > Installing io.js v1.6.2 ... | |
# > ######################################################################## 100.0% | |
# > Now using io.js v1.6.2 | |
# | |
# $ cat package.json | jq --raw-output .engines.node | |
# > 1.2.x | |
# $ nvmish | |
# > Now using node v0.12.0 | |
source $(brew --prefix nvm)/nvm.sh | |
# Adapted from JSON.sh https://github.com/dominictarr/JSON.sh | |
nvm_json_throw () { | |
echo "$*" >&2 | |
exit 1 | |
} | |
nvm_json_awk_egrep () { | |
local pattern_string=$1 | |
gawk '{ | |
while ($0) { | |
start=match($0, pattern); | |
token=substr($0, start, RLENGTH); | |
print token; | |
$0=substr($0, start+RLENGTH); | |
} | |
}' pattern=$pattern_string | |
} | |
nvm_json_tokenize () { | |
local GREP | |
local ESCAPE | |
local CHAR | |
if echo "test string" | egrep -ao --color=never "test" &>/dev/null | |
then | |
GREP='egrep -ao --color=never' | |
else | |
GREP='egrep -ao' | |
fi | |
if echo "test string" | egrep -o "test" &>/dev/null | |
then | |
ESCAPE='(\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})' | |
CHAR='[^[:cntrl:]"\\]' | |
else | |
GREP=nvm_json_awk_egrep | |
ESCAPE='(\\\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})' | |
CHAR='[^[:cntrl:]"\\\\]' | |
fi | |
local STRING="\"$CHAR*($ESCAPE$CHAR*)*\"" | |
local NUMBER='-?(0|[1-9][0-9]*)([.][0-9]*)?([eE][+-]?[0-9]*)?' | |
local KEYWORD='null|false|true' | |
local SPACE='[[:space:]]+' | |
$GREP "$STRING|$NUMBER|$KEYWORD|$SPACE|." | egrep -v "^$SPACE$" | |
} | |
_json_parse_array () { | |
local index=0 | |
local ary='' | |
read -r token | |
case "$token" in | |
']') ;; | |
*) | |
while : | |
do | |
_json_parse_value "$1" "$index" | |
index=$((index+1)) | |
ary="$ary""$value" | |
read -r token | |
case "$token" in | |
']') break ;; | |
',') ary="$ary," ;; | |
*) nvm_json_throw "EXPECTED , or ] GOT ${token:-EOF}" ;; | |
esac | |
read -r token | |
done | |
;; | |
esac | |
: | |
} | |
_json_parse_object () { | |
local key | |
local obj='' | |
read -r token | |
case "$token" in | |
'}') ;; | |
*) | |
while : | |
do | |
case "$token" in | |
'"'*'"') key=$token ;; | |
*) nvm_json_throw "EXPECTED string GOT ${token:-EOF}" ;; | |
esac | |
read -r token | |
case "$token" in | |
':') ;; | |
*) nvm_json_throw "EXPECTED : GOT ${token:-EOF}" ;; | |
esac | |
read -r token | |
_json_parse_value "$1" "$key" | |
obj="$obj$key:$value" | |
read -r token | |
case "$token" in | |
'}') break ;; | |
',') obj="$obj," ;; | |
*) nvm_json_throw "EXPECTED , or } GOT ${token:-EOF}" ;; | |
esac | |
read -r token | |
done | |
;; | |
esac | |
: | |
} | |
_json_parse_value () { | |
local jpath="${1:+$1,}$2" isleaf=0 isempty=0 print=0 | |
case "$token" in | |
'{') _json_parse_object "$jpath" ;; | |
'[') _json_parse_array "$jpath" ;; | |
# At this point, the only valid single-character tokens are digits. | |
''|[!0-9]) nvm_json_throw "EXPECTED value GOT ${token:-EOF}" ;; | |
*) value=$token | |
isleaf=1 | |
[ "$value" = '""' ] && isempty=1 | |
;; | |
esac | |
[ "$value" = '' ] && return | |
[ "$isleaf" -eq 1 ] && [ $isempty -eq 0 ] && print=1 | |
[ "$print" -eq 1 ] && printf "[%s]\t%s\n" "$jpath" "$value" | |
: | |
} | |
_json_parse () { | |
read -r token | |
_json_parse_value | |
read -r token | |
case "$token" in | |
'') ;; | |
*) nvm_json_throw "EXPECTED EOF GOT $token" ;; | |
esac | |
} | |
nvm_json_extract () { | |
local parsed=$(nvm_json_tokenize | _json_parse) | |
echo "$parsed" | grep -e "$1" | awk '{print $2 $3}' | |
} | |
# Install io.js/Node version specified in package.json | |
# | |
# Exit code: | |
# 0 Successfully installed and using latest version | |
# 1 No package.json in current directory | |
# 2 Found package.json but no engines specified | |
nvmish () { | |
if [[ ! -f package.json ]] ; then | |
echo "No package.json found in current directory" | |
return 1 | |
fi | |
local INSTALL_VERSION | |
local NVM_VERSION_DIR | |
local IOJS_VERSION=$(nvm_json_extract '\["engines","iojs"\]' < package.json | tr -d '"') | |
if [[ -n "$IOJS_VERSION" ]] ; then | |
if ! [[ "$IOJS_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
IOJS_VERSION=$(curl --silent --get --data-urlencode "range=${IOJS_VERSION}" https://semver.herokuapp.com/iojs/resolve) | |
fi | |
NVM_VERSION="iojs-v$IOJS_VERSION" | |
NVM_VERSION_DIR="$(nvm_version_path "$NVM_VERSION")" | |
if [ ! -d "$NVM_VERSION_DIR" ]; then | |
echo "Installing io.js v$IOJS_VERSION ..." | |
nvm install $NVM_VERSION | |
else | |
nvm use $NVM_VERSION | |
fi | |
return $? | |
fi | |
local NODE_VERSION=$(nvm_json_extract '\["engines","node"\]' < package.json | tr -d '"') | |
if [[ -n "$NODE_VERSION" ]] ; then | |
if ! [[ "$NODE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
NODE_VERSION=$(curl --silent --get --data-urlencode "range=${NODE_VERSION}" https://semver.herokuapp.com/node/resolve) | |
fi | |
NVM_VERSION="v$NODE_VERSION" | |
NVM_VERSION_DIR="$(nvm_version_path "$NVM_VERSION")" | |
if [ ! -d "$NVM_VERSION_DIR" ]; then | |
echo "Installing node v$NODE_VERSION ..." | |
nvm install $NVM_VERSION | |
else | |
nvm use $NVM_VERSION | |
fi | |
return $? | |
fi | |
echo "No engines.iojs or engine.node in package.json" | |
return 2 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can’t perform that action at this time.
Typically if people put
v1.2.x
inengines.node
, they meanio.js
- I've not seen anybody useengines.iojs
before. Is there a reason to not support that? The likelihood that a) node will get to v1.0 and create a version conflict b) before the two projects merge, or one dies, is pretty slim