Skip to content
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

Support for semver ranges? #95

Open
jsumners opened this issue Mar 2, 2022 · 25 comments · May be fixed by #300 or #634
Open

Support for semver ranges? #95

jsumners opened this issue Mar 2, 2022 · 25 comments · May be fixed by #300 or #634

Comments

@jsumners
Copy link

jsumners commented Mar 2, 2022

I'd like to write a package.json like:

{
  "packageJson": "pnpm@6"
}

Or maybe pnpm@^6.32.2, etc.

As it stands, adding a package manager to package.json requires a full specified version. This adds more maintenance overhead.

I think this is related to #93.

@shellscape
Copy link

Agreed. pnpm v7 was released just yesterday and I'd hoped to use corepack moving forward instead of manually installing it for all of our workflows. This is probably done so along the lines of "pin your dependencies," but doesn't meet all needs.

@styfle
Copy link
Member

styfle commented Jun 10, 2022

Would this need to perform a network request every time you do pnpm run <script> to check for the latest pnpm, since you can't rely the cached copy anymore?

@jsumners
Copy link
Author

Would this need to perform a network request every time you do pnpm run <script> to check for the latest pnpm, since you can't rely the cached copy anymore?

Good question. I think some sort of "check every X time window" would be acceptable. Similar to https://github.com/ohmyzsh/ohmyzsh/blob/d41ca84af1271e8bfbe26f581cebe3b86521d0db/oh-my-zsh.sh#L59-L62

@aduh95
Copy link
Contributor

aduh95 commented Jun 29, 2022

It looks like this was originally possible, and was removed in #18.

@boneskull
Copy link

This seems kind of odd to restrict matching on exact version when one can provide any dist-tag instead (which can be moved around at will).

Reverting the restriction would help my use case: use corepack to test or try something on a package manager where only the major version matters. I have sinking feeling my use case is out of scope...

@aduh95
Copy link
Contributor

aduh95 commented Aug 6, 2023

@boneskull The restriction only applies to the package.json ad hoc field, you can still do e.g. corepack [email protected] install, does that cover your use case?

@boneskull
Copy link

that wasn't working as of a couple hours ago. corepack npm@7 unknown version or smth to that effect

@boneskull
Copy link

wrapping corepack to support this, I've pulled down the result of npm show --json <npm|yarn|pnpm> versions, then use semver to try match a range.

@aduh95
Copy link
Contributor

aduh95 commented Aug 9, 2023

@boneskull are you using an old version of Corepack maybe? For me, running COREPACK_ENABLE_PROJECT_SPEC=0 corepack npm@7 --version works and returns 7.20.1.

@boneskull
Copy link

@aduh95 I wonder if the env var was the problem. Seems to work now, thanks.

@uiolee
Copy link

uiolee commented Oct 25, 2023

Totally agree.

The exact version of the package manager prevents me from working on different projects. I don't think most projects need an exact package manager. corepack should introduce the semver strategy likes dependencies management do.

@mrgrain
Copy link

mrgrain commented Nov 1, 2023

I always want to use the latest version of my package manager. The exception usually is on a new major release, when I first have to run a few validations.

With the current restrictions to only exact versions, I have to make a change every time I want to update the version of the package manger. Worst case, this needs to be done through a PR and I need to bother a co-worker with a review.

@boneskull
Copy link

boneskull commented Nov 13, 2023

@mrgrain Couldn't you use a dist tag? e.g., npm@latest

@mrgrain
Copy link

mrgrain commented Nov 13, 2023

@mrgrain Couldn't you use a dist tag? e.g., npm@latest

I don't think dist tags are supported either? If they are, that would certainly be better than nothing.

However the problem with dist tags is

a) it's usually latest which will cause users to receive untested major version upgrades.

b) since a dist tag points to a specific version, we still impose an upgrade to the user.

@MattSilvaa
Copy link

Hi! I'm curious whether a decision has been reached to add the functionality back for supporting semver ranges?

@mcollina
Copy link
Member

This would be great to implement this before calling it stable.

