You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I invoked eslint like this from the windows command prompt (same thing happens from gitbash): pre-commit run --run-all eslint
Note that I am in my python virtualenv and node_modules/.bin is in my PATH.
The result was a FileNotFoundError, raised from util.cmd_outpuit() at the line proc = __popen(cmd, **popen_kwargs).
The value of cmd was ('\\bin\\sh', 'C:\\<path to project>\\node_modules\\.bin\\eslint', '<js file for linting>', '<another js file for linting').
In my node_modules directory, I actually have the following files: eslint and eslint.cmd. Looking at the sourcecode of parse_shebang.find_execitable() I could see that there was a candidate list of filenames that were attempted to match based on the executable file extensions of the windows environment. The first item in the list was eslint without any extension, so it always matched.
In order to make eslint.cmd match inside parse_shebang.find_execitable(), I altered the code.
With the altered code, the value of cmd was like this: ('C:\\<path to project>\\node_modules\\.bin\\eslint', '<js file for linting>', '<another js file for linting>').
When subsequently invoked eslint as before worked in both the windows cmd prompt and gitbash.
I will submit a pull request for this shortly. I assume the new logic for matching files will not cause other problems.
So this refers to first-class support for node projects -- the goal of pre-commit is you don't need any dependencies other than installing pre-commit. It can then handle creating isolated node / ruby / python / etc. environments without requiring the user to globally install things. Proper node support (from pre-commit's persepective) is to make language: node work without dependencies.
neat, nodeenv has supported windows for a while. Unfortunately our tests choke on this a bit:
E Errors:
E * Install prebuilt node (8.1.3) ..... done.
E You do not have sufficient privilege to perform this operation.
E You do not have sufficient privilege to perform this operation.
E Error: Failed to create nodejs.exe link
E * Install npm.js (latest) ... Traceback (most recent call last):
E File "c:\python27\Lib\runpy.py", line 162, in _run_module_as_main
E "__main__", fname, loader, pkg_name)
E File "c:\python27\Lib\runpy.py", line 72, in _run_code
E exec code in run_globals
E File "C:\Users\Anthony\Desktop\git\pre-commit\venv\lib\site-packages\nodeenv.py", line 1277, in <modul
e>
E main()
E File "C:\Users\Anthony\Desktop\git\pre-commit\venv\lib\site-packages\nodeenv.py", line 1028, in main
E create_environment(env_dir, opt)
E File "C:\Users\Anthony\Desktop\git\pre-commit\venv\lib\site-packages\nodeenv.py", line 872, in create_
environment
E instfunc(env_dir, src_dir, opt)
E File "C:\Users\Anthony\Desktop\git\pre-commit\venv\lib\site-packages\nodeenv.py", line 742, in install
_npm_win
E zipf.extractall(src_dir)
E File "c:\python27\Lib\zipfile.py", line 1053, in extractall
E self.extract(zipinfo, path, pwd)
E File "c:\python27\Lib\zipfile.py", line 1041, in extract
E return self._extract_member(member, path, pwd)
E File "c:\python27\Lib\zipfile.py", line 1092, in _extract_member
E os.mkdir(targetpath)
E WindowsError: [Error 206] The filename or extension is too long: 'C:\\temp\\a\\test_run_a_node_hook0\\0\
\.pre-commit\\repogflpmz\\node_env-default\\src\\npm-latest\\node_modules\\pacote\\node_modules\\make-fetch-happen\\node
_modules\\http-proxy-agent\\node_modules\\agent-base\\node_modules\\es6-promisify\\node_modules\\es6-promise\\dist'
I'm wondering if we pick a shorter tempdir that it'll work better? Also wondering if this just works given my home directory depth.
I would hope so, but I've also seen that even with the setting enabled it still doesn't work (and I don't have a good reason for why) (maybe needs a system restart to take?)
I'm going to try poking this again with the reproduction I made in npm/npm#18978 and see what registry settings I can tweak.
wow. it works!?!?! I'm both terrified and amazed by this "api":
(venv) C:\Users\Anthony\workspace>nodeenv \\?\C:\Users\Anthony\workspace\nenv * Install prebuilt node (9.4.0) ..... done.You do not have sufficient privilege to perform this operation.You do not have sufficient privilege to perform this operation.Error: Failed to create nodejs.exe link * Install npm.js (latest) ...(venv) C:\Users\Anthony\workspace>nenv\Scripts\activate.bat(nenv) C:\Users\Anthony\workspace>nenv\Scripts\npm.cmd install left-padnpm WARN saveError ENOENT: no such file or directory, open 'C:\Users\Anthony\workspace\package.json'npm notice created a lockfile as package-lock.json. You should commit this file.npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Anthony\workspace\package.json'npm WARN workspace No descriptionnpm WARN workspace No repository field.npm WARN workspace No README datanpm WARN workspace No license field.+ [email protected]added 1 package in 0.547s
Activity
asottile commentedon Feb 21, 2016
Track ekalinin/nodeenv#140 for progress
alex-hutton commentedon Feb 10, 2017
Hi, I would appreciate more detail about what is broken and why it relates to
nodeenv.I found an apparent bug with node on Windows which may not be related to this bug. I also found a solution which I will explain below.
To summarise, the cmd given to __popen is the wrong cmd, eg the wrong exe is found by pre-commit.
I am using
pre-commit 0.12.2and theeslintmirror (http://github.com/pre-commit/mirrors-eslint),v3.9.1.I installed
eslintitself throughnpmand it resides in mynode_modulesdirectory within my project folder.npmis3.10.10andeslintisv3.15.0.The relevant block of my
.pre-commit-config.yamllooks like this:I invoked
eslintlike this from the windows command prompt (same thing happens from gitbash):pre-commit run --run-all eslintNote that I am in my python
virtualenvandnode_modules/.binis in my PATH.The result was a
FileNotFoundError, raised fromutil.cmd_outpuit()at the lineproc = __popen(cmd, **popen_kwargs).The value of
cmdwas('\\bin\\sh', 'C:\\<path to project>\\node_modules\\.bin\\eslint', '<js file for linting>', '<another js file for linting').In my
node_modulesdirectory, I actually have the following files:eslintandeslint.cmd. Looking at the sourcecode ofparse_shebang.find_execitable()I could see that there was a candidate list of filenames that were attempted to match based on the executable file extensions of the windows environment. The first item in the list waseslintwithout any extension, so it always matched.In order to make
eslint.cmdmatch insideparse_shebang.find_execitable(), I altered the code.With the altered code, the value of
cmdwas like this:('C:\\<path to project>\\node_modules\\.bin\\eslint', '<js file for linting>', '<another js file for linting>').When subsequently invoked
eslintas before worked in both the windows cmd prompt and gitbash.I will submit a pull request for this shortly. I assume the new logic for matching files will not cause other problems.
asottile commentedon Feb 10, 2017
A lot to parse but I'll try my best :)
So this refers to first-class support for node projects -- the goal of pre-commit is you don't need any dependencies other than installing pre-commit. It can then handle creating isolated node / ruby / python / etc. environments without requiring the user to globally install things. Proper node support (from pre-commit's persepective) is to make
language: nodework without dependencies.As for your hook configuration, you're not actually depending on the node environment that pre-commit may create so you may find a
localconfiguration more convenient: http://pre-commit.com/#repository-local-hooks. Something like thisAs for the PR, yeah that sounds fine. I think windows also does a similar prioritization.
alex-hutton commentedon Feb 10, 2017
Thanks for the reply and explanation. Thanks for telling me about local hooks! I missed them in the docs and they would work much better for me.
asottile commentedon Jul 9, 2017
neat, nodeenv has supported windows for a while. Unfortunately our tests choke on this a bit:
I'm wondering if we pick a shorter tempdir that it'll work better? Also wondering if this just works given my home directory depth.
asottile commentedon Jul 9, 2017
Yeah even with significantly limiting the path depth, I'm still having issues
asottile commentedon Jul 9, 2017
See also npm/npm#17663
asottile commentedon Nov 29, 2017
Here's the new issue: npm/npm#18978
wenzowski commentedon Jan 12, 2018
Shouldn't enabling long paths help with this? Spoiler: they don't.

asottile commentedon Jan 12, 2018
I would hope so, but I've also seen that even with the setting enabled it still doesn't work (and I don't have a good reason for why) (maybe needs a system restart to take?)
I'm going to try poking this again with the reproduction I made in npm/npm#18978 and see what registry settings I can tweak.
wenzowski commentedon Jan 12, 2018
Perhaps it's as simple as a missing
"\\?\"prefix...I'm not a windows dev; guessing based on msft docs.asottile commentedon Jan 12, 2018
interesting! I'll see if I can make that work -- either in cpython or in nodeenv -- never knew about
\\?\!asottile commentedon Jan 12, 2018
wow. it works!?!?! I'm both terrified and amazed by this "api":
asottile commentedon Jan 13, 2018
This'll make it into the next release. Note that due to https://bugs.python.org/issue32539, until python/cpython#5169 is merged python 2 will not work. Presumably this will get merged and it will work with 2.7.15 -- until then use python 3 :)