mirror of
https://github.com/withastro/astro.git
synced 2025-01-27 22:19:04 -05:00
Fix inline root resolve logic (#7977)
This commit is contained in:
parent
51028f85c6
commit
a4a637c8f7
3 changed files with 38 additions and 0 deletions
5
.changeset/quick-eagles-impress.md
Normal file
5
.changeset/quick-eagles-impress.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix inline root resolve logic
|
|
@ -211,6 +211,10 @@ async function loadConfig(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `AstroInlineConfig` is a union of `AstroUserConfig` and `AstroInlineOnlyConfig`.
|
||||||
|
* This functions splits it up.
|
||||||
|
*/
|
||||||
function splitInlineConfig(inlineConfig: AstroInlineConfig): {
|
function splitInlineConfig(inlineConfig: AstroInlineConfig): {
|
||||||
inlineUserConfig: AstroUserConfig;
|
inlineUserConfig: AstroUserConfig;
|
||||||
inlineOnlyConfig: AstroInlineOnlyConfig;
|
inlineOnlyConfig: AstroInlineOnlyConfig;
|
||||||
|
@ -231,6 +235,12 @@ interface ResolveConfigResult {
|
||||||
astroConfig: AstroConfig;
|
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(
|
export async function resolveConfig(
|
||||||
inlineConfig: AstroInlineConfig,
|
inlineConfig: AstroInlineConfig,
|
||||||
command: string,
|
command: string,
|
||||||
|
@ -239,6 +249,11 @@ export async function resolveConfig(
|
||||||
const root = resolveRoot(inlineConfig.root);
|
const root = resolveRoot(inlineConfig.root);
|
||||||
const { inlineUserConfig, inlineOnlyConfig } = splitInlineConfig(inlineConfig);
|
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 userConfig = await loadConfig(root, inlineOnlyConfig.configFile, fsMod);
|
||||||
const mergedConfig = mergeConfig(userConfig, inlineUserConfig);
|
const mergedConfig = mergeConfig(userConfig, inlineUserConfig);
|
||||||
const astroConfig = await validateConfig(mergedConfig, root, command);
|
const astroConfig = await validateConfig(mergedConfig, root, command);
|
||||||
|
|
18
packages/astro/test/units/config/config-resolve.test.js
Normal file
18
packages/astro/test/units/config/config-resolve.test.js
Normal file
|
@ -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);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue