9

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 installing glob, but whenever I run a build command, the error comes back saying "Cannot find module 'c:\www\project\static\js\components*.js'.

Here's my package.json:

{
  "name": "TEST",
  "description": "ITS ME MARIO",
  "author": "JJ",
  "version": "0.0.1",
  "dependencies": {
    "connect": "1.8.5",
    "express": "2.5.2",
    "jade": "0.20.0",
    "mongoose": "3.8.x",
    "socket.io": "0.8.7"
  },
  "devDependencies": {
    "vows": "0.5.x",
    "mocha": "*",
    "should": "*",
    "jshint": "latest",
    "browserify": "latest",
    "rimraf": "latest",
    "hashmark": "latest",
    "stylus": "latest",
    "glob": "latest"

  },
  "scripts": {
      "clean": "rimraf dist",
      "test": "mocha test/",
      "build:components-js": "browserify static/js/components/*.js > static/dist/components.js",
      "build:app-js": "browserify static/js/script > static/dist/app.js",
      "build:css": "stylus static/css/style.styl > static/dist/main.css",
      "build": "npm run build:css && npm run build:components-js && npm run build:app-js"

  },
  "engine": "node >= 0.6.6"
}

Anyone know what I'm doing wrong?

user3350508
  • 123
  • 1
  • 7
  • I'm having a similar issue with jshint. As a diagnostic test, I decided to run `npm install -g jshint` which installed jshint 2.5.11. When I ran `jshint **.js` from there, it returned `ERROR: Can't open **.js` I decided to try git bash, and running `jshint **.js` worked from there. However setting up a script like `"lint" : "jshint **.js"` with `npm run lint` also failed with the Error command. – ojintoad Jan 05 '15 at 20:25
  • What about `browserify "static/js/components/*.js"` instead of `browserify static/js/components/*.js`? – inf3rno Mar 17 '16 at 02:35

1 Answers1

9

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:

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:

Community
  • 1
  • 1
Jon Coombs
  • 2,135
  • 2
  • 25
  • 26
  • This is really great! How would you get it to start in one directory, so it doesn't go through node_modules? – Aarmora Jun 07 '16 at 20:10
  • @Aarmora I'm afraid I've not looked at npm for quite some time. I just happened to notice this question soon after I'd been fighting the same wildcard limitations when using jshint. – Jon Coombs Jun 09 '16 at 13:25
  • 1
    This guy did it for me `for /r src/ %f in (*.ts) do tslint %f`. Thanks for all of the help! – Aarmora Jun 09 '16 at 16:42
  • This worked for me as an example of multiple globs `for /d %A in (lib\\*) do for %B in (%A\\content\\scripts\\*.js) do jshint %B` to do the same as `jshint ./lib/*/content/scripts/**` – guillem Jun 28 '19 at 09:36