Merge pull request #11083 from backstage/freben/empty-config
handle empty config files gracefully
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/config-loader': patch
|
||||
---
|
||||
|
||||
Handle empty config files gracefully
|
||||
@@ -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 => {
|
||||
|
||||
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user