question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Babel-cli docs incorrectly imply that Babel supports generic blob pattern matching in `ignore`/`only` and such

See original GitHub issue

Bug Report

Current Behavior The file in src/__mocks__/@company is processed but Glob will ignore that file when given the same pattern.

Input Code https://github.com/jcollum-nike/babel-glob-bug

Run node glob-test.js:

[ 'src/index.js' ]
[ 'src/index.js' ]
[ 'src/index.js' ]

Then run these commands:

# nr = npm run (alias) 
nr --silent clean && nr --silent build:pass1 && tree cjs
Successfully compiled 1 file with Babel.
cjs
└── index.js

nr --silent clean && nr --silent build:pass2 && tree cjs
Successfully compiled 1 file with Babel.
cjs
└── index.js

nr --silent clean && nr --silent build:fail1 && tree cjs 
Successfully compiled 2 files with Babel.
cjs
├── __mocks__
│   └── @company
│       └── some-fn.js
└── index.js

Expected behavior/code The file in src/__mocks__/@company is ignored in all three scenarios when processed with babel CLI.

Environment

  • Babel version(s): 7.2.3 (@babel/core 7.3.4)
  • Node/npm version: Node 8.15
  • OS: OSX
  • Monorepo: no
  • How you are using Babel: cli in package.json

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
loganfsmythcommented, Mar 14, 2019

This is expected behavior, Babel has extremely minimal support for globs: https://babeljs.io/docs/en/options#matchpattern

We literally only global-match when * and ** are whole-path-segment placeholders, so __* in this case would not be treated as a glob, but rather as a folder with that specific name.

If you want to use more complex glob matching, you can always use a JS config file and pass a function that uses the glob library used in your example. Then you can toggle that with --env-name or your own environment variable or whatever you’d like.

0reactions
loganfsmythcommented, Mar 14, 2019

So it’s either a bug or the docs need some indication that the globs in Babel don’t work the same way as the globs in Glob.

I agree that the docs need to be updated. I’ve filed https://github.com/babel/website/issues/1986 since the website docs are not tracked in this repo.

Because, considering that Glob is a dependency of this tool it seems very surprising (Principle of Least Surprise after all) that the glob patterns would behave differently in the Babel CLI.

The dependencies of a package really isn’t something to depend on when considering functionality, specially since Babel is split across many packages. Making assumptions based on that can lead to confusion exactly like what you’re raising here. ignore is a feature of Babel as a whole, not the CLI, so it is implemented @babel/core which has no dependency on glob.

Gonna close since the doc update is tracked in the other repo, but happy to continue discussing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Babel CLI
Babel comes with a built-in CLI which can be used to compile files from the command line.
Read more >
@babel/plugin-transform-unicode-regex - Package Manager
Intro. Babel is a tool that helps you write code in the latest version of JavaScript. When your supported environments don't support certain...
Read more >
How do I tell Babel CLI to ignore any path with "__"
There seems to be some debate about whether Babel fully supports Glob patterns at the CLI level. I managed to get it working...
Read more >
@babel/preset-env: Versions | Openbase
#14950 Emit @babel/cli source maps based on configuration files (@liuxingbaoyu) ... babel-plugin-transform-named-capturing-groups-regex , babel-standalone.
Read more >
Why you don't need Babel - LogRocket Blog
Babel is a compiler that converts your modern JavaScript to run in older browsers. It can also perform other jobs such as converting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found