3
"@babel/cli": "^7.2.3",

Seems really simple.

https://babeljs.io/docs/en/babel-cli#ignore-files

 babel src --out-dir lib --ignore "src/**/*.spec.js","src/**/*.test.js"

So I set it up like so:

babel src --out-dir cjs --ignore "**/_*" --copy-file --watch

Glob reference: https://github.com/isaacs/node-glob

But I see this in the output:

add:cjs/__mocks__/@xyz/common-fn.js
add:cjs/middleware/__mocks__/uuid.js 

OK I try this:

babel src --out-dir cjs --ignore "**/_+","_+" --copy-file --watch

And these:

babel src --out-dir cjs --ignore "**/_*/*.*\ --copy-file --watch 
babel src --out-dir cjs --ignore "**/__mocks__/*.*",  --copy-file --watch 
babel src --out-dir cjs --ignore "[src|middleware]/**/__mocks__/*.*" --copy-file --watch"
babel src --out-dir cjs --ignore "**/_+/**/*.*" --copy-file --watch

Same result every time. It really seems like that last one should work: ignore any path with zero or more directories followed by a directory that has at least one _ in the name, then zero or more directories then a file matching any pattern. Am I reading that right?

Then I tried being very specific:

babel src --out-dir cjs --ignore "nes/middleware/__mocks__/*.js", --copy-file --watch

And I get:

add:nes/middleware/__mocks__/localize.js

I can't tell if this is a bug in Babel or me misunderstanding glob patterns.

jcollum
  • 43,623
  • 55
  • 191
  • 321
  • Some of your glob patterns are correct and some are incorrect. You can test using [globster.xyz](https://globster.xyz/?q=nes%2Fmiddleware%2F__mocks__%2F*.js&f=nes%2Fmiddleware%2F__mocks__%2Flocalize.js%2Cnes%2Fmiddleware%2Flocalize.js%2Cnes%2Fmiddleware%2Fmocks%2Flocalize.js) Can you share what is ur directory structure? Is `nes` folder inside `src` ? – Domajno Feb 28 '19 at 02:15
  • nes folder is not inside src – jcollum Feb 28 '19 at 17:24
  • Thanks @Domajno [globster helps](https://globster.xyz/?q=**%2F__*%2F**%2F*.js&f=src%2F__mocks__%2F%40co%2Fmex-fn.js%2Csrc%2Fmiddleware%2F__mocks__%2Fuuid.js). I submitted a bug report. – jcollum Feb 28 '19 at 19:33
  • @Domajno btw globster uses a different glob lib (minimatch) than babel (glob) so the results on globster aren't 100% helpful when it comes to figuring out issues with glob – jcollum Mar 11 '19 at 22:12
  • I think glob uses minimatch under the hood anyway. That's what it says in [npm package description](https://www.npmjs.com/package/glob). Ofc, minimatch provides certain configuration that may vary. – Domajno Mar 12 '19 at 01:16
  • Good catch, I stopped going down the package.json rabbit hole one level too soon – jcollum Mar 12 '19 at 05:01
  • @Domajno this appears to be a possible bug in Babel, filed a bug report (with a repo detailing the failure) here https://github.com/babel/babel/issues/9680 – jcollum Mar 14 '19 at 01:24

1 Answers1

5

There seems to be some debate about whether Babel fully supports Glob patterns at the CLI level.

I managed to get it working with this ignore pattern:

--ignore "src/**/__mocks__/**/*.js" --ignore "src/**/*.test.js"

This pattern **/__*/** will work in Glob but fails in Babel.

jcollum
  • 43,623
  • 55
  • 191
  • 321