in src/core/utils/user-config.ts [42:96]
export async function findSWAConfigFile(folder: string): Promise<{ filepath: string; content: SWAConfigFile } | null> {
const configFiles = new Map<string, { filepath: string; isLegacyConfigFile: boolean }>();
for await (const filepath of traverseFolder(folder)) {
const filename = path.basename(filepath) as string;
if (filename === SWA_CONFIG_FILENAME || filename === SWA_CONFIG_FILENAME_LEGACY) {
const isLegacyConfigFile = filename === SWA_CONFIG_FILENAME_LEGACY;
configFiles.set(filename, { filepath, isLegacyConfigFile });
}
}
// take staticwebapp.config.json if it exists
if (configFiles.has(SWA_CONFIG_FILENAME)) {
const file = configFiles.get(SWA_CONFIG_FILENAME);
if (file) {
const config = await loadJSON(file.filepath!);
if (config) {
const content = await validateConfigFile(config);
if (content) {
const fileSize = (await fs.stat(file.filepath)).size;
const fileSizeInKb = Math.round(fileSize / 1024);
if (fileSizeInKb > SWA_RUNTIME_CONFIG_MAX_SIZE_IN_KB) {
logger.warn(`WARNING: ${SWA_CONFIG_FILENAME} is ${fileSizeInKb} bytes. The maximum size is ${SWA_RUNTIME_CONFIG_MAX_SIZE_IN_KB} bytes.`);
}
logger.silly(`Content parsed successfully`);
logger.log(`\nFound configuration file:\n ${chalk.green(file.filepath)}\n`);
return {
filepath: file.filepath,
content,
};
}
}
}
return null;
}
// legacy config file detected. Warn and return null.
if (configFiles.has(SWA_CONFIG_FILENAME_LEGACY)) {
const file = configFiles.get(SWA_CONFIG_FILENAME_LEGACY);
logger.warn(`Found legacy configuration file: ${file?.filepath}.`);
logger.warn(
` WARNING: Functionality defined in the routes.json file is now deprecated. File will be ignored!\n` +
` Read more: https://docs.microsoft.com/azure/static-web-apps/configuration#routes`
);
return null;
}
// no config file found
logger.silly(`No ${SWA_CONFIG_FILENAME} found in current project`);
return null;
}