-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(node-version-file): support parsing devEngines
field
#1283
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Ferdinand Thiessen <[email protected]>
Awsome! Appreciate for your work. |
anything I can help with to push this forward? :) |
// support devEngines from npm 11 | ||
if ( | ||
manifest.devEngines?.runtime?.name === 'node' && | ||
manifest.devEngines.runtime.version | ||
) { | ||
return manifest.devEngines.runtime.version; | ||
} | ||
|
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.
manifest.devEngines.runtime
can be an array of objects. see: https://docs.npmjs.com/cli/v11/configuring-npm/package-json#devengines
// support devEngines from npm 11 | |
if ( | |
manifest.devEngines?.runtime?.name === 'node' && | |
manifest.devEngines.runtime.version | |
) { | |
return manifest.devEngines.runtime.version; | |
} | |
// support devEngines from npm 11 | |
if (manifest.devEngines?.runtime) { | |
const runtimes = [].concat(manifest.devEngines.runtime); | |
const { version } = runtimes.find( | |
(runtime) => runtime.name.toLowerCase() === "node" && runtime.version | |
); | |
return version; | |
} | |
${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'} | ${'>=14.0.0 <=17.0.0'} | ||
${'{"volta": {"extends": "./package.json"}}'} | ${'18.0.0'} | ||
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'} | ||
${'{"devEngines": {"runtime": {"name": "node", "version": "22.0.0"}}}'} | ${'22.0.0'} |
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.
${'{"devEngines": {"runtime": {"name": "node", "version": "22.0.0"}}}'} | ${'22.0.0'} | |
${'{"devEngines": {"runtime": {"name": "node", "version": "22.0.0"}}}'} | ${'22.0.0'} | |
${'{"devEngines": {"runtime": [{"name": "bun"}, {"name": "node", "version": "22.0.0"}]}}'} | ${'22.0.0'} |
@@ -0,0 +1,11 @@ | |||
{ | |||
"engines": { | |||
"node": "^20 || ^22" |
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.
this would make the test more reliable and easier to understand
"node": "^20 || ^22" | |
"node": "^19" |
node-version-file: '__tests__/data/package-dev-engines.json' | ||
- name: Verify node | ||
run: __tests__/verify-node.sh 20 | ||
|
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.
version-file-dev-engines-array: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup node from node version file | |
uses: ./ | |
with: | |
node-version-file: '__tests__/data/package-dev-engines-array.json' | |
- name: Verify node | |
run: __tests__/verify-node.sh 20 | |
suggested file content:
{
"engines": {
"node": "^19"
},
"devEngines": {
"runtime": [
{
"name": "bun",
"version": "^1"
},
{
"name": "node",
"version": "^20"
}
]
}
}
```json | ||
{ | ||
"engines": { | ||
"node": "^20 || ^22" |
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.
"node": "^20 || ^22" | |
"node": "^19" |
Description:
Currently if you want to support multiple versions for running (e.g. a library) but enforce a specific version for development you can set
devEngines
with npm 11.This PR adds support for parsing the
devEngines.runtime
field (if it is set tonode
) for allowing automatic setup.Related issue:
devEngines
field inpackage.json
#1255Check list: