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

[enhancement] Custom npm binary/script #151

Closed
fcarreiro opened this issue Jul 11, 2017 · 5 comments
Closed

[enhancement] Custom npm binary/script #151

fcarreiro opened this issue Jul 11, 2017 · 5 comments

Comments

@fcarreiro
Copy link

@fcarreiro fcarreiro commented Jul 11, 2017

Hi all!

I have the following use case: I have a few projects where we use Docker in the development environment. Basically, I don't have node/npm installed in my computer. I do have git, but everything else is encapsulated in the docker containers.

The problem, as you can probably foresee, is that even though husky gets installed and the hooks are setup correctly, it fails when trying to find node/npm because, well, it doesn't exist outside the container.

This can be fixed, however, if I manually change the hooks to use "the npm inside the container". That is, instead of executing npm run prepush it would run something like docker-compose api --rm run "npm run prepush". More elegantly, I can setup a script in my project (say bin/dnpm) which just redirects the npm arguments to the binary inside the container, then I can instruct husky (well, the hooks) to use this binary.

What I'm requesting/proposing here, is to create some way to explicitly tell the hooks where to find npm command (or better, something like the dnpm script). One possibility is to have a .huskyrc file which gets sourced from the hooks (source .huskyrc if existing) and which exports some kind of ENV var like NPM_SCRIPT. Then the hook checks whether NPM_SCRIPT is defined and uses that script, otherwise it goes on as usual.

I open the discussion of whether this implementation would make you happy. I could probably submit a PR for this when I have some more time.

Thanks!

@valoricDe
Copy link

@valoricDe valoricDe commented Oct 6, 2017

A good idea which I naively implemented in #190

@use-strict
Copy link

@use-strict use-strict commented Mar 23, 2018

Same problem here. I'm unsure why run-node is needed at all. I'd expect what's written in the hook file to be the exact command that I have in .huskyrc hooks section.

EDIT: I see husky proxies all commands. I assume this is to dynamically run what's in the config file without reinstalling the hooks. I there any way to specify the node path when installing husky? Custom ENV variable maybe?

@typicode
Copy link
Owner

@typicode typicode commented Apr 11, 2018

Hi @fcarreiro,

It's maybe possible to do this now with the current version and run-node:
https://github.com/sindresorhus/run-node

@use-strict as for why run-node, it's to be able to run husky in GUI clients, particularly when Node was installed using nvm.

@typicode typicode closed this Jul 12, 2018
@azz
Copy link

@azz azz commented Jan 9, 2019

Hey @typicode, was just trying to do this (run node via docker-compose), and I'm not quite sure I'm following your suggestion. If there was a bin/node in $PATH it might work, but there's no way to guarantee that bin/node ends up in $PATH without first sourceing a known file (like .huskyrc bash file as suggested above.)

@azz
Copy link

@azz azz commented Apr 24, 2019

Friendly bump. As far as I could surmise it's not currently possible to convince run-node to execute docker run/docker-compose run instead of node.

My suggestion is something like:

{
  "hooks": {
    "pre-commit": "yarn test -o"
  },
  "config": {
    "node": "docker-compose run --rm --no-deps app node"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.