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 --ignore option doesn't work with star at the end of patterns

See original GitHub issue

Bug Report

  • I would like to work on a fix!

Current behavior

Running a command such as babel src --out-dir dist --ignore '**/*.test.*' does not exclude files that should match *.test.* (e.g. thing.test.js). It does work when using --ignore '**/*.test.js', but that means each possible extension (e.g. .js, .jsx) has to be ignored individually.

Input Code

$ npx babel --version
7.10.5 (@babel/core 7.11.4)
$ ls src
thing.js  thing.test.js
$ npx babel src --out-dir dist --ignore '**/*.test.js' # works
Successfully compiled 1 file with Babel (230ms).
$ ls dist
thing.js
$ npx babel src --out-dir dist --ignore '**/*.test.*' # does not work
Successfully compiled 2 files with Babel (232ms).
$ ls dist
thing.js  thing.test.js

thing.js and thing.test.js are just empty files.

Expected behavior

* at the end of the glob pattern should work, and files that match should be ignored.

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • No config files, CLI commands are above.

Environment

$ npx envinfo --preset babel
npx: installed 1 in 4.212s

  System:
    OS: Linux 5.8 Arch Linux
  Binaries:
    Node: 14.8.0 - /usr/bin/node
    Yarn: 1.22.4 - /usr/bin/yarn
    npm: 6.14.7 - /usr/bin/npm
  npmPackages:
    @babel/cli: ^7.10.5 => 7.10.5 
    @babel/core: ^7.11.4 => 7.11.4 

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
conartist6commented, Nov 20, 2020

I contend that it is a bug because the behavior is not documented.

5reactions
JLHwungcommented, Nov 10, 2020

some.* is never supported to match any extensions. https://github.com/babel/babel/blob/2984f0cb882ea6d51033f37945e47eb2d9eb4760/packages/babel-core/src/config/pattern-to-regex.js#L39

Babel implements a very limited simple pattern that supports only **, * and *.ext. As a workaround, you can specify it multiple times

npx babel src --out-dir dist --ignore '**/*.test.js' --ignore '**/*.test.jsx'

Note that ignore supports RegEx and function, you can also use a function

{
  ignore(filename) {
    return filename.match(/\.test\.jsx?$/)
  }
}

Docs: https://babel.dev/docs/en/options#matchpattern

Feel free to submit a PR if you would like .* be supported.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Options - Babel.js
If all patterns fail to match, the current configuration object is considered inactive and is ignored during config processing. This option is most...
Read more >
Babel ignore several directories - Stack Overflow
You can ignore multiple directories and specify a globbing pattern within the .babelrc file like this { ..., "ignore": [ "node_modules" ...
Read more >
API - ESBuild
This API call is used by the command-line interface if no input files are provided and the --bundle flag is not present. In...
Read more >
Localization and internationalization Unicode TEX ... - TeXDoc
No hyphenation patterns were preloaded for (babel) the language 'LANG' ... EXAMPLE Some classes load babel with a hardcoded language option.
Read more >
@babel/preset-react | Yarn - Package Manager
:rocket: [New Feature]; :bug: [Bug Fix]; :memo: [Documentation] ...
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