Skip to content

Commit da6c909

Browse files
committed
refactor: Throw if both Component.js & Component.js exist at the same time
1 parent 85f7366 commit da6c909

5 files changed

Lines changed: 47 additions & 4 deletions

File tree

packages/project/lib/specifications/types/Component.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,17 @@ class Component extends ComponentProject {
291291
}
292292

293293
async _ensureComponent() {
294-
// Ensure that a Component.js/ts exists
295-
const componentResource = await this._getRawSourceReader().byPath("/Component.js") ||
296-
await this._getRawSourceReader().byPath("/Component.ts");
297-
if (!componentResource) {
294+
// Throw if neither Component.js nor Component.ts is present
295+
// or if both are present
296+
const componentJSResource = await this._getRawSourceReader().byPath("/Component.js");
297+
const componentTSResource = await this._getRawSourceReader().byPath("/Component.ts");
298+
if (componentJSResource && componentTSResource) {
299+
throw new Error(
300+
`Both "Component.js" and "Component.ts" found` +
301+
` in component project ${this.getName()}`
302+
);
303+
}
304+
if (!componentJSResource && !componentTSResource) {
298305
throw new Error(
299306
`Unable to find either required "Component.js" or "Component.ts"` +
300307
` in component project ${this.getName()}`
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){
2+
"use strict";
3+
return UIComponent.extend('application.h.Component', {
4+
metadata: {
5+
manifest: "json"
6+
}
7+
});
8+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import UIComponent from "sap/ui/core/UIComponent";
2+
3+
export default class Component extends UIComponent {
4+
public static metadata = {
5+
"manifest": "json"
6+
};
7+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"_version": "1.1.0",
3+
"sap.app": {
4+
"_version": "1.1.0",
5+
"id": "${componentName}",
6+
"type": "application",
7+
"applicationVersion": {
8+
"version": "1.2.2"
9+
},
10+
"embeds": ["embedded"],
11+
"title": "{{title}}"
12+
}
13+
}

packages/project/test/lib/specifications/types/Component.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,3 +697,11 @@ test("Do not throw when Component.ts exists", async (t) => {
697697
componentHInput.configuration.resources.configuration.paths.src = "src-with-component-ts";
698698
await t.notThrowsAsync(Specification.create(componentHInput), "Should not throw an error");
699699
});
700+
701+
test("Throw when both Component.js and Component.ts exist", async (t) => {
702+
const {componentHInput} = t.context;
703+
componentHInput.configuration.resources.configuration.paths.src = "src-with-component-js-and-component-ts";
704+
const error = await t.throwsAsync(Specification.create(componentHInput));
705+
t.is(error.message,
706+
"Both \"Component.js\" and \"Component.ts\" found in component project component.h");
707+
});

0 commit comments

Comments
 (0)