Skip to content

Commit

Permalink
Resolve babel.config.js 'babelrcRoots' values relative to the config …
Browse files Browse the repository at this point in the history
…file. (#8910)
  • Loading branch information
loganfsmyth committed Nov 5, 2018
1 parent 1d4d760 commit c6d2f45
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/babel-core/src/config/config-chain.js
Expand Up @@ -155,6 +155,7 @@ export function buildRootChain(
}

let { babelrc, babelrcRoots } = opts;
let babelrcRootsDirectory = context.cwd;

const configFileChain = emptyChain();
if (configFile) {
Expand All @@ -168,6 +169,7 @@ export function buildRootChain(
babelrc = validatedFile.options.babelrc;
}
if (babelrcRoots === undefined) {
babelrcRootsDirectory = validatedFile.dirname;
babelrcRoots = validatedFile.options.babelrcRoots;
}

Expand All @@ -185,7 +187,7 @@ export function buildRootChain(
if (
(babelrc === true || babelrc === undefined) &&
pkgData &&
babelrcLoadEnabled(context, pkgData, babelrcRoots)
babelrcLoadEnabled(context, pkgData, babelrcRoots, babelrcRootsDirectory)
) {
({ ignore: ignoreFile, config: babelrcFile } = findRelativeConfig(
pkgData,
Expand Down Expand Up @@ -229,6 +231,7 @@ function babelrcLoadEnabled(
context: ConfigContext,
pkgData: FilePackageData,
babelrcRoots: BabelrcSearch | void,
babelrcRootsDirectory: string,
): boolean {
if (typeof babelrcRoots === "boolean") return babelrcRoots;

Expand All @@ -243,7 +246,9 @@ function babelrcLoadEnabled(
let babelrcPatterns = babelrcRoots;
if (!Array.isArray(babelrcPatterns)) babelrcPatterns = [babelrcPatterns];
babelrcPatterns = babelrcPatterns.map(pat => {
return typeof pat === "string" ? path.resolve(context.cwd, pat) : pat;
return typeof pat === "string"
? path.resolve(babelrcRootsDirectory, pat)
: pat;
});

// Fast path to avoid having to match patterns if the babelrc is just
Expand All @@ -253,10 +258,12 @@ function babelrcLoadEnabled(
}

return babelrcPatterns.some(pat => {
if (typeof pat === "string") pat = pathPatternToRegex(pat, context.cwd);
if (typeof pat === "string") {
pat = pathPatternToRegex(pat, babelrcRootsDirectory);
}

return pkgData.directories.some(directory => {
return matchPattern(pat, context.cwd, directory, context);
return matchPattern(pat, babelrcRootsDirectory, directory, context);
});
});
}
Expand Down

0 comments on commit c6d2f45

Please sign in to comment.