Allow empty qlpack files

This commit is contained in:
Koen Vlaswinkel
2024-01-02 16:58:56 +01:00
parent e5ffdd0fbc
commit ed4b296e41

View File

@@ -8,7 +8,15 @@ const ajv = new Ajv({ allErrors: true });
const qlpackFileValidate = ajv.compile(qlpackFileSchemaJson);
export async function loadQlpackFile(path: string): Promise<QlPackFile> {
const qlPack = load(await readFile(path, "utf8")) as QlPackFile | undefined;
const qlpackFileText = await readFile(path, "utf8");
let qlPack = load(qlpackFileText) as QlPackFile | undefined;
if (qlPack === undefined || qlPack === null) {
// An empty file is not valid according to the schema since it's not an object,
// but it is equivalent to an empty object.
qlPack = {};
}
qlpackFileValidate(qlPack);
@@ -20,9 +28,5 @@ export async function loadQlpackFile(path: string): Promise<QlPackFile> {
);
}
if (!qlPack) {
throw new Error(`Could not parse ${path}`);
}
return qlPack;
}