Glob wildcards in windows npm

前端 未结 1 530
无人共我
无人共我 2021-02-09 10:55

I\'m trying to get npm to do a build browserify on a folder of scripts. The problem is, I\'m on windows and doing folder/*.js doesn\'t seem to work. I\'ve tried globally install

相关标签:
1条回答
  • 2021-02-09 11:27

    I don't think you're doing anything wrong; this is basically a limitation of the Windows shell/console/command prompt, although browserify could be 'improved' to sidestep that and use glob / node-glob instead. I'm not sure about browserify, but jshint is similar.

    Some ideas:

    • Try passing the root directory name instead. That's less powerful but seems to work well enough with jshint: https://github.com/jshint/jshint/issues/1904

    • Use cygwin as the shell you run npm from. It brings much *nix power to Windows.

    • Tweak or request a tweak to browserify (and jshint, and... ?) so that they invoke the glob library to handle these file-related parameters. Compare: https://github.com/jshint/jshint/issues/1998

    • Wrap said tools with 'translators' such https://www.npmjs.com/package/build-jshint . Note that this is explicitly designed to support ** wildcards etc.

    Just guessing, but there might also be a way to

    • use PowerShell (which comes with recent versions of Windows--see the Get-ChildItem command)

    • or Hamilton C shell (uses ... instead of **, I think), or something else, as your shell.

    • use a loop with /r for recursing into subfolders. I'm not recommending this--Windows-specific, not very chainable--but the 'wint' command set up below does 'work' (invoke with npm run wint) if I include the following in my package.json file.

    loop for Windows (Note: redirecting the output below to a file isn't a simple > because ...do jshint %f > chk.txt will overwrite itself and ...do jshint %f > %f.chk.txt may generate many chk.txt files sprinkled around):

    "scripts": {
      "lint": "jshint **.js",
      "wint": "for /r %f in (*.js) do jshint %f",
    },
    

    But the commands above would generally not be usable cross-platform. Also, using an alternative shell, you don't benefit by default from being able to shift+right-click on a folder and "Open command window here".

    Related:

    • Cannot use GLOB with JSHint in Windows?

    • https://superuser.com/questions/358863/wildcard-for-all-subdirectories-or-all-descendent-directories-in-windows-command

    0 讨论(0)
提交回复
热议问题