Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

ability to run scripts standalone, without their pre- and post- associates #17901

Open
andreineculau opened this issue Jul 23, 2017 · 1 comment

Comments

@andreineculau
Copy link

What's the feature?

Continue to allow npm <cmd or script> to call whatever scripts it is designed to call, but limit npm run <script>to ONLY call the specific script, without their pre- post- or any other associates (e.g. prebublish for prepare).

What problem is the feature intended to solve?

First of all, as per https://docs.npmjs.com/cli/run-script, the arguments passed to npm run <script> are not passed to the other calls e.g. npm run foo -- bar will only pass bar to the scripts.foo call, but not to the scripts.prefoo call.

Secondly, it is unexpected behaviour - it is not documented in https://docs.npmjs.com/cli/run-script, nor is it common-practice, nor common-sense. I'm instructing npm to run script X full-stop.

Thirdly, it is not possible to run standalone a script, except if it is a pre- or a post- script, I can run npm run pretest fine. npm run posttest fine. But npm run test will not make only the scripts.test call. This behaviour basically denies developers the possibility to have e.g. precheckout, checkout and postcheckout scripts, since npm run checkout will call the other scripts implicitly, leading to workaround like a. have all scripts include pre/post e.g. preprepre-precheckout, preprepre-checkout, preprepre-postcheckout b. use another naming scheme altogether e.g. before-checkout, checkout, after-checkout.

Fourthly, looking at how this behaviour came to be 7 years ago, I doubt it is 100% intentional and well thought out. @isaacs committed
04d74dc with the title "Support pre- and post- on npm (start|stop|test|restart)" but ended up adding a pre- and post- call for all scripts, leading to the following scenario:

  • npm install may call preinstall, install, postinstall, prepublish, prepare, etc. preshrinkwrap, shrinkwrap, postshrinkwrap
  • npm run install calls only preinstall, install, postinstall
  • npm run preinstall calls only preinstall

"Fifthly" :), having dummy pre- and post- scripts that are run without any intervention from npm adds little value.

Is the absence of this feature blocking you or your team? If so, how?

Scripts that are not pre- and post- cannot be tested standalone, since they will call pre- and post- as well.

By extension it is also blocking us because this behaviour or running pre- and post- is unexpected to 3rd party developers, leading to unexpected consequences and wasted energies.

Is this feature similar to an existing feature in another tool?

I actually have to answer with a question: which other tool has a "call script" feature that calls other scripts as well? I cannot think of any.

Is this a feature you're prepared to implement, with support from the npm CLI team?

ofc

@infn8
Copy link

infn8 commented Nov 8, 2017

I am in this camp as well. sometimes you just want that part of the flow. imagine you do:
npm run x
and then the task at
npm run prex
works great but takes a while. you then get a critical error in x. you fix it and then re-run
npm run x
just to sit through prex again for no reason
what about:
npm run x --no-pre-post
or something similar

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

2 participants