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

[feat]: prepublish script npm hook #1169

Closed
alan-agius4 opened this issue Dec 18, 2017 · 12 comments
Closed

[feat]: prepublish script npm hook #1169

alan-agius4 opened this issue Dec 18, 2017 · 12 comments

Comments

@alan-agius4
Copy link
Contributor

At the moment, in order to run a prepublish step when publishing you need to create a script under each modules like scripts/prepublish.js.

This is quite limiting considering the fact one, you are liberality forcing using to have that folder structure and also in most cases one would want to use the same script and not copy and paste it in all modules.

Expected Behaviour

  • Check if a "prepublish" npm script is present in the root "package.json" if so execute it
  • Check if a "prepublish" npm script is present in the package to be published "package.json" if so execute it.
  • Execute the scripts/prepublish.js file script as per current workflow.

Current Behaviour

There is no prepublish npm hook

@evocateur
Copy link
Member

No, the prepublish (if it exists) in every package to be published is always run (by npm/yarn), because we are just calling npm publish/yarn publish in those directories (which is done in topological dependency order, so dependents always have their local sibling devDependencies built).

Of course, npm5 has deprecated prepublish and it should probably be replaced with prepare or prepublishOnly. I personally don't see much use in the scripts/<lifecycle>.js pattern, but I don't have any plans to remove it.

The problem with a prepublish in the root is that it (currently) will run any time anyone runs npm install with no arguments in the root, complete with scary looking log and possibly executing something you don't really want to have happen then.

@alan-agius4
Copy link
Contributor Author

alan-agius4 commented Jan 21, 2018 via email

@gluons
Copy link

gluons commented Aug 22, 2018

Excuse me!

Where is the documentation about scripts/<lifecycle>.js?
I can't find it.

@kyrisu
Copy link

kyrisu commented Aug 23, 2018

@evocateur small correction to what you have said:

the prepublish (if it exists) in every package to be published is always run (by npm/yarn), because we are just calling npm publish/yarn publish in those directories

It seems that you are calling publish with --ignore-scripts so it won't run prepublish.

Any reason why that's there and how to overwrite it?

@evocateur
Copy link
Member

It's already run by a previously executed npm pack

@kyrisu
Copy link

kyrisu commented Aug 24, 2018

@evocateur you are right. I was thinking about prepublishOnly - it only runs on npm publish (duh!). So as you mentioned in the previous message it should be probably replaced with prepare script.

@evocateur
Copy link
Member

Ah, yes, that particular lifecycle does not appear to be run when publishing a tarball (as far as I recall when I traced through the npm source). It also doesn't run during npm pack (although "prepack" is run, and would be an acceptable replacement).

@wereHamster
Copy link

npm pack doesn't run prepublishOnly.

I have a monorepo with multiple packages that are written in typescript, and in prepublishOnly I need to run the compiler (tsc). Currently my canary releases on npm only contain a package.json because the files are not compiled. Do I need to manually run the prepublish scripts before calling into lerna?

@evocateur
Copy link
Member

You should be running compilers to generate build output once, from the root. Or move to the prepack lifecycle, if typescript can't handle building multiple packages at once.

@wereHamster
Copy link

Where can I read more about prepack lifecycle?

@gluons
Copy link

gluons commented Aug 27, 2018

@wereHamster https://docs.npmjs.com/misc/scripts

evocateur added a commit that referenced this issue Aug 27, 2018
This was lost when the unitary `npm publish` was split into `npm pack && npm publish <tgz>`.

Fixes #1169
@lock
Copy link

lock bot commented Dec 27, 2018

This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants