Prevent ignored files in out dir (#10831)

Co-Authored-By: Brian Ng <bng412@gmail.com>
This commit is contained in:
Raja Sekar 2019-12-18 04:39:36 +01:00 committed by Brian Ng
parent b3c7df9314
commit 2b3590929b
13 changed files with 33 additions and 4 deletions

View File

@ -84,8 +84,16 @@ export default async function({
async function handleFile(src: string, base: string): Promise<boolean> { async function handleFile(src: string, base: string): Promise<boolean> {
const written = await write(src, base); const written = await write(src, base);
const relative = path.relative(base, src);
if (!written && cliOptions.copyFiles) { const isCompilableExtension = util.isCompilableExtension(
relative,
cliOptions.extensions,
);
if (
!written &&
((!isCompilableExtension && cliOptions.copyFiles) ||
cliOptions.includeIgnored)
) {
const filename = path.relative(base, src); const filename = path.relative(base, src);
const dest = getDest(filename, base); const dest = getDest(filename, base);
outputFileSync(dest, fs.readFileSync(src)); outputFileSync(dest, fs.readFileSync(src));

View File

@ -161,6 +161,11 @@ commander.option(
"Delete the out directory before compilation.", "Delete the out directory before compilation.",
); );
commander.option(
"--include-ignored",
"Include ignored files when copying non-compilable files.",
);
commander.version(pkg.version + " (@babel/core " + version + ")"); commander.version(pkg.version + " (@babel/core " + version + ")");
commander.usage("[options] <files ...>"); commander.usage("[options] <files ...>");
// register an empty action handler so that commander.js can throw on // 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 {
quiet: opts.quiet, quiet: opts.quiet,
deleteDirOnStart: opts.deleteDirOnStart, deleteDirOnStart: opts.deleteDirOnStart,
sourceMapTarget: opts.sourceMapTarget, sourceMapTarget: opts.sourceMapTarget,
includeIgnored: opts.includeIgnored,
}, },
}; };
} }

View File

@ -0,0 +1,12 @@
{
"args": [
"src",
"--out-dir",
"lib",
"--copy-files",
"--ignore",
"src/foo/*",
"--include-ignored",
"--verbose"
]
}

View File

@ -0,0 +1,3 @@
"use strict";
index;

View File

@ -0,0 +1,2 @@
src/index.js -> lib/index.js
Successfully compiled 1 file with Babel.