Repository navigation
Description
This is a draft spec for nodejs/node#51888 (comment), to define the runtime and package manager for developing a project or package (not consuming/installing it as a dependency in another project). We could use the name devEngines and it would be a new top-level field defined with this schema:
interface DevEngines {
os?: DevEngineDependency | DevEngineDependency[];
cpu?: DevEngineDependency | DevEngineDependency[];
libc?: DevEngineDependency | DevEngineDependency[];
runtime?: DevEngineDependency | DevEngineDependency[];
packageManager?: DevEngineDependency | DevEngineDependency[];
}
interface DevEngineDependency {
name: string;
version?: string;
onFail?: 'ignore' | 'warn' | 'error' | 'download';
}The os, cpu, libc, runtime, and packageManager sub-fields could either be an object or an array of objects, if the user wants to define multiple acceptable OSes, CPUs, C compilers, runtimes or package managers. The first acceptable option would be used, and onFail would be triggered for the last defined option if none validate. If unspecified, onFail defaults to error for the non-array notation; or it defaults to error for the last element in the array and ignore for all prior elements, for the array notation. Validation would check the name and version ranges.
The name field would be a string, corresponding to different sources depending on the parent field:
os: NPM docs forengines.os.cpu: NPM docs forengines.cpu.libc:glibcormusl; see NPM docs forconfig.libc.runtime: WinterCG Runtime Keys.packageManager. . . I don’t know, we could define the list as part of the spec, or perhaps it would need to correspond to an npm registry package name. Suggestions welcome.
The version field syntax would match that defined for engines.node, so something like ">= 16.0.0 < 22" or ">= 20". If unspecified, any version matches.
The onFail field defines what should happen if validation fails:
ignore: nothing.warn: print something and continue.error: print something and exit.download: remediate the validation failure by downloading the requested tool/version.
In the event of onFail: 'download', it would be the responsibility of the tool to determine what and how to download, perhaps by looking in the tool’s associated lockfile for a specific version and integrity hash. It could also be supported on a case-by-case basis, like perhaps Yarn and pnpm could support downloading a satisfactory version while npm would error.
Typical example:
"devEngines": {
"runtime": {
"name": "node",
"version": ">= 20.0.0",
"onFail": "error"
},
"packageManager": {
"name": "yarn",
"version": "3.2.3",
"onFail": "download"
}
}“Uses every possible field” example:
"devEngines": {
"os": {
"name": "darwin",
"version": ">= 23.0.0"
},
"cpu": [
{
"name": "arm"
}, {
"name": "x86"
}
],
"libc": {
"name": "glibc"
},
"runtime": [
{
"name": "bun",
"version": ">= 1.0.0",
"onFail": "ignore"
},
{
"name": "node",
"version": ">= 20.0.0",
"onFail": "error"
},
],
"packageManager": [
{
"name": "bun",
"version": ">= 1.0.0",
"onFail": "ignore"
},
{
"name": "yarn",
"version": "3.2.3",
"onFail": "download"
}
]
}Some potential future expansions of this spec that have been discussed are:
runtimeandpackageManagermight take shorthand string values defining the desired name or name with version/version range.
Activity
ljharb commentedon Feb 27, 2024
wesleytodd commentedon Feb 27, 2024
GeoffreyBooth commentedon Feb 27, 2024
wraithgar commentedon Feb 27, 2024
GeoffreyBooth commentedon Feb 27, 2024
But in this case, the user is the maintainer. This whole configuration block only applies when it’s the developer of the package/project.
wraithgar commentedon Feb 27, 2024
How does
downloadeven work with a semver range? If these are all npm registry packages then there is already a well defined discovery mechanism for downloading a given named package at a given version.I'd love to hear from yarn or pnpm if and how they'd plan on handling the failure state where the user has indicated they want to download the correct version. How do you pick the version? Do you spawn it yourself? Why not fail and let the user remediate?
wraithgar commentedon Feb 27, 2024
Good point. As you can see the lines between "installing as module" and "interacting as app" are so blurry that even I missed that.
GeoffreyBooth commentedon Feb 27, 2024
If a URL is provided, we’re just downloading that exact URL. The version constraint wouldn’t apply.
If we want to allow
onFail: 'download'and a missingdownloadfield, the only behavior I can think of would be to query the npm registry for the requested package manager and download the newest version that fits within the range.wesleytodd commentedon Feb 27, 2024
GeoffreyBooth commentedon Feb 27, 2024
ljharb commentedon Feb 27, 2024
This is a great start. I think it's important that it not just be limited to the runtime and the package manager -
process.versionshas a lot of things in it that would be really nice to also constrain in various cases, especially openssl which has lots of CVEs.styfle commentedon Feb 27, 2024
Tagging relevant people to review the draft spec: @Ethan-Arrowood @arcanis @zkochan @aduh95
wraithgar commentedon Feb 27, 2024
I am not very good at reading specs like this. What would it look like in implementation to limit the local dev environment to a given os or cpu for example? From what I see it doesn't look like that field is sufficiently decoupled from "named" which doesn't make sense in that context.
aduh95 commentedon Feb 27, 2024
packageManageris already used in the wild as a string, we'd need to define what happens when the value is a string to allow a smooth transition – another option is to use a different key, butpackageManageris quite good a describing what it is.wesleytodd commentedon Feb 27, 2024
This proposal covers way more than package manager and would not be under that field name (although it is not mentioned above). I think that should have always been the goal, so that is why keeping the field "experimental" in node core was important. I agree we would want to smooth the path. But I think that is up to the folks who implemented the field in their tools. Maybe here we would just discuss goals for ways to make that transition?
117 remaining items
GeoffreyBooth commentedon Sep 7, 2024
I can open a PR with the top post as a file.
reggi commentedon Sep 10, 2024
Not sure if this has been touched on. This does have some interesting consequences for runtimes which do
nodeinterop if someone specifiesnodebut is running within thedeno, it supports an emulated version ofnodeas(await import('node:process')).version"v20.11.1". If you putnodedo you really mean truenode, or is emulatednodeok? Ifdenowere to implement adevEnginescheck ondeno installshould it fail on a project that specifiesnode? Alsobunanddenoare both runtimes and package managers unlikeyarnandpnpm, not sure if this has any consequences as well, except for the duplication of the fields.ljharb commentedon Sep 10, 2024
I think that'd be up to the runtime providing emulation - if it's confident it's the same, then it'd be ok to pretend it's the same, and if it's not exactly the same, it wouldn't count.
I think one runtime actually emulating another is a rare enough scenario that we don't have to plan for it much.
chore: add engines-field
feat: devEngines (#7766)
wraithgar commentedon Oct 4, 2024
npm@10.9.0has an initial implementation of this spec.ljharb commentedon Oct 5, 2024
Awesome! Within the next week, I'll try to make a PR to npm to add a way to make it useful in a CI matrix.
Ethan-Arrowood commentedon Oct 8, 2024
With #27 merged, lets continue and start new discussions regarding this field through separate issues or PRs to that document. Everyone is welcome to contribute details to that document as well if there are certain discussions/decisions you'd like to be documented. Thank you all for the collaboration here 🚀 together we are making JS development better and better
chore: use devEngines field
Nayawana commentedon Dec 5, 2024
Nayawana commentedon Dec 5, 2024
Nayawana commentedon Dec 5, 2024
Update dependency pnpm to v10
zkochan commentedon Oct 29, 2025
I am thinking about adopting the same format in "engines". For a CLI tool package it would make sense to be able to choose which version of node.js it is installed with. So, with the following "engines" field:
{ "engines": { "runtime": { "name": "node", "version": "24" "onFail": "download" } } }the package manager would install the package with the desired node.js runtime. This would allow popular CLI tools that are not meant to be used via a programmatic API, to just support one version of Node.js and it would make the tools more stable overall.