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

[Bug] Yarn 2 does not run prepare script for git dependencies #957

Closed
trusktr opened this issue Feb 16, 2020 · 7 comments
Closed

[Bug] Yarn 2 does not run prepare script for git dependencies #957

trusktr opened this issue Feb 16, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@trusktr
Copy link

trusktr commented Feb 16, 2020

This issue is basically the same as described at yarnpkg/yarn#7910, but for Yarn 2.

@trusktr trusktr added the bug Something isn't working label Feb 16, 2020
@arcanis arcanis closed this as completed Feb 16, 2020
@arcanis arcanis reopened this Feb 16, 2020
@arcanis
Copy link
Member

arcanis commented Feb 16, 2020

This is expected, cf:
https://yarnpkg.com/advanced/lifecycle-scripts

Tldr: use prepack rather than prepare.

@trusktr
Copy link
Author

trusktr commented Feb 16, 2020

@arcanis Ah, interesting. Does Yarn have plans to be compatible with the same scripts as npm?

I hadn't known about prepack running on git installs (maybe a newer npm feature after prepare was used for git installs?), but it does seem like the better option.

@trusktr
Copy link
Author

trusktr commented Feb 16, 2020

(updated my last comment, accidentally wrote "Lerna" instead of "Yarn")

@arcanis
Copy link
Member

arcanis commented Feb 16, 2020

Does Yarn have plans to be compatible with the same scripts as npm?

From the page I linked:

Note that we don't support every single lifecycle script originally present in npm. This is a deliberate decision based on the observation that too many lifecycle scripts make it difficult to know which one to use in which circumstances, leading to confusion and mistakes. We are open to add the missing ones on a case-by-case basis if compelling use cases are provided.

As for

I hadn't known about prepack running on git installs (maybe a newer npm feature after prepare was used for git installs?), but it does seem like the better option.

No, prepack is an fairly old script. The difference between it and prepare was very subtle (prepare runs on installs too), hence why people really didn't know which one to use.

@arcanis arcanis closed this as completed Feb 16, 2020
@cinderblock
Copy link

Why doesn't prepack run on "git install"? "git install" as in adding a git repository as a package.json dependency.

One major feature, imho, of how Npm runs prepare scripts is being able to directly install a git repository as a package.json dependency. Since a git repository should not contain compiled sources, a "build" step is often necessary to generate usable sources. Having that "build" step run as a prepare script means it's trivial to add a git "package" as a dependency and it will work just like it had been installed via npmjs.com.

If instead the prepack hook is used, it will correctly build before packing, but won't build after installing from git.

What is the intended way for Yarn to support adding/installing from (git) sources and automatically building after?

@arcanis
Copy link
Member

arcanis commented Aug 8, 2021

Why doesn't prepack run on "git install"? "git install" as in adding a git repository as a package.json dependency.

It does.

@cinderblock
Copy link

My mistake. I was accidentally testing with Yarn 1.

However, my point remains, how is a package maintainer expected to make their git package work for both Yarn and Npm?

Lifecycle scripts run on "git install".

Yarn 2.4.2 Npm v7.15.1 Match
postinstall postinstall ✔️
prepack
prepare
prepublish

A postinstall script is the only one they both run. So that? Or the same script in prepack and prepare? Doesn't that make Npm potentially double up on scripts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants