From 95ae87922badf729deeb6f71eb4ae61b0b1471d8 Mon Sep 17 00:00:00 2001 From: rajasekarm Date: Fri, 6 Dec 2019 15:46:37 +0100 Subject: [PATCH 1/5] prevent ignored files in out dir --- packages/babel-cli/src/babel/dir.js | 8 ++++++-- .../out-files/lib/foo/.foo.js | 1 - .../out-files/lib/foo/index.js | 1 - .../out-files/lib/index.js | 1 - .../--copy-files with ignore/out-files/lib/foo/bar.js | 1 - .../babel/--copy-files with only/out-files/lib/index.js | 1 - 6 files changed, 6 insertions(+), 7 deletions(-) delete mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore/out-files/lib/foo/.foo.js delete mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore/out-files/lib/foo/index.js delete mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with only/out-files/lib/index.js delete mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore/out-files/lib/foo/bar.js delete mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with only/out-files/lib/index.js diff --git a/packages/babel-cli/src/babel/dir.js b/packages/babel-cli/src/babel/dir.js index 234eb7c8f60b..cdbd163d8839 100644 --- a/packages/babel-cli/src/babel/dir.js +++ b/packages/babel-cli/src/babel/dir.js @@ -84,8 +84,12 @@ export default async function({ async function handleFile(src: string, base: string): Promise { const written = await write(src, base); - - if (!written && cliOptions.copyFiles) { + const relative = path.relative(base, src); + const isCompilableExtension = util.isCompilableExtension( + relative, + cliOptions.extensions, + ); + if (!written && !isCompilableExtension && cliOptions.copyFiles) { const filename = path.relative(base, src); const dest = getDest(filename, base); outputFileSync(dest, fs.readFileSync(src)); diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore/out-files/lib/foo/.foo.js b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore/out-files/lib/foo/.foo.js deleted file mode 100644 index 31142aabfe70..000000000000 --- a/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore/out-files/lib/foo/.foo.js +++ /dev/null @@ -1 +0,0 @@ -a; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore/out-files/lib/foo/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore/out-files/lib/foo/index.js deleted file mode 100644 index e46160df1c7a..000000000000 --- a/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore/out-files/lib/foo/index.js +++ /dev/null @@ -1 +0,0 @@ -bar; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with only/out-files/lib/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with only/out-files/lib/index.js deleted file mode 100644 index c6788558edcb..000000000000 --- a/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with only/out-files/lib/index.js +++ /dev/null @@ -1 +0,0 @@ -index; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore/out-files/lib/foo/bar.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore/out-files/lib/foo/bar.js deleted file mode 100644 index e46160df1c7a..000000000000 --- a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore/out-files/lib/foo/bar.js +++ /dev/null @@ -1 +0,0 @@ -bar; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with only/out-files/lib/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with only/out-files/lib/index.js deleted file mode 100644 index c6788558edcb..000000000000 --- a/packages/babel-cli/test/fixtures/babel/--copy-files with only/out-files/lib/index.js +++ /dev/null @@ -1 +0,0 @@ -index; From 8b082ca2eed9bff24cf8a22ca6e7442e92fadf91 Mon Sep 17 00:00:00 2001 From: Rajasekar Murugan Date: Tue, 17 Dec 2019 11:36:11 +0100 Subject: [PATCH 2/5] added includeIgnore cli option --- packages/babel-cli/src/babel/dir.js | 6 +++++- packages/babel-cli/src/babel/options.js | 6 ++++++ .../in-files/src/.foorc | 0 .../in-files/src/README.md | 0 .../in-files/src/foo/bar.js | 1 + .../in-files/src/index.js | 1 + .../options.json | 12 ++++++++++++ .../out-files/lib/README.md | 0 .../out-files/lib/foo/bar.js | 1 + .../out-files/lib/index.js | 3 +++ .../stdout.txt | 2 ++ 11 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/.foorc create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/README.md create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/foo/bar.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/index.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/options.json create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/out-files/lib/README.md create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/out-files/lib/foo/bar.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/out-files/lib/index.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/stdout.txt diff --git a/packages/babel-cli/src/babel/dir.js b/packages/babel-cli/src/babel/dir.js index cdbd163d8839..824576d1f075 100644 --- a/packages/babel-cli/src/babel/dir.js +++ b/packages/babel-cli/src/babel/dir.js @@ -89,7 +89,11 @@ export default async function({ relative, cliOptions.extensions, ); - if (!written && !isCompilableExtension && cliOptions.copyFiles) { + if ( + !written && + ((!isCompilableExtension && cliOptions.copyFiles) || + cliOptions.includeIgnore) + ) { const filename = path.relative(base, src); const dest = getDest(filename, base); outputFileSync(dest, fs.readFileSync(src)); diff --git a/packages/babel-cli/src/babel/options.js b/packages/babel-cli/src/babel/options.js index fa09d6b64ed3..16477bdf4b9d 100644 --- a/packages/babel-cli/src/babel/options.js +++ b/packages/babel-cli/src/babel/options.js @@ -161,6 +161,11 @@ commander.option( "Delete the out directory before compilation.", ); +commander.option( + "--include-ignore", + "Include ignored files when compiling and copy to destination", +); + commander.version(pkg.version + " (@babel/core " + version + ")"); commander.usage("[options] "); // register an empty action handler so that commander.js can throw on @@ -304,6 +309,7 @@ export default function parseArgv(args: Array): CmdOptions | null { quiet: opts.quiet, deleteDirOnStart: opts.deleteDirOnStart, sourceMapTarget: opts.sourceMapTarget, + includeIgnore: opts.includeIgnore, }, }; } diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/.foorc b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/.foorc new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/README.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/foo/bar.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/foo/bar.js new file mode 100644 index 000000000000..e46160df1c7a --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/foo/bar.js @@ -0,0 +1 @@ +bar; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/index.js new file mode 100644 index 000000000000..c6788558edcb --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/index.js @@ -0,0 +1 @@ +index; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/options.json b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/options.json new file mode 100644 index 000000000000..a119aac9e611 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/options.json @@ -0,0 +1,12 @@ +{ + "args": [ + "src", + "--out-dir", + "lib", + "--copy-files", + "--ignore", + "src/foo/*", + "--include-ignore", + "--verbose" + ] +} diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/out-files/lib/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/out-files/lib/README.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/out-files/lib/foo/bar.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/out-files/lib/foo/bar.js new file mode 100644 index 000000000000..e46160df1c7a --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/out-files/lib/foo/bar.js @@ -0,0 +1 @@ +bar; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/out-files/lib/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/out-files/lib/index.js new file mode 100644 index 000000000000..cb5e86b12ef3 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/out-files/lib/index.js @@ -0,0 +1,3 @@ +"use strict"; + +index; \ No newline at end of file diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/stdout.txt b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/stdout.txt new file mode 100644 index 000000000000..84a430432e47 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/stdout.txt @@ -0,0 +1,2 @@ +src/index.js -> lib/index.js +Successfully compiled 1 file with Babel. From f322ec548bad1b8169605a13cdb9b6fbed66a53b Mon Sep 17 00:00:00 2001 From: Raja Sekar Date: Tue, 17 Dec 2019 12:03:43 +0100 Subject: [PATCH 3/5] Help text change --- packages/babel-cli/src/babel/options.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-cli/src/babel/options.js b/packages/babel-cli/src/babel/options.js index 16477bdf4b9d..0763be66615e 100644 --- a/packages/babel-cli/src/babel/options.js +++ b/packages/babel-cli/src/babel/options.js @@ -163,7 +163,7 @@ commander.option( commander.option( "--include-ignore", - "Include ignored files when compiling and copy to destination", + "Copy the ignored files to destination", ); commander.version(pkg.version + " (@babel/core " + version + ")"); From a52c449293d2b70e89cb742499426e2e3a4fe260 Mon Sep 17 00:00:00 2001 From: Raja Sekar Date: Tue, 17 Dec 2019 17:21:00 +0100 Subject: [PATCH 4/5] Update packages/babel-cli/src/babel/options.js Copy review. Co-Authored-By: Brian Ng --- packages/babel-cli/src/babel/options.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-cli/src/babel/options.js b/packages/babel-cli/src/babel/options.js index 0763be66615e..77f33da8d43f 100644 --- a/packages/babel-cli/src/babel/options.js +++ b/packages/babel-cli/src/babel/options.js @@ -163,7 +163,7 @@ commander.option( commander.option( "--include-ignore", - "Copy the ignored files to destination", + "Include ignored files when compiling and copying non-compilable files.", ); commander.version(pkg.version + " (@babel/core " + version + ")"); From 20cef1d9fce7232c56948310094cbc7ac20e5722 Mon Sep 17 00:00:00 2001 From: Rajasekar Murugan Date: Tue, 17 Dec 2019 22:07:22 +0100 Subject: [PATCH 5/5] review comments --- packages/babel-cli/src/babel/dir.js | 2 +- packages/babel-cli/src/babel/options.js | 6 +++--- .../in-files/src/.foorc | 0 .../in-files/src/README.md | 0 .../in-files/src/foo/bar.js | 0 .../in-files/src/index.js | 0 .../options.json | 2 +- .../out-files/lib/README.md | 0 .../out-files/lib/foo/bar.js | 0 .../out-files/lib/index.js | 0 .../stdout.txt | 0 11 files changed, 5 insertions(+), 5 deletions(-) rename packages/babel-cli/test/fixtures/babel/{--copy-files with ignore with includeIgnore => --copy-files with ignore with includeIgnored}/in-files/src/.foorc (100%) rename packages/babel-cli/test/fixtures/babel/{--copy-files with ignore with includeIgnore => --copy-files with ignore with includeIgnored}/in-files/src/README.md (100%) rename packages/babel-cli/test/fixtures/babel/{--copy-files with ignore with includeIgnore => --copy-files with ignore with includeIgnored}/in-files/src/foo/bar.js (100%) rename packages/babel-cli/test/fixtures/babel/{--copy-files with ignore with includeIgnore => --copy-files with ignore with includeIgnored}/in-files/src/index.js (100%) rename packages/babel-cli/test/fixtures/babel/{--copy-files with ignore with includeIgnore => --copy-files with ignore with includeIgnored}/options.json (83%) rename packages/babel-cli/test/fixtures/babel/{--copy-files with ignore with includeIgnore => --copy-files with ignore with includeIgnored}/out-files/lib/README.md (100%) rename packages/babel-cli/test/fixtures/babel/{--copy-files with ignore with includeIgnore => --copy-files with ignore with includeIgnored}/out-files/lib/foo/bar.js (100%) rename packages/babel-cli/test/fixtures/babel/{--copy-files with ignore with includeIgnore => --copy-files with ignore with includeIgnored}/out-files/lib/index.js (100%) rename packages/babel-cli/test/fixtures/babel/{--copy-files with ignore with includeIgnore => --copy-files with ignore with includeIgnored}/stdout.txt (100%) diff --git a/packages/babel-cli/src/babel/dir.js b/packages/babel-cli/src/babel/dir.js index 824576d1f075..62ad36ba5832 100644 --- a/packages/babel-cli/src/babel/dir.js +++ b/packages/babel-cli/src/babel/dir.js @@ -92,7 +92,7 @@ export default async function({ if ( !written && ((!isCompilableExtension && cliOptions.copyFiles) || - cliOptions.includeIgnore) + cliOptions.includeIgnored) ) { const filename = path.relative(base, src); const dest = getDest(filename, base); diff --git a/packages/babel-cli/src/babel/options.js b/packages/babel-cli/src/babel/options.js index 77f33da8d43f..45590ae9341e 100644 --- a/packages/babel-cli/src/babel/options.js +++ b/packages/babel-cli/src/babel/options.js @@ -162,8 +162,8 @@ commander.option( ); commander.option( - "--include-ignore", - "Include ignored files when compiling and copying non-compilable files.", + "--include-ignored", + "Include ignored files when copying non-compilable files.", ); commander.version(pkg.version + " (@babel/core " + version + ")"); @@ -309,7 +309,7 @@ export default function parseArgv(args: Array): CmdOptions | null { quiet: opts.quiet, deleteDirOnStart: opts.deleteDirOnStart, sourceMapTarget: opts.sourceMapTarget, - includeIgnore: opts.includeIgnore, + includeIgnored: opts.includeIgnored, }, }; } diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/.foorc b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/.foorc similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/.foorc rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/.foorc diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/README.md similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/README.md rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/README.md diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/foo/bar.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/foo/bar.js similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/foo/bar.js rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/foo/bar.js diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/index.js similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/in-files/src/index.js rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/index.js diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/options.json b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/options.json similarity index 83% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/options.json rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/options.json index a119aac9e611..36b8f50db7b2 100644 --- a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/options.json +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/options.json @@ -6,7 +6,7 @@ "--copy-files", "--ignore", "src/foo/*", - "--include-ignore", + "--include-ignored", "--verbose" ] } diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/out-files/lib/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/out-files/lib/README.md similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/out-files/lib/README.md rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/out-files/lib/README.md diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/out-files/lib/foo/bar.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/out-files/lib/foo/bar.js similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/out-files/lib/foo/bar.js rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/out-files/lib/foo/bar.js diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/out-files/lib/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/out-files/lib/index.js similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/out-files/lib/index.js rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/out-files/lib/index.js diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/stdout.txt b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/stdout.txt similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnore/stdout.txt rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/stdout.txt