yarnpkg/yarn

prepublish is run on `yarn add package`

wclr opened this issue ยท 36 comments

wclr commented

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 commented

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

wclr commented

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

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.

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 commented

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
#1323

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

if (!config.disablePrepublish) {

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? ๐Ÿ˜•

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

phlmn commented

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 () => {
).

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

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

@BYK please reopen.

Still an issue...

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.

As of 2022 this bug still there...

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

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

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.