Skip to content

Commit

Permalink
fix(ui5-application-writer): don't add reuse lib to local yaml (#2134)
Browse files Browse the repository at this point in the history
* fix(ui5-application-writer): don't add reuse lib to local yaml

* fix(ui5-application-writer): add changeset

* Linting auto fix commit

* fix(ui5-application-writer): don't add reuse lib to local yaml

* fix(ui5-application-writer): code smells

* fix(ui5-application-writer): lint

* fix(ui5-application-writer): code review

* fix(ui5-application-writer): code review

* Linting auto fix commit

* fix(ui5-application-writer): update test

* fix(ui5-application-writer): code review

* fix(ui5-application-writer): code review

* fix(ui5-application-writer): code review

* fix(ui5-application-writer): code review

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
korotkovao and github-actions[bot] authored Jul 10, 2024
1 parent cec4a97 commit 8b7ee1f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 29 deletions.
6 changes: 6 additions & 0 deletions .changeset/smooth-eagles-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sap-ux/ui5-application-writer': patch
'@sap-ux/fiori-elements-writer': patch
---

Do not add reuse libraries to the ui5-local.yaml
25 changes: 10 additions & 15 deletions packages/fiori-elements-writer/src/data/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
} from '../types';
import { TableSelectionMode, TableType, TemplateType } from '../types';
import { getBaseComponent, getTemplateUi5Libs, TemplateTypeAttributes } from './templateAttributes';
import { getAnnotationV4Libs } from './annotationReuseLibs';
import { getAnnotationV4Libs } from './annotationCustomUi5Libs';

const defaultModelName = 'mainModel'; // UI5 default model name is '' but some floorplans require a named default model

