Resolve babel.config.js 'babelrcRoots' values relative to the config file. (#8910)
This commit is contained in:
parent
1d4d760ffc
commit
c6d2f45cab
@ -155,6 +155,7 @@ export function buildRootChain(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let { babelrc, babelrcRoots } = opts;
|
let { babelrc, babelrcRoots } = opts;
|
||||||
|
let babelrcRootsDirectory = context.cwd;
|
||||||
|
|
||||||
const configFileChain = emptyChain();
|
const configFileChain = emptyChain();
|
||||||
if (configFile) {
|
if (configFile) {
|
||||||
@ -168,6 +169,7 @@ export function buildRootChain(
|
|||||||
babelrc = validatedFile.options.babelrc;
|
babelrc = validatedFile.options.babelrc;
|
||||||
}
|
}
|
||||||
if (babelrcRoots === undefined) {
|
if (babelrcRoots === undefined) {
|
||||||
|
babelrcRootsDirectory = validatedFile.dirname;
|
||||||
babelrcRoots = validatedFile.options.babelrcRoots;
|
babelrcRoots = validatedFile.options.babelrcRoots;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +187,7 @@ export function buildRootChain(
|
|||||||
if (
|
if (
|
||||||
(babelrc === true || babelrc === undefined) &&
|
(babelrc === true || babelrc === undefined) &&
|
||||||
pkgData &&
|
pkgData &&
|
||||||
babelrcLoadEnabled(context, pkgData, babelrcRoots)
|
babelrcLoadEnabled(context, pkgData, babelrcRoots, babelrcRootsDirectory)
|
||||||
) {
|
) {
|
||||||
({ ignore: ignoreFile, config: babelrcFile } = findRelativeConfig(
|
({ ignore: ignoreFile, config: babelrcFile } = findRelativeConfig(
|
||||||
pkgData,
|
pkgData,
|
||||||
@ -229,6 +231,7 @@ function babelrcLoadEnabled(
|
|||||||
context: ConfigContext,
|
context: ConfigContext,
|
||||||
pkgData: FilePackageData,
|
pkgData: FilePackageData,
|
||||||
babelrcRoots: BabelrcSearch | void,
|
babelrcRoots: BabelrcSearch | void,
|
||||||
|
babelrcRootsDirectory: string,
|
||||||
): boolean {
|
): boolean {
|
||||||
if (typeof babelrcRoots === "boolean") return babelrcRoots;
|
if (typeof babelrcRoots === "boolean") return babelrcRoots;
|
||||||
|
|
||||||
@ -243,7 +246,9 @@ function babelrcLoadEnabled(
|
|||||||
let babelrcPatterns = babelrcRoots;
|
let babelrcPatterns = babelrcRoots;
|
||||||
if (!Array.isArray(babelrcPatterns)) babelrcPatterns = [babelrcPatterns];
|
if (!Array.isArray(babelrcPatterns)) babelrcPatterns = [babelrcPatterns];
|
||||||
babelrcPatterns = babelrcPatterns.map(pat => {
|
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
|
// Fast path to avoid having to match patterns if the babelrc is just
|
||||||
@ -253,10 +258,12 @@ function babelrcLoadEnabled(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return babelrcPatterns.some(pat => {
|
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 pkgData.directories.some(directory => {
|
||||||
return matchPattern(pat, context.cwd, directory, context);
|
return matchPattern(pat, babelrcRootsDirectory, directory, context);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user