Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

susnux
Copy link

@susnux susnux commented Apr 20, 2025

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 to node) for allowing automatic setup.

Related issue:

Check list:

  • Mark if documentation changes are required.
  • Mark if tests were added or updated to cover the changes.

@susnux susnux requested a review from a team as a code owner April 20, 2025 11:24
@zanminkian
Copy link

Awsome! Appreciate for your work.

@susnux
Copy link
Author

susnux commented Jun 4, 2025

anything I can help with to push this forward? :)

Comment on lines +29 to +36
// support devEngines from npm 11
if (
manifest.devEngines?.runtime?.name === 'node' &&
manifest.devEngines.runtime.version
) {
return manifest.devEngines.runtime.version;
}

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

Suggested change
// 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'}
Copy link

@SunsetTechuila SunsetTechuila Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
${'{"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"

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

Suggested change
"node": "^20 || ^22"
"node": "^19"

node-version-file: '__tests__/data/package-dev-engines.json'
- name: Verify node
run: __tests__/verify-node.sh 20

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"node": "^20 || ^22"
"node": "^19"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support devEngines field in package.json
3 participants