diff --git a/packages/babel-cli/src/babel/dir.js b/packages/babel-cli/src/babel/dir.js index 4e8a48daa6..9b199b98a4 100644 --- a/packages/babel-cli/src/babel/dir.js +++ b/packages/babel-cli/src/babel/dir.js @@ -9,6 +9,13 @@ import fs from "fs"; import * as util from "./util"; import { type CmdOptions } from "./options"; +const FILE_TYPE = Object.freeze({ + NON_COMPILABLE: "NON_COMPILABLE", + COMPILED: "COMPILED", + IGNORED: "IGNORED", + ERR_COMPILATION: "ERR_COMPILATION", +}); + function outputFileSync(filePath: string, data: string | Buffer): void { makeDirSync(path.dirname(filePath)); fs.writeFileSync(filePath, data); @@ -20,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 false; + return FILE_TYPE.NON_COMPILABLE; } relative = util.withExtension( @@ -47,7 +57,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 ( @@ -68,11 +78,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; @@ -89,13 +99,16 @@ export default async function({ async function handleFile(src: string, base: string): Promise { const written = await write(src, base); - if (!written && cliOptions.copyFiles) { + if ( + (cliOptions.copyFiles && written === FILE_TYPE.NON_COMPILABLE) || + (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 e32144c678..6e4dfeaed2 100644 --- a/packages/babel-cli/src/babel/options.js +++ b/packages/babel-cli/src/babel/options.js @@ -165,6 +165,11 @@ commander.option( "Use a specific extension for the output files", ); +commander.option( + "--copy-ignored", + "Include ignored files when copying non-compilable files.", +); + commander.version(pkg.version + " (@babel/core " + version + ")"); commander.usage("[options] "); // register an empty action handler so that commander.js can throw on @@ -315,6 +320,7 @@ export default function parseArgv(args: Array): CmdOptions | null { quiet: opts.quiet, deleteDirOnStart: opts.deleteDirOnStart, sourceMapTarget: opts.sourceMapTarget, + copyIgnored: opts.copyIgnored, }, }; } 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 0000000000..b1fb07ff86 --- /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 0000000000..e69de29bb2 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 0000000000..e69de29bb2 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 in babelrc/in-files/src/foo/.foo.js similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore/out-files/lib/foo/.foo.js rename to packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/foo/.foo.js 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 in babelrc/in-files/src/foo/index.js similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore/out-files/lib/foo/index.js rename to packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/foo/index.js 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 ignore in babelrc/in-files/src/index.js similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with only/out-files/lib/index.js rename to packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with ignore in babelrc/in-files/src/index.js 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 0000000000..bb94e945f8 --- /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 0000000000..e69de29bb2 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 0000000000..e69de29bb2 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 0000000000..1073b618d0 --- /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 0000000000..84a430432e --- /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. 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 0000000000..8b4ba6ce4d --- /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 0000000000..e69de29bb2 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 0000000000..e69de29bb2 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 and copyIgnored in babelignore/in-files/src/foo/bar.js similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files with ignore/out-files/lib/foo/bar.js rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/in-files/src/foo/bar.js 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 ignore and copyIgnored in babelignore/in-files/src/index.js similarity index 100% rename from packages/babel-cli/test/fixtures/babel/--copy-files with only/out-files/lib/index.js rename to packages/babel-cli/test/fixtures/babel/--copy-files with ignore and copyIgnored in babelignore/in-files/src/index.js 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 0000000000..d16d70e6ff --- /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 0000000000..e69de29bb2 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 0000000000..e46160df1c --- /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 0000000000..1073b618d0 --- /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 0000000000..84a430432e --- /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 0000000000..b1fb07ff86 --- /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 0000000000..e69de29bb2 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 0000000000..e69de29bb2 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 0000000000..e46160df1c --- /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 0000000000..c6788558ed --- /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 0000000000..d16d70e6ff --- /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 0000000000..e69de29bb2 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 0000000000..e46160df1c --- /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 0000000000..1073b618d0 --- /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 0000000000..84a430432e --- /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 0000000000..8b4ba6ce4d --- /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 0000000000..e69de29bb2 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 0000000000..e69de29bb2 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 0000000000..e46160df1c --- /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 0000000000..c6788558ed --- /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 0000000000..39e3d0dc26 --- /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 0000000000..e69de29bb2 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 0000000000..1073b618d0 --- /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 0000000000..84a430432e --- /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 0000000000..b1fb07ff86 --- /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 0000000000..e69de29bb2 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 0000000000..e69de29bb2 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 0000000000..e46160df1c --- /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 0000000000..c6788558ed --- /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 0000000000..39e3d0dc26 --- /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 0000000000..e69de29bb2 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 0000000000..1073b618d0 --- /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 0000000000..84a430432e --- /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 ignore with copyIgnored/in-files/src/.foorc b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/in-files/src/.foorc new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/in-files/src/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/in-files/src/README.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/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 new file mode 100644 index 0000000000..e46160df1c --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/in-files/src/foo/bar.js @@ -0,0 +1 @@ +bar; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/in-files/src/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/in-files/src/index.js new file mode 100644 index 0000000000..c6788558ed --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/in-files/src/index.js @@ -0,0 +1 @@ +index; 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 new file mode 100644 index 0000000000..f49a79c08f --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/options.json @@ -0,0 +1,12 @@ +{ + "args": [ + "src", + "--out-dir", + "lib", + "--copy-files", + "--ignore", + "src/foo", + "--copy-ignored", + "--verbose" + ] +} diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/out-files/lib/README.md b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/out-files/lib/README.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/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 new file mode 100644 index 0000000000..e46160df1c --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/out-files/lib/foo/bar.js @@ -0,0 +1 @@ +bar; diff --git a/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/out-files/lib/index.js b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/out-files/lib/index.js new file mode 100644 index 0000000000..cb5e86b12e --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/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 copyIgnored/stdout.txt b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/stdout.txt new file mode 100644 index 0000000000..84a430432e --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/--copy-files with ignore with copyIgnored/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 0000000000..e69de29bb2 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 0000000000..e69de29bb2 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 0000000000..e46160df1c --- /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 0000000000..c6788558ed --- /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 0000000000..f3adb3c91b --- /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 0000000000..e69de29bb2 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 0000000000..0ed075a193 --- /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 0000000000..c6788558ed --- /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 0000000000..673dafc748 --- /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 88d5967401..e7ee2cbb6f 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);