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

[RRFC] ability to run scripts standalone, without their pre- and post- associates #158

Closed
morgaan opened this issue Jun 4, 2020 · 10 comments

Comments

@morgaan
Copy link

morgaan commented Jun 4, 2020

Motivation ("The Why")

To provide a way to run npm script without the pre- and/or post- scripts

When

When running npm run <script>

Where

npm cli

How

By passing flags for example:

  • npm run test --no-pre, or
  • npm run test --no-post, or
  • npm run test --no-pre-post

Current Behaviour

pre- and post- scripts cannot be skipped, workaround exist but clumsy, for example:

"scripts": {
    "rawtest": "mocha -r ts-node/register src/**/*.spec.ts",
    "pretest": "<some flow that isn't always desired>"
    "test": "npm run rawtest",
  }

Desired Behaviour

  • the pre- scripts should be skipped when run npm run <script> --no-pre
  • the post- scripts should be skipped when run npm run <script> --no-post
  • both pre- and post- scripts should be skipped when run npm run <script> --no-pre-post

References

Was added by @beenotung there npm/cli#484

@gingur
Copy link

gingur commented Jun 16, 2020

I think this could also solve https://npm.community/t/ignore-scripts-ignores-all-scripts/1403 , being able to run npm install without "post" scripts (but let dependency installs work as expected)

@askirmas
Copy link

askirmas commented Jun 17, 2020

I found 2 better sugar syntaxes until it is not implemented on core level

{
  "test--raw": "mocha",
  "pretest": "<some flow that isn't always desired>",
  "test": "npm run test--raw",
  "start --raw": "node server",
  "poststart": "open champagne",
  "start": "npm run start\\ --raw"
}

Besides, git uses -n --no-verify

@ljharb
Copy link
Contributor

ljharb commented Jun 17, 2020

@askirmas npm run start -- --raw and npm test -- --raw works without all those -- hijinks in the scripts.

@askirmas
Copy link

askirmas commented Jun 18, 2020

@askirmas npm run start -- --raw and npm test -- --raw works without all those -- hijinks in the scripts.

start --raw will run also hooks: prestart, start with arg --raw and poststart. That's not the point of issue.

I explained a visual trick for human eyes until npm run has no option itself like --ignore-scripts or --dry-run

@ljharb
Copy link
Contributor

ljharb commented Jun 18, 2020

In that case, I use your technique often :-) about 240 of my projects all use npm run tests-only for just the tests, because npm test invokes npm run pretest and npm run posttest, and in CI, i don't want the linter running on the 100 node versions i want the tests running, for example.

@askirmas
Copy link

But this hack makes package.json to look dirty.

@ljharb
Copy link
Contributor

ljharb commented Jun 18, 2020

I don't think a single extra script looks "dirty", especially not compared to a bunch of extra double-dashes everywhere - but obviously the cleanest would be a way to do npm test --ignore-pre-post-scripts or similar.

@askirmas
Copy link

@beenotung
Copy link

I think we can (easily?) write a script to read from the package.json and execute the command from local node_module or PATH in env according to archive what we want, once we made it, npm may adopt our impl into the core

@ruyadorno
Copy link
Contributor

We have implemented #185 in the the v7 beta which does what is described here but with a different syntax:

npm run <script-name> --ignore-scripts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants