Repository: pre-commit/pre-commit

Issue:
nodeenv try to download non existing tar.gz prebuilt under Cygwin
Hi,

Strange issue: I suspect a recent change broke this as it used to work last week, on another Windows computer with Cygwin.

Bug reproduction: `pre-commit run` using e.g. https://github.com/Lucas-C/pre-commit-hooks-html v1.1.0

`pre-commit` execute the following command under the hood, a command that also fails if I execute it manually:
```
nodeenv --prebuilt /cygdrive/c/Users/admin/.pre-commit/repoYHJ85q/node_env-default
```
The error is the following:
```
urllib2.HTTPError: HTTP Error 404: Not Found
```
The `tar.gz` it tries to install is https://nodejs.org/dist/v7.2.1/node-v7.2.1-cygwin_nt-6.1-x64.tar.gz, which does not exist. My guess is that `nodeenv` should use the Windows prebuilts instead: https://nodejs.org/dist/v7.2.1/node-v7.2.1-win-x64.zip This is because `platform.system()` is used: https://github.com/ekalinin/nodeenv/blob/master/nodeenv.py#L503

I'm going to ask for help on the https://github.com/ekalinin/nodeenv project, but do you have any hint at what the root cause could be here ?


Discussion:
I'm actually surprised cygwin worked before, nothing seems changed in the last couple weeks in `nodeenv` and I don't see any changes to the files provided by nodejs either.  To be honest, I didn't know nodeenv even worked on windows/cygwin: #200 

I think you're probably right about the source of the issue.  Another solution might be to have the nodejs guys compile against cygwin though it's a difficult platform to target (since the packaging moves like arch).
You're right, I must have mixed up things, it probably never worked.

I think there's no need to keep this ticket open, I'm tracking this in https://github.com/ekalinin/nodeenv/issues/178
Could it be possible to use the latest nodeenv version to fix this please ? :)
https://github.com/ekalinin/nodeenv/releases/tag/1.2.0
Yeah! pre-commit doesn't limit to a specific version of nodeenv so you should be able to just `pip install --upgrade nodeenv`
Great, thanks :)
Bad news : NodeJS hooks still do not work under Cygwin :(
To be more precise, currently dependencies are not installed in the dedicated node env, but globally

The issue comes from the `NPM_CONFIG_PREFIX` / `npm_config_prefix` environment variables:
https://github.com/pre-commit/pre-commit/blob/master/pre_commit/languages/node.py#L22-L23

Among the fixes I made in `nodeenv` to add support for Cygwin, I had to alter those 2 env variables:
https://github.com/ekalinin/nodeenv/blob/master/nodeenv.py#L850

Are you OK if I send a PR adding a `if cygwin` conditional in `node.py:get_env_patch` ?
seems fine to me :)

Resolving patch:
diff --git a/pre_commit/languages/node.py b/pre_commit/languages/node.py
--- a/pre_commit/languages/node.py
+++ b/pre_commit/languages/node.py
@@ -17,10 +17,11 @@
 
 
 def get_env_patch(venv):  # pragma: windows no cover
+    config = os.path.join(venv, 'bin') if sys.platform == 'cygwin' else venv
     return (
         ('NODE_VIRTUAL_ENV', venv),
-        ('NPM_CONFIG_PREFIX', venv),
-        ('npm_config_prefix', venv),
+        ('NPM_CONFIG_PREFIX', config),
+        ('npm_config_prefix', config),
         ('NODE_PATH', os.path.join(venv, 'lib', 'node_modules')),
         ('PATH', (os.path.join(venv, 'bin'), os.pathsep, Var('PATH'))),
     )


Test patch: