From 564ca6638f2ef278c78dde72d208fa68eeb38836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Tue, 23 Mar 2021 20:11:10 +0100 Subject: [PATCH] Set `rootMode: "root"` in `loadPartialConfig` (#13040) --- packages/babel-core/src/config/partial.js | 1 + packages/babel-core/test/config-chain.js | 1 + packages/babel-core/test/config-loading.js | 19 +++++++++++++++++++ .../config-loading/root/babel.config.json | 1 + 4 files changed, 22 insertions(+) create mode 100644 packages/babel-core/test/fixtures/config-loading/root/babel.config.json diff --git a/packages/babel-core/src/config/partial.js b/packages/babel-core/src/config/partial.js index 5d74daa00e..dc0a0e0229 100644 --- a/packages/babel-core/src/config/partial.js +++ b/packages/babel-core/src/config/partial.js @@ -139,6 +139,7 @@ export default function* loadPrivatePartialConfig( envName: context.envName, cwd: context.cwd, root: context.root, + rootMode: "root", filename: typeof context.filename === "string" ? context.filename : undefined, diff --git a/packages/babel-core/test/config-chain.js b/packages/babel-core/test/config-chain.js index 7e345fd013..68c204603b 100644 --- a/packages/babel-core/test/config-chain.js +++ b/packages/babel-core/test/config-chain.js @@ -982,6 +982,7 @@ describe("buildConfigChain", function () { browserslistConfigFile: false, cwd: process.cwd(), root: process.cwd(), + rootMode: "root", envName: "development", passPerPreset: false, plugins: [], diff --git a/packages/babel-core/test/config-loading.js b/packages/babel-core/test/config-loading.js index da84e590d4..dcdf0ceb64 100644 --- a/packages/babel-core/test/config-loading.js +++ b/packages/babel-core/test/config-loading.js @@ -118,6 +118,25 @@ describe("@babel/core config loading", () => { expect(item.value).toBe(preset); expect(item.options).toBe(false); }); + + it("should always set 'rootMode' to 'root'", async () => { + const cwd = path.join( + path.dirname(fileURLToPath(import.meta.url)), + "fixtures", + "config-loading", + "root", + "nested", + ); + + const { options } = await loadPartialConfig({ + cwd, + filename: path.join(cwd, "file.js"), + rootMode: "upward", + }); + + expect(options.root).toBe(path.join(cwd, "..")); + expect(options.rootMode).toBe("root"); + }); }); describe("config file", () => { diff --git a/packages/babel-core/test/fixtures/config-loading/root/babel.config.json b/packages/babel-core/test/fixtures/config-loading/root/babel.config.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/babel-core/test/fixtures/config-loading/root/babel.config.json @@ -0,0 +1 @@ +{}