Skip to content

Commit 460684d

Browse files
[Node] - nvm - fallback to previous version - code fix (devcontainers#904)
* [node] - nvm - added fallback to prev. version - if latest version tag released but binary not found * bumped patch version
1 parent 8af4ce3 commit 460684d

4 files changed

Lines changed: 41 additions & 3 deletions

File tree

src/node/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "node",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"name": "Node.js (via nvm), yarn and pnpm",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/node",
66
"description": "Installs Node.js, nvm, yarn, pnpm, and needed dependencies.",

src/node/install.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,11 @@ set -e
293293
umask 0002
294294
# Do not update profile - we'll do this manually
295295
export PROFILE=/dev/null
296-
curl -so- "https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh" | bash
297-
296+
curl -so- "https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh" | bash || {
297+
PREV_NVM_VERSION=$(curl -s https://api.github.com/repos/nvm-sh/nvm/releases/latest | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
298+
curl -so- "https://raw.githubusercontent.com/nvm-sh/nvm/\${PREV_NVM_VERSION}/install.sh" | bash
299+
NVM_VERSION="\${PREV_NVM_VERSION}"
300+
}
298301
source "${NVM_DIR}/nvm.sh"
299302
if [ "${NODE_VERSION}" != "" ]; then
300303
nvm alias default "${NODE_VERSION}"

test/node/nvm_test_fallback.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
set -e
9+
10+
trap 'echo "Error occurred at line $LINENO"; exit 1' ERR
11+
source /usr/local/share/nvm/nvm.sh
12+
#check nvm version
13+
echo -e "\n✅ nvm version as installed by feature = v$(nvm --version)";
14+
NVM_DIR="/usr/local/share/nvm"
15+
NODE_VERSION="lts"
16+
FAKE_NVM_VERSION="1.2.XYZ"
17+
curl -so- "https://raw.githubusercontent.com/nvm-sh/nvm/v${FAKE_NVM_VERSION}/install.sh" | bash || {
18+
PREV_NVM_VERSION=$(curl -s https://api.github.com/repos/nvm-sh/nvm/releases/latest | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
19+
curl -so- "https://raw.githubusercontent.com/nvm-sh/nvm/${PREV_NVM_VERSION}/install.sh" | bash
20+
NVM_VERSION="${PREV_NVM_VERSION}"
21+
}
22+
23+
#check nvm version
24+
echo -e "\n✅ nvm version as installed by test = v$(nvm --version)";
25+
26+
# Report result
27+
reportResults

test/node/scenarios.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
{
2+
"nvm_test_fallback": {
3+
"image": "debian:11",
4+
"features": {
5+
"node": {
6+
"version": "lts"
7+
}
8+
}
9+
},
210
"install_additional_node": {
311
"image": "debian:11",
412
"features": {

0 commit comments

Comments
 (0)