-
Notifications
You must be signed in to change notification settings - Fork 169
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
Feature request: corepack run #57
Comments
This isn't possible. Each package manager has different implementations of |
Maybe you can forward the args if you implement #25, then |
I believe there are two slightly different issues here. The choice of the package manager for the root command and for the commands inside In particular, situations like the following are problematic as they require the consumer to have
Yarn 2+ supports "package manager independent
This is the best solution for portable scripts calling other scripts in my opinion, I just hope this is adopted by
|
@demurgos the "scripts" field can not be run by consumers - it can only be run by developers of the project. Only the "bin" field are things that can be executed by consumers. |
I think @demurgos' point was that postinstall scripts find it difficult to execute scripts in a portable way across package managers (in a way that whatever package manager is used to install the package will also be called to run the scripts). The two options are currently to either hardcode Yarn supports calling As for |
Some of the the Even if I find |
Ha, good point, i wasn’t thinking about lifecycle scripts. |
I believe there are some legitimate usecases. Muscle memory works when you use the same package manager in all the projects you are working on but that is not always the case. https://github.com/antfu/ni Seems to be somewhat popular to address some of this, not the best data point but it shows a bit of community thirst for something like this. Would also help when writing a sharable CI config in orgs where they use multiple package managers. Simplifying running commands / installing deps / etc. |
Also checkout https://github.com/egoist/dum which solves most of these use cases. I would like a feature like this, although I'm not sure this is the responsibility of corepack. Or rather, I wouldn't want it exposed as a public command through corepack cli. Ideally, this feature would be exposed like |
Running scripts depend on knowledge unique to each package manager, so it couldn't be in Node (at best it perhaps could be in Corepack since it could then delegate to the right package manager, but even that could lead into conflict problems). |
What I mean is that I don't think the user should be interacting with the corepack cli (it could still be implemented in corepack under the hood though). For example, if corepack is enabled by default (#104), then users won't really ever use corepack cli so it would feel strange to suddenly introduce it to run scripts. |
Adding a feature to corepack CLI doesn't force anyone to use it though, it may make that feature harder to discover, but that doesn't seem to be a good enough reason for rejecting it on that basis alone. FWIW, it happened to me more than once to try to run e.g. |
The situation is different - Yarn is a single program, so even if there's a conflict between its commands and the user scripts, those problem tends to be easily spotted (commands and scripts tend to do very different things). In Corepack, we are abstracting multiple package managers, each with their own different behaviours (for example For this reason, I agree with @styfle that the
I don't agree with this - the JS community is large, and many many many people would misinterpret the very existence of such an optional feature in Node as meaning "it's official, you don't need to specify the package manager name anymore" - then they would get pissed when it doesn't work as they expect from one project to the other, or because it doesn't work for all commands, or [...] - eventually blaming it on either Corepack or package manager authors. |
To clarify, I agree that "we don't see a way to make it work without breaking users expectations" is a perfectly valid reason for not implementing it. I just wanted to point out that "I don't think the user should be interacting with the corepack cli" is not imo, because folks who don't want to use corepack cli won't be forced to use it whether or not we add features to it. |
Just wanted to mention another package https://github.com/BendingBender/yarpm as a solution to the package.json scripts issue. I liked that the readme for yarpm makes it clear that it is not trying to be a package manager abstraction layer and that package authors must make sure that their scripts are compatible with all package managers if they want to use yarpm in their package.json scripts. This seems important for package authors to know, that you don't just get compatibility with all package managers for free (to arcanis' point above). |
It sounds like the path forward here is to create a npm RFC for the Are there any yarn docs that the npm team can reference to make sure it works the same way if/when they implement it? |
Adding a new top-level binary is likely to be a nonstarter; |
I should add a note about it to our documentation, for sure.
This isn't a top-level binary in the same way you may think about it. It's only available inside |
What would be the point of that? |
Make install scripts able to cross-refer to other scripts without having to hardcode package manager names (or use |
TIL, that would indeed fix the issue! I suspect most |
I must have missed that above! I tried {
"scripts": {
"compile": "echo 'compile done'",
"download": "echo 'download done'",
"postinstall": "$npm_execpath run download && $npm_execpath run compile"
}
}
|
Oh no, I just realized that That explains why no one would use it for |
Although it doesn't solve the underlying portability problem, it actually works for Yarn Modern even on Windows. |
Looks like this might be solved with |
closes: #8288 ## Description ui-kit was recently bumped to Yarn 4 and @samsiegart hit a snag that required patching : Agoric/ui-kit@464f61d This removes `yarn` dependence in [NPM lifecycle scripts](https://docs.npmjs.com/cli/v10/using-npm/scripts#life-cycle-operation-order). It does so by using `npm run`, which should be available everywhere. In Node 22 we'll [have `node --run`](nodejs/corepack#57 (comment)) available. ### Security Considerations none ### Scaling Considerations none ### Documentation Considerations none ### Testing Considerations working in Agoric/ui-kit@464f61d ### Upgrade Considerations none
Add
corepack run
with the same behavior as[npm|yarn] run
to reduce the necessity of a package manager to run user-defined scripts in thepackage.json
. e.g. with this start scriptwe don't need a package manager to run:
Also, we should add the Corepack's wrappers (
npm
,pnpm
andyarn
) to thePATH
automatically. Achieving the same effect likecorepack enable
but only on the context of the command execution to support scripts like the following:Without adding the package managers as global commands.
The text was updated successfully, but these errors were encountered: