Skip to content

Commit 18bef62

Browse files
committed
[INTERNAL] projectPreprocessor: Add _isRoot flag to root project
Alternative to (_level === 0) checks.
1 parent eb961c3 commit 18bef62

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

lib/projectPreprocessor.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class ProjectPreprocessor {
6161

6262
await Promise.all(projectsToProcess.map(async (project) => {
6363
project._level = level;
64+
if (level === 0) {
65+
project._isRoot = true;
66+
}
6467
log.verbose(`Processing project ${project.id} on level ${project._level}...`);
6568

6669
if (project.dependencies && project.dependencies.length) {
@@ -266,7 +269,7 @@ class ProjectPreprocessor {
266269

267270
isConfigValid(project) {
268271
if (!project.specVersion) {
269-
if (project._level === 0) {
272+
if (project._isRoot) {
270273
throw new Error(`No specification version defined for root project ${project.id}`);
271274
}
272275
log.verbose(`No specification version defined for project ${project.id}`);
@@ -282,14 +285,14 @@ class ProjectPreprocessor {
282285
}
283286

284287
if (!project.type) {
285-
if (project._level === 0) {
288+
if (project._isRoot) {
286289
throw new Error(`No type configured for root project ${project.id}`);
287290
}
288291
log.verbose(`No type configured for project ${project.id}`);
289292
return false; // ignore this project
290293
}
291294

292-
if (project.kind !== "project" && project._level === 0) {
295+
if (project.kind !== "project" && project._isRoot) {
293296
// This is arguable. It is not the concern of ui5-project to define the entry point of a project tree
294297
// On the other hand, there is no known use case for anything else right now and failing early here
295298
// makes sense in that regard
@@ -325,12 +328,12 @@ class ProjectPreprocessor {
325328
}
326329

327330
checkProjectMetadata(parent, project) {
328-
if (project.metadata.deprecated && parent && parent._level === 0) {
331+
if (project.metadata.deprecated && parent && parent._isRoot) {
329332
// Only warn for direct dependencies of the root project
330333
log.warn(`Dependency ${project.metadata.name} is deprecated and should not be used for new projects!`);
331334
}
332335

333-
if (project.metadata.sapInternal && parent && parent._level === 0 && !parent.metadata.allowSapInternal) {
336+
if (project.metadata.sapInternal && parent && parent._isRoot && !parent.metadata.allowSapInternal) {
334337
// Only warn for direct dependencies of the root project, except it defines "allowSapInternal"
335338
log.warn(`Dependency ${project.metadata.name} is restricted for use by SAP internal projects only! ` +
336339
`If the project ${parent.metadata.name} is an SAP internal project, add the attribute ` +
@@ -389,7 +392,7 @@ class ProjectPreprocessor {
389392
`${project.id} at "${configPath}". Error: ${err.message}`;
390393

391394
// Something else than "File or directory does not exist" or root project
392-
if (err.code !== "ENOENT" || project._level === 0) {
395+
if (err.code !== "ENOENT" || project._isRoot) {
393396
throw new Error(errorText);
394397
} else {
395398
log.verbose(errorText);
@@ -609,7 +612,8 @@ class ProjectPreprocessor {
609612
"version",
610613
"path",
611614
"dependencies",
612-
"_level"
615+
"_level",
616+
"_isRoot"
613617
];
614618
const config = {};
615619
for (const key in project) {

lib/translators/ui5Framework.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ module.exports = {
237237
return true;
238238
}
239239
// Filter out development and unresolved optional dependencies for non-root projects
240-
return utils.shouldIncludeDependency(dependency, project._level === 0);
240+
return utils.shouldIncludeDependency(dependency, project._isRoot);
241241
})
242242
.map((dependency) => {
243243
if (!frameworkLibs[dependency.name]) {

test/lib/extensions.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ test("Project with project-shim extension with dependency configuration", (t) =>
6060
return projectPreprocessor.processTree(tree).then((parsedTree) => {
6161
t.deepEqual(parsedTree, {
6262
_level: 0,
63+
_isRoot: true,
6364
type: "application",
6465
metadata: {
6566
name: "xy",
@@ -218,6 +219,7 @@ test("Project with project-shim extension with dependency declaration and config
218219
return projectPreprocessor.processTree(tree).then((parsedTree) => {
219220
t.deepEqual(parsedTree, {
220221
_level: 0,
222+
_isRoot: true,
221223
type: "application",
222224
metadata: {
223225
name: "xy",
@@ -392,6 +394,7 @@ test("Project with project-shim extension with collection", (t) => {
392394
return projectPreprocessor.processTree(tree).then((parsedTree) => {
393395
t.deepEqual(parsedTree, {
394396
_level: 0,
397+
_isRoot: true,
395398
type: "application",
396399
metadata: {
397400
name: "xy",
@@ -526,6 +529,7 @@ test("Project with project-type extension dependency inline configuration", (t)
526529
return t.throwsAsync(projectPreprocessor.processTree(tree).then((parsedTree) => {
527530
t.deepEqual(parsedTree, {
528531
_level: 0,
532+
_isRoot: true,
529533
type: "z",
530534
metadata: {
531535
name: "xy",

test/lib/projectPreprocessor.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ test("Project with inline configuration", (t) => {
3636
return projectPreprocessor.processTree(tree).then((parsedTree) => {
3737
t.deepEqual(parsedTree, {
3838
_level: 0,
39+
_isRoot: true,
3940
type: "application",
4041
metadata: {
4142
name: "xy",
@@ -73,6 +74,7 @@ test("Project with configPath", (t) => {
7374
return projectPreprocessor.processTree(tree).then((parsedTree) => {
7475
t.deepEqual(parsedTree, {
7576
_level: 0,
77+
_isRoot: true,
7678
type: "application",
7779
metadata: {
7880
name: "application.b",
@@ -110,6 +112,7 @@ test("Project with ui5.yaml at default location", (t) => {
110112
return projectPreprocessor.processTree(tree).then((parsedTree) => {
111113
t.deepEqual(parsedTree, {
112114
_level: 0,
115+
_isRoot: true,
113116
type: "application",
114117
metadata: {
115118
name: "application.a",
@@ -146,6 +149,7 @@ test("Project with ui5.yaml at default location and some configuration", (t) =>
146149
return projectPreprocessor.processTree(tree).then((parsedTree) => {
147150
t.deepEqual(parsedTree, {
148151
_level: 0,
152+
_isRoot: true,
149153
type: "application",
150154
metadata: {
151155
name: "application.c",
@@ -334,6 +338,7 @@ test("Ignores additional application-projects", (t) => {
334338
return projectPreprocessor.processTree(tree).then((parsedTree) => {
335339
t.deepEqual(parsedTree, {
336340
_level: 0,
341+
_isRoot: true,
337342
type: "application",
338343
metadata: {
339344
name: "application.a",
@@ -425,6 +430,7 @@ test("Inconsistent dependencies with same ID", (t) => {
425430
specVersion: "0.1",
426431
path: applicationAPath,
427432
_level: 0,
433+
_isRoot: true,
428434
type: "application",
429435
metadata: {
430436
name: "application.a",
@@ -703,6 +709,7 @@ const expectedTreeWithInvalidModules = {
703709
"namespace": "id1"
704710
},
705711
"_level": 0,
712+
"_isRoot": true,
706713
"kind": "project",
707714
"resources": {
708715
"configuration": {
@@ -839,6 +846,7 @@ const expectedTreeAWithInlineConfigs = {
839846
"specVersion": "1.0",
840847
"path": applicationAPath,
841848
"_level": 0,
849+
"_isRoot": true,
842850
"type": "application",
843851
"metadata": {
844852
"name": "application.a",
@@ -954,6 +962,7 @@ const expectedTreeAWithConfigPaths = {
954962
"path": applicationAPath,
955963
"configPath": path.join(applicationAPath, "ui5.yaml"),
956964
"_level": 0,
965+
"_isRoot": true,
957966
"type": "application",
958967
"metadata": {
959968
"name": "application.a",
@@ -1159,6 +1168,7 @@ const expectedTreeBWithInlineConfigs = {
11591168
"specVersion": "0.1",
11601169
"path": applicationBPath,
11611170
"_level": 0,
1171+
"_isRoot": true,
11621172
"type": "application",
11631173
"metadata": {
11641174
"name": "application.b",
@@ -1543,6 +1553,7 @@ const expectedTreeApplicationCycleA = {
15431553
}
15441554
],
15451555
"_level": 0,
1556+
"_isRoot": true,
15461557
"kind": "project",
15471558
"resources": {
15481559
"configuration": {
@@ -1850,6 +1861,7 @@ test.serial("checkProjectMetadata: Warning logged for deprecated dependencies",
18501861

18511862
const project1 = {
18521863
_level: 0,
1864+
_isRoot: true,
18531865
metadata: {
18541866
name: "root.project",
18551867
deprecated: true
@@ -1931,6 +1943,7 @@ test.serial("checkProjectMetadata: Warning logged for SAP internal dependencies"
19311943

19321944
const project1 = {
19331945
_level: 0,
1946+
_isRoot: true,
19341947
metadata: {
19351948
name: "root.project",
19361949
sapInternal: true
@@ -1978,6 +1991,7 @@ test.serial("checkProjectMetadata: No warning logged for allowed SAP internal li
19781991

19791992
const project1 = {
19801993
_level: 0,
1994+
_isRoot: true,
19811995
metadata: {
19821996
name: "root.project",
19831997
allowSapInternal: true // parent project (=root) allows sap internal project use

test/lib/translators/ui5Framework.integration.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ function defineTest(testName, {
108108
},
109109
dependencies
110110
};
111+
if (_level === 0) {
112+
proj._isRoot = true;
113+
}
111114
if (framework) {
112115
proj.framework = framework;
113116
}

0 commit comments

Comments
 (0)