Expand Down Expand Up @@ -70,23 +70,12 @@ export function setDefaultTemplateSettings<T extends {}>(template: Template<T>,
*
* @param type - The template type of the required base component
* @param version - The odata service version determines the appropriate base component to use
* @param metadata - metadata string to be checked for specific annotations
* @param ui5Libs - ui5 libs
* @returns The UI5 libs required by the specified template type and OData version and UI5 annotation libs
*/
export function getUi5Libs(
type: TemplateType,
version: OdataVersion,
metadata?: string,
ui5Libs?: string | string[]
): string[] {
export function getUi5Libs(type: TemplateType, version: OdataVersion, ui5Libs?: string | string[]): string[] {
const templateLibs = getTemplateUi5Libs(type, version);
if (version === OdataVersion.v4 && metadata) {
const annotationLibs = getAnnotationV4Libs(metadata);
return [...templateLibs, ...annotationLibs].concat(ui5Libs ?? []);
} else {
return [...templateLibs].concat(ui5Libs ?? []);
}
return [...templateLibs].concat(ui5Libs ?? []);
}

/**
Expand All @@ -110,11 +99,17 @@ export function setAppDefaults<T>(feApp: FioriElementsApp<T>): FioriElementsApp<
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
feApp.app.baseComponent = feApp.app.baseComponent || getBaseComponent(feApp.template.type, feApp.service.version);

const customUi5Libs =
feApp.service.version === OdataVersion.v4 && feApp.service.metadata
? getAnnotationV4Libs(feApp.service.metadata)
: [];

// Add ui5 libs for specified template and odata version
// Dups will be removed by call to `generateUI5Project`
feApp.ui5 = {
...feApp.ui5,
ui5Libs: getUi5Libs(feApp.template.type, feApp.service.version, feApp.service.metadata, feApp.ui5?.ui5Libs)
ui5Libs: getUi5Libs(feApp.template.type, feApp.service.version, feApp.ui5?.ui5Libs),
customUi5Libs: customUi5Libs
};

// Assign a default annotation name if the service type is EDMX and no local annotation name is provided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22691,7 +22691,6 @@ framework:
- name: sap.ui.core
- name: sap.ushell
- name: sap.fe.templates
- name: sap.nw.core.gbt.notes.lib.reuse
- name: themelib_sap_belize
server:
customMiddleware:
Expand Down Expand Up @@ -23500,7 +23499,7 @@ xmlns:edmx=\\"http://docs.oasis-open.org/odata/ns/edmx\\">
<!-- Bootstrap the UI5 core library. 'data-sap-ui-frameOptions=\\"allow\\"'' is a NON-SECURE setting for test environments -->
<script id=\\"sap-ui-bootstrap\\"
src=\\"../resources/sap-ui-core.js\\"
data-sap-ui-libs=\\"sap.m,sap.ui.core,sap.ushell,sap.fe.templates,sap.nw.core.gbt.notes.lib.reuse\\"
data-sap-ui-libs=\\"sap.m,sap.ui.core,sap.ushell,sap.fe.templates\\"
data-sap-ui-async=\\"true\\"
data-sap-ui-preload=\\"async\\"
data-sap-ui-theme=\\"sap_belize\\"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { FioriElementsApp, LROPSettings } from '../../src';
import { OdataVersion, TemplateType } from '../../src';
import { feBaseConfig, getTestData } from '../common';
import { getAnnotationV4Libs } from '../../src/data/annotationReuseLibs';
import { getUi5Libs } from '../../src/data/defaults';
import { getAnnotationV4Libs } from '../../src/data/annotationCustomUi5Libs';
import { setAppDefaults } from '../../src/data/defaults';

describe('getAnnotationV4Libs', () => {
test('Metadata has the required annotation to return a Reuse lib', () => {
Expand All @@ -19,9 +19,8 @@ describe('getAnnotationV4Libs', () => {
})
} as FioriElementsApp<LROPSettings>;

expect(getUi5Libs(feApp.template.type, feApp.service.version, feApp.service.metadata as string)).toContain(
'sap.nw.core.gbt.notes.lib.reuse'
);
setAppDefaults(feApp);
expect(feApp.ui5?.customUi5Libs).toContain('sap.nw.core.gbt.notes.lib.reuse');
});

test('Metadata does not contain the required annotation to return a Reuse lib', () => {
Expand All @@ -38,9 +37,8 @@ describe('getAnnotationV4Libs', () => {
})
} as FioriElementsApp<LROPSettings>;

expect(getUi5Libs(feApp.template.type, feApp.service.version, feApp.service.metadata as string)).not.toContain(
'sap.nw.core.gbt.notes.lib.reuse'
);
setAppDefaults(feApp);
expect(feApp.ui5?.customUi5Libs).not.toContain('sap.nw.core.gbt.notes.lib.reuse');
expect(getAnnotationV4Libs(feApp.service.metadata as string)).toEqual([]);
});

Expand All @@ -58,8 +56,7 @@ describe('getAnnotationV4Libs', () => {
})
} as FioriElementsApp<LROPSettings>;

expect(getUi5Libs(feApp.template.type, feApp.service.version, feApp.service.metadata as string)).not.toContain(
'sap.nw.core.gbt.notes.lib.reuse'
);
setAppDefaults(feApp);
expect(feApp.ui5?.customUi5Libs).not.toContain('sap.nw.core.gbt.notes.lib.reuse');
});
});
1 change: 1 addition & 0 deletions packages/ui5-application-writer/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface UI5 {
descriptorVersion: string;
ui5Libs: string | string[];
ui5Theme: string;
customUi5Libs?: string[];
}

// Additional configurable features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"flexEnabled": true,
"dependencies": {
"minUI5Version": "<%- ui5.minUI5Version %>",
"libs": {<% ui5.ui5Libs.forEach((ui5Lib, idx, libs) => { %>
"libs": {<% ui5.ui5Libs.concat(ui5.customUi5Libs ?? []).forEach((ui5Lib, idx, libs) => { %>
<%- `"${ui5Lib}": {}${idx+1 < libs.length ? ',' : ''}` %><% }); %>
}
},
Expand Down

0 comments on commit 8b7ee1f

Please sign in to comment.