Skip to content

Define spec for development environment field #15

Closed

Description

@GeoffreyBooth

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:

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:

  • runtime and packageManager might take shorthand string values defining the desired name or name with version/version range.

Activity

  1. ljharb commented on Feb 27, 2024

    @ljharb
  2. wesleytodd commented on Feb 27, 2024

    @wesleytodd
  3. GeoffreyBooth commented on Feb 27, 2024

    @GeoffreyBooth
    Author
  4. wraithgar commented on Feb 27, 2024

    @wraithgar
  5. GeoffreyBooth commented on Feb 27, 2024

    @GeoffreyBooth
    ContributorAuthor

    onFail is a user directive, not a maintainer directive.

    But in this case, the user is the maintainer. This whole configuration block only applies when it’s the developer of the package/project.

  6. wraithgar commented on Feb 27, 2024

    @wraithgar

    How does download even 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?

  7. wraithgar commented on Feb 27, 2024

    @wraithgar

    But in this case, the user is the maintainer

    Good point. As you can see the lines between "installing as module" and "interacting as app" are so blurry that even I missed that.

  8. GeoffreyBooth commented on Feb 27, 2024

    @GeoffreyBooth
    ContributorAuthor

    How does download even work with a semver range?

    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 missing download field, 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.

  9. wesleytodd commented on Feb 27, 2024

    @wesleytodd
  10. GeoffreyBooth commented on Feb 27, 2024

    @GeoffreyBooth
    Author
  11. ljharb commented on Feb 27, 2024

    @ljharb
    Member

    This is a great start. I think it's important that it not just be limited to the runtime and the package manager - process.versions has a lot of things in it that would be really nice to also constrain in various cases, especially openssl which has lots of CVEs.

  12. styfle commented on Feb 27, 2024

    @styfle
    Contributor

    Tagging relevant people to review the draft spec: @Ethan-Arrowood @arcanis @zkochan @aduh95

  13. wraithgar commented on Feb 27, 2024

    @wraithgar

    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.

  14. aduh95 commented on Feb 27, 2024

    @aduh95

    packageManager is 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, but packageManager is quite good a describing what it is.

  15. wesleytodd commented on Feb 27, 2024

    @wesleytodd
    Member

    but packageManager is quite good a describing what it is .... is already used in the wild as a string

    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?

  16. 117 remaining items

  17. GeoffreyBooth commented on Sep 7, 2024

    @GeoffreyBooth
    ContributorAuthor

    Would anyone like to volunteer to do step 1?

    I can open a PR with the top post as a file.

  18. reggi commented on Sep 10, 2024

    @reggi

    Not sure if this has been touched on. This does have some interesting consequences for runtimes which do node interop if someone specifies node but is running within the deno, it supports an emulated version of node as (await import('node:process')).version "v20.11.1". If you put node do you really mean truenode, or is emulated node ok? If deno were to implement a devEnginescheck on deno install should it fail on a project that specifies node? Also bun and deno are both runtimes and package managers unlike yarn and pnpm, not sure if this has any consequences as well, except for the duplication of the fields.

  19. ljharb commented on Sep 10, 2024

    @ljharb
    Member

    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.

  20. added a commit that references this issue on Sep 24, 2024
  21. added a commit that references this issue on Oct 3, 2024
  22. wraithgar commented on Oct 4, 2024

    @wraithgar

    npm@10.9.0 has an initial implementation of this spec.

  23. ljharb commented on Oct 5, 2024

    @ljharb
    Member

    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.

  24. Ethan-Arrowood commented on Oct 8, 2024

    @Ethan-Arrowood
    Collaborator

    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

  25. added a commit that references this issue on Oct 27, 2024
  26. Nayawana commented on Dec 5, 2024

    @Nayawana
  27. Nayawana commented on Dec 5, 2024

    @Nayawana
  28. Nayawana commented on Dec 5, 2024

    @Nayawana
  29. added a commit that references this issue on Aug 16, 2025
  30. zkochan commented on Oct 29, 2025

    @zkochan

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions