Skip to content

Commit

Permalink
Normalize file paths windows->unix
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Sep 9, 2019
1 parent 24ee72d commit 43f6795
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions packages/babel-core/src/transformation/normalize-opts.js
Expand Up @@ -3,21 +3,48 @@
import path from "path";
import type { ResolvedConfig } from "../config";

function normalizePath(filepath: string) {
return filepath && filepath.replace(/\\/g, "/");
}

function pickMap(obj, keys, fn) {
const res = {};
for (const k of keys) res[k] = fn(obj[k]);
return res;
}

export default function normalizeOptions(config: ResolvedConfig): {} {
const normalizedPaths = pickMap(
config.options,
[
"filename",
"cwd",
"filenameRelative",
"moduleRoot",
"sourceRoot",
"sourceFileName",
],
normalizePath,
);

const {
filename,
cwd,

filenameRelative = typeof filename === "string"
? path.relative(cwd, filename)
? path.posix.relative(cwd, filename)
: "unknown",
sourceType = "module",
inputSourceMap,
sourceMaps = !!inputSourceMap,

moduleRoot,
sourceRoot = moduleRoot,

sourceFileName = path.basename(filenameRelative),
} = normalizedPaths;

const {
sourceType = "module",
inputSourceMap,
sourceMaps = !!inputSourceMap,

comments = true,
compact = "auto",
Expand All @@ -27,6 +54,7 @@ export default function normalizeOptions(config: ResolvedConfig): {} {

const options = {
...opts,
...normalizedPaths,

parserOpts: {
sourceType:
Expand All @@ -39,7 +67,7 @@ export default function normalizeOptions(config: ResolvedConfig): {} {

generatorOpts: {
// General generator flags.
filename,
filename: filename,

auxiliaryCommentBefore: opts.auxiliaryCommentBefore,
auxiliaryCommentAfter: opts.auxiliaryCommentAfter,
Expand Down

0 comments on commit 43f6795

Please sign in to comment.