Skip to content

Commit 3b8ce29

Browse files
authored
fix(project): Allow Component.ts (#1243)
Fixes #1242. This allows the use of TS for Component files.
1 parent d0976b0 commit 3b8ce29

File tree

10 files changed

+96
-7
lines changed

10 files changed

+96
-7
lines changed

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

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

293293
async _ensureComponent() {
294-
// Ensure that a Component.js exists
295-
const componentResource = await this._getRawSourceReader().byPath("/Component.js");
294+
// Throw if neither Component.js nor Component.ts is present
295+
const componentResource = await this._getRawSourceReader().byPath("/Component.js") ||
296+
await this._getRawSourceReader().byPath("/Component.ts");
296297
if (!componentResource) {
297298
throw new Error(
298-
`Unable to find required file Component.js in component project ${this.getName()}`);
299+
`Unable to find either required "Component.js" or "Component.ts"` +
300+
` in component project ${this.getName()}`
301+
);
299302
}
300303
}
301304
}

packages/project/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"version": "git-chglog --sort semver --next-tag v$npm_package_version -o CHANGELOG.md v4.0.0.. && git add CHANGELOG.md",
4949
"prepublishOnly": "git push --follow-tags",
5050
"release-note": "git-chglog --sort semver -c .chglog/release-config.yml v$npm_package_version",
51-
"depcheck": "depcheck --ignores @ui5/project,@istanbuljs/esm-loader-hook,rimraf"
51+
"depcheck": "depcheck --ignores @ui5/project,@istanbuljs/esm-loader-hook,rimraf,sap"
5252
},
5353
"files": [
5454
"CHANGELOG.md",
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+
}
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: 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+
}
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: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,11 +678,28 @@ test("namespace: detect namespace from pom.xml via ${appId} from properties", as
678678
" couldn't be resolved from maven property \"appId\" of pom.xml of project component.h");
679679
});
680680

681-
test("Throw for missing Component.js", async (t) => {
681+
test("Throw when neither Component.js nor Component.ts exists", async (t) => {
682682
const {componentHInput} = t.context;
683683
componentHInput.configuration.resources.configuration.paths.src = "src-no-component";
684-
685684
const error = await t.throwsAsync(Specification.create(componentHInput));
686685
t.is(error.message,
687-
"Unable to find required file Component.js in component project component.h");
686+
"Unable to find either required \"Component.js\" or \"Component.ts\" in component project component.h");
687+
});
688+
689+
test("Do not throw when Component.js exists", async (t) => {
690+
const {componentHInput} = t.context;
691+
componentHInput.configuration.resources.configuration.paths.src = "src-with-component-js";
692+
await t.notThrowsAsync(Specification.create(componentHInput), "Should not throw an error");
693+
});
694+
695+
test("Do not throw when Component.ts exists", async (t) => {
696+
const {componentHInput} = t.context;
697+
componentHInput.configuration.resources.configuration.paths.src = "src-with-component-ts";
698+
await t.notThrowsAsync(Specification.create(componentHInput), "Should not throw an error");
699+
});
700+
701+
test("Do not 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+
await t.notThrowsAsync(Specification.create(componentHInput), "Should not throw an error");
688705
});

0 commit comments

Comments
 (0)