babel: `--no-copy-ignored` only ignores `.js` files and does not enforce config "ignore:" settings
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.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 19
- Comments: 15 (4 by maintainers)
Commits related to this issue
- Add png as an extension to get around copy-files limitation/bug See https://github.com/babel/babel/issues/11394 — committed to teamleadercrm/ui by lorgan3 3 years ago
- Add png as an extension to get around copy-files limitation/bug See https://github.com/babel/babel/issues/11394 — committed to teamleadercrm/ui by lorgan3 3 years ago
- feat: Add images to transpiled folder When I put InstallFlagshipAppDialog images in /assets/images folder, they were automatically added in the app bundle even if the app was not using InstallFlagshi... — committed to cozy/cozy-ui by zatteo a year ago
- feat: Add images to transpiled folder When I put InstallFlagshipAppDialog images in /assets/images folder, they were automatically added in the app bundle even if the app was not using InstallFlagshi... — committed to cozy/cozy-ui by zatteo a year ago
- feat: Add images to transpiled folder When I put InstallFlagshipAppDialog images in /assets/images folder, they were automatically added in the app bundle even if the app was not using InstallFlagshi... — committed to cozy/cozy-ui by zatteo a year ago
- chore(release): 88.5.0 [skip ci] # [88.5.0](https://github.com/cozy/cozy-ui/compare/v88.4.0...v88.5.0) (2023-07-06) ### Features * Add images to transpiled folder ([17c2440](https://github.com/cozy... — committed to cozy/cozy-ui by semantic-release-bot a year ago
@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
dirhttps://github.com/babel/babel/blob/65911144e9eee760052e20fed9780bd78922f942/packages/babel-cli/src/babel/dir.js#L103-L106
This condition is the cause of this issue. If the
--copy-files
is flagged and the file is not compilable such as.json
, the condition skips the check for whether the file is ignored.Could I work on this?
same issue, directories or for example
.json
,.snap
are not been ignoredI have this problem too. I use babel to build several packages that have
node_modules
in them. When I useno-copy-ignored
, babel tries to copynode_modules
(although I have added it to the ignore list).I use
pnpm
which install packages via symlinks. However, tries to follow these symlinks and copy them which takes a lot of time.For me, non-following the symlinks during copying is enough, but it would be nice if this behavior is fixed.
I have added a script to remove
node_modules
to speed upbuild.nuclide
: https://github.com/atom-ide-community/atom-ide-base/blob/f5cae309f3fff8fe57ef0e897002722ce12ddeb5/package.json#L57I also had to add
png
andsnap
so they did not get copied. That’s not how it should be:--extensions '.js,.ts,.tsx,.png,.snap'
I really hope @barronwei could have a look into that issue, could you? 🙏
same issue:
"build:es2015": "NODE_ENV=production babel ./src --out-dir ./build --copy-files --no-copy-ignored",
babel.config looks like:
output includes
__test__
and__tests__
and__snapshots__
dirs, but correctly excludesdevMode
andsrc/index.js
.