Skip to content

Support an "engines" field in package.json #5846

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
Tracked by #159
lgarron opened this issue Sep 21, 2023 · 14 comments
Open
Tracked by #159

Support an "engines" field in package.json #5846

lgarron opened this issue Sep 21, 2023 · 14 comments
Labels
bun install Something that relates to the npm-compatible client enhancement New feature or request

Comments

@lgarron
Copy link
Contributor

lgarron commented Sep 21, 2023

What is the problem this feature would solve?

In #5845 I was testing with an outdated version of bun. Although I was creating a project from scratch, it is possible to catch similar compatibility issues among developers of a given repo by using the "engines" field of package.json — in particular, bun could show a compatibility warning (optionally overridable) instead of erroring deep in implementation code.

For those of us testing various versions of bun, this could be particularly useful to avoid head-scratching situations. It's also just generally useful for any project that is using features of bun as they become available, if any of those projects are checked out by multiple developers or on multiple devices.

What is the feature you are proposing to solve the problem?

Support "bun" version ranges in the "engines" field of package.json for both the project and dependencies.

What alternatives have you considered?

Leave things as-is, especially if it's a performance concern?

@lgarron lgarron added the enhancement New feature or request label Sep 21, 2023
@paperclover
Copy link
Contributor

i dont think its a huge big deal, but right now yarn puts a warning for packages that use an unknonw engine. but this is the only package manager to do it.

image

otherwise, this is something we've thought about.

@Electroid Electroid added the bun install Something that relates to the npm-compatible client label Sep 21, 2023
@adematte
Copy link

as most teams will end up with a mix of node and bun for their projects, this would make sense to support the engines field of package.json. Otherwise we are left with only README.md to indicate what version of bun or node (or both), we need to run a given project.

@Kleywalker
Copy link

Are there any plans to implement this feature?

@paperclover
Copy link
Contributor

yes but probably not right now. i think it would be cool if bun in the engines field could be used to force the --bun flag for clis

@gornostay25
Copy link
Contributor

@lgarron Any updates?

@strafe
Copy link

strafe commented Feb 27, 2024

Seems like this is the only reasonable way to know which runtime a project is meant to be used with. For reproducibility's sake, this is kind of needed. Once this is done and bun is supported by corepack we can all sleep easy.

lgarron added a commit to lgarron/barely-a-dev-server that referenced this issue Mar 6, 2024
…omises`.

This requires `bun` v1.0.30. `bun` doesn't support the `"engines"` field in `package.json`, but I'm going to try setting it to see what happens: oven-sh/bun#5846
@vitch
Copy link
Contributor

vitch commented May 23, 2024

I came across this while trying to find a way to force all users of our monorepo to update to the newly released [email protected].

It looks like the oven-sh/setup-bun@v1 GitHub action searches package.json for the string bun@ in the packageManager field which is what corepack would use if corepack supported bun.

Is there any way to try and force all users to use a particular version of bun or should I add a test which checks Bun.version against package.json::packageManager or something?

lgarron added a commit to cubing/twsearch that referenced this issue Jun 1, 2024
@Kleywalker
Copy link

Is this being considered as a possible feature, and if so, will it be implemented in the near future?

@afonsojramos
Copy link

I came across this while trying to find a way to force all users of our monorepo to update to the newly released [email protected].

It looks like the oven-sh/setup-bun@v1 GitHub action searches package.json for the string bun@ in the packageManager field which is what corepack would use if corepack supported bun.

Is there any way to try and force all users to use a particular version of bun or should I add a test which checks Bun.version against package.json::packageManager or something?

@vitch Nice callout!

Found this in the setup-bun action, pay attention to the bum file, which references: https://github.com/owenizedd/bum
image

Might be a good intermediate solution while bun itself doesn't add support to it.

Note: I'll try to setup the bun project locally today and try to work on this. Can't guarantee success as it will be the first dabble in Zig

@therealparmesh
Copy link

therealparmesh commented Aug 21, 2024

@wesleytodd
Copy link

I saw this issue because of the link in the comment above. In case folks hadn't seen this, a group of folks have been working on a more robust proposal to cover packageManager and related things. We are calling it devEngines and it looks to be acceptable by both the npm and pnpm teams. Worth considering in this conversation I would think.

openjs-foundation/package-metadata-interoperability-collab-space#15

@lgarron
Copy link
Contributor Author

lgarron commented Jan 3, 2025

Now that Bun is gaining a new lockfile format, I think it would be more valuable than ever to be able to specify "this project requires a minimum bun version".

@RiskyMH RiskyMH marked this as a duplicate of #12566 Jan 31, 2025
@dy0gu
Copy link
Contributor

dy0gu commented Feb 23, 2025

Any plans for this? It would aid migration to the new lockfile in codebases with multiple devs that may not have bun updated.

@vitch
Copy link
Contributor

vitch commented Feb 23, 2025

FWIW I just wrote a check-bun-version.ts script which looks like this:

#!/usr/bin/env bun
let { default: packageJson } = await import('../../package.json');

let { packageManager } = packageJson;
let [, expectedBunVersion] = packageManager.split('@');

if (expectedBunVersion === Bun.version) {
  console.log(`Bun version ${expectedBunVersion} ok`);
} else {
  throw new Error(
    `Running with wrong bun version. Got ${Bun.version}, expected ${expectedBunVersion}`,
  );
}

I call the script at the head of my other scripts. It's not fool proof but it has helped keep our small team synced and make sure no one forgets to update. And it's reading the same field that CI does (via oven-sh/setup-bun) which means we're synced with that too...

Something built in would obviously be way better but this might help someone out in the meantime...

lgarron added a commit to cubing/twsearch that referenced this issue Mar 7, 2025
This costs just under 30ms on my computer.

This is a stopgap for an implementation in `bun` itself: oven-sh/bun#5846
lgarron added a commit to cubing/twsearch that referenced this issue Mar 7, 2025
This costs just under 45ms on my computer.

This is a stopgap for an implementation in `bun` itself: oven-sh/bun#5846
lgarron added a commit to cubing/twsearch that referenced this issue Mar 7, 2025
This costs just under 45ms on my computer.

This is a stopgap for an implementation in `bun` itself: oven-sh/bun#5846
lgarron added a commit to cubing/twsearch that referenced this issue Mar 9, 2025
I specifically wanted to do it the other way around, but that only works if older dependencies are not yet installed.

I don't want to vendor version checking code, so the only proper fix is to wait for oven-sh/bun#5846

Installing deps first should usually be safe, though, so we do that for now. If there's version mismatch, `make setup-js` will probably be run before the deps need to be used, and hopefully `bun` can handle installation continuity between versions consistently.
lgarron added a commit to cubing/cubing.js that referenced this issue May 18, 2025
This takes about 0.1 seconds, which increases parallel `make test-fast` by about 10% for something that is *almost* never necessary. 😕

I'm hoping oven-sh/bun#5846 will eliminate the need for this some day.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bun install Something that relates to the npm-compatible client enhancement New feature or request
Projects
None yet
Development

No branches or pull requests