Add --keep-file-extension option to babel-cli (#6221)
* Add --keep-module-extension option to babel-cli * Rename keep-module-extension option to keep-file-extension; Change option to preserve all file extensions
This commit is contained in:
parent
4daf11528c
commit
8742012b5e
@ -13,7 +13,7 @@ export default function(commander, filenames, opts) {
|
||||
}
|
||||
|
||||
// remove extension and then append back on .js
|
||||
relative = relative.replace(/\.(\w*?)$/, "") + ".js";
|
||||
relative = util.adjustRelative(relative, commander.keepFileExtension);
|
||||
|
||||
const dest = getDest(commander, relative, base);
|
||||
|
||||
|
||||
@ -129,6 +129,10 @@ commander.option(
|
||||
"List of extensions to compile when a directory has been input [.es6,.js,.es,.jsx,.mjs]",
|
||||
collect,
|
||||
);
|
||||
commander.option(
|
||||
"--keep-file-extension",
|
||||
"Preserve the file extensions of the input files",
|
||||
);
|
||||
commander.option("-w, --watch", "Recompile files on changes");
|
||||
commander.option(
|
||||
"--skip-initial-build",
|
||||
@ -232,6 +236,7 @@ delete opts.copyFiles;
|
||||
delete opts.quiet;
|
||||
delete opts.configFile;
|
||||
delete opts.deleteDirOnStart;
|
||||
delete opts.keepFileExtension;
|
||||
|
||||
// Commander will default the "--no-" arguments to true, but we want to leave them undefined so that
|
||||
// babel-core can handle the default-assignment logic on its own.
|
||||
|
||||
@ -98,3 +98,10 @@ export function requireChokidar() {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
export function adjustRelative(relative, keepFileExtension) {
|
||||
if (keepFileExtension) {
|
||||
return relative;
|
||||
}
|
||||
return relative.replace(/\.(\w*?)$/, "") + ".js";
|
||||
}
|
||||
|
||||
@ -0,0 +1 @@
|
||||
arr.map(x => x / DIVIDER);
|
||||
@ -0,0 +1 @@
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
3
packages/babel-cli/test/fixtures/babel/dir --out-dir --keep-file-extension/options.json
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/dir --out-dir --keep-file-extension/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["src", "--out-dir", "lib", "--keep-file-extension"]
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
arr.map(function (x) {
|
||||
return x / DIVIDER;
|
||||
});
|
||||
@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
arr.map(function (x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
2
packages/babel-cli/test/fixtures/babel/dir --out-dir --keep-file-extension/stdout.txt
vendored
Normal file
2
packages/babel-cli/test/fixtures/babel/dir --out-dir --keep-file-extension/stdout.txt
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
src/bar.mjs -> lib/bar.mjs
|
||||
src/foo.js -> lib/foo.js
|
||||
Loading…
x
Reference in New Issue
Block a user