Skip to content

Commit 2b35909

Browse files
Prevent ignored files in out dir (#10831)
Co-Authored-By: Brian Ng <bng412@gmail.com>
1 parent b3c7df9 commit 2b35909

13 files changed

Lines changed: 33 additions & 4 deletions

File tree

packages/babel-cli/src/babel/dir.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,16 @@ export default async function({
8484

8585
async function handleFile(src: string, base: string): Promise<boolean> {
8686
const written = await write(src, base);
87-
88-
if (!written && cliOptions.copyFiles) {
87+
const relative = path.relative(base, src);
88+
const isCompilableExtension = util.isCompilableExtension(
89+
relative,
90+
cliOptions.extensions,
91+
);
92+
if (
93+
!written &&
94+
((!isCompilableExtension && cliOptions.copyFiles) ||
95+
cliOptions.includeIgnored)
96+
) {
8997
const filename = path.relative(base, src);
9098
const dest = getDest(filename, base);
9199
outputFileSync(dest, fs.readFileSync(src));

packages/babel-cli/src/babel/options.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ commander.option(
161161
"Delete the out directory before compilation.",
162162
);
163163

164+
commander.option(
165+
"--include-ignored",
166+
"Include ignored files when copying non-compilable files.",
167+
);
168+
164169
commander.version(pkg.version + " (@babel/core " + version + ")");
165170
commander.usage("[options] <files ...>");
166171
// register an empty action handler so that commander.js can throw on
@@ -304,6 +309,7 @@ export default function parseArgv(args: Array<string>): CmdOptions | null {
304309
quiet: opts.quiet,
305310
deleteDirOnStart: opts.deleteDirOnStart,
306311
sourceMapTarget: opts.sourceMapTarget,
312+
includeIgnored: opts.includeIgnored,
307313
},
308314
};
309315
}

packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore/out-files/lib/foo/.foo.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/.foorc

Whitespace-only changes.

packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/README.md

Whitespace-only changes.

packages/babel-cli/test/fixtures/babel/--copy-files with ignore/out-files/lib/foo/bar.js renamed to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/foo/bar.js

File renamed without changes.

packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with only/out-files/lib/index.js renamed to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/index.js

File renamed without changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"args": [
3+
"src",
4+
"--out-dir",
5+
"lib",
6+
"--copy-files",
7+
"--ignore",
8+
"src/foo/*",
9+
"--include-ignored",
10+
"--verbose"
11+
]
12+
}

packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/out-files/lib/README.md

Whitespace-only changes.

packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore/out-files/lib/foo/index.js renamed to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/out-files/lib/foo/bar.js

File renamed without changes.

0 commit comments

Comments
 (0)