`--no-copy-ignored` only ignores `.js` files and does not enforce config "ignore:" settings
See original GitHub issueBug 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:
- Created 3 years ago
- Reactions:16
- Comments:14 (4 by maintainers)
@babel/core
usesshouldIgnore
to check whether a file should be ignored givenignore
config items: https://github.com/babel/babel/blob/65911144e9eee760052e20fed9780bd78922f942/packages/babel-core/src/config/config-chain.js#L466If a file is ignored,
@babel/core
will returnnull
, which is used by@babel/cli
later to mark it asFILE_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 theignore
config also applied)@vxcamiloxv
.json
and.snap
are not considered as compilable and thus it will be picked up by--copy-files
. You can useextensions
.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.--ignore
and--only
are not working at all,babel-cli
keeps copying.git
dir