diff --git a/vike/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.ts b/vike/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.ts index f1d8cd7f821..f1c20ebb839 100644 --- a/vike/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.ts +++ b/vike/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.ts @@ -375,6 +375,7 @@ async function loadVikeConfig(userRootDir: string, outDirRoot: string, isDev: bo importedFilesLoaded ) + // interfaceFilesByLocationId => pageConfigs const pageConfigs: PageConfigBuildTime[] = await Promise.all( objectEntries(interfaceFilesByLocationId) .filter(([_pageId, interfaceFiles]) => isDefiningPage(interfaceFiles)) @@ -388,8 +389,7 @@ async function loadVikeConfig(userRootDir: string, outDirRoot: string, isDev: bo getInterfaceFileList(interfaceFilesRelevant).map(async (interfaceFile) => { if (!interfaceFile.isValueFile) return const { configName } = interfaceFile - const configValue = interfaceFile.fileExportsByConfigName[configName]?.configValue - if (isGlobalConfig(configName, configValue)) return + if (isGlobalConfig_interfaceFile(configName, interfaceFile)) return const configDef = getConfigDefinition( configDefinitions, configName, @@ -406,19 +406,18 @@ async function loadVikeConfig(userRootDir: string, outDirRoot: string, isDev: bo let configValueSources: ConfigValueSources = {} await Promise.all( - objectEntries(configDefinitions) - .filter(([configName]) => !isGlobalConfig(configName)) - .map(async ([configName, configDef]) => { - const sources = await resolveConfigValueSources( - configName, - configDef, - interfaceFilesRelevant, - userRootDir, - importedFilesLoaded - ) - if (sources.length === 0) return - configValueSources[configName] = sources - }) + objectEntries(configDefinitions).map(async ([configName, configDef]) => { + const sources = await resolveConfigValueSources( + configName, + configDef, + interfaceFilesRelevant, + userRootDir, + importedFilesLoaded, + true + ) + if (sources.length === 0) return + configValueSources[configName] = sources + }) ) configValueSources = sortConfigValueSources(configValueSources, locationId) @@ -553,7 +552,8 @@ async function getGlobalConfigs( configDef, interfaceFilesGlobal, userRootDir, - importedFilesLoaded + importedFilesLoaded, + false ) const configValueSource = sources[0] if (!configValueSource) return @@ -575,14 +575,17 @@ async function resolveConfigValueSources( configDef: ConfigDefinitionInternal, interfaceFilesRelevant: InterfaceFilesByLocationId, userRootDir: string, - importedFilesLoaded: ImportedFilesLoaded + importedFilesLoaded: ImportedFilesLoaded, + isForGlobalConfig: boolean ): Promise { const sourcesInfo: Parameters[] = [] // interfaceFilesRelevant is sorted by sortAfterInheritanceOrder() for (const interfaceFiles of Object.values(interfaceFilesRelevant)) { const interfaceFilesDefiningConfig = interfaceFiles.filter( - (interfaceFile) => interfaceFile.fileExportsByConfigName[configName] + (interfaceFile) => + interfaceFile.fileExportsByConfigName[configName] && + (isForGlobalConfig || !isGlobalConfig_interfaceFile(configName, interfaceFile)) ) if (interfaceFilesDefiningConfig.length === 0) continue const visited = new WeakSet() @@ -1320,6 +1323,13 @@ function isGlobalConfig(configName: string, configValue: undefined | unknown): c const configNamesGlobal = getConfigNamesGlobal() return arrayIncludes(configNamesGlobal, configName) } +function isGlobalConfig_interfaceFile( + configName: string, + interfaceFile: InterfaceFile +): configName is ConfigNameGlobal { + const configValue = interfaceFile.fileExportsByConfigName[configName]?.configValue + return isGlobalConfig(configName, configValue) +} function getConfigNamesGlobal() { return Object.keys(configDefinitionsBuiltInGlobal) } diff --git a/vike/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.ts b/vike/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.ts index 62d6412932a..ef21665cb85 100644 --- a/vike/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.ts +++ b/vike/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.ts @@ -70,7 +70,7 @@ async function loadVikeConfigFile() { const found = findVikeConfigFile(process.cwd()) if (!found) return null const { vikeConfigFilePath, userRootDir } = found - const { fileExports } = await transpileAndExecuteFile(vikeConfigFilePath, true, userRootDir) + const { fileExports } = await transpileAndExecuteFile(vikeConfigFilePath, userRootDir, true) return { fileExports } } function findVikeConfigFile(cwd: string): { vikeConfigFilePath: FilePathResolved; userRootDir: string } | null {