@arcanis
Copy link
Contributor

arcanis commented Jan 12, 2024

I'm still not convinced this is a good idea:

  • It prevents using hashes to ensure the version is the expected one
  • It gives users a false sense of confidence that their project will always be installable (bugfixes may be breaking changes)

You can already use corepack up whenever you want to upgrade the package manager, I don't think an implicit upgrade should be encouraged as a good practice.

@mcollina
Copy link
Member

What i would like the default behavior to be given version of Node.js 22, is that corepack is enabled by default and pnpm i always installs the same major. I might have misunderstood this issue, but it would look like this is needed for that.

@mrgrain
Copy link

mrgrain commented Jan 12, 2024

I'm still not convinced this is a good idea:

  • It prevents using hashes to ensure the version is the expected one
  • It gives users a false sense of confidence that their project will always be installable (bugfixes may be breaking changes)
    You can already use corepack up whenever you want to upgrade the package manager, I don't think an implicit upgrade should be encouraged as a good practice.

These are vary valid concerns and I understand that we should encourage explicit versions as the best practice. However I believe that many projects do not currently see this as a major concern, otherwise we would see a lot of very specific engines declaration.

The other use case is really around validation. If corepack already has a version of pnpm installed that satisfies the constraint pnpm@6, why should it install a slightly different version? This is just a waste of resources. Like you've said, users can run corepack up to upgrade. Of course explicit versions are still supported if you as owner prefer this. Ultimately this is about choice.

G-Rath added a commit to ackama/rails-template that referenced this issue Jan 26, 2024
…#528)

[`react-rails` now supports other package
managers](reactjs/react-rails#1306) using
`package_json`, meaning it now defaults to `npm` if a package manager is
not explicitly set in `package.json`, causing a stray
`package-lock.json` to be created.

I've specified an exact version because currently `corepack` requires
that ([ranges are not yet
supported](nodejs/corepack#95)) but we're not
actually expecting anyone to be using `corepack` and we're definitely
not using it in production (not explicitly at least...) so in theory
this shouldn't cause problems and it means `package.json` conforms to
the JSON schema - it'll also help to flush out any potential problems
early before(/if) `corepack` becomes more mainstream.
@xsjcTony
Copy link

+1

vanyauhalin added a commit to vanyauhalin/moondusttheme that referenced this issue May 1, 2024
Remove the packageManager field from the package.json due to nodejs/corepack#95
@jordanebelanger
Copy link

Every well known package manager supported by the experimental packageManager field uses semver (and most large opensource projects in general). From that perspective where semver is usually expected, it's common sense that it should be possible to restrict to a major version. If the maintainers of a package manager introduce a breaking change for an existing major version by accident and it breaks our installations, so be it, if someone is that worried about that there should simply be a way of specifying an exact version.

@Aeolun
Copy link

Aeolun commented May 14, 2024

if someone is that worried about that there should simply be a way of specifying an exact version

Yeah, this is common practice literally everywhere. If you care about getting exact versions, you specify the exact version. If you do not, you specify a range.

I don't really understand how you can make a field that looks like it's a semver specifier, in a file full of semver specifiers, and then not actually make it semver. Like, wut?

JoshuaKGoldberg added a commit to JoshuaKGoldberg/create-typescript-app that referenced this issue May 21, 2024
## PR Checklist

- [x] Addresses an existing open issue: fixes #1513
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

Right now, trying to use `create-typescript-app` with anything but the
_exact correct pnpm major.minor.patch version_ installed produces an
error. That's very annoying.

Pending nodejs/corepack#95, removes usage of
the [experimental `package.json` `packageManager`
field](https://nodejs.org/api/packages.html#packagemanager).
@guilherssousa
Copy link

+1

@anthonyalayo
Copy link

What is the current best practice for this? Remove the entry in the package.json?

@aduh95
Copy link
Contributor

aduh95 commented Jan 24, 2025

What is the current best practice for this? Remove the entry in the package.json?

You can run corepack up to bump the version in the same major, and corepack use <your package manager>@<major version>.x to use a different major version.

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