Yarn: prepublish is run on `yarn add package`

Created on 20 Apr 2017  Â·  28Comments  Â·  Source: yarnpkg/yarn

0.23.2
prepublish script is run on yarn add package
I wonder why is it so? NPM does this only when npm install not npm install package

cat-bug help wanted needs-discussion triaged

Most helpful comment

Honestly, those lifecycle phases stopped making sense to me quite a long time ago.
I think we should just break legacy and do the same as npm 5 when it is released.
Feel free to send and RFC.

All 28 comments

@bestander have you seen this? really annoying and strange.

also note that npm@5 is going to run prepublish solely for pre-publish.

Honestly, those lifecycle phases stopped making sense to me quite a long time ago.
I think we should just break legacy and do the same as npm 5 when it is released.
Feel free to send and RFC.

@bestander

lifecycle phases stopped making sense to me quite a long time ago

in simple cases these hooks may prevent errors, when don't use other tools to automate lifecycle besides package manager.

Btw how is workspaces feature going? I didn't find a place where it can be tracked or read about.

It would be great for Yarn to have a richer API that allows hooking up to
lifecycle events or even provide implementation for some phases, i.e.
resolving, fetching or linking.

As for Workspaces we are starting to actively working on solutions starting
this week.
I've created an issue that will link all the RFC and PRs related to it
https://github.com/yarnpkg/yarn/issues/3294.

On Sat, 29 Apr 2017 at 11:10, Alex notifications@github.com wrote:

@bestander https://github.com/bestander

lifecycle phases stopped making sense to me quite a long time ago

in simple cases this hooks may prevent errors, when don't use other tools
to automate lifecycle besides package manager.

Btw how is workspaces feature going? I didn't find a place where it can
be tracked or read about.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/yarnpkg/yarn/issues/3209#issuecomment-298159949, or mute
the thread
https://github.com/notifications/unsubscribe-auth/ACBdWG9aMyaO8JaP-qAzvESuBjyyZB_dks5r0wywgaJpZM4NDNV9
.

Hey, just want to add my frustration. Slows yarn dramatically for yarn add or yarn install. Theres no point IMO. I'm not ready to publish, I just want to add a dependency. The major shift to yarn for me was speed, but if I have a pre-publish script I'm not going to see that efficiency anymore.

Anyone wants to champion this change?

We need to build a chart which scripts and when they should run.
If npm@5 does not run prepublish on install anymore makes sense for Yarn to do the same

Yeah, I'm happy to give this a shot.

So we need a list of what hooks to run and when, and then update the code to run the hooks at the right time?

Thanks for volunteering, @deecewan.

Yeah, are you up to create an RFC https://github.com/yarnpkg/rfcs?
There might be some arguments about this or that hook change.

sure thing. i'll have a crack over the next couple of days. exam on saturday, but free after that.
I think this'd be a good first crack at the yarn codebase.

FYI a programmatic comparison of which hooks run and in what order, along with the toold can now be found at https://github.com/andreineculau/package-json-scripts

@andreineculau, that is quite cool, thanks for categorizing all this, I am sure many people are confused about the state of install scripts.

Do you want to send a PR to https://yarnpkg.com/en/docs and link to the spreadsheet?
That would be a great start.

To answer the question in your repo, @andreineculau, Yarn tries to match npm@5 where it is applicable.

@bestander would https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/run.md be a good place to have a footnote?

I think a section in https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/install.md would be more appropriate because it is more related to install command lifecycle

Closing this due to lack of activity. I also think this is no longer a problem on the latest versions of Yarn.

@BYK this still is a problem.. yarn 1.3.2 is still running prepublish when you add a package.

Now, given I have "prepublish": "npm run build" in order to ensure I always have the latest build when I publish I end up with the annoying case whereby if my build fails due to a needed dependency (or update) then yarn add will also fail.

as a work around I can change to prepublishOnly but this is deprecated from npm 5 on-wards because they changed the prepublish lifecycle, as far as I know.

I am experiencing this on 1.3.2 also!

Looks like running prepublish script has been added for npm compatibility
https://github.com/yarnpkg/yarn/issues/1323

But you should be able to set disablePrepublish option to true in config https://github.com/yarnpkg/yarn/blob/19c8cd5b85b837278e74b42a94c4b5bb1b28fc35/src/cli/commands/install.js#L993

I still experience this quirk for v1.3.2.

Is there any reasonable explanation why prepublish need to be executed although we have preinstall there? :confused:

@kaylieEB I tried to do yarn config set disablePrepublish true but Yarn still tries to run the prepublish scripts for my dependencies.

(I'm using Yarn 1.3.2.)

This should be reopened!

The bug still exists and development is quite annoying when you have something like "prepublish": "tsc" in your package.json. Then you want to add a library after you already added an import for that and yarn add … fails due to the import...

Also this might be quite easy to fix by giving the add command an own wrapLifecycle(…) function (here https://github.com/yarnpkg/yarn/blob/4177b081dcee74cd7385e1ce2922159513f5bee1/src/cli/commands/add.js#L313).

@phlmn I was able to work around this problem by switching to prepublishOnly, which explicitly opts into the new behavior of not running on any kind of install, just before publish. But note that then it won't run on plain yarn install.

But yeah, agreed that it should match whatever latest npm is doing, and sounds like npm never ran prepublish when adding a specific package as a dependency.

Encountering this issue as well, which generate an infinite loop of commands, using yarn 1.13.0

Is there a way to disable prepublish when adding a package, but still running it when actually publishing? If not, any workaround?

Still an issue over two years later :(

+1

+1

What is the recommended solution to this problem? As far I see that one option is enabling prepublishOnly as per https://github.com/yarnpkg/yarn/issues/3209#issuecomment-343105283.

However I would like to see anyone accountable for decision tell us it is either the only way, or that the community is free to contribute to resolve this issue.

Was this page helpful?
0 / 5 - 0 ratings