summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/quick-eagles-impress.md5
-rw-r--r--packages/astro/src/core/config/config.ts15
-rw-r--r--packages/astro/test/units/config/config-resolve.test.js18
3 files changed, 38 insertions, 0 deletions
diff --git a/.changeset/quick-eagles-impress.md b/.changeset/quick-eagles-impress.md
new file mode 100644
index 000000000..8729df039
--- /dev/null
+++ b/.changeset/quick-eagles-impress.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fix inline root resolve logic
diff --git a/packages/astro/src/core/config/config.ts b/packages/astro/src/core/config/config.ts
index 0872145db..29b0bb23a 100644
--- a/packages/astro/src/core/config/config.ts
+++ b/packages/astro/src/core/config/config.ts
@@ -211,6 +211,10 @@ async function loadConfig(
}
}
+/**
+ * `AstroInlineConfig` is a union of `AstroUserConfig` and `AstroInlineOnlyConfig`.
+ * This functions splits it up.
+ */
function splitInlineConfig(inlineConfig: AstroInlineConfig): {
inlineUserConfig: AstroUserConfig;
inlineOnlyConfig: AstroInlineOnlyConfig;
@@ -231,6 +235,12 @@ interface ResolveConfigResult {
astroConfig: AstroConfig;
}
+/**
+ * Resolves the Astro config with a given inline config.
+ *
+ * @param inlineConfig An inline config that takes highest priority when merging and resolving the final config.
+ * @param command The running command that uses this config. Usually 'dev' or 'build'.
+ */
export async function resolveConfig(
inlineConfig: AstroInlineConfig,
command: string,
@@ -239,6 +249,11 @@ export async function resolveConfig(
const root = resolveRoot(inlineConfig.root);
const { inlineUserConfig, inlineOnlyConfig } = splitInlineConfig(inlineConfig);
+ // If the root is specified, assign the resolved path so it takes the highest priority
+ if (inlineConfig.root) {
+ inlineUserConfig.root = root;
+ }
+
const userConfig = await loadConfig(root, inlineOnlyConfig.configFile, fsMod);
const mergedConfig = mergeConfig(userConfig, inlineUserConfig);
const astroConfig = await validateConfig(mergedConfig, root, command);
diff --git a/packages/astro/test/units/config/config-resolve.test.js b/packages/astro/test/units/config/config-resolve.test.js
new file mode 100644
index 000000000..c3c19da64
--- /dev/null
+++ b/packages/astro/test/units/config/config-resolve.test.js
@@ -0,0 +1,18 @@
+import { expect } from 'chai';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { resolveConfig } from '../../../dist/core/config/index.js';
+
+describe('resolveConfig', () => {
+ it('resolves relative inline root correctly', async () => {
+ const { astroConfig } = await resolveConfig(
+ {
+ configFile: false,
+ root: 'relative/path',
+ },
+ 'dev'
+ );
+ const expectedRoot = path.join(process.cwd(), 'relative/path/');
+ expect(fileURLToPath(astroConfig.root)).to.equal(expectedRoot);
+ });
+});