Skip to content

Commit 9478c4b

Browse files
authored
refactor(builder): generateFlexChangesBundle should not rely on existing manifest.json (#1218)
When running the `generateFlexChangesBundle` task, `manifest.json` might not be present. Follow-up of #1165
1 parent 9f13b7c commit 9478c4b

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

packages/builder/lib/tasks/bundlers/generateFlexChangesBundle.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ export default async function({workspace, taskUtil, options = {}}) {
6363

6464
async function updateManifestWithFlDependencyAndFlexBundleFlag(bBundleCreated) {
6565
const manifestResource = await workspace.byPath(`${pathPrefix}/manifest.json`);
66+
if (!manifestResource) {
67+
log.verbose("No manifest.json found, skipping update of sap.ui.fl dependency and flexBundle flag");
68+
return;
69+
}
6670
const manifestContent = JSON.parse(await manifestResource.getString());
6771

6872
updateJson(manifestContent, bBundleCreated);
@@ -73,6 +77,10 @@ export default async function({workspace, taskUtil, options = {}}) {
7377

7478
async function readManifestMinUI5Version() {
7579
const manifestResource = await workspace.byPath(`${pathPrefix}/manifest.json`);
80+
if (!manifestResource) {
81+
log.verbose("No manifest.json found, cannot read minUI5Version");
82+
return [];
83+
}
7684
const manifestContent = JSON.parse(await manifestResource.getString());
7785

7886
manifestContent["sap.ui5"] = manifestContent["sap.ui5"] || {};

packages/builder/test/lib/tasks/bundlers/generateFlexChangesBundle.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,3 +579,74 @@ test("flexBundle property overrides existing value when bundle is created", asyn
579579
t.true(manifestContent["sap.ui5"].flexBundle, "flexBundle should be overridden to true when bundle is created");
580580
t.deepEqual(manifestContent["sap.ui5"].dependencies.libs["sap.ui.fl"], {}, "sap.ui.fl dependency should be added");
581581
});
582+
583+
test("task does not fail when manifest.json is missing and no changes exist", async (t) => {
584+
const placeholderWorkspace = {
585+
byGlob: async () => [], // No changes
586+
byPath: async (path) => {
587+
// Return null for all paths (no manifest.json, no flexibility-bundle.json)
588+
return null;
589+
},
590+
write: sinon.stub().returnsArg(0)
591+
};
592+
593+
// This should not throw an error
594+
await t.notThrowsAsync(async () => {
595+
await generateFlexChangesBundle({
596+
workspace: placeholderWorkspace,
597+
taskUtil: false,
598+
options: {
599+
projectNamespace: "sap/ui/demo/app"
600+
}
601+
});
602+
}, "Task should not fail when manifest.json is missing");
603+
604+
// No write calls should have been made since there's no manifest and no changes
605+
t.is(placeholderWorkspace.write.callCount, 0, "workspace.write should not be called when manifest is missing");
606+
});
607+
608+
test("task does not fail when manifest.json is missing but changes exist", async (t) => {
609+
const changeList = [{
610+
"fileName": "test_change",
611+
"fileType": "change",
612+
"changeType": "rename",
613+
"reference": "test.Component",
614+
"content": {},
615+
"selector": {"id": "testId"},
616+
"layer": "CUSTOMER"
617+
}];
618+
619+
const placeholderWorkspace = {
620+
byGlob: async () => changeList.map((change) => createPlaceholderResource(change)),
621+
byPath: async (path) => {
622+
// Return null for all paths (no manifest.json, no flexibility-bundle.json)
623+
return null;
624+
},
625+
write: sinon.stub().returnsArg(0)
626+
};
627+
628+
// This should not throw an error
629+
await t.notThrowsAsync(async () => {
630+
await generateFlexChangesBundle({
631+
workspace: placeholderWorkspace,
632+
taskUtil: false,
633+
options: {
634+
projectNamespace: "sap/ui/demo/app"
635+
}
636+
});
637+
}, "Task should not fail when manifest.json is missing even with changes");
638+
639+
// Verify the task created the flexibility-bundle.json
640+
const writeCalls = [];
641+
for (let i = 0; i < placeholderWorkspace.write.callCount; i++) {
642+
const call = placeholderWorkspace.write.getCall(i);
643+
const path = call.args[0].getPath ? await call.args[0].getPath() : "unknown";
644+
writeCalls.push(path);
645+
}
646+
647+
// Should have written flexibility-bundle.json but NOT manifest.json
648+
t.true(writeCalls.some((path) => path.includes("flexibility-bundle.json")),
649+
"flexibility-bundle.json should be created");
650+
t.false(writeCalls.some((path) => path.includes("manifest.json")),
651+
"No manifest.json write should occur when manifest is missing");
652+
});

0 commit comments

Comments
 (0)