Skip to content

Getting set/add usage displayed when using proper command line #978

@xorbis

Description

@xorbis

Context
Using Git Bash for Windows
Node 14.16.1
npm 6.14.12

$ npx husky set .husky/pre-commit 'npm run lint'
Usage
  husky install [dir] (default: .husky)
  husky uninstall
  husky set|add <file> [cmd]

But using this works and creates an empty file:

$ npx husky set .husky/pre-commit

Activity

xorbis

xorbis commented on May 21, 2021

@xorbis
Author

At the prompt, this works.

npx husky set .husky/pre-commit \"npm run lint\"
rifftual

rifftual commented on Jun 1, 2021

@rifftual

Workaround doesn't work on Windows 10 (PowerShell) with Husky v. 6.0.0

lkjimy

lkjimy commented on Jun 2, 2021

@lkjimy

Same issue
node: 12.22.1 npm: 6.14.12 husky: ^6.0.0

Powershell

# MS PowerShell v.5.1.19041.906

> npx husky set .husky/pre-commit "npm test"
Usage
  husky install [dir] (default: .husky)
  husky uninstall
  husky set|add <file> [cmd]

> npx husky set .husky/pre-commit \"npm test\"
Usage
  husky install [dir] (default: .husky)
  husky uninstall
  husky set|add <file> [cmd]

> npx husky set .husky/pre-commit
husky - created .husky/pre-commit

Command Prompt

# MS Windows 10.0.19042.928 Command Prompt

> npx husky set .husky/pre-commit "npm test"
Usage
  husky install [dir] (default: .husky)
  husky uninstall
  husky set|add <file> [cmd]

> npx husky set .husky/pre-commit \"npm test\"
husky - created .husky/pre-commit

> npx husky set .husky/pre-commit
husky - created .husky/pre-commit

WSL Ubuntu node: 10.15.3 npm: 6.4.1

# WSL Ubuntu 18.04.1 LTS

$ npx husky set .husky/pre-commit "npm test"
husky - created .husky/pre-commit

$ npx husky set .husky/pre-commit \"npm test\"
Usage
  husky install [dir] (default: .husky)
  husky uninstall
  husky set|add <file> [cmd]

$ npx husky set .husky/pre-commit
husky - created .husky/pre-commit
nearzeno

nearzeno commented on Jun 10, 2021

@nearzeno

image

the husky/lib/bin.js was wrong?

nathonius

nathonius commented on Jun 12, 2021

@nathonius

Seeing the same on windows 10. Using a newer version of node/npm fixes it. But I can't rely on all end users having a non LTS version of node.

With node v14.17.0, npm v6.14.13

$ npx husky add .husky/pre-commit "npx lint-staged"
Usage
  husky install [dir] (default: .husky)
  husky uninstall
  husky set|add <file> [cmd]

With node v16.1.0, npm v7.11.2

$ npx husky add .husky/pre-commit "npx lint-staged"
husky - created .husky/pre-commit

Not sure if the issue lies here or with node/npm though. Maybe the handling of quotes or process.argv changed between the standalone npx and npm exec which is used under the hood in v7+?

EDIT:
Thinking that might be the case. Directly running husky with node works fine:

$ npx husky add .husky/pre-commit "npx lint-staged"
Usage
  husky install [dir] (default: .husky)
  husky uninstall
  husky set|add <file> [cmd]

$ node node_modules\husky\lib\bin.js add .husky/pre-commit "npx lint-staged"
husky - updated .husky/pre-commit
arsize

arsize commented on Jun 16, 2021

@arsize

Seeing the same on windows 10. Using a newer version of node/npm fixes it. But I can't rely on all end users having a non LTS version of node.

With node v14.17.0, npm v6.14.13

$ npx husky add .husky/pre-commit "npx lint-staged"
Usage
  husky install [dir] (default: .husky)
  husky uninstall
  husky set|add <file> [cmd]

With node v16.1.0, npm v7.11.2

$ npx husky add .husky/pre-commit "npx lint-staged"
husky - created .husky/pre-commit

Not sure if the issue lies here or with node/npm though. Maybe the handling of quotes or process.argv changed between the standalone npx and npm exec which is used under the hood in v7+?

EDIT:
Thinking that might be the case. Directly running husky with node works fine:

$ npx husky add .husky/pre-commit "npx lint-staged"
Usage
  husky install [dir] (default: .husky)
  husky uninstall
  husky set|add <file> [cmd]

$ node node_modules\husky\lib\bin.js add .husky/pre-commit "npx lint-staged"
husky - updated .husky/pre-commit

it's works for me

typicode

typicode commented on Jul 2, 2021

@typicode
Owner

I'd say it's related to npm.

// index.js
console.log(process.argv)
node index.js a b "c d" '$1'
# is correctly parsed 

There's not much that can be down on husky's side unfortunately. Hope it gets solved soon (if it hasn't already with most recent versions)

stale

stale commented on Aug 31, 2021

@stale

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @xorbis@nathonius@typicode@lkjimy@nearzeno

        Issue actions

          Getting set/add usage displayed when using proper command line · Issue #978 · typicode/husky