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

don't output npm default error message #47

Closed
wants to merge 1 commit into from
Closed

don't output npm default error message #47

wants to merge 1 commit into from

Conversation

ccbikai
Copy link

@ccbikai ccbikai commented May 7, 2016

So annoying

@typicode
Copy link
Owner

typicode commented May 8, 2016

Thank you for the PR and the feedback.
There were some "debate" about it #26

It's kind of hard to decide what should be the best by default. So in the end, husky output is the same as npm run <hook-script>. Sorry for not merging your PR.

But you can configure npm to be more silent:

project $ cat .npmrc
loglevel=silent

@typicode typicode closed this May 8, 2016
@alisianoi
Copy link

Hey @typicode, I have a similar problem with npm flags in jzaefferer/commitplease#60

My goal is to pass the --silent flag when the commitmsg npm script is run. I do not want to affect npm behvaiour in other cases, so setting verbosity in .npmrc, like above, is not an option.

Husky uses bash scripts inside .git/hooks. In particluar, the commit-msg bash script has the line:

npm run commitmsg

where commitmsg comes from package.json. So, I tried these two approaches in package.json:

  1. "commitmsg": "--silent node node_modules/commitplease"
  2. "commitmsg": "-s node node_modules/commitplease"

In my opinion, inside the bash script they are supposed to become:

  1. npm run --silent node node_modules/commitplease
  2. npm run -s node node_modules/commitplease

Instead the hook fails with the messages (the number of dashes differs):

  1. sh: --: invalid option
  2. sh: - : invalid option

It works silently if I put "commitmsg": "node node_modules/commitplease" into package.json and run manually from console (zsh version 5.2):

npm run --silent commitmsg

It also works if I run the following in console:

sh
sh-4.3$ npm run --silent commitmsg

Any hints on how I could debug that?

@iamstarkov
Copy link

@all3fox i dont get your intention, but maybe you can use -- to pass arguments to npm scripts

@alisianoi
Copy link

alisianoi commented Jun 3, 2016

@iamstarkov thank you for the hint, this is what I tried:

  1. "commitmsg": "-- --silent node node_modules/commitplease"
  2. "commitmsg": "-- -s node node_modules/commitplease"
  3. "commitmsg": "node node_modules/commitplease -- --silent"
  4. "commitmsg": "node node_modules/commitplease -- -s"

None of the above pass the --silent flag to npm, which is what I want. Number 3 and 4 are actually passing the silent flag to commitplease instead of npm, which is not what I want. But I tried that anyway. Numbers 1 and 2 are failing with the same error that in my previous message:

  1. sh: --: invalid option
  2. sh: - : invalid option

So, I am still looking for a way to pass the --silent flag to npm when executing a particular npm run script.

Update: I have also tried these with no luck:

  1. "commitmsg": "--silent -- node node_modules/commitplease"
  2. "commitmsg": "-s -- node node_modules/commitplease"

@iamstarkov
Copy link

you can try to pipe all the input to /dev/null, "commitmsg": "commitplease > /dev/null"

@iamstarkov
Copy link

also you dont need to point to node_modules explicitly in you npm scripts, npm is dynamically updating $path to node_modules binaries on the fly

@alisianoi
Copy link

alisianoi commented Jun 4, 2016

you can try to pipe all the input to /dev/null, "commitmsg": "commitplease > /dev/null"

Piping all the output to 2> /dev/null pipes the output of commitplease instead of npm:

  1. Here is the output for "commitmsg": "commitplease"
    screenshot from 2016-06-04 12-14-22
  2. Here is the output with "commitmsg": "commitplease 2>/dev/null"
    screenshot from 2016-06-04 12-16-17

So, it does the opposite of what I would like to achieve: instead of hiding the output of npm, it hides the output of commitplease. I have also tried the following with no luck:

  1. "commitmsg" : "2>/dev/null commitplease"
  2. "commitmsg" : "2>/dev/null -- commitplease"
  3. "commitmsg" : "commitplease -- 2>/dev/null"

also you dont need to point to node_modules explicitly in you npm scripts, npm is dynamically updating $path to node_modules binaries on the fly

thank you for that, I read this and this sections of the manual to make npm put a commitplease script under node_modules/.bin. It now runs as "commitmsg": "commitplease"

However, I still did not figure out a way to pass the --silent flag to npm

Update: and this is what I actually want, the result of npm run --silent commitmsg
screenshot from 2016-06-04 12-37-54

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

Successfully merging this pull request may close these issues.

4 participants