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

prepublish is run on yarn add package #3209

Closed
wclr opened this issue Apr 20, 2017 · 36 comments
Closed

prepublish is run on yarn add package #3209

wclr opened this issue Apr 20, 2017 · 36 comments

Comments

@wclr
Copy link
Contributor

wclr commented Apr 20, 2017

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

@wclr
Copy link
Contributor Author

wclr commented Apr 27, 2017

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

@deecewan
Copy link

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

@bestander
Copy link
Member

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.

@wclr
Copy link
Contributor Author

wclr commented Apr 29, 2017

@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.

@bestander
Copy link
Member

bestander commented May 1, 2017 via email

@CraigglesO
Copy link

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.

@bestander
Copy link
Member

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

@deecewan
Copy link

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?

@bestander
Copy link
Member

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.

@deecewan
Copy link

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.

@andreineculau
Copy link

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

@bestander
Copy link
Member

@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.

@bestander
Copy link
Member

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

@andreineculau
Copy link

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

@bestander
Copy link
Member

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

@BYK
Copy link
Member

BYK commented Oct 30, 2017

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

@MeirionHughes
Copy link

MeirionHughes commented Nov 9, 2017

@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.

molefrog added a commit to molefrog/redux-actuator that referenced this issue Nov 29, 2017
@ryami333
Copy link

I am experiencing this on 1.3.2 also!

@kaylie-alexa
Copy link
Member

Looks like running prepublish script has been added for npm compatibility
#1323

But you should be able to set disablePrepublish option to true in config

if (!config.disablePrepublish) {

@DrSensor
Copy link

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? 😕

@Rudloff
Copy link

Rudloff commented Feb 5, 2018

@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.)

alangpierce added a commit to alangpierce/sucrase that referenced this issue Jun 18, 2018
Some discussion here:
yarnpkg/yarn#3209

The long-term behavior of `publish` is to eventually only run on actual publish,
but for now, it runs on publish or install, which isn't what we want.
`prepublishOnly` is a transitionary hook that unambiguously gets the behavior I
want.
alangpierce added a commit to alangpierce/sucrase that referenced this issue Jun 18, 2018
Some discussion here:
yarnpkg/yarn#3209

The long-term behavior of `publish` is to eventually only run on actual publish,
but for now, it runs on publish or install, which isn't what we want.
`prepublishOnly` is a transitionary hook that unambiguously gets the behavior I
want.
@phlmn
Copy link

phlmn commented Nov 4, 2018

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

await wrapLifecycle(config, flags, async () => {
).

@alangpierce
Copy link

@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.

@Vadorequest
Copy link

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?

earshinov added a commit to earshinov/extract-scss-variables that referenced this issue Jun 17, 2019
… publication. Update README.

The problem with the old approach with a `prepublish` script is that Yarn keeps running this script all the time (yarnpkg/yarn#3209)
@runfaj
Copy link

runfaj commented Nov 27, 2019

Still an issue over two years later :(

@PCASME
Copy link

PCASME commented Feb 11, 2020

+1

1 similar comment
@bkotrys
Copy link

bkotrys commented Apr 7, 2020

+1

@dulowski-marek
Copy link

What is the recommended solution to this problem? As far I see that one option is enabling prepublishOnly as per #3209 (comment).

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.

ncuillery added a commit to ncuillery/prettier-plugin-mdx-no-text-child that referenced this issue Apr 12, 2020
The prepublish script is run on install or add.
Apparently this is the standard behavior.
See yarnpkg/yarn#3209
peterbraden pushed a commit to hoprnet/hoprnet that referenced this issue Sep 22, 2020
@lopugit
Copy link

lopugit commented May 7, 2022

Sorry but why the fuck does prepublish run after installing? Huh?

@ryami333
Copy link

ryami333 commented May 9, 2022

@BYK please reopen.

@lukaskj
Copy link

lukaskj commented Jun 1, 2022

Still an issue...

@CraigglesO
Copy link

For anyone coming here, I strongly urge you to consider using PNPM rather than NPM or Yarn.

Since the switch literally everything just.. works. No hassle, no issues, all dependencies live in one place not hogging memory.

@sunboshan
Copy link

As of 2022 this bug still there...

@kiosion
Copy link

kiosion commented Jul 28, 2022

This should be reopened, it's still an issue, and incredibly annoying given my 'prepublish' script runs tests. Why is 'prepublish' even run after 'add'?

@jonluca
Copy link

jonluca commented Aug 2, 2022

I agree that this should be reopened. Seems very odd that the prepublish script runs after adding a package or even just running yarn.

Also as a sidenote, I came here expecting to find that this was intended behavior, and to be given reason that I disagreed with but would accept due to yarns general ideologies. I didn't think a bug like this was just unfixed lol

@ronny1020
Copy link

I agree this should be reopened. I was so confused until I found this issue. no idea why this will happen after the install script.

cmil added a commit to dracor-org/dracor-react that referenced this issue Jul 21, 2023
Since the `prepublish` script is also executed before `yarn add` and
other yarn commands (see yarnpkg/yarn#3209)
we now use our own release script to avoid this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests