-
Notifications
You must be signed in to change notification settings - Fork 593
Check for a .nvmrc or .node-version file to determine the Node.js version #1374
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
Changes from 8 commits
f32eb2c
f81c735
0af147a
b53b4f5
95fa5bc
97d81bd
c103184
7a45e54
9fc7ae9
a46abe2
c7c3f4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,7 +82,7 @@ | |
| "features": { | ||
| "node": { | ||
| "version": "16", | ||
| "pnpmVersion":"8.8.0" | ||
| "pnpmVersion": "8.8.0" | ||
| } | ||
| } | ||
| }, | ||
|
|
@@ -199,5 +199,35 @@ | |
| "installYarnUsingApt": false | ||
| } | ||
| } | ||
| }, | ||
| "test_node_project_nvmrc": { | ||
| "build": { | ||
| "dockerfile": "DockerFile" | ||
| }, | ||
| "features": { | ||
| "node": { | ||
| "version": "project-file" | ||
| } | ||
| } | ||
| }, | ||
| "test_node_project_nodev": { | ||
| "build": { | ||
| "dockerfile": "DockerFile" | ||
| }, | ||
| "features": { | ||
| "node": { | ||
| "version": "project-file" | ||
| } | ||
| } | ||
| }, | ||
| "test_node_project_nvm_nodev": { | ||
| "build": { | ||
| "dockerfile": "DockerFile" | ||
| }, | ||
| "features": { | ||
| "node": { | ||
| "version": "project-file" | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any specific reason why we are adding these test cases such that the container is built from Dockerfile only & not using the image tag directly?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes @Kaniska244 |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Optional: Import test library | ||
| source dev-container-features-test-lib | ||
|
|
||
| cd test_node_project_nodev/sample-node | ||
|
|
||
| # Check that .nvmrc exists | ||
| if [ ! -f .node-version ]; then | ||
| echo ".node-version file not found!" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Read the version from .nvmrc and compare with current node version | ||
| N_VERSION=$(cat .node-version | tr -d 'v') | ||
| NODE_VERSION=$(node -v | tr -d 'v') | ||
|
|
||
| if [ "$N_VERSION" != "$NODE_VERSION" ]; then | ||
| echo "Node version mismatch: .node-version specifies $N_VERSION, but current node is $NODE_VERSION" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo ".node-version is used and matches the current Node.js version." | ||
| # Report result | ||
| reportResults |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| FROM debian:11 | ||
|
|
||
| COPY sample-node /tmp/dev-container-features/node_0/sample-node |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 20.19.2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| console.log('Hello from Node.js!'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Optional: Import test library | ||
| source dev-container-features-test-lib | ||
|
|
||
| cd test_node_project_nvm_nodev/sample-node | ||
|
|
||
| # Check that .node-version exists | ||
| if [ ! -f .node-version ]; then | ||
| echo ".node-version file not found!" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Read the version from .node-version and compare with current node version | ||
| N_VERSION=$(cat .node-version | tr -d 'v') | ||
| NODE_VERSION=$(node -v | tr -d 'v') | ||
|
|
||
| if [ "$N_VERSION" != "$NODE_VERSION" ]; then | ||
| echo "Node version mismatch: .nvmrc specifies $N_VERSION, but current node is $NODE_VERSION" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo ".node-version is used and matches the current Node.js version." | ||
| # Report result | ||
| reportResults |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| FROM debian:11 | ||
|
|
||
| COPY sample-node /tmp/dev-container-features/node_0/sample-node |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 20.19.2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 22.9.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| console.log('Hello from Node.js!'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Optional: Import test library | ||
| source dev-container-features-test-lib | ||
|
|
||
| cd test_node_project_nvmrc/sample-node | ||
|
|
||
| # Check that .nvmrc exists | ||
| if [ ! -f .nvmrc ]; then | ||
| echo ".nvmrc file not found!" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Read the version from .nvmrc and compare with current node version | ||
| NVMRC_VERSION=$(cat .nvmrc | tr -d 'v') | ||
| NODE_VERSION=$(node -v | tr -d 'v') | ||
|
|
||
| if [ "$NVMRC_VERSION" != "$NODE_VERSION" ]; then | ||
| echo "Node version mismatch: .nvmrc specifies $NVMRC_VERSION, but current node is $NODE_VERSION" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo ".nvmrc is used and matches the current Node.js version." | ||
| # Report result | ||
| reportResults |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| FROM debian:11 | ||
|
|
||
| COPY sample-node /tmp/dev-container-features/node_0/sample-node |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 22.9.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| console.log('Hello from Node.js!'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure
findis the best option. Can we not assume the files need to be in the root directory? What if the project is huge,findwould take a long time. if there are multiple of these files,findmight order them differently based on where it is running, so something like:might work more predictably