Skip to content

Package manager detection #25

Open
@arcanis

Description

@arcanis

We were discussing with @iansu the case where package managers are detected depending on whether they are or not in the global path (@ljharb mentioned that as well in another thread). Tracking some thoughts:

  • Existing CRA & similar tutorials mention npm, so newcomers might be surprised if it gets installed via Yarn.

  • At the same time, it would be similarly confusing if tools like CRA were to always default to npm, given their current behavior.

  • If we do this Corepack thing, it's at least in part so that all package managers are on the same foot.

  • The problem only affects scaffolders, since existing projects will necessarily already have their install creations.

One potential solution would be to offer a BrowserChoice-like system under the form of a Corepack command (let's say corepack elect for now) that, when called:

  • If the command was never run before, it would print all supported package managers with an interactive interface listing their name and a link towards their respective websites. Upon selecting one of the options, Corepack would save the result inside its data folder, then would print the name of the selected package manager.

  • If the command ran before, it would simply read the data previously stored inside the data folder, and print again without prompting the user.

From the integrator perspective, the way it would work:

  • Instead of checking for Yarn's existence with things like yarn --version, the program would run corepack elect and capture the output. It would then branch depending on the result as before.

  • They could still implement their flags like --use-npm or --use-yarn, so that users can override their choice on a per-command basis.

One nice effect is that this would make it much clearer for the users which package manager they would be using. Right now, it's difficult to know whether Yarn or npm will end up being used unless 1/ you know that CRA has this behavior, and 2/ you remember whether you installed Yarn or not (you may have installed it only for another project a long time ago).

On the minus side it means that tools like CRA would have to add support for this feature, so it would require their input to know how they would feel about this workflow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions