@squiz/dxp-cli-next 5.33.0-develop.4 → 5.33.0-develop.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -82,7 +82,13 @@ function loadLayoutFromFile(layoutFile) {
|
|
|
82
82
|
encoding: 'utf-8',
|
|
83
83
|
});
|
|
84
84
|
try {
|
|
85
|
-
|
|
85
|
+
let layout;
|
|
86
|
+
if (fileType === 'json') {
|
|
87
|
+
// First validate with JSON.parse (enforces double quotes, valid JSON syntax)
|
|
88
|
+
layout = JSON.parse(content);
|
|
89
|
+
}
|
|
90
|
+
// Then parse with YAML to catch duplicate keys (which JSON.parse silently ignores)
|
|
91
|
+
layout = (0, yaml_1.parse)(content);
|
|
86
92
|
const fileName = path.basename(layoutFile);
|
|
87
93
|
if (fileName === exports.LAYOUT_MANIFEST_FILE) {
|
|
88
94
|
exports.InputLayoutDefinitionV2.parse(layout);
|
|
@@ -218,6 +218,32 @@ entry: template.hbs
|
|
|
218
218
|
});
|
|
219
219
|
yield expect((0, definitions_1.loadLayoutDefinition)(manifestJson)).rejects.toThrowErrorMatchingInlineSnapshot('"Failed loading layout definition: Failed to parse ./some-dir/manifest.json: Unexpected token \'\'\', ..." "name": \'test-layo"... is not valid JSON"');
|
|
220
220
|
}));
|
|
221
|
+
it('should throw an error if JSON layout file has duplicate keys', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
222
|
+
fs.readFile.mockImplementation((filePath) => {
|
|
223
|
+
if (filePath.endsWith('manifest.json')) {
|
|
224
|
+
return `{
|
|
225
|
+
"name": "test-layout",
|
|
226
|
+
"displayName": "Test Layout",
|
|
227
|
+
"entry": "template.hbs",
|
|
228
|
+
"zones": [],
|
|
229
|
+
"name": "test-layout"
|
|
230
|
+
}`;
|
|
231
|
+
}
|
|
232
|
+
if (filePath.endsWith('template.hbs')) {
|
|
233
|
+
return templateContent;
|
|
234
|
+
}
|
|
235
|
+
throw new Error('File not found');
|
|
236
|
+
});
|
|
237
|
+
yield expect((0, definitions_1.loadLayoutDefinition)(manifestJson)).rejects
|
|
238
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
239
|
+
"Failed loading layout definition: Failed to parse ./some-dir/manifest.json: Map keys must be unique at line 6, column 9:
|
|
240
|
+
|
|
241
|
+
"zones": [],
|
|
242
|
+
"name": "test-layout"
|
|
243
|
+
^
|
|
244
|
+
"
|
|
245
|
+
`);
|
|
246
|
+
}));
|
|
221
247
|
it('should throw an error if layout file do not have valid extension', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
222
248
|
yield expect((0, definitions_1.loadLayoutDefinition)('/foo/manifest.html')).rejects.toThrow('Layout file must have a valid extension: [yaml|json]');
|
|
223
249
|
}));
|