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): {
|
||||
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);
|
||||
|
|
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…
Reference in a new issue