Merge pull request #11083 from backstage/freben/empty-config

handle empty config files gracefully
This commit is contained in:
Fredrik Adelöw
2022-04-26 14:17:50 +02:00
committed by GitHub
3 changed files with 27 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/config-loader': patch
---
Handle empty config files gracefully
+12
View File
@@ -104,6 +104,7 @@ describe('loadConfig', () => {
`,
'/root/secrets/substituted.txt': '123abc',
'/root/${ESCAPE_ME}.txt': 'notSubstituted',
'/root/empty.yaml': '# just a comment',
});
});
@@ -469,6 +470,17 @@ describe('loadConfig', () => {
await new Promise(resolve => setTimeout(resolve, 1000));
});
it('handles empty files gracefully', async () => {
await expect(
loadConfig({
configRoot: '/root',
configTargets: [{ path: '/root/empty.yaml' }],
}),
).resolves.toEqual({
appConfigs: [],
});
});
function defer<T>() {
let resolve: (value: T) => void;
const promise = new Promise<T>(_resolve => {
+10 -6
View File
@@ -160,13 +160,17 @@ export async function loadConfig(
};
const input = yaml.parse(await readFile(configPath));
const substitutionTransform = createSubstitutionTransform(env);
const data = await applyConfigTransforms(dir, input, [
createIncludeTransform(env, readFile, substitutionTransform),
substitutionTransform,
]);
fileConfigs.push({ data, context: basename(configPath) });
// A completely empty file ends up as a null return value
if (input !== null) {
const substitutionTransform = createSubstitutionTransform(env);
const data = await applyConfigTransforms(dir, input, [
createIncludeTransform(env, readFile, substitutionTransform),
substitutionTransform,
]);
fileConfigs.push({ data, context: basename(configPath) });
}
}
return { fileConfigs, loadedPaths };