From 6923c30a855b840079f22ff75b0f5abb01f86638 Mon Sep 17 00:00:00 2001 From: rajasekarm Date: Fri, 6 Dec 2019 15:46:37 +0100 Subject: [PATCH 01/13] 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 1bfab81db1fa975639117cc306faf7436b8cf15e Mon Sep 17 00:00:00 2001 From: Rajasekar Murugan Date: Tue, 17 Dec 2019 11:36:11 +0100 Subject: [PATCH 02/13] 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 96b4aa9c2401..e01df7e046b6 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 65291646e9bf9aa409afefd34b839d9721df75fa Mon Sep 17 00:00:00 2001 From: Raja Sekar Date: Tue, 17 Dec 2019 12:03:43 +0100 Subject: [PATCH 03/13] 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 e01df7e046b6..970c3978eab8 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 d279ce63948cdb71cceb3e87a3c65782704ab084 Mon Sep 17 00:00:00 2001 From: Raja Sekar Date: Tue, 17 Dec 2019 17:21:00 +0100 Subject: [PATCH 04/13] 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 970c3978eab8..6106625c646d 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 099ae0d958a56159fe364cf77de048eae68ddb2e Mon Sep 17 00:00:00 2001 From: Rajasekar Murugan Date: Tue, 17 Dec 2019 22:07:22 +0100 Subject: [PATCH 05/13] 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 6106625c646d..03e8d12d86af 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 From a58c0a55b6aa0d0ac27f3b11aae1d317ceb2332e Mon Sep 17 00:00:00 2001 From: Rajasekar Murugan Date: Fri, 20 Dec 2019 14:23:34 +0100 Subject: [PATCH 06/13] throw error if copyIgnored is used without ignore flag --- packages/babel-cli/src/babel/dir.js | 2 +- packages/babel-cli/src/babel/options.js | 8 ++++++-- .../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 .../in-files/src/index.js | 1 + .../error --copy-ignored without --ignore/options.json | 9 +++++++++ .../error --copy-ignored without --ignore/stderr.txt | 2 ++ 14 files changed, 20 insertions(+), 4 deletions(-) rename packages/babel-cli/test/fixtures/babel/{--copy-files with ignore with includeIgnored => --copy-files with ignore with copyIgnored}/in-files/src/.foorc (100%) rename packages/babel-cli/test/fixtures/babel/{--copy-files with ignore with includeIgnored => --copy-files with ignore with copyIgnored}/in-files/src/README.md (100%) rename packages/babel-cli/test/fixtures/babel/{--copy-files with ignore with includeIgnored => --copy-files with ignore with copyIgnored}/in-files/src/foo/bar.js (100%) rename packages/babel-cli/test/fixtures/babel/{--copy-files with ignore with includeIgnored => --copy-files with ignore with copyIgnored}/in-files/src/index.js (100%) rename packages/babel-cli/test/fixtures/babel/{--copy-files with ignore with includeIgnored => --copy-files with ignore with copyIgnored}/options.json (83%) rename packages/babel-cli/test/fixtures/babel/{--copy-files with ignore with includeIgnored => --copy-files with ignore with copyIgnored}/out-files/lib/README.md (100%) rename packages/babel-cli/test/fixtures/babel/{--copy-files with ignore with includeIgnored => --copy-files with ignore with copyIgnored}/out-files/lib/foo/bar.js (100%) rename packages/babel-cli/test/fixtures/babel/{--copy-files with ignore with includeIgnored => --copy-files with ignore with copyIgnored}/out-files/lib/index.js (100%) rename packages/babel-cli/test/fixtures/babel/{--copy-files with ignore with includeIgnored => --copy-files with ignore with copyIgnored}/stdout.txt (100%) create mode 100644 packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/in-files/src/index.js create mode 100644 packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/options.json create mode 100644 packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/stderr.txt diff --git a/packages/babel-cli/src/babel/dir.js b/packages/babel-cli/src/babel/dir.js index 62ad36ba5832..045ce57b8d5f 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.includeIgnored) + cliOptions.copyIgnored) ) { 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 03e8d12d86af..c54eb7224bc1 100644 --- a/packages/babel-cli/src/babel/options.js +++ b/packages/babel-cli/src/babel/options.js @@ -162,7 +162,7 @@ commander.option( ); commander.option( - "--include-ignored", + "--copy-ignored", "Include ignored files when copying non-compilable files.", ); @@ -231,6 +231,10 @@ export default function parseArgv(args: Array): CmdOptions | null { errors.push("--verbose and --quiet cannot be used together"); } + if (commander.copyIgnored && !commander.ignore) { + errors.push("--copy-ignored requires --ignore"); + } + if ( !commander.outDir && filenames.length === 0 && @@ -309,7 +313,7 @@ export default function parseArgv(args: Array): CmdOptions | null { quiet: opts.quiet, deleteDirOnStart: opts.deleteDirOnStart, sourceMapTarget: opts.sourceMapTarget, - includeIgnored: opts.includeIgnored, + copyIgnored: opts.copyIgnored, }, }; } diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/.foorc b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/in-files/src/.foorc similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/.foorc rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/in-files/src/.foorc diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/in-files/src/README.md similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/README.md rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/in-files/src/README.md diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/foo/bar.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/in-files/src/foo/bar.js similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/foo/bar.js rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/in-files/src/foo/bar.js diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/in-files/src/index.js similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/in-files/src/index.js rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/in-files/src/index.js diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/options.json b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/options.json similarity index 83% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/options.json rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/options.json index 36b8f50db7b2..4b527d0aba5d 100644 --- a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/options.json +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/options.json @@ -6,7 +6,7 @@ "--copy-files", "--ignore", "src/foo/*", - "--include-ignored", + "--copy-ignored", "--verbose" ] } diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/out-files/lib/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/out-files/lib/README.md similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/out-files/lib/README.md rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/out-files/lib/README.md diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/out-files/lib/foo/bar.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/out-files/lib/foo/bar.js similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/out-files/lib/foo/bar.js rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/out-files/lib/foo/bar.js diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/out-files/lib/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/out-files/lib/index.js similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/out-files/lib/index.js rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/out-files/lib/index.js diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/stdout.txt b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/stdout.txt similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore with includeIgnored/stdout.txt rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/stdout.txt diff --git a/packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/in-files/src/index.js b/packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/in-files/src/index.js new file mode 100644 index 000000000000..c6788558edcb --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/in-files/src/index.js @@ -0,0 +1 @@ +index; diff --git a/packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/options.json b/packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/options.json new file mode 100644 index 000000000000..ab4a3655a135 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/options.json @@ -0,0 +1,9 @@ +{ + "args": [ + "src", + "--out-dir", + "lib", + "--copy-ignored", + "--verbose" + ] +} diff --git a/packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/stderr.txt b/packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/stderr.txt new file mode 100644 index 000000000000..ba448991eba5 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/stderr.txt @@ -0,0 +1,2 @@ +babel: + --copy-ignored requires --ignore From 6980ee3e1acc6a995b554723acba2535ed32b65c Mon Sep 17 00:00:00 2001 From: Rajasekar Murugan Date: Wed, 25 Dec 2019 16:54:58 +0100 Subject: [PATCH 07/13] check for ignored files --- packages/babel-cli/src/babel/dir.js | 27 ++++++++++++++++++- packages/babel-cli/src/babel/options.js | 1 + .../options.json | 2 +- .../in-files/src/bar/bar.js | 1 + .../in-files/src/index.js | 1 + .../options.json | 11 ++++++++ .../stderr.txt | 2 ++ packages/babel-core/src/config/index.js | 1 + packages/babel-core/src/index.js | 2 +- 9 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/in-files/src/bar/bar.js create mode 100644 packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/in-files/src/index.js create mode 100644 packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/options.json create mode 100644 packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/stderr.txt diff --git a/packages/babel-cli/src/babel/dir.js b/packages/babel-cli/src/babel/dir.js index 045ce57b8d5f..fe046388bfc1 100644 --- a/packages/babel-cli/src/babel/dir.js +++ b/packages/babel-cli/src/babel/dir.js @@ -5,6 +5,7 @@ import { sync as makeDirSync } from "make-dir"; import slash from "slash"; import path from "path"; import fs from "fs"; +import { pathToPattern } from "@babel/core"; import * as util from "./util"; import { type CmdOptions } from "./options"; @@ -14,6 +15,28 @@ function outputFileSync(filePath: string, data: string | Buffer): void { fs.writeFileSync(filePath, data); } +function isIgnoredFile(fileName: string, ignoredList: Array): boolean { + const dir = process.cwd(); + + if (ignoredList.length === 1) { + const pattern = pathToPattern(ignoredList[0], dir); + const absolutePath = path.resolve(dir, fileName); + return pattern.test(absolutePath); + } + const cache = {}; + return ignoredList.some(ignorePattern => { + let pattern; + if (cache[ignorePattern]) { + pattern = cache[ignorePattern]; + } else { + cache[ignorePattern] = pathToPattern(ignorePattern, dir); + } + pattern = cache[ignorePattern]; + const absolutePath = path.resolve(dir, fileName); + return pattern.test(absolutePath); + }); +} + export default async function({ cliOptions, babelOptions, @@ -92,7 +115,9 @@ export default async function({ if ( !written && ((!isCompilableExtension && cliOptions.copyFiles) || - cliOptions.copyIgnored) + (cliOptions.copyIgnored && + cliOptions.ignore.length && + isIgnoredFile(src, cliOptions.ignore))) ) { 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 c54eb7224bc1..0fac3faf3415 100644 --- a/packages/babel-cli/src/babel/options.js +++ b/packages/babel-cli/src/babel/options.js @@ -313,6 +313,7 @@ export default function parseArgv(args: Array): CmdOptions | null { quiet: opts.quiet, deleteDirOnStart: opts.deleteDirOnStart, sourceMapTarget: opts.sourceMapTarget, + ignore: opts.ignore, copyIgnored: opts.copyIgnored, }, }; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/options.json b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/options.json index 4b527d0aba5d..f49a79c08fe5 100644 --- a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/options.json +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/options.json @@ -5,7 +5,7 @@ "lib", "--copy-files", "--ignore", - "src/foo/*", + "src/foo", "--copy-ignored", "--verbose" ] diff --git a/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/in-files/src/bar/bar.js b/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/in-files/src/bar/bar.js new file mode 100644 index 000000000000..e46160df1c7a --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/in-files/src/bar/bar.js @@ -0,0 +1 @@ +bar; diff --git a/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/in-files/src/index.js b/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/in-files/src/index.js new file mode 100644 index 000000000000..c6788558edcb --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/in-files/src/index.js @@ -0,0 +1 @@ +index; diff --git a/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/options.json b/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/options.json new file mode 100644 index 000000000000..a1f2915fdcba --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/options.json @@ -0,0 +1,11 @@ +{ + "args": [ + "src", + "--out-dir", + "lib", + "--only", + "src/bar", + "--copy-ignored", + "--verbose" + ] +} diff --git a/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/stderr.txt b/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/stderr.txt new file mode 100644 index 000000000000..ba448991eba5 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/stderr.txt @@ -0,0 +1,2 @@ +babel: + --copy-ignored requires --ignore diff --git a/packages/babel-core/src/config/index.js b/packages/babel-core/src/config/index.js index 51016d34c757..e59e79644a0b 100644 --- a/packages/babel-core/src/config/index.js +++ b/packages/babel-core/src/config/index.js @@ -11,6 +11,7 @@ export type { export { loadFullConfig as default }; export { loadPartialConfig } from "./partial"; export type { PartialConfig } from "./partial"; +export { default as pathToPattern } from "./pattern-to-regex"; export function loadOptions(opts: {}): Object | null { const config = loadFullConfig(opts); diff --git a/packages/babel-core/src/index.js b/packages/babel-core/src/index.js index 888a8096d5cc..fa273cabfafd 100644 --- a/packages/babel-core/src/index.js +++ b/packages/babel-core/src/index.js @@ -15,7 +15,7 @@ export { default as template } from "@babel/template"; export { createConfigItem } from "./config/item"; -export { loadPartialConfig, loadOptions } from "./config"; +export { loadPartialConfig, loadOptions, pathToPattern } from "./config"; export { transform, transformSync, transformAsync } from "./transform"; export { From e7a99e9ef5bc6dd396f9c27b43d75a4163f80634 Mon Sep 17 00:00:00 2001 From: Rajasekar Murugan Date: Wed, 25 Dec 2019 21:59:31 +0100 Subject: [PATCH 08/13] duplicate pathToPattern fn in babel/cli --- packages/babel-cli/src/babel/dir.js | 2 +- .../babel-cli/src/babel/pattern-to-regex.js | 58 +++++++++++++++++++ packages/babel-core/src/config/index.js | 1 - .../babel-core/src/config/pattern-to-regex.js | 7 +++ packages/babel-core/src/index.js | 2 +- 5 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 packages/babel-cli/src/babel/pattern-to-regex.js diff --git a/packages/babel-cli/src/babel/dir.js b/packages/babel-cli/src/babel/dir.js index fe046388bfc1..96b4cd1155b8 100644 --- a/packages/babel-cli/src/babel/dir.js +++ b/packages/babel-cli/src/babel/dir.js @@ -5,7 +5,7 @@ import { sync as makeDirSync } from "make-dir"; import slash from "slash"; import path from "path"; import fs from "fs"; -import { pathToPattern } from "@babel/core"; +import pathToPattern from "./pattern-to-regex"; import * as util from "./util"; import { type CmdOptions } from "./options"; diff --git a/packages/babel-cli/src/babel/pattern-to-regex.js b/packages/babel-cli/src/babel/pattern-to-regex.js new file mode 100644 index 000000000000..d8ae5302db60 --- /dev/null +++ b/packages/babel-cli/src/babel/pattern-to-regex.js @@ -0,0 +1,58 @@ +// @flow +import path from "path"; +import escapeRegExp from "lodash/escapeRegExp"; + +const sep = `\\${path.sep}`; +const endSep = `(?:${sep}|$)`; + +const substitution = `[^${sep}]+`; + +const starPat = `(?:${substitution}${sep})`; +const starPatLast = `(?:${substitution}${endSep})`; + +const starStarPat = `${starPat}*?`; +const starStarPatLast = `${starPat}*?${starPatLast}?`; + +/** + * Implement basic pattern matching that will allow users to do the simple + * tests with * and **. If users want full complex pattern matching, then can + * always use regex matching, or function validation. + */ + +/** + * NOTE - This is copied from babel/core. Any changes to be made in function + * should be made in babel/core as well. This will be removed in v8 + * Path - babel-core/src/config/pattern-to-regex + */ + +export default function pathToPattern( + pattern: string, + dirname: string, +): RegExp { + const parts = path.resolve(dirname, pattern).split(path.sep); + + return new RegExp( + [ + "^", + ...parts.map((part, i) => { + const last = i === parts.length - 1; + + // ** matches 0 or more path parts. + if (part === "**") return last ? starStarPatLast : starStarPat; + + // * matches 1 path part. + if (part === "*") return last ? starPatLast : starPat; + + // *.ext matches a wildcard with an extension. + if (part.indexOf("*.") === 0) { + return ( + substitution + escapeRegExp(part.slice(1)) + (last ? endSep : sep) + ); + } + + // Otherwise match the pattern text. + return escapeRegExp(part) + (last ? endSep : sep); + }), + ].join(""), + ); +} diff --git a/packages/babel-core/src/config/index.js b/packages/babel-core/src/config/index.js index e59e79644a0b..51016d34c757 100644 --- a/packages/babel-core/src/config/index.js +++ b/packages/babel-core/src/config/index.js @@ -11,7 +11,6 @@ export type { export { loadFullConfig as default }; export { loadPartialConfig } from "./partial"; export type { PartialConfig } from "./partial"; -export { default as pathToPattern } from "./pattern-to-regex"; export function loadOptions(opts: {}): Object | null { const config = loadFullConfig(opts); diff --git a/packages/babel-core/src/config/pattern-to-regex.js b/packages/babel-core/src/config/pattern-to-regex.js index d796617f89b4..f5ad092011c2 100644 --- a/packages/babel-core/src/config/pattern-to-regex.js +++ b/packages/babel-core/src/config/pattern-to-regex.js @@ -18,6 +18,13 @@ const starStarPatLast = `${starPat}*?${starPatLast}?`; * tests with * and **. If users want full complex pattern matching, then can * always use regex matching, or function validation. */ + +/** + * NOTE - This function is duplicated in babel-cli. Any changes to be made in function + * should be made in babel/cli as well. This will be removed in v8 + * Path - babel-cli/src/pattern-to-regex + */ + export default function pathToPattern( pattern: string, dirname: string, diff --git a/packages/babel-core/src/index.js b/packages/babel-core/src/index.js index fa273cabfafd..888a8096d5cc 100644 --- a/packages/babel-core/src/index.js +++ b/packages/babel-core/src/index.js @@ -15,7 +15,7 @@ export { default as template } from "@babel/template"; export { createConfigItem } from "./config/item"; -export { loadPartialConfig, loadOptions, pathToPattern } from "./config"; +export { loadPartialConfig, loadOptions } from "./config"; export { transform, transformSync, transformAsync } from "./transform"; export { From 0e27625c081dbce60e606edddd5883dd01052c8d Mon Sep 17 00:00:00 2001 From: Rajasekar Murugan Date: Fri, 27 Dec 2019 11:16:26 +0100 Subject: [PATCH 09/13] change implementation --- packages/babel-cli/src/babel/dir.js | 55 +++++------------- packages/babel-cli/src/babel/options.js | 4 -- .../babel-cli/src/babel/pattern-to-regex.js | 58 ------------------- .../in-files/src/bar/bar.js | 1 - .../in-files/src/index.js | 1 - .../options.json | 11 ---- .../stderr.txt | 2 - .../in-files/src/index.js | 1 - .../options.json | 9 --- .../stderr.txt | 2 - .../babel-core/src/config/pattern-to-regex.js | 7 --- 11 files changed, 16 insertions(+), 135 deletions(-) delete mode 100644 packages/babel-cli/src/babel/pattern-to-regex.js delete mode 100644 packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/in-files/src/bar/bar.js delete mode 100644 packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/in-files/src/index.js delete mode 100644 packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/options.json delete mode 100644 packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/stderr.txt delete mode 100644 packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/in-files/src/index.js delete mode 100644 packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/options.json delete mode 100644 packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/stderr.txt diff --git a/packages/babel-cli/src/babel/dir.js b/packages/babel-cli/src/babel/dir.js index 96b4cd1155b8..a0d92ed21f6d 100644 --- a/packages/babel-cli/src/babel/dir.js +++ b/packages/babel-cli/src/babel/dir.js @@ -5,49 +5,33 @@ import { sync as makeDirSync } from "make-dir"; import slash from "slash"; import path from "path"; import fs from "fs"; -import pathToPattern from "./pattern-to-regex"; import * as util from "./util"; import { type CmdOptions } from "./options"; +const FILE_TYPE = Object.freeze({ + NON_COMPACTIBLE: "NON_COMPACTIBLE", + COMPILED: "COMPILED", + IGNORED: "IGNORED", + ERR_COMPILATION: "ERR_COMPILATION", +}); + function outputFileSync(filePath: string, data: string | Buffer): void { makeDirSync(path.dirname(filePath)); fs.writeFileSync(filePath, data); } -function isIgnoredFile(fileName: string, ignoredList: Array): boolean { - const dir = process.cwd(); - - if (ignoredList.length === 1) { - const pattern = pathToPattern(ignoredList[0], dir); - const absolutePath = path.resolve(dir, fileName); - return pattern.test(absolutePath); - } - const cache = {}; - return ignoredList.some(ignorePattern => { - let pattern; - if (cache[ignorePattern]) { - pattern = cache[ignorePattern]; - } else { - cache[ignorePattern] = pathToPattern(ignorePattern, dir); - } - pattern = cache[ignorePattern]; - const absolutePath = path.resolve(dir, fileName); - return pattern.test(absolutePath); - }); -} - export default async function({ cliOptions, babelOptions, }: CmdOptions): Promise { const filenames = cliOptions.filenames; - async function write(src: string, base: string): Promise { + async function write(src: string, base: string): Promise { let relative = path.relative(base, src); if (!util.isCompilableExtension(relative, cliOptions.extensions)) { - return false; + return FILE_TYPE.NON_COMPACTIBLE; } // remove extension and then append back on .js @@ -66,7 +50,7 @@ export default async function({ ), ); - if (!res) return false; + if (!res) return FILE_TYPE.IGNORED; // we've requested explicit sourcemaps to be written to disk if ( @@ -87,11 +71,11 @@ export default async function({ console.log(src + " -> " + dest); } - return true; + return FILE_TYPE.COMPILED; } catch (err) { if (cliOptions.watch) { console.error(err); - return false; + return FILE_TYPE.ERR_COMPILATION; } throw err; @@ -107,24 +91,17 @@ export default async function({ async function handleFile(src: string, base: string): Promise { const written = await write(src, base); - const relative = path.relative(base, src); - const isCompilableExtension = util.isCompilableExtension( - relative, - cliOptions.extensions, - ); + if ( - !written && - ((!isCompilableExtension && cliOptions.copyFiles) || - (cliOptions.copyIgnored && - cliOptions.ignore.length && - isIgnoredFile(src, cliOptions.ignore))) + (cliOptions.copyFiles && written === FILE_TYPE.NON_COMPACTIBLE) || + (cliOptions.copyIgnored && written === FILE_TYPE.IGNORED) ) { const filename = path.relative(base, src); const dest = getDest(filename, base); outputFileSync(dest, fs.readFileSync(src)); util.chmod(src, dest); } - return written; + return written === FILE_TYPE.COMPILED; } async function handle(filenameOrDir: string): Promise { diff --git a/packages/babel-cli/src/babel/options.js b/packages/babel-cli/src/babel/options.js index 0fac3faf3415..3ad98637c57f 100644 --- a/packages/babel-cli/src/babel/options.js +++ b/packages/babel-cli/src/babel/options.js @@ -231,10 +231,6 @@ export default function parseArgv(args: Array): CmdOptions | null { errors.push("--verbose and --quiet cannot be used together"); } - if (commander.copyIgnored && !commander.ignore) { - errors.push("--copy-ignored requires --ignore"); - } - if ( !commander.outDir && filenames.length === 0 && diff --git a/packages/babel-cli/src/babel/pattern-to-regex.js b/packages/babel-cli/src/babel/pattern-to-regex.js deleted file mode 100644 index d8ae5302db60..000000000000 --- a/packages/babel-cli/src/babel/pattern-to-regex.js +++ /dev/null @@ -1,58 +0,0 @@ -// @flow -import path from "path"; -import escapeRegExp from "lodash/escapeRegExp"; - -const sep = `\\${path.sep}`; -const endSep = `(?:${sep}|$)`; - -const substitution = `[^${sep}]+`; - -const starPat = `(?:${substitution}${sep})`; -const starPatLast = `(?:${substitution}${endSep})`; - -const starStarPat = `${starPat}*?`; -const starStarPatLast = `${starPat}*?${starPatLast}?`; - -/** - * Implement basic pattern matching that will allow users to do the simple - * tests with * and **. If users want full complex pattern matching, then can - * always use regex matching, or function validation. - */ - -/** - * NOTE - This is copied from babel/core. Any changes to be made in function - * should be made in babel/core as well. This will be removed in v8 - * Path - babel-core/src/config/pattern-to-regex - */ - -export default function pathToPattern( - pattern: string, - dirname: string, -): RegExp { - const parts = path.resolve(dirname, pattern).split(path.sep); - - return new RegExp( - [ - "^", - ...parts.map((part, i) => { - const last = i === parts.length - 1; - - // ** matches 0 or more path parts. - if (part === "**") return last ? starStarPatLast : starStarPat; - - // * matches 1 path part. - if (part === "*") return last ? starPatLast : starPat; - - // *.ext matches a wildcard with an extension. - if (part.indexOf("*.") === 0) { - return ( - substitution + escapeRegExp(part.slice(1)) + (last ? endSep : sep) - ); - } - - // Otherwise match the pattern text. - return escapeRegExp(part) + (last ? endSep : sep); - }), - ].join(""), - ); -} diff --git a/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/in-files/src/bar/bar.js b/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/in-files/src/bar/bar.js deleted file mode 100644 index e46160df1c7a..000000000000 --- a/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/in-files/src/bar/bar.js +++ /dev/null @@ -1 +0,0 @@ -bar; diff --git a/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/in-files/src/index.js b/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/in-files/src/index.js deleted file mode 100644 index c6788558edcb..000000000000 --- a/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/in-files/src/index.js +++ /dev/null @@ -1 +0,0 @@ -index; diff --git a/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/options.json b/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/options.json deleted file mode 100644 index a1f2915fdcba..000000000000 --- a/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/options.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "args": [ - "src", - "--out-dir", - "lib", - "--only", - "src/bar", - "--copy-ignored", - "--verbose" - ] -} diff --git a/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/stderr.txt b/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/stderr.txt deleted file mode 100644 index ba448991eba5..000000000000 --- a/packages/babel-cli/test/fixtures/babel/error --copy-files --only --copy-ignored/stderr.txt +++ /dev/null @@ -1,2 +0,0 @@ -babel: - --copy-ignored requires --ignore diff --git a/packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/in-files/src/index.js b/packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/in-files/src/index.js deleted file mode 100644 index c6788558edcb..000000000000 --- a/packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/in-files/src/index.js +++ /dev/null @@ -1 +0,0 @@ -index; diff --git a/packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/options.json b/packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/options.json deleted file mode 100644 index ab4a3655a135..000000000000 --- a/packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/options.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "args": [ - "src", - "--out-dir", - "lib", - "--copy-ignored", - "--verbose" - ] -} diff --git a/packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/stderr.txt b/packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/stderr.txt deleted file mode 100644 index ba448991eba5..000000000000 --- a/packages/babel-cli/test/fixtures/babel/error --copy-ignored without --ignore/stderr.txt +++ /dev/null @@ -1,2 +0,0 @@ -babel: - --copy-ignored requires --ignore diff --git a/packages/babel-core/src/config/pattern-to-regex.js b/packages/babel-core/src/config/pattern-to-regex.js index f5ad092011c2..d796617f89b4 100644 --- a/packages/babel-core/src/config/pattern-to-regex.js +++ b/packages/babel-core/src/config/pattern-to-regex.js @@ -18,13 +18,6 @@ const starStarPatLast = `${starPat}*?${starPatLast}?`; * tests with * and **. If users want full complex pattern matching, then can * always use regex matching, or function validation. */ - -/** - * NOTE - This function is duplicated in babel-cli. Any changes to be made in function - * should be made in babel/cli as well. This will be removed in v8 - * Path - babel-cli/src/pattern-to-regex - */ - export default function pathToPattern( pattern: string, dirname: string, From 219c378249751045cdcfd5a6fd20068a85274b81 Mon Sep 17 00:00:00 2001 From: Rajasekar Murugan Date: Fri, 27 Dec 2019 11:27:24 +0100 Subject: [PATCH 10/13] removed ignore option from cliOption --- packages/babel-cli/src/babel/options.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/babel-cli/src/babel/options.js b/packages/babel-cli/src/babel/options.js index 3ad98637c57f..a6f1c523e99f 100644 --- a/packages/babel-cli/src/babel/options.js +++ b/packages/babel-cli/src/babel/options.js @@ -309,7 +309,6 @@ export default function parseArgv(args: Array): CmdOptions | null { quiet: opts.quiet, deleteDirOnStart: opts.deleteDirOnStart, sourceMapTarget: opts.sourceMapTarget, - ignore: opts.ignore, copyIgnored: opts.copyIgnored, }, }; From f620970c17d72e35c28119959c587246c8edfe65 Mon Sep 17 00:00:00 2001 From: Rajasekar Murugan Date: Fri, 27 Dec 2019 12:03:13 +0100 Subject: [PATCH 11/13] added test case with ignore in config --- .../.babelrc | 3 +++ .../in-files/src/.foorc | 0 .../in-files/src/README.md | 0 .../in-files/src/foo/.foo.js | 1 + .../in-files/src/foo/index.js | 1 + .../in-files/src/index.js | 1 + .../options.json | 10 ++++++++++ .../out-files/lib/.foorc | 0 .../out-files/lib/README.md | 0 .../out-files/lib/index.js | 3 +++ .../stdout.txt | 2 ++ 11 files changed, 21 insertions(+) create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/.babelrc create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/.foorc create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/README.md create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/foo/.foo.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/foo/index.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/index.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/options.json create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/out-files/lib/.foorc create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/out-files/lib/README.md create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/out-files/lib/index.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/stdout.txt diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/.babelrc b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/.babelrc new file mode 100644 index 000000000000..b1fb07ff865b --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/.babelrc @@ -0,0 +1,3 @@ +{ + "ignore": ["src/foo"] +} diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/.foorc b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/.foorc new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/README.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/foo/.foo.js b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/foo/.foo.js new file mode 100644 index 000000000000..31142aabfe70 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/foo/.foo.js @@ -0,0 +1 @@ +a; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/foo/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/foo/index.js new file mode 100644 index 000000000000..e46160df1c7a --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/foo/index.js @@ -0,0 +1 @@ +bar; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/index.js new file mode 100644 index 000000000000..c6788558edcb --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/index.js @@ -0,0 +1 @@ +index; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/options.json b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/options.json new file mode 100644 index 000000000000..bb94e945f80e --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/options.json @@ -0,0 +1,10 @@ +{ + "args": [ + "src", + "--out-dir", + "lib", + "--copy-files", + "--include-dotfiles", + "--verbose" + ] +} diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/out-files/lib/.foorc b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/out-files/lib/.foorc new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/out-files/lib/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/out-files/lib/README.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/out-files/lib/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/out-files/lib/index.js new file mode 100644 index 000000000000..1073b618d0dd --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/out-files/lib/index.js @@ -0,0 +1,3 @@ +"use strict"; + +index; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/stdout.txt b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/stdout.txt new file mode 100644 index 000000000000..84a430432e47 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/stdout.txt @@ -0,0 +1,2 @@ +src/index.js -> lib/index.js +Successfully compiled 1 file with Babel. From 0abfbefba1e2500dc58a1c5e752c4f13134d8991 Mon Sep 17 00:00:00 2001 From: Rajasekar Murugan Date: Fri, 27 Dec 2019 14:09:32 +0100 Subject: [PATCH 12/13] added test case with ignore in config --- .../.babelignore | 1 + .../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 | 10 ++++++++++ .../out-files/lib/README.md | 0 .../out-files/lib/foo/bar.js | 1 + .../out-files/lib/index.js | 3 +++ .../stdout.txt | 2 ++ .../.babelrc | 3 +++ .../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 | 10 ++++++++++ .../out-files/lib/README.md | 0 .../out-files/lib/foo/bar.js | 1 + .../out-files/lib/index.js | 3 +++ .../stdout.txt | 2 ++ .../.babelignore | 1 + .../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 | 9 +++++++++ .../out-files/lib/README.md | 0 .../out-files/lib/index.js | 3 +++ .../stdout.txt | 2 ++ .../--copy-files with ignore in babelrc/.babelrc | 3 +++ .../in-files/src/.foorc | 0 .../in-files/src/README.md | 0 .../in-files/src/foo/bar.js | 1 + .../in-files/src/index.js | 1 + .../--copy-files with ignore in babelrc/options.json | 9 +++++++++ .../out-files/lib/README.md | 0 .../out-files/lib/index.js | 3 +++ .../--copy-files with ignore in babelrc/stdout.txt | 2 ++ .../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 | 3 +++ .../out-files/lib/index.js | 1 + .../stdout.txt | 2 ++ packages/babel-cli/test/index.js | 7 +++++++ 48 files changed, 103 insertions(+) create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/.babelignore create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/in-files/src/.foorc create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/in-files/src/README.md create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/in-files/src/foo/bar.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/in-files/src/index.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/options.json create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/out-files/lib/README.md create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/out-files/lib/foo/bar.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/out-files/lib/index.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/stdout.txt create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/.babelrc create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/in-files/src/.foorc create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/in-files/src/README.md create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/in-files/src/foo/bar.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/in-files/src/index.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/options.json create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/out-files/lib/README.md create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/out-files/lib/foo/bar.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/out-files/lib/index.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/stdout.txt create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/.babelignore create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/in-files/src/.foorc create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/in-files/src/README.md create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/in-files/src/foo/bar.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/in-files/src/index.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/options.json create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/out-files/lib/README.md create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/out-files/lib/index.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/stdout.txt create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/.babelrc create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/in-files/src/.foorc create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/in-files/src/README.md create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/in-files/src/foo/bar.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/in-files/src/index.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/options.json create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/out-files/lib/README.md create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/out-files/lib/index.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/stdout.txt create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/in-files/src/.foorc create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/in-files/src/README.md create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/in-files/src/foo/bar.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/in-files/src/index.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/options.json create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/out-files/lib/README.md create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/out-files/lib/foo/bar.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/out-files/lib/index.js create mode 100644 packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/stdout.txt diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/.babelignore b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/.babelignore new file mode 100644 index 000000000000..8b4ba6ce4d35 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/.babelignore @@ -0,0 +1 @@ +src/foo diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/in-files/src/.foorc b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/in-files/src/.foorc new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/in-files/src/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/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 and copyIgnored in babelignore/in-files/src/foo/bar.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/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 and copyIgnored in babelignore/in-files/src/foo/bar.js @@ -0,0 +1 @@ +bar; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/in-files/src/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/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 and copyIgnored in babelignore/in-files/src/index.js @@ -0,0 +1 @@ +index; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/options.json b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/options.json new file mode 100644 index 000000000000..d16d70e6ffec --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/options.json @@ -0,0 +1,10 @@ +{ + "args": [ + "src", + "--out-dir", + "lib", + "--copy-files", + "--copy-ignored", + "--verbose" + ] +} diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/out-files/lib/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/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 and copyIgnored in babelignore/out-files/lib/foo/bar.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/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 and copyIgnored in babelignore/out-files/lib/foo/bar.js @@ -0,0 +1 @@ +bar; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/out-files/lib/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/out-files/lib/index.js new file mode 100644 index 000000000000..1073b618d0dd --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/out-files/lib/index.js @@ -0,0 +1,3 @@ +"use strict"; + +index; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/stdout.txt b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/stdout.txt new file mode 100644 index 000000000000..84a430432e47 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/stdout.txt @@ -0,0 +1,2 @@ +src/index.js -> lib/index.js +Successfully compiled 1 file with Babel. diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/.babelrc b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/.babelrc new file mode 100644 index 000000000000..b1fb07ff865b --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/.babelrc @@ -0,0 +1,3 @@ +{ + "ignore": ["src/foo"] +} diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/in-files/src/.foorc b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/in-files/src/.foorc new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/in-files/src/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/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 and copyIgnored in babelrc/in-files/src/foo/bar.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/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 and copyIgnored in babelrc/in-files/src/foo/bar.js @@ -0,0 +1 @@ +bar; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/in-files/src/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/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 and copyIgnored in babelrc/in-files/src/index.js @@ -0,0 +1 @@ +index; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/options.json b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/options.json new file mode 100644 index 000000000000..d16d70e6ffec --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/options.json @@ -0,0 +1,10 @@ +{ + "args": [ + "src", + "--out-dir", + "lib", + "--copy-files", + "--copy-ignored", + "--verbose" + ] +} diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/out-files/lib/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/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 and copyIgnored in babelrc/out-files/lib/foo/bar.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/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 and copyIgnored in babelrc/out-files/lib/foo/bar.js @@ -0,0 +1 @@ +bar; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/out-files/lib/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/out-files/lib/index.js new file mode 100644 index 000000000000..1073b618d0dd --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/out-files/lib/index.js @@ -0,0 +1,3 @@ +"use strict"; + +index; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/stdout.txt b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/stdout.txt new file mode 100644 index 000000000000..84a430432e47 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelrc/stdout.txt @@ -0,0 +1,2 @@ +src/index.js -> lib/index.js +Successfully compiled 1 file with Babel. diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/.babelignore b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/.babelignore new file mode 100644 index 000000000000..8b4ba6ce4d35 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/.babelignore @@ -0,0 +1 @@ +src/foo diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/in-files/src/.foorc b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/in-files/src/.foorc new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/in-files/src/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/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 in babelignore/in-files/src/foo/bar.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/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 in babelignore/in-files/src/foo/bar.js @@ -0,0 +1 @@ +bar; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/in-files/src/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/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 in babelignore/in-files/src/index.js @@ -0,0 +1 @@ +index; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/options.json b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/options.json new file mode 100644 index 000000000000..39e3d0dc2606 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/options.json @@ -0,0 +1,9 @@ +{ + "args": [ + "src", + "--out-dir", + "lib", + "--copy-files", + "--verbose" + ] +} diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/out-files/lib/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/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 in babelignore/out-files/lib/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/out-files/lib/index.js new file mode 100644 index 000000000000..1073b618d0dd --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/out-files/lib/index.js @@ -0,0 +1,3 @@ +"use strict"; + +index; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/stdout.txt b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/stdout.txt new file mode 100644 index 000000000000..84a430432e47 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelignore/stdout.txt @@ -0,0 +1,2 @@ +src/index.js -> lib/index.js +Successfully compiled 1 file with Babel. diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/.babelrc b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/.babelrc new file mode 100644 index 000000000000..b1fb07ff865b --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/.babelrc @@ -0,0 +1,3 @@ +{ + "ignore": ["src/foo"] +} diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/in-files/src/.foorc b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/in-files/src/.foorc new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/in-files/src/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/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 in babelrc/in-files/src/foo/bar.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/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 in babelrc/in-files/src/foo/bar.js @@ -0,0 +1 @@ +bar; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/in-files/src/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/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 in babelrc/in-files/src/index.js @@ -0,0 +1 @@ +index; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/options.json b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/options.json new file mode 100644 index 000000000000..39e3d0dc2606 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/options.json @@ -0,0 +1,9 @@ +{ + "args": [ + "src", + "--out-dir", + "lib", + "--copy-files", + "--verbose" + ] +} diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/out-files/lib/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/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 in babelrc/out-files/lib/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/out-files/lib/index.js new file mode 100644 index 000000000000..1073b618d0dd --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/out-files/lib/index.js @@ -0,0 +1,3 @@ +"use strict"; + +index; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/stdout.txt b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/stdout.txt new file mode 100644 index 000000000000..84a430432e47 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore in babelrc/stdout.txt @@ -0,0 +1,2 @@ +src/index.js -> lib/index.js +Successfully compiled 1 file with Babel. diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/in-files/src/.foorc b/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/in-files/src/.foorc new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/in-files/src/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/in-files/src/README.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/in-files/src/foo/bar.js b/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/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 only copy copyIgnored/in-files/src/foo/bar.js @@ -0,0 +1 @@ +bar; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/in-files/src/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/in-files/src/index.js new file mode 100644 index 000000000000..c6788558edcb --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/in-files/src/index.js @@ -0,0 +1 @@ +index; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/options.json b/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/options.json new file mode 100644 index 000000000000..f3adb3c91b91 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/options.json @@ -0,0 +1,12 @@ +{ + "args": [ + "src", + "--out-dir", + "lib", + "--copy-files", + "--only", + "src/foo/*", + "--copy-ignored", + "--verbose" + ] +} diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/out-files/lib/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/out-files/lib/README.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/out-files/lib/foo/bar.js b/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/out-files/lib/foo/bar.js new file mode 100644 index 000000000000..0ed075a19327 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/out-files/lib/foo/bar.js @@ -0,0 +1,3 @@ +"use strict"; + +bar; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/out-files/lib/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/out-files/lib/index.js new file mode 100644 index 000000000000..c6788558edcb --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/out-files/lib/index.js @@ -0,0 +1 @@ +index; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/stdout.txt b/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/stdout.txt new file mode 100644 index 000000000000..673dafc7483e --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with only copy copyIgnored/stdout.txt @@ -0,0 +1,2 @@ +src/foo/bar.js -> lib/foo/bar.js +Successfully compiled 1 file with Babel. diff --git a/packages/babel-cli/test/index.js b/packages/babel-cli/test/index.js index 88d596740133..e7ee2cbb6f40 100644 --- a/packages/babel-cli/test/index.js +++ b/packages/babel-cli/test/index.js @@ -97,6 +97,7 @@ const assertTest = function(stdout, stderr, opts, cwd) { if ( // saveInFiles always creates an empty .babelrc, so lets exclude for now filename !== ".babelrc" && + filename !== ".babelignore" && !Object.prototype.hasOwnProperty.call(opts.inFiles, filename) ) { const expected = opts.outFiles[filename]; @@ -239,9 +240,15 @@ fs.readdirSync(fixtureLoc).forEach(function(binName) { opts.inFiles = readDir(path.join(testLoc, "in-files"), fileFilter); const babelrcLoc = path.join(testLoc, ".babelrc"); + const babelIgnoreLoc = path.join(testLoc, ".babelignore"); if (fs.existsSync(babelrcLoc)) { // copy .babelrc file to tmp directory opts.inFiles[".babelrc"] = helper.readFile(babelrcLoc); + opts.inFiles[".babelignore"] = helper.readFile(babelIgnoreLoc); + } + if (fs.existsSync(babelIgnoreLoc)) { + // copy .babelignore file to tmp directory + opts.inFiles[".babelignore"] = helper.readFile(babelIgnoreLoc); } it(testName, buildTest(binName, testName, opts), 20000); From f6e19633715e50726cc17a7bac0171b2a78d38c1 Mon Sep 17 00:00:00 2001 From: Rajasekar Murugan Date: Sat, 28 Dec 2019 19:50:10 +0100 Subject: [PATCH 13/13] review --- packages/babel-cli/src/babel/dir.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/babel-cli/src/babel/dir.js b/packages/babel-cli/src/babel/dir.js index a0d92ed21f6d..cdda03ab0309 100644 --- a/packages/babel-cli/src/babel/dir.js +++ b/packages/babel-cli/src/babel/dir.js @@ -10,7 +10,7 @@ import * as util from "./util"; import { type CmdOptions } from "./options"; const FILE_TYPE = Object.freeze({ - NON_COMPACTIBLE: "NON_COMPACTIBLE", + NON_COMPILABLE: "NON_COMPILABLE", COMPILED: "COMPILED", IGNORED: "IGNORED", ERR_COMPILATION: "ERR_COMPILATION", @@ -27,11 +27,14 @@ export default async function({ }: CmdOptions): Promise { const filenames = cliOptions.filenames; - async function write(src: string, base: string): Promise { + async function write( + src: string, + base: string, + ): Promise<$Keys> { let relative = path.relative(base, src); if (!util.isCompilableExtension(relative, cliOptions.extensions)) { - return FILE_TYPE.NON_COMPACTIBLE; + return FILE_TYPE.NON_COMPILABLE; } // remove extension and then append back on .js @@ -93,7 +96,7 @@ export default async function({ const written = await write(src, base); if ( - (cliOptions.copyFiles && written === FILE_TYPE.NON_COMPACTIBLE) || + (cliOptions.copyFiles && written === FILE_TYPE.NON_COMPILABLE) || (cliOptions.copyIgnored && written === FILE_TYPE.IGNORED) ) { const filename = path.relative(base, src);