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.

`--no-copy-ignored` only ignores `.js` files and does not enforce config "ignore:" settings

See original GitHub issue

Bug Report

Current Behavior When using babel cli with --copy-files --no-copy-ignored, files and directories configured in my babel.config.js ARE copied into my build directory (with the exception of specified file types ending in .js). To be clear:

  • there are no included files with names including test.js
  • there are included files with names including test.ts
  • there are included directories named __tests__
  • there are included directories named __mocks__

Input Code

“package.json” build script: babel src -d dist --delete-dir-on-start --copy-files --no-copy-ignored

Expected behavior/code When running yarn build, I expect babel to build my files and output to the “dist/” directory. The build will include non-js files because I am using the flag --copy-files, for example, template files ending in .template. The build will not include directories and files from the babel.config.js “ignore” list because I am using --no-copy-ignored:

  • directory __tests__
  • directory __mocks__
  • files with name including test.js
  • files with name including test.ts

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

  • Filename: babel.config.js
{
  ...
  ignore:
     [
          /\.test\.(js|ts)/,
          '**/__tests__',
          '**/__mocks__',
     ]
}

Environment

  System:
    OS: macOS 10.15.4
  Binaries:
    Node: 12.16.0 - ~/.nvm/versions/node/v12.16.0/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.13.4 - ~/.nvm/versions/node/v12.16.0/bin/npm
  • Monorepo: Lerna
  • How you are using Babel: cli

Possible Solution I have tried using --ignore, which also does NOT work. I suspect the --no-copy-ignored flag has a bug.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:16
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
JLHwungcommented, Jun 24, 2020

Is there a utility function in the CLI that checks if a file matches the ignore parameter?

@babel/core uses shouldIgnore to check whether a file should be ignored given ignore config items: https://github.com/babel/babel/blob/65911144e9eee760052e20fed9780bd78922f942/packages/babel-core/src/config/config-chain.js#L466

If a file is ignored, @babel/core will return null, which is used by @babel/cli later to mark it as FILE_TYPE.IGNORED:

https://github.com/babel/babel/blob/65911144e9eee760052e20fed9780bd78922f942/packages/babel-cli/src/babel/dir.js#L61

However I doubt whether there is any to fix here: --no-copy-ignored works only if the file itself is considered compilable by @babel/cli and thus it has been supplied to @babel/core.

@thedavidprice In your cases, you can tell @babel/cli that it should compile .ts files (so the ignore config also applied)

babel src --extensions ".ts" -d dist --delete-dir-on-start --copy-files --no-copy-ignored

@vxcamiloxv .json and .snap are not considered as compilable and thus it will be picked up by --copy-files. You can use extensions.

I agree with @loganfsmyth expressed before in https://github.com/babel/babel/issues/6226#issuecomment-328660064, that @babel/cli is meant to be used in simple projects. Consider migrate to Gulp or Rollup if you are bundling a middle-large scale apps.

5reactions
douniwan5788commented, Dec 3, 2020

--ignore and --only are not working at all,babel-cli keeps copying .git dir

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ignored config is exported with other config changes - Drupal
Hi, I've created a custom module in my Drupal 8 instance, which contains some custom configuration forms. That configuration may differ for ...
Read more >
Ignore *.js and *.jsx files with tsconfig.json - Stack Overflow
For us, this tsconfig file worked to ignore all js and jsx files. { "compilerOptions": { "outDir": "build", "module": "esnext", ...
Read more >
Ignoring Code - ESLint - Pluggable JavaScript Linter
You can ignore files in the following ways: Add ignorePatterns to a configuration file. Create a dedicated file that contains the ignore patterns...
Read more >
Module | webpack - JS.ORG
Similar to the module.generator , you can configure all parsers' options in one ... Ignored files should not have calls to import ,...
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