Skip to content

Windows: Node Support #200

Closed
Closed

Description

@asottile

This involves solving this ticket: ekalinin/nodeenv#53

I've already started some work on this

Activity

  1. asottile commented on Feb 21, 2016

    @asottile
    MemberAuthor

    Track ekalinin/nodeenv#140 for progress

  2. alex-hutton commented on Feb 10, 2017

    @alex-hutton

    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.2 and the eslint mirror (http://github.com/pre-commit/mirrors-eslint), v3.9.1.

    I installed eslint itself through npm and it resides in my node_modules directory within my project folder. npm is 3.10.10 and eslint is v3.15.0.

    The relevant block of my .pre-commit-config.yaml looks like this:

    - repo: git://github.com/pre-commit/mirrors-eslint
      sha: 'v3.9.1'
      hooks:
      - id: eslint
        language: system
    

    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.

  3. asottile commented on Feb 10, 2017

    @asottile
    MemberAuthor

    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: node work 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 local configuration more convenient: http://pre-commit.com/#repository-local-hooks. Something like this

    -   repo: local
        hooks:
        -   id: eslint
            name: eslint
            entry: eslint
            language: system
            files: \.js$

    As for the PR, yeah that sounds fine. I think windows also does a similar prioritization.

  4. alex-hutton commented on Feb 10, 2017

    @alex-hutton

    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.

  5. asottile commented on Jul 9, 2017

    @asottile
    MemberAuthor

    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.

  6. asottile commented on Jul 9, 2017

    @asottile
    MemberAuthor

    Yeah even with significantly limiting the path depth, I'm still having issues

  7. asottile commented on Jul 9, 2017

    @asottile
    MemberAuthor

    See also npm/npm#17663

  8. asottile commented on Nov 29, 2017

    @asottile
    MemberAuthor

    Here's the new issue: npm/npm#18978

  9. wenzowski commented on Jan 12, 2018

    @wenzowski

    Shouldn't enabling long paths help with this? Spoiler: they don't.
    policy-editor-long-paths

  10. asottile commented on Jan 12, 2018

    @asottile
    MemberAuthor

    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.

  11. wenzowski commented on Jan 12, 2018

    @wenzowski

    Perhaps it's as simple as a missing "\\?\" prefix...I'm not a windows dev; guessing based on msft docs.

  12. asottile commented on Jan 12, 2018

    @asottile
    MemberAuthor

    interesting! I'll see if I can make that work -- either in cpython or in nodeenv -- never knew about \\?\!

  13. asottile commented on Jan 12, 2018

    @asottile
    MemberAuthor

    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-pad
    npm 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 description
    npm WARN workspace No repository field.
    npm WARN workspace No README data
    npm WARN workspace No license field.
    
    + [email protected]
    added 1 package in 0.547s
  14. asottile commented on Jan 13, 2018

    @asottile
    MemberAuthor

    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 :)

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions