From fb54e35b3baf565a05e9d22d4c5217fb840a7dde Mon Sep 17 00:00:00 2001 From: D048415 Date: Fri, 14 Feb 2025 09:45:10 +0100 Subject: [PATCH 01/17] bugfix wrong convert preview-config prerequisites check for usage of cds-plugin-ui5 --- .changeset/long-planets-sing.md | 5 +++++ .../src/preview-config/prerequisites.ts | 16 ++++++++++++---- .../unit/preview-config/prerequisites.test.ts | 4 +++- 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 .changeset/long-planets-sing.md diff --git a/.changeset/long-planets-sing.md b/.changeset/long-planets-sing.md new file mode 100644 index 0000000000..cb3b150b2b --- /dev/null +++ b/.changeset/long-planets-sing.md @@ -0,0 +1,5 @@ +--- +'@sap-ux/app-config-writer': patch +--- + +fix: wrong convert preview-config prerequisites check for usage of cds-plugin-ui5 diff --git a/packages/app-config-writer/src/preview-config/prerequisites.ts b/packages/app-config-writer/src/preview-config/prerequisites.ts index fd4ead2baa..ab21ab25bb 100644 --- a/packages/app-config-writer/src/preview-config/prerequisites.ts +++ b/packages/app-config-writer/src/preview-config/prerequisites.ts @@ -1,6 +1,6 @@ import { join } from 'path'; import type { Editor } from 'mem-fs-editor'; -import type { Package } from '@sap-ux/project-access'; +import { type Package, findCapProjectRoot } from '@sap-ux/project-access'; import type { ToolsLogger } from '@sap-ux/logger'; import { satisfies, valid } from 'semver'; @@ -85,14 +85,22 @@ export async function checkPrerequisites( prerequisitesMet = false; } + let cdsPluginUi5Exists = false; + const capProjectRootPath = await findCapProjectRoot(basePath, false, fs); + if (capProjectRootPath) { + const capRootPackageJsonPath = join(capProjectRootPath, 'package.json'); + const capRootPackageJson = fs.readJSON(capRootPackageJsonPath) as Package | undefined; + cdsPluginUi5Exists = + !!capRootPackageJson?.devDependencies?.['cds-plugin-ui5'] || + !!capRootPackageJson?.dependencies?.['cds-plugin-ui5']; + } + const ui5MiddlewareMockserverExists = !!packageJson?.devDependencies?.['@sap-ux/ui5-middleware-fe-mockserver'] || !!packageJson?.dependencies?.['@sap-ux/ui5-middleware-fe-mockserver']; - const cdsPluginUi5Exists = - !!packageJson?.devDependencies?.['cds-plugin-ui5'] || !!packageJson?.dependencies?.['cds-plugin-ui5']; if (!ui5MiddlewareMockserverExists && !cdsPluginUi5Exists) { logger?.error( - "Conversion from 'sap/ui/core/util/MockServer' is not supported. You must migrate from '@sap-ux/ui5-middleware-fe-mockserver'. For more information, see https://www.npmjs.com/package/@sap-ux/ui5-middleware-fe-mockserver." + "Conversion from 'sap/ui/core/util/MockServer' or '@sap/ux-ui5-fe-mockserver-middleware' is not supported. You must migrate from '@sap-ux/ui5-middleware-fe-mockserver'. For more information, see https://www.npmjs.com/package/@sap-ux/ui5-middleware-fe-mockserver." ); prerequisitesMet = false; } diff --git a/packages/app-config-writer/test/unit/preview-config/prerequisites.test.ts b/packages/app-config-writer/test/unit/preview-config/prerequisites.test.ts index af51dd2692..5f3259c67d 100644 --- a/packages/app-config-writer/test/unit/preview-config/prerequisites.test.ts +++ b/packages/app-config-writer/test/unit/preview-config/prerequisites.test.ts @@ -3,12 +3,14 @@ import { create } from 'mem-fs-editor'; import { create as createStorage } from 'mem-fs'; import { join } from 'path'; import { ToolsLogger } from '@sap-ux/logger'; +import * as ProjectAccess from '@sap-ux/project-access'; describe('prerequisites', () => { const logger = new ToolsLogger(); const errorLogMock = jest.spyOn(ToolsLogger.prototype, 'error').mockImplementation(() => {}); const warnLogMock = jest.spyOn(ToolsLogger.prototype, 'warn').mockImplementation(() => {}); const basePath = join(__dirname, '../../fixtures/preview-config'); + jest.spyOn(ProjectAccess, 'findCapProjectRoot').mockImplementation(() => Promise.resolve(basePath)); const fs = create(createStorage()); beforeEach(() => { @@ -112,7 +114,7 @@ describe('prerequisites', () => { expect(await checkPrerequisites(basePath, fs, false, logger)).toBeFalsy(); expect(errorLogMock).toHaveBeenCalledWith( - "Conversion from 'sap/ui/core/util/MockServer' is not supported. You must migrate from '@sap-ux/ui5-middleware-fe-mockserver'. For more information, see https://www.npmjs.com/package/@sap-ux/ui5-middleware-fe-mockserver." + "Conversion from 'sap/ui/core/util/MockServer' or '@sap/ux-ui5-fe-mockserver-middleware' is not supported. You must migrate from '@sap-ux/ui5-middleware-fe-mockserver'. For more information, see https://www.npmjs.com/package/@sap-ux/ui5-middleware-fe-mockserver." ); }); From 05778fd255d76f244237ff52f8d2ce94f82e8b40 Mon Sep 17 00:00:00 2001 From: D048415 Date: Fri, 14 Feb 2025 10:53:16 +0100 Subject: [PATCH 02/17] fix sonar issue --- packages/app-config-writer/src/preview-config/prerequisites.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app-config-writer/src/preview-config/prerequisites.ts b/packages/app-config-writer/src/preview-config/prerequisites.ts index ab21ab25bb..41ef25a8b6 100644 --- a/packages/app-config-writer/src/preview-config/prerequisites.ts +++ b/packages/app-config-writer/src/preview-config/prerequisites.ts @@ -54,7 +54,7 @@ export async function checkPrerequisites( logger?: ToolsLogger ): Promise { const packageJsonPath = join(basePath, 'package.json'); - const packageJson = fs.readJSON(packageJsonPath) as Package | undefined; + const packageJson = fs.readJSON(packageJsonPath); let prerequisitesMet = true; if (!packageJson) { From 68591ade958038647546719c45f17da12844a8cf Mon Sep 17 00:00:00 2001 From: D048415 Date: Fri, 14 Feb 2025 10:53:58 +0100 Subject: [PATCH 03/17] undo fix sonar issue --- packages/app-config-writer/src/preview-config/prerequisites.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app-config-writer/src/preview-config/prerequisites.ts b/packages/app-config-writer/src/preview-config/prerequisites.ts index 41ef25a8b6..ab21ab25bb 100644 --- a/packages/app-config-writer/src/preview-config/prerequisites.ts +++ b/packages/app-config-writer/src/preview-config/prerequisites.ts @@ -54,7 +54,7 @@ export async function checkPrerequisites( logger?: ToolsLogger ): Promise { const packageJsonPath = join(basePath, 'package.json'); - const packageJson = fs.readJSON(packageJsonPath); + const packageJson = fs.readJSON(packageJsonPath) as Package | undefined; let prerequisitesMet = true; if (!packageJson) { From 6304341b0b475f6b554fe172e120324da5e2ddea Mon Sep 17 00:00:00 2001 From: D048415 Date: Mon, 17 Feb 2025 09:57:20 +0100 Subject: [PATCH 04/17] refactoring --- .../src/preview-config/prerequisites.ts | 72 ++++++++++++------- .../unit/preview-config/prerequisites.test.ts | 2 +- 2 files changed, 49 insertions(+), 25 deletions(-) diff --git a/packages/app-config-writer/src/preview-config/prerequisites.ts b/packages/app-config-writer/src/preview-config/prerequisites.ts index ab21ab25bb..728b2c04aa 100644 --- a/packages/app-config-writer/src/preview-config/prerequisites.ts +++ b/packages/app-config-writer/src/preview-config/prerequisites.ts @@ -1,9 +1,19 @@ import { join } from 'path'; import type { Editor } from 'mem-fs-editor'; -import { type Package, findCapProjectRoot } from '@sap-ux/project-access'; +import { type Package, findCapProjectRoot, FileName } from '@sap-ux/project-access'; import type { ToolsLogger } from '@sap-ux/logger'; import { satisfies, valid } from 'semver'; +const packageName = { + WDIO_QUNIT_SERVICE: 'wdio-qunit-service', + KARMA_UI5: 'karma-ui5', + UI5_CLI: '@ui5/cli', + SAP_UX_UI5_TOOLING: '@sap/ux-ui5-tooling', + SAP_UX_UI5_MIDDLEWARE_FE_MOCKSERVER: '@sap-ux/ui5-middleware-fe-mockserver', + CDS_PLUGIN_UI5: 'cds-plugin-ui5', + SAP_GRUNT_SAPUI5_BESTPRACTICE_BUILD: '@sap/grunt-sapui5-bestpractice-build' +} as const; + /** * Check if the version of the given package is lower than the minimal version. * @@ -35,6 +45,26 @@ function isLowerThanMinimalVersion( return !satisfies(minVersionInfo, versionInfo); } +/** + * Check if the project is a CAP project that uses 'cds-plugin-ui5'. + * + * @param basePath - base path of the app + * @param fs - file system reference + * @returns indicator if the project is a CAP project that uses 'cds-plugin-ui5' + */ +async function isUsingCdsPluginUi5(basePath: string, fs: Editor): Promise { + const capProjectRootPath = await findCapProjectRoot(basePath, false, fs); + if (!capProjectRootPath) { + return false; + } + const capRootPackageJsonPath = join(capProjectRootPath, FileName.Package); + const capRootPackageJson = fs.readJSON(capRootPackageJsonPath) as Package | undefined; + return ( + !!capRootPackageJson?.devDependencies?.[packageName.CDS_PLUGIN_UI5] || + !!capRootPackageJson?.dependencies?.[packageName.CDS_PLUGIN_UI5] + ); +} + /** * Check if the prerequisites for the conversion are met. * - UI5 CLI version 3.0.0 or higher is being used. @@ -53,59 +83,52 @@ export async function checkPrerequisites( convertTests: boolean = false, logger?: ToolsLogger ): Promise { - const packageJsonPath = join(basePath, 'package.json'); + const packageJsonPath = join(basePath, FileName.Package); const packageJson = fs.readJSON(packageJsonPath) as Package | undefined; let prerequisitesMet = true; if (!packageJson) { - throw Error(`File 'package.json' not found at '${basePath}'`); + throw Error(`File '${FileName.Package}' not found at '${basePath}'`); } const sapui5BestpracticeBuildExists = - !!packageJson?.devDependencies?.['@sap/grunt-sapui5-bestpractice-build'] || - !!packageJson?.dependencies?.['@sap/grunt-sapui5-bestpractice-build']; + !!packageJson?.devDependencies?.[packageName.SAP_GRUNT_SAPUI5_BESTPRACTICE_BUILD] || + !!packageJson?.dependencies?.[packageName.SAP_GRUNT_SAPUI5_BESTPRACTICE_BUILD]; if (sapui5BestpracticeBuildExists) { logger?.error( - "Conversion from '@sap/grunt-sapui5-bestpractice-build' is not supported. You must migrate to UI5 CLI version 3.0.0 or higher. For more information, see https://sap.github.io/ui5-tooling/v3/updates/migrate-v3." + `Conversion from '${packageName.SAP_GRUNT_SAPUI5_BESTPRACTICE_BUILD}' is not supported. You must migrate to UI5 CLI version 3.0.0 or higher. For more information, see https://sap.github.io/ui5-tooling/v3/updates/migrate-v3.` ); prerequisitesMet = false; } - if (isLowerThanMinimalVersion(packageJson, '@ui5/cli', '3.0.0')) { + if (isLowerThanMinimalVersion(packageJson, packageName.UI5_CLI, '3.0.0')) { logger?.error( 'UI5 CLI version 3.0.0 or higher is required to convert the preview to virtual files. For more information, see https://sap.github.io/ui5-tooling/v3/updates/migrate-v3.' ); prerequisitesMet = false; } - if (isLowerThanMinimalVersion(packageJson, '@sap/ux-ui5-tooling', '1.15.4', false)) { + if (isLowerThanMinimalVersion(packageJson, packageName.SAP_UX_UI5_TOOLING, '1.15.4', false)) { logger?.error( 'UX UI5 Tooling version 1.15.4 or higher is required to convert the preview to virtual files. For more information, see https://www.npmjs.com/package/@sap/ux-ui5-tooling.' ); prerequisitesMet = false; } - let cdsPluginUi5Exists = false; - const capProjectRootPath = await findCapProjectRoot(basePath, false, fs); - if (capProjectRootPath) { - const capRootPackageJsonPath = join(capProjectRootPath, 'package.json'); - const capRootPackageJson = fs.readJSON(capRootPackageJsonPath) as Package | undefined; - cdsPluginUi5Exists = - !!capRootPackageJson?.devDependencies?.['cds-plugin-ui5'] || - !!capRootPackageJson?.dependencies?.['cds-plugin-ui5']; - } - const ui5MiddlewareMockserverExists = - !!packageJson?.devDependencies?.['@sap-ux/ui5-middleware-fe-mockserver'] || - !!packageJson?.dependencies?.['@sap-ux/ui5-middleware-fe-mockserver']; - if (!ui5MiddlewareMockserverExists && !cdsPluginUi5Exists) { + !!packageJson?.devDependencies?.[packageName.SAP_UX_UI5_MIDDLEWARE_FE_MOCKSERVER] || + !!packageJson?.dependencies?.[packageName.SAP_UX_UI5_MIDDLEWARE_FE_MOCKSERVER]; + if (!ui5MiddlewareMockserverExists && !(await isUsingCdsPluginUi5(basePath, fs))) { logger?.error( - "Conversion from 'sap/ui/core/util/MockServer' or '@sap/ux-ui5-fe-mockserver-middleware' is not supported. You must migrate from '@sap-ux/ui5-middleware-fe-mockserver'. For more information, see https://www.npmjs.com/package/@sap-ux/ui5-middleware-fe-mockserver." + `Conversion from 'sap/ui/core/util/MockServer' or '@sap/ux-ui5-fe-mockserver-middleware' is not supported. You must migrate to '${packageName.SAP_UX_UI5_MIDDLEWARE_FE_MOCKSERVER}' first. For more information, see https://www.npmjs.com/package/@sap-ux/ui5-middleware-fe-mockserver.` ); prerequisitesMet = false; } - if (convertTests && (packageJson?.devDependencies?.['karma-ui5'] ?? packageJson?.dependencies?.['karma-ui5'])) { + if ( + convertTests && + (packageJson?.devDependencies?.[packageName.KARMA_UI5] ?? packageJson?.dependencies?.[packageName.KARMA_UI5]) + ) { logger?.warn( "This app seems to use Karma as a test runner. Please note that the converter does not convert any Karma configuration files. Please update your karma configuration ('ui5.configPath' and 'ui5.testpage') according to the new virtual endpoints after the conversion." ); @@ -113,7 +136,8 @@ export async function checkPrerequisites( if ( convertTests && - (packageJson?.devDependencies?.['wdio-qunit-service'] ?? packageJson?.dependencies?.['wdio-qunit-service']) + (packageJson?.devDependencies?.[packageName.WDIO_QUNIT_SERVICE] ?? + packageJson?.dependencies?.[packageName.WDIO_QUNIT_SERVICE]) ) { logger?.warn( 'This app seems to use the WebdriverIO QUnit Service as a test runner. Please note that the converter does not convert any WebdriverIO configuration files. Please update your WebdriverIO QUnit Service test paths according to the new virtual endpoints after the conversion.' diff --git a/packages/app-config-writer/test/unit/preview-config/prerequisites.test.ts b/packages/app-config-writer/test/unit/preview-config/prerequisites.test.ts index 5f3259c67d..4950f2b621 100644 --- a/packages/app-config-writer/test/unit/preview-config/prerequisites.test.ts +++ b/packages/app-config-writer/test/unit/preview-config/prerequisites.test.ts @@ -114,7 +114,7 @@ describe('prerequisites', () => { expect(await checkPrerequisites(basePath, fs, false, logger)).toBeFalsy(); expect(errorLogMock).toHaveBeenCalledWith( - "Conversion from 'sap/ui/core/util/MockServer' or '@sap/ux-ui5-fe-mockserver-middleware' is not supported. You must migrate from '@sap-ux/ui5-middleware-fe-mockserver'. For more information, see https://www.npmjs.com/package/@sap-ux/ui5-middleware-fe-mockserver." + "Conversion from 'sap/ui/core/util/MockServer' or '@sap/ux-ui5-fe-mockserver-middleware' is not supported. You must migrate to '@sap-ux/ui5-middleware-fe-mockserver' first. For more information, see https://www.npmjs.com/package/@sap-ux/ui5-middleware-fe-mockserver." ); }); From 104f6942aad4af4e03f7663b9737554454477fc9 Mon Sep 17 00:00:00 2001 From: D048415 Date: Fri, 21 Feb 2025 17:21:27 +0100 Subject: [PATCH 05/17] move checkCdsUi5PluginEnabled from cap-config-writer to project-access and use in app-config-writer --- .../src/preview-config/prerequisites.ts | 10 +- .../unit/preview-config/prerequisites.test.ts | 25 +- .../cap-config-writer/src/cap-config/index.ts | 98 +------ .../src/cap-config/package-json.ts | 79 +----- .../cap-config-writer/src/cap-config/types.ts | 21 +- .../src/cap-writer/package-json.ts | 6 +- packages/cap-config-writer/src/index.ts | 4 +- .../test/unit/cap-config/index.test.ts | 109 +------- .../test/unit/cap-config/package-json.test.ts | 154 ----------- .../test/unit/cap-writer/package-json.test.ts | 19 +- .../cap-config-writer/test/unit/index.test.ts | 2 - packages/project-access/src/index.ts | 10 +- packages/project-access/src/project/cap.ts | 154 +++++++++++ packages/project-access/src/project/index.ts | 8 +- .../project-access/src/types/cap/index.ts | 19 ++ .../fixture/cap-no-cds-plugin-ui/package.json | 5 + .../cap-valid-cds-plugin-ui/package.json | 11 + .../project-access/test/project/cap.test.ts | 253 +++++++++++++++++- 18 files changed, 499 insertions(+), 488 deletions(-) delete mode 100644 packages/cap-config-writer/test/unit/cap-config/package-json.test.ts create mode 100644 packages/project-access/test/fixture/cap-no-cds-plugin-ui/package.json create mode 100644 packages/project-access/test/fixture/cap-valid-cds-plugin-ui/package.json diff --git a/packages/app-config-writer/src/preview-config/prerequisites.ts b/packages/app-config-writer/src/preview-config/prerequisites.ts index 728b2c04aa..e093067365 100644 --- a/packages/app-config-writer/src/preview-config/prerequisites.ts +++ b/packages/app-config-writer/src/preview-config/prerequisites.ts @@ -1,6 +1,6 @@ import { join } from 'path'; import type { Editor } from 'mem-fs-editor'; -import { type Package, findCapProjectRoot, FileName } from '@sap-ux/project-access'; +import { type Package, findCapProjectRoot, FileName, checkCdsUi5PluginEnabled } from '@sap-ux/project-access'; import type { ToolsLogger } from '@sap-ux/logger'; import { satisfies, valid } from 'semver'; @@ -10,7 +10,6 @@ const packageName = { UI5_CLI: '@ui5/cli', SAP_UX_UI5_TOOLING: '@sap/ux-ui5-tooling', SAP_UX_UI5_MIDDLEWARE_FE_MOCKSERVER: '@sap-ux/ui5-middleware-fe-mockserver', - CDS_PLUGIN_UI5: 'cds-plugin-ui5', SAP_GRUNT_SAPUI5_BESTPRACTICE_BUILD: '@sap/grunt-sapui5-bestpractice-build' } as const; @@ -57,12 +56,7 @@ async function isUsingCdsPluginUi5(basePath: string, fs: Editor): Promise { const errorLogMock = jest.spyOn(ToolsLogger.prototype, 'error').mockImplementation(() => {}); const warnLogMock = jest.spyOn(ToolsLogger.prototype, 'warn').mockImplementation(() => {}); const basePath = join(__dirname, '../../fixtures/preview-config'); - jest.spyOn(ProjectAccess, 'findCapProjectRoot').mockImplementation(() => Promise.resolve(basePath)); + jest.spyOn(ProjectAccess, 'findCapProjectRoot').mockResolvedValue(basePath); const fs = create(createStorage()); beforeEach(() => { jest.clearAllMocks(); fs.delete(join(basePath, 'various-configs', 'package.json')); + jest.spyOn(ProjectAccess, 'checkCdsUi5PluginEnabled').mockResolvedValue(true); }); test('check prerequisites w/o package.json', async () => { @@ -44,19 +45,13 @@ describe('prerequisites', () => { }); test('check prerequisites with UI5 cli ^3 dependency', async () => { - fs.write( - join(basePath, 'package.json'), - JSON.stringify({ devDependencies: { '@ui5/cli': '^3', 'cds-plugin-ui5': '6.6.6' } }) - ); + fs.write(join(basePath, 'package.json'), JSON.stringify({ devDependencies: { '@ui5/cli': '^3' } })); expect(await checkPrerequisites(basePath, fs, false, logger)).toBeTruthy(); }); test('check prerequisites with UI5 cli ^2 dependency', async () => { - fs.write( - join(basePath, 'package.json'), - JSON.stringify({ devDependencies: { '@ui5/cli': '^2', 'cds-plugin-ui5': '6.6.6' } }) - ); + fs.write(join(basePath, 'package.json'), JSON.stringify({ devDependencies: { '@ui5/cli': '^2' } })); expect(await checkPrerequisites(basePath, fs, false, logger)).toBeFalsy(); expect(errorLogMock).toHaveBeenCalledWith( @@ -68,7 +63,7 @@ describe('prerequisites', () => { fs.write( join(basePath, 'package.json'), JSON.stringify({ - devDependencies: { '@sap/ux-ui5-tooling': '1.16.0', '@ui5/cli': '^3', 'cds-plugin-ui5': '6.6.6' } + devDependencies: { '@sap/ux-ui5-tooling': '1.16.0', '@ui5/cli': '^3' } }) ); @@ -79,7 +74,7 @@ describe('prerequisites', () => { fs.write( join(basePath, 'package.json'), JSON.stringify({ - devDependencies: { '@sap/ux-ui5-tooling': '1', '@ui5/cli': '^3', 'cds-plugin-ui5': '6.6.6' } + devDependencies: { '@sap/ux-ui5-tooling': '1', '@ui5/cli': '^3' } }) ); @@ -90,7 +85,7 @@ describe('prerequisites', () => { fs.write( join(basePath, 'package.json'), JSON.stringify({ - devDependencies: { '@sap/ux-ui5-tooling': 'latest', '@ui5/cli': '^3', 'cds-plugin-ui5': '6.6.6' } + devDependencies: { '@sap/ux-ui5-tooling': 'latest', '@ui5/cli': '^3' } }) ); @@ -110,6 +105,7 @@ describe('prerequisites', () => { }); test('check prerequisites w/o mockserver dependency', async () => { + jest.spyOn(ProjectAccess, 'checkCdsUi5PluginEnabled').mockResolvedValue(false); fs.write(join(basePath, 'package.json'), JSON.stringify({ devDependencies: { '@ui5/cli': '3.0.0' } })); expect(await checkPrerequisites(basePath, fs, false, logger)).toBeFalsy(); @@ -119,10 +115,7 @@ describe('prerequisites', () => { }); test('check prerequisites w/o mockserver dependency but with cds-plugin-ui5 dependency', async () => { - fs.write( - join(basePath, 'package.json'), - JSON.stringify({ devDependencies: { '@ui5/cli': '3.0.0', 'cds-plugin-ui5': '6.6.6' } }) - ); + fs.write(join(basePath, 'package.json'), JSON.stringify({ devDependencies: { '@ui5/cli': '3.0.0' } })); expect(await checkPrerequisites(basePath, fs, false, logger)).toBeTruthy(); }); diff --git a/packages/cap-config-writer/src/cap-config/index.ts b/packages/cap-config-writer/src/cap-config/index.ts index cbd8f5ed6f..68241ab90e 100644 --- a/packages/cap-config-writer/src/cap-config/index.ts +++ b/packages/cap-config-writer/src/cap-config/index.ts @@ -2,19 +2,8 @@ import { join } from 'path'; import { create as createStorage } from 'mem-fs'; import { create } from 'mem-fs-editor'; import type { Editor } from 'mem-fs-editor'; -import type { Package, CdsVersionInfo } from '@sap-ux/project-access'; -import { - addCdsPluginUi5, - enableWorkspaces, - ensureMinCdsVersion, - getWorkspaceInfo, - hasCdsPluginUi5, - satisfiesMinCdsVersion, - minCdsVersion -} from './package-json'; -export { satisfiesMinCdsVersion } from './package-json'; -import type { CdsUi5PluginInfo } from './types'; -import { satisfies } from 'semver'; +import type { Package } from '@sap-ux/project-access'; +import { addCdsPluginUi5, enableWorkspaces, ensureMinCdsVersion } from './package-json'; /** * Enable workspace and cds-plugin-ui5 for given CAP project. @@ -37,86 +26,3 @@ export async function enableCdsUi5Plugin(basePath: string, fs?: Editor): Promise fs.writeJSON(packageJsonPath, packageJson); return fs; } - -/** - * Check if cds-plugin-ui5 is enabled on a CAP project. Checks also all prerequisites, like minimum @sap/cds version. - * Overloaded function that returns detailed CAP plugin info. - * - * @param basePath - root path of the CAP project, where package.json is located - * @param [fs] - optional: the memfs editor instance - * @returns true: cds-plugin-ui5 and all prerequisites are fulfilled; false: cds-plugin-ui5 is not enabled or not all prerequisites are fulfilled - */ -export async function checkCdsUi5PluginEnabled(basePath: string, fs?: Editor): Promise; - -/** - * Check if cds-plugin-ui5 is enabled on a CAP project. Checks also all prerequisites, like minimum @sap/cds version. - * - * @param basePath - root path of the CAP project, where package.json is located - * @param [fs] - optional: the memfs editor instance - * @param [moreInfo] if true return an object specifying detailed info about the cds and workspace state - * @returns false if package.json is not found at specified path or {@link CdsUi5PluginInfo} with additional info - */ -export async function checkCdsUi5PluginEnabled( - basePath: string, - fs?: Editor, - moreInfo?: boolean -): Promise; - -/** - * Check if cds-plugin-ui5 is enabled on a CAP project. Checks also all prerequisites, like minimum @sap/cds version. - * - * @param basePath - root path of the CAP project, where package.json is located - * @param [fs] - optional: the memfs editor instance - * @param [moreInfo] if true return an object specifying detailed info about the cds and workspace state - * @param {CdsVersionInfo} [cdsVersionInfo] - If provided will be used instead of parsing the package.json file to determine the cds version. - * @returns false if package.json is not found at specified path or {@link CdsUi5PluginInfo} with additional info - */ -export async function checkCdsUi5PluginEnabled( - basePath: string, - fs?: Editor, - moreInfo?: boolean, - cdsVersionInfo?: CdsVersionInfo -): Promise; - -/** - * Implementation of the overloaded function. - * Check if cds-plugin-ui5 is enabled on a CAP project. Checks also all prerequisites, like minimum @sap/cds version. - * - * @param basePath - root path of the CAP project, where package.json is located - * @param [fs] - optional: the memfs editor instance - * @param [moreInfo] if true return an object specifying detailed info about the cds and workspace state - * @param {CdsVersionInfo} [cdsVersionInfo] - If provided will be used instead of parsing the package.json file to determine the cds version. - * @returns false if package.json is not found at specified path or {@link CdsUi5PluginInfo} with additional info or true if - * cds-plugin-ui5 and all prerequisites are fulfilled - */ -export async function checkCdsUi5PluginEnabled( - basePath: string, - fs?: Editor, - moreInfo?: boolean, - cdsVersionInfo?: CdsVersionInfo -): Promise { - if (!fs) { - fs = create(createStorage()); - } - const packageJsonPath = join(basePath, 'package.json'); - if (!fs.exists(packageJsonPath)) { - return false; - } - const packageJson = fs.readJSON(packageJsonPath) as Package; - const { workspaceEnabled } = await getWorkspaceInfo(basePath, packageJson); - const cdsInfo: CdsUi5PluginInfo = { - // Below line checks if 'cdsVersionInfo' is available and contains version information. - // If it does, it uses that version information to determine if it satisfies the minimum CDS version required. - // If 'cdsVersionInfo' is not available or does not contain version information,it falls back to check the version specified in the package.json file. - hasMinCdsVersion: cdsVersionInfo?.version - ? satisfies(cdsVersionInfo?.version, `>=${minCdsVersion}`) - : satisfiesMinCdsVersion(packageJson), - isWorkspaceEnabled: workspaceEnabled, - hasCdsUi5Plugin: hasCdsPluginUi5(packageJson), - isCdsUi5PluginEnabled: false - }; - cdsInfo.isCdsUi5PluginEnabled = cdsInfo.hasMinCdsVersion && cdsInfo.isWorkspaceEnabled && cdsInfo.hasCdsUi5Plugin; - return moreInfo ? cdsInfo : cdsInfo.isCdsUi5PluginEnabled; -} - -export { minCdsVersion }; diff --git a/packages/cap-config-writer/src/cap-config/package-json.ts b/packages/cap-config-writer/src/cap-config/package-json.ts index 01f6d106a6..ac60a2aeba 100644 --- a/packages/cap-config-writer/src/cap-config/package-json.ts +++ b/packages/cap-config-writer/src/cap-config/package-json.ts @@ -1,8 +1,12 @@ -import { coerce, gte, satisfies } from 'semver'; -import { getCapCustomPaths } from '@sap-ux/project-access'; -import type { Package } from '@sap-ux/project-access'; +import { + type Package, + hasCdsPluginUi5, + getWorkspaceInfo, + getWorkspacePackages, + minCdsVersion, + hasMinCdsVersion +} from '@sap-ux/project-access'; -export const minCdsVersion = '6.8.2'; const minCdsPluginUi5Version = '0.9.3'; /** @@ -52,70 +56,3 @@ export function addCdsPluginUi5(packageJson: Package): void { packageJson.devDependencies['cds-plugin-ui5'] = `^${minCdsPluginUi5Version}`; } } - -/** - * Check if package.json has dependency to the minimum min version of @sap/cds, - * that is required to enable cds-plugin-ui. - * - * @param packageJson - the parsed package.json - * @returns - true: min cds version is present; false: cds version needs update - */ -export function hasMinCdsVersion(packageJson: Package): boolean { - return gte(coerce(packageJson.dependencies?.['@sap/cds']) ?? '0.0.0', minCdsVersion); -} - -/** - * Check if package.json has version or version range that satisfies the minimum version of @sap/cds. - * - * @param packageJson - the parsed package.json - * @returns - true: cds version satisfies the min cds version; false: cds version does not satisfy min cds version - */ -export function satisfiesMinCdsVersion(packageJson: Package): boolean { - return hasMinCdsVersion(packageJson) || satisfies(minCdsVersion, packageJson.dependencies?.['@sap/cds'] ?? '0.0.0'); -} - -/** - * Get information about the workspaces in the CAP project. - * - * @param basePath - root path of the CAP project, where package.json is located - * @param packageJson - the parsed package.json - * @returns - appWorkspace containing the path to the appWorkspace including wildcard; workspaceEnabled: boolean that states whether workspace for apps are enabled - */ -export async function getWorkspaceInfo( - basePath: string, - packageJson: Package -): Promise<{ appWorkspace: string; workspaceEnabled: boolean }> { - const capPaths = await getCapCustomPaths(basePath); - const appWorkspace = capPaths.app.endsWith('/') ? `${capPaths.app}*` : `${capPaths.app}/*`; - const workspacePackages = getWorkspacePackages(packageJson) ?? []; - const workspaceEnabled = workspacePackages.includes(appWorkspace); - return { appWorkspace, workspaceEnabled }; -} - -/** - * Return the reference to the array of workspace packages or undefined if not defined. - * The workspace packages can either be defined directly as workspaces in package.json - * or in workspaces.packages, e.g. in yarn workspaces. - * - * @param packageJson - the parsed package.json - * @returns ref to the packages in workspaces or undefined - */ -function getWorkspacePackages(packageJson: Package): string[] | undefined { - let workspacePackages: string[] | undefined; - if (Array.isArray(packageJson.workspaces)) { - workspacePackages = packageJson.workspaces; - } else if (Array.isArray(packageJson.workspaces?.packages)) { - workspacePackages = packageJson.workspaces?.packages; - } - return workspacePackages; -} - -/** - * Check if devDependency to cds-plugin-ui5 is present in package.json. - * - * @param packageJson - the parsed package.json - * @returns true: devDependency to cds-plugin-ui5 exists; false: devDependency to cds-plugin-ui5 does not exist - */ -export function hasCdsPluginUi5(packageJson: Package): boolean { - return !!packageJson.devDependencies?.['cds-plugin-ui5']; -} diff --git a/packages/cap-config-writer/src/cap-config/types.ts b/packages/cap-config-writer/src/cap-config/types.ts index ce86eb5b23..be1360c6a7 100644 --- a/packages/cap-config-writer/src/cap-config/types.ts +++ b/packages/cap-config-writer/src/cap-config/types.ts @@ -1,23 +1,4 @@ -import type { CdsVersionInfo } from '@sap-ux/project-access'; - -export type CdsUi5PluginInfo = { - /** - * Convienience property. The CDS UI5 plugin is considered enabled if `hasCdsUi5Plugin`, `hasMinCdsVersion`, `isWorkspaceEnabled` are all true. - */ - isCdsUi5PluginEnabled: boolean; - /** - * True if the CDS version satisfies the minimum supported CDS version - */ - hasMinCdsVersion: boolean; - /** - * True if NPM workspaces are enabled at the root of a CAP project - */ - isWorkspaceEnabled: boolean; - /** - * True if the CDS ui5 plugin is specified as a dependency - */ - hasCdsUi5Plugin: boolean; -}; +import type { CdsVersionInfo, CdsUi5PluginInfo } from '@sap-ux/project-access'; export type CapRuntime = 'Node.js' | 'Java'; diff --git a/packages/cap-config-writer/src/cap-writer/package-json.ts b/packages/cap-config-writer/src/cap-writer/package-json.ts index 88a3d693ce..17daf746dd 100644 --- a/packages/cap-config-writer/src/cap-writer/package-json.ts +++ b/packages/cap-config-writer/src/cap-writer/package-json.ts @@ -1,16 +1,16 @@ import type { Package } from '@sap-ux/project-access'; -import { getCapCustomPaths } from '@sap-ux/project-access'; +import { getCapCustomPaths, checkCdsUi5PluginEnabled } from '@sap-ux/project-access'; import type { Editor } from 'mem-fs-editor'; import { dirname, join, normalize, posix } from 'path'; import type { CapServiceCdsInfo } from '../cap-config/types'; -import { enableCdsUi5Plugin, checkCdsUi5PluginEnabled } from '../cap-config'; +import { enableCdsUi5Plugin } from '../cap-config'; import type { Logger } from '@sap-ux/logger'; /** * Retrieves the CDS watch script for the CAP app. * * @param {string} projectName - The project's name, which is the module name. - * @param {string} appId - The application's ID, including its namespace and the module name. + * @param {string} appId - The application's ID, including its namespace and the module name. If appId is provided, it will be used to open the application instead of the project name. This option is available for use with npm workspaces. * @returns {{ [x: string]: string }} The CDS watch script for the CAP app. */ diff --git a/packages/cap-config-writer/src/index.ts b/packages/cap-config-writer/src/index.ts index f75d9e2948..3bd088d6e2 100644 --- a/packages/cap-config-writer/src/index.ts +++ b/packages/cap-config-writer/src/index.ts @@ -1,4 +1,4 @@ -export { checkCdsUi5PluginEnabled, enableCdsUi5Plugin, satisfiesMinCdsVersion } from './cap-config'; +export { enableCdsUi5Plugin } from './cap-config'; export type { CapService, CapRuntime } from './cap-config/types'; -export type { CdsUi5PluginInfo, CapServiceCdsInfo, CapProjectSettings } from './cap-config/types'; +export type { CapServiceCdsInfo, CapProjectSettings } from './cap-config/types'; export * from './cap-writer'; diff --git a/packages/cap-config-writer/test/unit/cap-config/index.test.ts b/packages/cap-config-writer/test/unit/cap-config/index.test.ts index b187fcb716..8d0ce7fe67 100644 --- a/packages/cap-config-writer/test/unit/cap-config/index.test.ts +++ b/packages/cap-config-writer/test/unit/cap-config/index.test.ts @@ -2,8 +2,9 @@ import { promises } from 'fs'; import { join } from 'path'; import { create as createStorage } from 'mem-fs'; import { create } from 'mem-fs-editor'; -import * as projectAccessMock from '@sap-ux/project-access'; -import { checkCdsUi5PluginEnabled, enableCdsUi5Plugin } from '../../../src/cap-config'; +import type { Package } from '@sap-ux/project-access'; +import { enableCdsUi5Plugin } from '../../../src'; +import * as ProjectAccessMock from '@sap-ux/project-access'; const fixturesPath = join(__dirname, '../../fixture'); @@ -52,19 +53,19 @@ describe('Test enableCdsUi5Plugin()', () => { workspaces: ['app/*'] }); const fs = await enableCdsUi5Plugin(__dirname, memFs); - const packageJson = fs.readJSON(join(__dirname, 'package.json')) as projectAccessMock.Package; + const packageJson = fs.readJSON(join(__dirname, 'package.json')) as Package; expect(packageJson.devDependencies).toEqual({ 'cds-plugin-ui5': '^0.9.3' }); }); test('CAP with custom app path and mem-fs editor', async () => { - jest.spyOn(projectAccessMock, 'getCapCustomPaths').mockResolvedValueOnce({ - app: 'customAppPath', - db: 'db', - srv: 'srv' + jest.spyOn(ProjectAccessMock, 'hasMinCdsVersion').mockReturnValue(true); + jest.spyOn(ProjectAccessMock, 'getWorkspaceInfo').mockResolvedValueOnce({ + appWorkspace: 'customAppPath/*', + workspaceEnabled: false }); const memFs = create(createStorage()); const fs = await enableCdsUi5Plugin(__dirname, memFs); - const packageJson = fs.readJSON(join(__dirname, 'package.json')) as projectAccessMock.Package; + const packageJson = fs.readJSON(join(__dirname, 'package.json')) as Package; expect(packageJson.workspaces).toEqual(['customAppPath/*']); }); @@ -72,99 +73,9 @@ describe('Test enableCdsUi5Plugin()', () => { const memFs = create(createStorage()); memFs.writeJSON(join(__dirname, 'package.json'), { workspaces: {} }); await enableCdsUi5Plugin(__dirname, memFs); - const packageJson = memFs.readJSON(join(__dirname, 'package.json')) as projectAccessMock.Package; + const packageJson = memFs.readJSON(join(__dirname, 'package.json')) as Package; expect(packageJson.workspaces).toEqual({ packages: ['app/*'] }); }); }); - -describe('Test checkCdsUi5PluginEnabled()', () => { - test('Empty project should return false', async () => { - expect(await checkCdsUi5PluginEnabled(__dirname)).toBe(false); - expect(await checkCdsUi5PluginEnabled(__dirname, undefined, true)).toBe(false); - }); - - test('CAP project with valid cds-plugin-ui', async () => { - expect(await checkCdsUi5PluginEnabled(join(fixturesPath, 'cap-valid-cds-plugin-ui'))).toBe(true); - expect(await checkCdsUi5PluginEnabled(join(fixturesPath, 'cap-valid-cds-plugin-ui'), undefined, true)).toEqual({ - hasCdsUi5Plugin: true, - hasMinCdsVersion: true, - isCdsUi5PluginEnabled: true, - isWorkspaceEnabled: true - }); - }); - - test('CAP project with missing apps folder in workspaces', async () => { - const memFs = create(createStorage()); - memFs.writeJSON(join(__dirname, 'package.json'), { - dependencies: { '@sap/cds': '6.8.2' }, - devDependencies: { 'cds-plugin-ui5': '0.0.1' }, - workspaces: [] - }); - expect(await checkCdsUi5PluginEnabled(__dirname, memFs)).toBe(false); - expect(await checkCdsUi5PluginEnabled(__dirname, memFs, true)).toEqual({ - hasCdsUi5Plugin: true, - hasMinCdsVersion: true, - isCdsUi5PluginEnabled: false, - isWorkspaceEnabled: false - }); - }); - - test('CAP project with workspaces config as object, but no apps folder', async () => { - const memFs = create(createStorage()); - memFs.writeJSON(join(__dirname, 'package.json'), { - dependencies: { '@sap/cds': '6.8.2' }, - devDependencies: { 'cds-plugin-ui5': '0.0.1' }, - workspaces: {} - }); - expect(await checkCdsUi5PluginEnabled(__dirname, memFs)).toBe(false); - expect(await checkCdsUi5PluginEnabled(__dirname, memFs, true)).toEqual({ - hasCdsUi5Plugin: true, - hasMinCdsVersion: true, - isCdsUi5PluginEnabled: false, - isWorkspaceEnabled: false - }); - }); - - test('CAP project with workspaces config as object, app folder in workspace', async () => { - const memFs = create(createStorage()); - memFs.writeJSON(join(__dirname, 'package.json'), { - dependencies: { '@sap/cds': '6.8.2' }, - devDependencies: { 'cds-plugin-ui5': '0.0.1' }, - workspaces: { - packages: ['app/*'] - } - }); - expect(await checkCdsUi5PluginEnabled(__dirname, memFs)).toBe(true); - expect(await checkCdsUi5PluginEnabled(__dirname, memFs, true)).toEqual({ - hasCdsUi5Plugin: true, - hasMinCdsVersion: true, - isCdsUi5PluginEnabled: true, - isWorkspaceEnabled: true - }); - }); - - test('CAP project with cds version info greater than minimum cds requirement', async () => { - const memFs = create(createStorage()); - memFs.writeJSON(join(__dirname, 'package.json'), { - dependencies: { '@sap/cds': '6.8.2' }, - devDependencies: { 'cds-plugin-ui5': '0.0.1' }, - workspaces: { - packages: ['app/*'] - } - }); - const cdsVersionInfo = { - home: '/path', - version: '7.7.2', - root: '/path/root' - }; - expect(await checkCdsUi5PluginEnabled(__dirname, memFs)).toBe(true); - expect(await checkCdsUi5PluginEnabled(__dirname, memFs, true, cdsVersionInfo)).toEqual({ - hasCdsUi5Plugin: true, - hasMinCdsVersion: true, - isCdsUi5PluginEnabled: true, - isWorkspaceEnabled: true - }); - }); -}); diff --git a/packages/cap-config-writer/test/unit/cap-config/package-json.test.ts b/packages/cap-config-writer/test/unit/cap-config/package-json.test.ts deleted file mode 100644 index 7873755f92..0000000000 --- a/packages/cap-config-writer/test/unit/cap-config/package-json.test.ts +++ /dev/null @@ -1,154 +0,0 @@ -import { satisfiesMinCdsVersion } from '../../../src'; -import { hasMinCdsVersion } from '../../../src/cap-config/package-json'; - -describe('Test hasMinCdsVersion()', () => { - test('CAP project with valid @sap/cds version using caret(^)', async () => { - expect( - hasMinCdsVersion({ - dependencies: { '@sap/cds': '^6.7.0' } - }) - ).toBe(false); - }); - - test('CAP project with invalid @sap/cds version using caret(^)', async () => { - expect( - hasMinCdsVersion({ - dependencies: { '@sap/cds': '^4' } - }) - ).toBe(false); - }); - - test('CAP project with valid @sap/cds version using x-range', async () => { - expect( - hasMinCdsVersion({ - dependencies: { '@sap/cds': '6.x' } - }) - ).toBe(false); - }); - - test('CAP project with invalid @sap/cds version using x-range', async () => { - expect( - hasMinCdsVersion({ - dependencies: { '@sap/cds': '4.x' } - }) - ).toBe(false); - }); - - test('CAP project with valid @sap/cds version using greater than (>)', async () => { - expect( - hasMinCdsVersion({ - dependencies: { '@sap/cds': '>4.0.0' } - }) - ).toBe(false); - }); - - test('CAP project with invalid @sap/cds version containing semver with letters', async () => { - expect( - hasMinCdsVersion({ - dependencies: { '@sap/cds': 'a.b.c' } - }) - ).toBe(false); - }); - - test('CAP project with invalid @sap/cds version containing text', async () => { - expect( - hasMinCdsVersion({ - dependencies: { '@sap/cds': 'test' } - }) - ).toBe(false); - }); - - test('CAP project with valid @sap/cds version using higher version', async () => { - expect( - hasMinCdsVersion({ - dependencies: { '@sap/cds': '6.8.4' } - }) - ).toBe(true); - }); - - test('CAP project with valid @sap/cds version using higher version with caret (^)', async () => { - expect( - hasMinCdsVersion({ - dependencies: { '@sap/cds': '^7' } - }) - ).toBe(true); - }); -}); - -describe('Test satisfiesMinCdsVersion()', () => { - test('CAP project with valid @sap/cds version using caret(^)', async () => { - expect( - satisfiesMinCdsVersion({ - dependencies: { '@sap/cds': '^6.7.0' } - }) - ).toBe(true); - }); - - test('CAP project with invalid @sap/cds version using caret(^)', async () => { - expect( - satisfiesMinCdsVersion({ - dependencies: { '@sap/cds': '^4' } - }) - ).toBe(false); - }); - - test('CAP project with valid @sap/cds version using x-range', async () => { - expect( - satisfiesMinCdsVersion({ - dependencies: { '@sap/cds': '6.x' } - }) - ).toBe(true); - }); - - test('CAP project with invalid @sap/cds version using x-range', async () => { - expect( - satisfiesMinCdsVersion({ - dependencies: { '@sap/cds': '4.x' } - }) - ).toBe(false); - }); - - test('CAP project with valid @sap/cds version using greater than (>)', async () => { - expect( - satisfiesMinCdsVersion({ - dependencies: { '@sap/cds': '>4.0.0' } - }) - ).toBe(true); - }); - - test('CAP project with invalid @sap/cds version containing semver with letters', async () => { - expect( - satisfiesMinCdsVersion({ - dependencies: { '@sap/cds': 'a.b.c' } - }) - ).toBe(false); - }); - - test('CAP project with invalid @sap/cds version containing text', async () => { - expect( - satisfiesMinCdsVersion({ - dependencies: { '@sap/cds': 'test' } - }) - ).toBe(false); - }); - - test('CAP project with valid @sap/cds version using higher version', async () => { - expect( - satisfiesMinCdsVersion({ - dependencies: { '@sap/cds': '6.8.4' } - }) - ).toBe(true); - }); - - test('CAP project with valid @sap/cds version using higher version with caret (^)', async () => { - expect(satisfiesMinCdsVersion({ dependencies: { '@sap/cds': '^7' } })).toBe(true); - }); - - test('CAP project with missing @sap/cds', async () => { - expect(satisfiesMinCdsVersion({ dependencies: {} })).toBe(false); - }); - - test('CAP project with missing dependencies', async () => { - expect(satisfiesMinCdsVersion({})).toBe(false); - }); -}); diff --git a/packages/cap-config-writer/test/unit/cap-writer/package-json.test.ts b/packages/cap-config-writer/test/unit/cap-writer/package-json.test.ts index 4eb70c8af4..e0ec413115 100644 --- a/packages/cap-config-writer/test/unit/cap-writer/package-json.test.ts +++ b/packages/cap-config-writer/test/unit/cap-writer/package-json.test.ts @@ -1,23 +1,17 @@ -import type { CapRuntime } from '../../../src/cap-config/types'; -import { satisfiesMinCdsVersion } from '../../../src/cap-config/package-json'; +import type { CapRuntime, CapServiceCdsInfo } from '../../../src'; import memFs from 'mem-fs'; import { ToolsLogger } from '@sap-ux/logger'; import editor, { type Editor } from 'mem-fs-editor'; import { dirname, join } from 'path'; -import { minCdsVersion } from '../../../src/cap-config'; import { updateRootPackageJson, updateAppPackageJson } from '../../../src/cap-writer/package-json'; import type { Package } from '@sap-ux/project-access'; -import type { CapServiceCdsInfo } from '../../../src/index'; -import { dir } from 'console'; - -jest.mock('../../../src/cap-config/package-json', () => ({ - ...jest.requireActual('../../../src/cap-config/package-json'), - satisfiesMinCdsVersion: jest.fn() -})); +import * as ProjectAccessMock from '@sap-ux/project-access'; jest.mock('@sap-ux/project-access', () => ({ ...jest.requireActual('@sap-ux/project-access'), - getCdsVersionInfo: jest.fn() + getCdsVersionInfo: jest.fn(), + satisfiesMinCdsVersion: jest.fn().mockReturnValue(true), + checkCdsUi5PluginEnabled: jest.fn().mockReturnValue(false) })); describe('Writing/package json files', () => { @@ -60,7 +54,6 @@ describe('Writing/package json files', () => { const packageJsonPath = join(testInputPath, testProjectNameWithSapUx, 'package.json'); const isSapUxEnabled = true; capService.projectPath = join(testInputPath, testProjectNameWithSapUx); - (satisfiesMinCdsVersion as jest.Mock).mockReturnValue(true); await updateRootPackageJson(fs, testProjectNameNoSapUx, isSapUxEnabled, capService, 'test.app.project'); const packageJson = (fs.readJSON(packageJsonPath) ?? {}) as Package; const scripts = packageJson.scripts; @@ -95,6 +88,7 @@ describe('Writing/package json files', () => { ); }); test('should add watch script when workspace is NOT enabled', async () => { + jest.spyOn(ProjectAccessMock, 'checkCdsUi5PluginEnabled').mockResolvedValue(true); const isSapUxEnabled = true; const isNpmWorkspacesEnabled = false; const testProjectWSAlreadyEnabled = 'testprojectwsalreadyenabled'; @@ -118,7 +112,6 @@ describe('Writing/package json files', () => { isNpmWorkspacesEnabled ); const packageJson = (fs.readJSON(packageJsonPath) ?? {}) as Package; - const devDependencies = packageJson.devDependencies; const scripts = packageJson.scripts; expect(scripts?.['watch-testprojectwsalreadyenabled']).toBeDefined(); expect(scripts?.['watch-testprojectwsalreadyenabled']).toEqual( diff --git a/packages/cap-config-writer/test/unit/index.test.ts b/packages/cap-config-writer/test/unit/index.test.ts index 5dfb4f837f..b0a352d1e8 100644 --- a/packages/cap-config-writer/test/unit/index.test.ts +++ b/packages/cap-config-writer/test/unit/index.test.ts @@ -2,7 +2,5 @@ import * as capConfigWriter from '../../src'; test('Smoke test', () => { expect(capConfigWriter).toBeDefined(); - expect(typeof capConfigWriter.checkCdsUi5PluginEnabled).toBe('function'); expect(typeof capConfigWriter.enableCdsUi5Plugin).toBe('function'); - expect(typeof capConfigWriter.satisfiesMinCdsVersion).toBe('function'); }); diff --git a/packages/project-access/src/index.ts b/packages/project-access/src/index.ts index 9b817ff251..a902338c93 100644 --- a/packages/project-access/src/index.ts +++ b/packages/project-access/src/index.ts @@ -47,8 +47,14 @@ export { readUi5Yaml, refreshSpecificationDistTags, toReferenceUri, - updatePackageScript + updatePackageScript, + hasCdsPluginUi5, + getWorkspaceInfo, + getWorkspacePackages, + minCdsVersion, + hasMinCdsVersion, + checkCdsUi5PluginEnabled } from './project'; export { execNpmCommand } from './command/npm-command'; export * from './types'; -export * from './library'; +export * from './library'; \ No newline at end of file diff --git a/packages/project-access/src/project/cap.ts b/packages/project-access/src/project/cap.ts index 37fe6e26ef..87bf4acff1 100644 --- a/packages/project-access/src/project/cap.ts +++ b/packages/project-access/src/project/cap.ts @@ -26,6 +26,10 @@ import { } from '../file'; import { loadModuleFromProject } from './module-loader'; import { findCapProjectRoot } from './search'; +import type { CdsUi5PluginInfo } from '../types'; +import { coerce, gte, satisfies } from 'semver'; +import { create as createStorage } from 'mem-fs'; +import { create } from 'mem-fs-editor'; interface CdsFacade { env: { for: (mode: string, path: string) => CdsEnvironment }; @@ -48,6 +52,8 @@ interface ResolveWithCache { cache: Record; paths: string[] }>; } +export const minCdsVersion = '6.8.2'; + /** * Returns true if the project is a CAP Node.js project. * @@ -821,3 +827,151 @@ export async function deleteCapApp(appPath: string, memFs?: Editor, logger?: Log await deleteDirectory(dirname(appPath), memFs); } } + +/** + * Check if cds-plugin-ui5 is enabled on a CAP project. Checks also all prerequisites, like minimum @sap/cds version. + * Overloaded function that returns detailed CAP plugin info. + * + * @param basePath - root path of the CAP project, where package.json is located + * @param [fs] - optional: the memfs editor instance + * @returns true: cds-plugin-ui5 and all prerequisites are fulfilled; false: cds-plugin-ui5 is not enabled or not all prerequisites are fulfilled + */ +export async function checkCdsUi5PluginEnabled(basePath: string, fs?: Editor): Promise; + +/** + * Check if cds-plugin-ui5 is enabled on a CAP project. Checks also all prerequisites, like minimum @sap/cds version. + * + * @param basePath - root path of the CAP project, where package.json is located + * @param [fs] - optional: the memfs editor instance + * @param [moreInfo] if true return an object specifying detailed info about the cds and workspace state + * @returns false if package.json is not found at specified path or {@link CdsUi5PluginInfo} with additional info + */ +export async function checkCdsUi5PluginEnabled( + basePath: string, + fs?: Editor, + moreInfo?: boolean +): Promise; + +/** + * Check if cds-plugin-ui5 is enabled on a CAP project. Checks also all prerequisites, like minimum @sap/cds version. + * + * @param basePath - root path of the CAP project, where package.json is located + * @param [fs] - optional: the memfs editor instance + * @param [moreInfo] if true return an object specifying detailed info about the cds and workspace state + * @param {CdsVersionInfo} [cdsVersionInfo] - If provided will be used instead of parsing the package.json file to determine the cds version. + * @returns false if package.json is not found at specified path or {@link CdsUi5PluginInfo} with additional info + */ +export async function checkCdsUi5PluginEnabled( + basePath: string, + fs?: Editor, + moreInfo?: boolean, + cdsVersionInfo?: CdsVersionInfo +): Promise; + +/** + * Implementation of the overloaded function. + * Check if cds-plugin-ui5 is enabled on a CAP project. Checks also all prerequisites, like minimum @sap/cds version. + * + * @param basePath - root path of the CAP project, where package.json is located + * @param [fs] - optional: the memfs editor instance + * @param [moreInfo] if true return an object specifying detailed info about the cds and workspace state + * @param {CdsVersionInfo} [cdsVersionInfo] - If provided will be used instead of parsing the package.json file to determine the cds version. + * @returns false if package.json is not found at specified path or {@link CdsUi5PluginInfo} with additional info or true if + * cds-plugin-ui5 and all prerequisites are fulfilled + */ +export async function checkCdsUi5PluginEnabled( + basePath: string, + fs?: Editor, + moreInfo?: boolean, + cdsVersionInfo?: CdsVersionInfo +): Promise { + if (!fs) { + fs = create(createStorage()); + } + const packageJsonPath = join(basePath, 'package.json'); + if (!fs.exists(packageJsonPath)) { + return false; + } + const packageJson = fs.readJSON(packageJsonPath) as Package; + const { workspaceEnabled } = await getWorkspaceInfo(basePath, packageJson); + const cdsInfo: CdsUi5PluginInfo = { + // Below line checks if 'cdsVersionInfo' is available and contains version information. + // If it does, it uses that version information to determine if it satisfies the minimum CDS version required. + // If 'cdsVersionInfo' is not available or does not contain version information,it falls back to check the version specified in the package.json file. + hasMinCdsVersion: cdsVersionInfo?.version + ? satisfies(cdsVersionInfo?.version, `>=${minCdsVersion}`) + : satisfiesMinCdsVersion(packageJson), + isWorkspaceEnabled: workspaceEnabled, + hasCdsUi5Plugin: hasCdsPluginUi5(packageJson), + isCdsUi5PluginEnabled: false + }; + cdsInfo.isCdsUi5PluginEnabled = cdsInfo.hasMinCdsVersion && cdsInfo.isWorkspaceEnabled && cdsInfo.hasCdsUi5Plugin; + return moreInfo ? cdsInfo : cdsInfo.isCdsUi5PluginEnabled; +} + +/** + * Get information about the workspaces in the CAP project. + * + * @param basePath - root path of the CAP project, where package.json is located + * @param packageJson - the parsed package.json + * @returns - appWorkspace containing the path to the appWorkspace including wildcard; workspaceEnabled: boolean that states whether workspace for apps are enabled + */ +export async function getWorkspaceInfo( + basePath: string, + packageJson: Package +): Promise<{ appWorkspace: string; workspaceEnabled: boolean }> { + const capPaths = await getCapCustomPaths(basePath); + const appWorkspace = capPaths.app.endsWith('/') ? `${capPaths.app}*` : `${capPaths.app}/*`; + const workspacePackages = getWorkspacePackages(packageJson) ?? []; + const workspaceEnabled = workspacePackages.includes(appWorkspace); + return { appWorkspace, workspaceEnabled }; +} + +/** + * Return the reference to the array of workspace packages or undefined if not defined. + * The workspace packages can either be defined directly as workspaces in package.json + * or in workspaces.packages, e.g. in yarn workspaces. + * + * @param packageJson - the parsed package.json + * @returns ref to the packages in workspaces or undefined + */ +export function getWorkspacePackages(packageJson: Package): string[] | undefined { + let workspacePackages: string[] | undefined; + if (Array.isArray(packageJson.workspaces)) { + workspacePackages = packageJson.workspaces; + } else if (Array.isArray(packageJson.workspaces?.packages)) { + workspacePackages = packageJson.workspaces?.packages; + } + return workspacePackages; +} + +/** + * Check if devDependency to cds-plugin-ui5 is present in package.json. + * + * @param packageJson - the parsed package.json + * @returns true: devDependency to cds-plugin-ui5 exists; false: devDependency to cds-plugin-ui5 does not exist + */ +export function hasCdsPluginUi5(packageJson: Package): boolean { + return !!packageJson.devDependencies?.['cds-plugin-ui5']; +} + +/** + * Check if package.json has version or version range that satisfies the minimum version of @sap/cds. + * + * @param packageJson - the parsed package.json + * @returns - true: cds version satisfies the min cds version; false: cds version does not satisfy min cds version + */ +export function satisfiesMinCdsVersion(packageJson: Package): boolean { + return hasMinCdsVersion(packageJson) || satisfies(minCdsVersion, packageJson.dependencies?.['@sap/cds'] ?? '0.0.0'); +} + +/** + * Check if package.json has dependency to the minimum min version of @sap/cds, + * that is required to enable cds-plugin-ui. + * + * @param packageJson - the parsed package.json + * @returns - true: min cds version is present; false: cds version needs update + */ +export function hasMinCdsVersion(packageJson: Package): boolean { + return gte(coerce(packageJson.dependencies?.['@sap/cds']) ?? '0.0.0', minCdsVersion); +} diff --git a/packages/project-access/src/project/index.ts b/packages/project-access/src/project/index.ts index b396d2ff58..908340388a 100644 --- a/packages/project-access/src/project/index.ts +++ b/packages/project-access/src/project/index.ts @@ -13,7 +13,13 @@ export { isCapJavaProject, isCapNodeJsProject, readCapServiceMetadataEdmx, - toReferenceUri + toReferenceUri, + hasCdsPluginUi5, + getWorkspaceInfo, + getWorkspacePackages, + minCdsVersion, + hasMinCdsVersion, + checkCdsUi5PluginEnabled } from './cap'; export { filterDataSourcesByType } from './service'; export { addPackageDevDependency, getNodeModulesPath } from './dependencies'; diff --git a/packages/project-access/src/types/cap/index.ts b/packages/project-access/src/types/cap/index.ts index dc357c05c1..969630f6c9 100644 --- a/packages/project-access/src/types/cap/index.ts +++ b/packages/project-access/src/types/cap/index.ts @@ -235,3 +235,22 @@ export interface CdsVersionInfo { version: string; root: string; } + +export type CdsUi5PluginInfo = { + /** + * Convienience property. The CDS UI5 plugin is considered enabled if `hasCdsUi5Plugin`, `hasMinCdsVersion`, `isWorkspaceEnabled` are all true. + */ + isCdsUi5PluginEnabled: boolean; + /** + * True if the CDS version satisfies the minimum supported CDS version + */ + hasMinCdsVersion: boolean; + /** + * True if NPM workspaces are enabled at the root of a CAP project + */ + isWorkspaceEnabled: boolean; + /** + * True if the CDS ui5 plugin is specified as a dependency + */ + hasCdsUi5Plugin: boolean; +} \ No newline at end of file diff --git a/packages/project-access/test/fixture/cap-no-cds-plugin-ui/package.json b/packages/project-access/test/fixture/cap-no-cds-plugin-ui/package.json new file mode 100644 index 0000000000..b15b9a1948 --- /dev/null +++ b/packages/project-access/test/fixture/cap-no-cds-plugin-ui/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "@sap/cds": "6.8.0" + } +} diff --git a/packages/project-access/test/fixture/cap-valid-cds-plugin-ui/package.json b/packages/project-access/test/fixture/cap-valid-cds-plugin-ui/package.json new file mode 100644 index 0000000000..3c6fb1785e --- /dev/null +++ b/packages/project-access/test/fixture/cap-valid-cds-plugin-ui/package.json @@ -0,0 +1,11 @@ +{ + "dependencies": { + "@sap/cds": "^6.8.2" + }, + "devDependencies": { + "cds-plugin-ui5": "0.9.3" + }, + "workspaces": [ + "app/*" + ] +} diff --git a/packages/project-access/test/project/cap.test.ts b/packages/project-access/test/project/cap.test.ts index 675d46529c..c0a32dc1b0 100644 --- a/packages/project-access/test/project/cap.test.ts +++ b/packages/project-access/test/project/cap.test.ts @@ -5,7 +5,14 @@ import { create, type Editor } from 'mem-fs-editor'; import * as projectModuleMock from '../../src/project/module-loader'; import type { Package } from '../../src'; import { FileName } from '../../src/constants'; -import { clearCdsModuleCache, clearGlobalCdsModulePromiseCache, getCapServiceName } from '../../src/project/cap'; +import { + clearCdsModuleCache, + clearGlobalCdsModulePromiseCache, + getCapServiceName, + checkCdsUi5PluginEnabled, + satisfiesMinCdsVersion, + hasMinCdsVersion +} from '../../src/project/cap'; import { getCapCustomPaths, getCapEnvironment, @@ -1375,6 +1382,250 @@ describe('deleteCapApp', () => { }); }); +const fixturesPath = join(__dirname, '../fixture'); + +describe('Test checkCdsUi5PluginEnabled()', () => { + test('Empty project should return false', async () => { + expect(await checkCdsUi5PluginEnabled(__dirname)).toBe(false); + expect(await checkCdsUi5PluginEnabled(__dirname, undefined, true)).toBe(false); + }); + + test('CAP project with valid cds-plugin-ui', async () => { + expect(await checkCdsUi5PluginEnabled(join(fixturesPath, 'cap-valid-cds-plugin-ui'))).toBe(true); + expect(await checkCdsUi5PluginEnabled(join(fixturesPath, 'cap-valid-cds-plugin-ui'), undefined, true)).toEqual({ + hasCdsUi5Plugin: true, + hasMinCdsVersion: true, + isCdsUi5PluginEnabled: true, + isWorkspaceEnabled: true + }); + }); + + test('CAP project with missing apps folder in workspaces', async () => { + const memFs = create(createStorage()); + memFs.writeJSON(join(__dirname, 'package.json'), { + dependencies: { '@sap/cds': '6.8.2' }, + devDependencies: { 'cds-plugin-ui5': '0.0.1' }, + workspaces: [] + }); + expect(await checkCdsUi5PluginEnabled(__dirname, memFs)).toBe(false); + expect(await checkCdsUi5PluginEnabled(__dirname, memFs, true)).toEqual({ + hasCdsUi5Plugin: true, + hasMinCdsVersion: true, + isCdsUi5PluginEnabled: false, + isWorkspaceEnabled: false + }); + }); + + test('CAP project with workspaces config as object, but no apps folder', async () => { + const memFs = create(createStorage()); + memFs.writeJSON(join(__dirname, 'package.json'), { + dependencies: { '@sap/cds': '6.8.2' }, + devDependencies: { 'cds-plugin-ui5': '0.0.1' }, + workspaces: {} + }); + expect(await checkCdsUi5PluginEnabled(__dirname, memFs)).toBe(false); + expect(await checkCdsUi5PluginEnabled(__dirname, memFs, true)).toEqual({ + hasCdsUi5Plugin: true, + hasMinCdsVersion: true, + isCdsUi5PluginEnabled: false, + isWorkspaceEnabled: false + }); + }); + + test('CAP project with workspaces config as object, app folder in workspace', async () => { + const memFs = create(createStorage()); + memFs.writeJSON(join(__dirname, 'package.json'), { + dependencies: { '@sap/cds': '6.8.2' }, + devDependencies: { 'cds-plugin-ui5': '0.0.1' }, + workspaces: { + packages: ['app/*'] + } + }); + expect(await checkCdsUi5PluginEnabled(__dirname, memFs)).toBe(true); + expect(await checkCdsUi5PluginEnabled(__dirname, memFs, true)).toEqual({ + hasCdsUi5Plugin: true, + hasMinCdsVersion: true, + isCdsUi5PluginEnabled: true, + isWorkspaceEnabled: true + }); + }); + + test('CAP project with cds version info greater than minimum cds requirement', async () => { + const memFs = create(createStorage()); + memFs.writeJSON(join(__dirname, 'package.json'), { + dependencies: { '@sap/cds': '6.8.2' }, + devDependencies: { 'cds-plugin-ui5': '0.0.1' }, + workspaces: { + packages: ['app/*'] + } + }); + const cdsVersionInfo = { + home: '/path', + version: '7.7.2', + root: '/path/root' + }; + expect(await checkCdsUi5PluginEnabled(__dirname, memFs)).toBe(true); + expect(await checkCdsUi5PluginEnabled(__dirname, memFs, true, cdsVersionInfo)).toEqual({ + hasCdsUi5Plugin: true, + hasMinCdsVersion: true, + isCdsUi5PluginEnabled: true, + isWorkspaceEnabled: true + }); + }); +}); + +describe('Test satisfiesMinCdsVersion()', () => { + test('CAP project with valid @sap/cds version using caret(^)', async () => { + expect( + satisfiesMinCdsVersion({ + dependencies: { '@sap/cds': '^6.7.0' } + }) + ).toBe(true); + }); + + test('CAP project with invalid @sap/cds version using caret(^)', async () => { + expect( + satisfiesMinCdsVersion({ + dependencies: { '@sap/cds': '^4' } + }) + ).toBe(false); + }); + + test('CAP project with valid @sap/cds version using x-range', async () => { + expect( + satisfiesMinCdsVersion({ + dependencies: { '@sap/cds': '6.x' } + }) + ).toBe(true); + }); + + test('CAP project with invalid @sap/cds version using x-range', async () => { + expect( + satisfiesMinCdsVersion({ + dependencies: { '@sap/cds': '4.x' } + }) + ).toBe(false); + }); + + test('CAP project with valid @sap/cds version using greater than (>)', async () => { + expect( + satisfiesMinCdsVersion({ + dependencies: { '@sap/cds': '>4.0.0' } + }) + ).toBe(true); + }); + + test('CAP project with invalid @sap/cds version containing semver with letters', async () => { + expect( + satisfiesMinCdsVersion({ + dependencies: { '@sap/cds': 'a.b.c' } + }) + ).toBe(false); + }); + + test('CAP project with invalid @sap/cds version containing text', async () => { + expect( + satisfiesMinCdsVersion({ + dependencies: { '@sap/cds': 'test' } + }) + ).toBe(false); + }); + + test('CAP project with valid @sap/cds version using higher version', async () => { + expect( + satisfiesMinCdsVersion({ + dependencies: { '@sap/cds': '6.8.4' } + }) + ).toBe(true); + }); + + test('CAP project with valid @sap/cds version using higher version with caret (^)', async () => { + expect(satisfiesMinCdsVersion({ dependencies: { '@sap/cds': '^7' } })).toBe(true); + }); + + test('CAP project with missing @sap/cds', async () => { + expect(satisfiesMinCdsVersion({ dependencies: {} })).toBe(false); + }); + + test('CAP project with missing dependencies', async () => { + expect(satisfiesMinCdsVersion({})).toBe(false); + }); +}); + +describe('Test hasMinCdsVersion()', () => { + test('CAP project with valid @sap/cds version using caret(^)', async () => { + expect( + hasMinCdsVersion({ + dependencies: { '@sap/cds': '^6.7.0' } + }) + ).toBe(false); + }); + + test('CAP project with invalid @sap/cds version using caret(^)', async () => { + expect( + hasMinCdsVersion({ + dependencies: { '@sap/cds': '^4' } + }) + ).toBe(false); + }); + + test('CAP project with valid @sap/cds version using x-range', async () => { + expect( + hasMinCdsVersion({ + dependencies: { '@sap/cds': '6.x' } + }) + ).toBe(false); + }); + + test('CAP project with invalid @sap/cds version using x-range', async () => { + expect( + hasMinCdsVersion({ + dependencies: { '@sap/cds': '4.x' } + }) + ).toBe(false); + }); + + test('CAP project with valid @sap/cds version using greater than (>)', async () => { + expect( + hasMinCdsVersion({ + dependencies: { '@sap/cds': '>4.0.0' } + }) + ).toBe(false); + }); + + test('CAP project with invalid @sap/cds version containing semver with letters', async () => { + expect( + hasMinCdsVersion({ + dependencies: { '@sap/cds': 'a.b.c' } + }) + ).toBe(false); + }); + + test('CAP project with invalid @sap/cds version containing text', async () => { + expect( + hasMinCdsVersion({ + dependencies: { '@sap/cds': 'test' } + }) + ).toBe(false); + }); + + test('CAP project with valid @sap/cds version using higher version', async () => { + expect( + hasMinCdsVersion({ + dependencies: { '@sap/cds': '6.8.4' } + }) + ).toBe(true); + }); + + test('CAP project with valid @sap/cds version using higher version with caret (^)', async () => { + expect( + hasMinCdsVersion({ + dependencies: { '@sap/cds': '^7' } + }) + ).toBe(true); + }); +}); + function fail(message: string) { expect(message).toBeFalsy(); } From c65e8465113c76c98ee11ed2b72df39153e48b8b Mon Sep 17 00:00:00 2001 From: D048415 Date: Fri, 21 Feb 2025 17:27:51 +0100 Subject: [PATCH 06/17] prettier --- packages/project-access/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/project-access/src/index.ts b/packages/project-access/src/index.ts index a902338c93..33528c3b14 100644 --- a/packages/project-access/src/index.ts +++ b/packages/project-access/src/index.ts @@ -57,4 +57,4 @@ export { } from './project'; export { execNpmCommand } from './command/npm-command'; export * from './types'; -export * from './library'; \ No newline at end of file +export * from './library'; From 8f3b0a01abd6204b9f3d98ad898862b05ba2f3ee Mon Sep 17 00:00:00 2001 From: D048415 Date: Fri, 21 Feb 2025 17:39:36 +0100 Subject: [PATCH 07/17] adjust imports --- packages/ui5-application-inquirer/src/index.ts | 2 +- packages/ui5-application-inquirer/src/prompts/prompts.ts | 2 +- packages/ui5-application-inquirer/src/types.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/ui5-application-inquirer/src/index.ts b/packages/ui5-application-inquirer/src/index.ts index 266416241a..c3275cbba7 100644 --- a/packages/ui5-application-inquirer/src/index.ts +++ b/packages/ui5-application-inquirer/src/index.ts @@ -1,4 +1,4 @@ -import { type CdsUi5PluginInfo } from '@sap-ux/cap-config-writer'; +import { type CdsUi5PluginInfo } from '@sap-ux/project-access'; import type { InquirerAdapter, PromptDefaultValue } from '@sap-ux/inquirer-common'; import { getDefaultUI5Theme, getUI5Versions, type UI5VersionFilterOptions } from '@sap-ux/ui5-info'; import autocomplete from 'inquirer-autocomplete-prompt'; diff --git a/packages/ui5-application-inquirer/src/prompts/prompts.ts b/packages/ui5-application-inquirer/src/prompts/prompts.ts index 83671d14b6..0fae8ce360 100644 --- a/packages/ui5-application-inquirer/src/prompts/prompts.ts +++ b/packages/ui5-application-inquirer/src/prompts/prompts.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */ // Nullish coalescing operator lint warnings disabled as its not appropriate in most cases where empty strings are not considered valid -import { type CdsUi5PluginInfo } from '@sap-ux/cap-config-writer'; +import { type CdsUi5PluginInfo } from '@sap-ux/project-access'; import { getUI5ThemesChoices, searchChoices, diff --git a/packages/ui5-application-inquirer/src/types.ts b/packages/ui5-application-inquirer/src/types.ts index b8a41ce426..3aa39f2cfd 100644 --- a/packages/ui5-application-inquirer/src/types.ts +++ b/packages/ui5-application-inquirer/src/types.ts @@ -1,4 +1,4 @@ -import type { CdsUi5PluginInfo } from '@sap-ux/cap-config-writer'; +import type { CdsUi5PluginInfo } from '@sap-ux/project-access'; import type { CommonPromptOptions, PromptDefaultValue, UI5VersionChoice, YUIQuestion } from '@sap-ux/inquirer-common'; import type { AutocompleteQuestionOptions } from 'inquirer-autocomplete-prompt'; From fa8f4a407b7f0c33bbbd2cc1bfcd427afbf39b1f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 21 Feb 2025 16:45:34 +0000 Subject: [PATCH 08/17] Linting auto fix commit --- packages/project-access/src/types/cap/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/project-access/src/types/cap/index.ts b/packages/project-access/src/types/cap/index.ts index 969630f6c9..c59047592f 100644 --- a/packages/project-access/src/types/cap/index.ts +++ b/packages/project-access/src/types/cap/index.ts @@ -253,4 +253,4 @@ export type CdsUi5PluginInfo = { * True if the CDS ui5 plugin is specified as a dependency */ hasCdsUi5Plugin: boolean; -} \ No newline at end of file +}; From f63da1fff238397fea4c848b7f3293928b69f692 Mon Sep 17 00:00:00 2001 From: Dominik Heim <73878785+heimwege@users.noreply.github.com> Date: Fri, 21 Feb 2025 21:58:55 +0100 Subject: [PATCH 09/17] fix typo Co-authored-by: Klaus Keller <66327622+Klaus-Keller@users.noreply.github.com> --- packages/project-access/src/types/cap/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/project-access/src/types/cap/index.ts b/packages/project-access/src/types/cap/index.ts index c59047592f..395907687c 100644 --- a/packages/project-access/src/types/cap/index.ts +++ b/packages/project-access/src/types/cap/index.ts @@ -238,7 +238,7 @@ export interface CdsVersionInfo { export type CdsUi5PluginInfo = { /** - * Convienience property. The CDS UI5 plugin is considered enabled if `hasCdsUi5Plugin`, `hasMinCdsVersion`, `isWorkspaceEnabled` are all true. + * Convenience property. The CDS UI5 plugin is considered enabled if `hasCdsUi5Plugin`, `hasMinCdsVersion`, `isWorkspaceEnabled` are all true. */ isCdsUi5PluginEnabled: boolean; /** From 06238777de7f403890915c29e19c7b61e1d551a8 Mon Sep 17 00:00:00 2001 From: D048415 Date: Mon, 24 Feb 2025 09:46:11 +0100 Subject: [PATCH 10/17] adjust changeset --- .changeset/long-planets-sing.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.changeset/long-planets-sing.md b/.changeset/long-planets-sing.md index cb3b150b2b..c588dcaf69 100644 --- a/.changeset/long-planets-sing.md +++ b/.changeset/long-planets-sing.md @@ -1,5 +1,7 @@ --- '@sap-ux/app-config-writer': patch +'@sap-ux/project-access': patch +'@sap-ux/ui5-application-inquirer': patch --- fix: wrong convert preview-config prerequisites check for usage of cds-plugin-ui5 From b2f7ce79d8ca6945121fd4cdde2a4a6d893c5f57 Mon Sep 17 00:00:00 2001 From: D048415 Date: Mon, 24 Feb 2025 09:47:14 +0100 Subject: [PATCH 11/17] keep checkCdsUi5PluginEnabled as export in cap-config-writer --- packages/cap-config-writer/src/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/cap-config-writer/src/index.ts b/packages/cap-config-writer/src/index.ts index 3bd088d6e2..91f73aadf6 100644 --- a/packages/cap-config-writer/src/index.ts +++ b/packages/cap-config-writer/src/index.ts @@ -1,3 +1,5 @@ +import { checkCdsUi5PluginEnabled } from '@sap-ux/project-access'; +export { checkCdsUi5PluginEnabled }; export { enableCdsUi5Plugin } from './cap-config'; export type { CapService, CapRuntime } from './cap-config/types'; export type { CapServiceCdsInfo, CapProjectSettings } from './cap-config/types'; From 9a73113afb62a4e0d54f9bb2ebf1a94b6aa26f54 Mon Sep 17 00:00:00 2001 From: D048415 Date: Mon, 24 Feb 2025 09:51:04 +0100 Subject: [PATCH 12/17] rename minCdsVersion and move to constants --- packages/project-access/src/constants.ts | 2 ++ packages/project-access/src/project/cap.ts | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/project-access/src/constants.ts b/packages/project-access/src/constants.ts index 7e9efebf4a..a4a93ca13b 100644 --- a/packages/project-access/src/constants.ts +++ b/packages/project-access/src/constants.ts @@ -64,3 +64,5 @@ export const fioriToolsDirectory = join(homedir(), FioriToolsSettings.dir); * Directory where modules are cached */ export const moduleCacheRoot = join(fioriToolsDirectory, DirName.ModuleCache); + +export const MinCdsVersionUi5Plugin = '6.8.2'; diff --git a/packages/project-access/src/project/cap.ts b/packages/project-access/src/project/cap.ts index 87bf4acff1..14bad6e8a6 100644 --- a/packages/project-access/src/project/cap.ts +++ b/packages/project-access/src/project/cap.ts @@ -2,7 +2,7 @@ import { spawn } from 'child_process'; import { basename, dirname, join, normalize, relative, sep, resolve } from 'path'; import type { Logger } from '@sap-ux/logger'; import type { Editor } from 'mem-fs-editor'; -import { FileName } from '../constants'; +import { FileName, MinCdsVersionUi5Plugin } from '../constants'; import type { CapCustomPaths, CapProjectType, @@ -52,8 +52,6 @@ interface ResolveWithCache { cache: Record; paths: string[] }>; } -export const minCdsVersion = '6.8.2'; - /** * Returns true if the project is a CAP Node.js project. * @@ -899,7 +897,7 @@ export async function checkCdsUi5PluginEnabled( // If it does, it uses that version information to determine if it satisfies the minimum CDS version required. // If 'cdsVersionInfo' is not available or does not contain version information,it falls back to check the version specified in the package.json file. hasMinCdsVersion: cdsVersionInfo?.version - ? satisfies(cdsVersionInfo?.version, `>=${minCdsVersion}`) + ? satisfies(cdsVersionInfo?.version, `>=${MinCdsVersionUi5Plugin}`) : satisfiesMinCdsVersion(packageJson), isWorkspaceEnabled: workspaceEnabled, hasCdsUi5Plugin: hasCdsPluginUi5(packageJson), @@ -962,7 +960,10 @@ export function hasCdsPluginUi5(packageJson: Package): boolean { * @returns - true: cds version satisfies the min cds version; false: cds version does not satisfy min cds version */ export function satisfiesMinCdsVersion(packageJson: Package): boolean { - return hasMinCdsVersion(packageJson) || satisfies(minCdsVersion, packageJson.dependencies?.['@sap/cds'] ?? '0.0.0'); + return ( + hasMinCdsVersion(packageJson) || + satisfies(MinCdsVersionUi5Plugin, packageJson.dependencies?.['@sap/cds'] ?? '0.0.0') + ); } /** @@ -973,5 +974,5 @@ export function satisfiesMinCdsVersion(packageJson: Package): boolean { * @returns - true: min cds version is present; false: cds version needs update */ export function hasMinCdsVersion(packageJson: Package): boolean { - return gte(coerce(packageJson.dependencies?.['@sap/cds']) ?? '0.0.0', minCdsVersion); + return gte(coerce(packageJson.dependencies?.['@sap/cds']) ?? '0.0.0', MinCdsVersionUi5Plugin); } From db9e0cffbf8dfc703e7df3a5fd32f0c4be3abd30 Mon Sep 17 00:00:00 2001 From: D048415 Date: Mon, 24 Feb 2025 10:19:23 +0100 Subject: [PATCH 13/17] various fixes + combine getWorkspaceInfo and getWorkspacePackages --- .../cap-config-writer/src/cap-config/package-json.ts | 10 ++++------ .../test/unit/cap-config/index.test.ts | 3 ++- packages/project-access/src/index.ts | 4 +--- packages/project-access/src/project/cap.ts | 6 +++--- packages/project-access/src/project/index.ts | 2 -- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/packages/cap-config-writer/src/cap-config/package-json.ts b/packages/cap-config-writer/src/cap-config/package-json.ts index ac60a2aeba..6529cd871a 100644 --- a/packages/cap-config-writer/src/cap-config/package-json.ts +++ b/packages/cap-config-writer/src/cap-config/package-json.ts @@ -2,8 +2,7 @@ import { type Package, hasCdsPluginUi5, getWorkspaceInfo, - getWorkspacePackages, - minCdsVersion, + MinCdsVersionUi5Plugin, hasMinCdsVersion } from '@sap-ux/project-access'; @@ -17,7 +16,7 @@ const minCdsPluginUi5Version = '0.9.3'; export function ensureMinCdsVersion(packageJson: Package): void { if (!hasMinCdsVersion(packageJson)) { packageJson.dependencies ??= {}; - packageJson.dependencies['@sap/cds'] = `^${minCdsVersion}`; + packageJson.dependencies['@sap/cds'] = `^${MinCdsVersionUi5Plugin}`; } } @@ -28,12 +27,11 @@ export function ensureMinCdsVersion(packageJson: Package): void { * @param packageJson - the parsed package.json */ export async function enableWorkspaces(basePath: string, packageJson: Package): Promise { - const { appWorkspace, workspaceEnabled } = await getWorkspaceInfo(basePath, packageJson); + let { appWorkspace, workspaceEnabled, workspacePackages } = await getWorkspaceInfo(basePath, packageJson); if (workspaceEnabled) { return; } - let workspacePackages = getWorkspacePackages(packageJson); - if (!workspacePackages) { + if (workspacePackages.length === 0) { packageJson.workspaces ??= []; if (Array.isArray(packageJson.workspaces)) { workspacePackages = packageJson.workspaces; diff --git a/packages/cap-config-writer/test/unit/cap-config/index.test.ts b/packages/cap-config-writer/test/unit/cap-config/index.test.ts index 8d0ce7fe67..3b3a0a2534 100644 --- a/packages/cap-config-writer/test/unit/cap-config/index.test.ts +++ b/packages/cap-config-writer/test/unit/cap-config/index.test.ts @@ -61,7 +61,8 @@ describe('Test enableCdsUi5Plugin()', () => { jest.spyOn(ProjectAccessMock, 'hasMinCdsVersion').mockReturnValue(true); jest.spyOn(ProjectAccessMock, 'getWorkspaceInfo').mockResolvedValueOnce({ appWorkspace: 'customAppPath/*', - workspaceEnabled: false + workspaceEnabled: false, + workspacePackages: [] }); const memFs = create(createStorage()); const fs = await enableCdsUi5Plugin(__dirname, memFs); diff --git a/packages/project-access/src/index.ts b/packages/project-access/src/index.ts index 33528c3b14..b22a64984f 100644 --- a/packages/project-access/src/index.ts +++ b/packages/project-access/src/index.ts @@ -1,4 +1,4 @@ -export { FileName, DirName, FioriToolsSettings } from './constants'; +export { FileName, DirName, FioriToolsSettings, MinCdsVersionUi5Plugin } from './constants'; export { getFilePaths } from './file'; export { addPackageDevDependency, @@ -50,8 +50,6 @@ export { updatePackageScript, hasCdsPluginUi5, getWorkspaceInfo, - getWorkspacePackages, - minCdsVersion, hasMinCdsVersion, checkCdsUi5PluginEnabled } from './project'; diff --git a/packages/project-access/src/project/cap.ts b/packages/project-access/src/project/cap.ts index 14bad6e8a6..d2b30fc3fa 100644 --- a/packages/project-access/src/project/cap.ts +++ b/packages/project-access/src/project/cap.ts @@ -917,12 +917,12 @@ export async function checkCdsUi5PluginEnabled( export async function getWorkspaceInfo( basePath: string, packageJson: Package -): Promise<{ appWorkspace: string; workspaceEnabled: boolean }> { +): Promise<{ appWorkspace: string; workspaceEnabled: boolean; workspacePackages: string[] }> { const capPaths = await getCapCustomPaths(basePath); const appWorkspace = capPaths.app.endsWith('/') ? `${capPaths.app}*` : `${capPaths.app}/*`; const workspacePackages = getWorkspacePackages(packageJson) ?? []; const workspaceEnabled = workspacePackages.includes(appWorkspace); - return { appWorkspace, workspaceEnabled }; + return { appWorkspace, workspaceEnabled, workspacePackages }; } /** @@ -933,7 +933,7 @@ export async function getWorkspaceInfo( * @param packageJson - the parsed package.json * @returns ref to the packages in workspaces or undefined */ -export function getWorkspacePackages(packageJson: Package): string[] | undefined { +function getWorkspacePackages(packageJson: Package): string[] | undefined { let workspacePackages: string[] | undefined; if (Array.isArray(packageJson.workspaces)) { workspacePackages = packageJson.workspaces; diff --git a/packages/project-access/src/project/index.ts b/packages/project-access/src/project/index.ts index 908340388a..ad1984f520 100644 --- a/packages/project-access/src/project/index.ts +++ b/packages/project-access/src/project/index.ts @@ -16,8 +16,6 @@ export { toReferenceUri, hasCdsPluginUi5, getWorkspaceInfo, - getWorkspacePackages, - minCdsVersion, hasMinCdsVersion, checkCdsUi5PluginEnabled } from './cap'; From 8ae391b8f4bf13b033dff330acf0431261821321 Mon Sep 17 00:00:00 2001 From: D048415 Date: Mon, 24 Feb 2025 10:36:58 +0100 Subject: [PATCH 14/17] delete 'hasCdsPluginUi5' in favor of new export 'hasDependency' --- .../src/preview-config/package-json.ts | 7 ++-- .../src/preview-config/prerequisites.ts | 32 ++++++++----------- .../src/cap-config/package-json.ts | 6 ++-- packages/project-access/src/index.ts | 2 +- packages/project-access/src/project/cap.ts | 13 ++------ packages/project-access/src/project/index.ts | 3 +- 6 files changed, 23 insertions(+), 40 deletions(-) diff --git a/packages/app-config-writer/src/preview-config/package-json.ts b/packages/app-config-writer/src/preview-config/package-json.ts index caeca66a7d..6b9ae47217 100644 --- a/packages/app-config-writer/src/preview-config/package-json.ts +++ b/packages/app-config-writer/src/preview-config/package-json.ts @@ -3,7 +3,7 @@ import { extractYamlConfigFileName, isTestPath } from './ui5-yaml'; import { generateVariantsConfig } from '../variants-config'; import type { Editor } from 'mem-fs-editor'; import type { ToolsLogger } from '@sap-ux/logger'; -import type { Package } from '@sap-ux/project-access'; +import { type Package, hasDependency } from '@sap-ux/project-access'; import type { FlpConfig } from '@sap-ux/preview-middleware'; import type { Script } from './ui5-yaml'; @@ -22,11 +22,8 @@ export function ensurePreviewMiddlewareDependency(fs: Editor, basePath: string): return; } - const hasDependency = (dependency: string): boolean => - !!packageJson?.devDependencies?.[dependency] || !!packageJson?.dependencies?.[dependency]; - const dependencies = ['@sap-ux/preview-middleware', '@sap/ux-ui5-tooling']; - if (dependencies.some((dependency) => hasDependency(dependency))) { + if (dependencies.some((dependency) => hasDependency(packageJson, dependency))) { return; } diff --git a/packages/app-config-writer/src/preview-config/prerequisites.ts b/packages/app-config-writer/src/preview-config/prerequisites.ts index e093067365..1c42f8a04b 100644 --- a/packages/app-config-writer/src/preview-config/prerequisites.ts +++ b/packages/app-config-writer/src/preview-config/prerequisites.ts @@ -1,6 +1,12 @@ import { join } from 'path'; import type { Editor } from 'mem-fs-editor'; -import { type Package, findCapProjectRoot, FileName, checkCdsUi5PluginEnabled } from '@sap-ux/project-access'; +import { + type Package, + findCapProjectRoot, + FileName, + checkCdsUi5PluginEnabled, + hasDependency +} from '@sap-ux/project-access'; import type { ToolsLogger } from '@sap-ux/logger'; import { satisfies, valid } from 'semver'; @@ -85,10 +91,7 @@ export async function checkPrerequisites( throw Error(`File '${FileName.Package}' not found at '${basePath}'`); } - const sapui5BestpracticeBuildExists = - !!packageJson?.devDependencies?.[packageName.SAP_GRUNT_SAPUI5_BESTPRACTICE_BUILD] || - !!packageJson?.dependencies?.[packageName.SAP_GRUNT_SAPUI5_BESTPRACTICE_BUILD]; - if (sapui5BestpracticeBuildExists) { + if (hasDependency(packageJson, packageName.SAP_GRUNT_SAPUI5_BESTPRACTICE_BUILD)) { logger?.error( `Conversion from '${packageName.SAP_GRUNT_SAPUI5_BESTPRACTICE_BUILD}' is not supported. You must migrate to UI5 CLI version 3.0.0 or higher. For more information, see https://sap.github.io/ui5-tooling/v3/updates/migrate-v3.` ); @@ -109,30 +112,23 @@ export async function checkPrerequisites( prerequisitesMet = false; } - const ui5MiddlewareMockserverExists = - !!packageJson?.devDependencies?.[packageName.SAP_UX_UI5_MIDDLEWARE_FE_MOCKSERVER] || - !!packageJson?.dependencies?.[packageName.SAP_UX_UI5_MIDDLEWARE_FE_MOCKSERVER]; - if (!ui5MiddlewareMockserverExists && !(await isUsingCdsPluginUi5(basePath, fs))) { + if ( + !hasDependency(packageJson, packageName.SAP_UX_UI5_MIDDLEWARE_FE_MOCKSERVER) && + !(await isUsingCdsPluginUi5(basePath, fs)) + ) { logger?.error( `Conversion from 'sap/ui/core/util/MockServer' or '@sap/ux-ui5-fe-mockserver-middleware' is not supported. You must migrate to '${packageName.SAP_UX_UI5_MIDDLEWARE_FE_MOCKSERVER}' first. For more information, see https://www.npmjs.com/package/@sap-ux/ui5-middleware-fe-mockserver.` ); prerequisitesMet = false; } - if ( - convertTests && - (packageJson?.devDependencies?.[packageName.KARMA_UI5] ?? packageJson?.dependencies?.[packageName.KARMA_UI5]) - ) { + if (convertTests && hasDependency(packageJson, packageName.KARMA_UI5)) { logger?.warn( "This app seems to use Karma as a test runner. Please note that the converter does not convert any Karma configuration files. Please update your karma configuration ('ui5.configPath' and 'ui5.testpage') according to the new virtual endpoints after the conversion." ); } - if ( - convertTests && - (packageJson?.devDependencies?.[packageName.WDIO_QUNIT_SERVICE] ?? - packageJson?.dependencies?.[packageName.WDIO_QUNIT_SERVICE]) - ) { + if (convertTests && hasDependency(packageJson, packageName.WDIO_QUNIT_SERVICE)) { logger?.warn( 'This app seems to use the WebdriverIO QUnit Service as a test runner. Please note that the converter does not convert any WebdriverIO configuration files. Please update your WebdriverIO QUnit Service test paths according to the new virtual endpoints after the conversion.' ); diff --git a/packages/cap-config-writer/src/cap-config/package-json.ts b/packages/cap-config-writer/src/cap-config/package-json.ts index 6529cd871a..1fa099b336 100644 --- a/packages/cap-config-writer/src/cap-config/package-json.ts +++ b/packages/cap-config-writer/src/cap-config/package-json.ts @@ -1,9 +1,9 @@ import { type Package, - hasCdsPluginUi5, getWorkspaceInfo, MinCdsVersionUi5Plugin, - hasMinCdsVersion + hasMinCdsVersion, + hasDependency } from '@sap-ux/project-access'; const minCdsPluginUi5Version = '0.9.3'; @@ -49,7 +49,7 @@ export async function enableWorkspaces(basePath: string, packageJson: Package): * @param packageJson - the parsed package.json */ export function addCdsPluginUi5(packageJson: Package): void { - if (!hasCdsPluginUi5(packageJson)) { + if (!hasDependency(packageJson, 'cds-plugin-ui5')) { packageJson.devDependencies ??= {}; packageJson.devDependencies['cds-plugin-ui5'] = `^${minCdsPluginUi5Version}`; } diff --git a/packages/project-access/src/index.ts b/packages/project-access/src/index.ts index b22a64984f..ed09cff34d 100644 --- a/packages/project-access/src/index.ts +++ b/packages/project-access/src/index.ts @@ -48,7 +48,6 @@ export { refreshSpecificationDistTags, toReferenceUri, updatePackageScript, - hasCdsPluginUi5, getWorkspaceInfo, hasMinCdsVersion, checkCdsUi5PluginEnabled @@ -56,3 +55,4 @@ export { export { execNpmCommand } from './command/npm-command'; export * from './types'; export * from './library'; +export { hasDependency } from './project'; diff --git a/packages/project-access/src/project/cap.ts b/packages/project-access/src/project/cap.ts index d2b30fc3fa..7ea99d831c 100644 --- a/packages/project-access/src/project/cap.ts +++ b/packages/project-access/src/project/cap.ts @@ -30,6 +30,7 @@ import type { CdsUi5PluginInfo } from '../types'; import { coerce, gte, satisfies } from 'semver'; import { create as createStorage } from 'mem-fs'; import { create } from 'mem-fs-editor'; +import { hasDependency } from './dependencies'; interface CdsFacade { env: { for: (mode: string, path: string) => CdsEnvironment }; @@ -900,7 +901,7 @@ export async function checkCdsUi5PluginEnabled( ? satisfies(cdsVersionInfo?.version, `>=${MinCdsVersionUi5Plugin}`) : satisfiesMinCdsVersion(packageJson), isWorkspaceEnabled: workspaceEnabled, - hasCdsUi5Plugin: hasCdsPluginUi5(packageJson), + hasCdsUi5Plugin: hasDependency(packageJson, 'cds-plugin-ui5'), isCdsUi5PluginEnabled: false }; cdsInfo.isCdsUi5PluginEnabled = cdsInfo.hasMinCdsVersion && cdsInfo.isWorkspaceEnabled && cdsInfo.hasCdsUi5Plugin; @@ -943,16 +944,6 @@ function getWorkspacePackages(packageJson: Package): string[] | undefined { return workspacePackages; } -/** - * Check if devDependency to cds-plugin-ui5 is present in package.json. - * - * @param packageJson - the parsed package.json - * @returns true: devDependency to cds-plugin-ui5 exists; false: devDependency to cds-plugin-ui5 does not exist - */ -export function hasCdsPluginUi5(packageJson: Package): boolean { - return !!packageJson.devDependencies?.['cds-plugin-ui5']; -} - /** * Check if package.json has version or version range that satisfies the minimum version of @sap/cds. * diff --git a/packages/project-access/src/project/index.ts b/packages/project-access/src/project/index.ts index ad1984f520..db92ae9a51 100644 --- a/packages/project-access/src/project/index.ts +++ b/packages/project-access/src/project/index.ts @@ -14,13 +14,12 @@ export { isCapNodeJsProject, readCapServiceMetadataEdmx, toReferenceUri, - hasCdsPluginUi5, getWorkspaceInfo, hasMinCdsVersion, checkCdsUi5PluginEnabled } from './cap'; export { filterDataSourcesByType } from './service'; -export { addPackageDevDependency, getNodeModulesPath } from './dependencies'; +export { addPackageDevDependency, getNodeModulesPath, hasDependency } from './dependencies'; export { getCapI18nFolderNames, getI18nPropertiesPaths, getI18nBundles } from './i18n'; export { getAppProgrammingLanguage, From 928db26a62a34ed0995f9ae6d5b9466970fd0d27 Mon Sep 17 00:00:00 2001 From: Klaus Keller Date: Tue, 25 Feb 2025 12:28:23 -0800 Subject: [PATCH 15/17] fix: unit test for card --- .../cards-editor-middleware/test/unit/index.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/cards-editor-middleware/test/unit/index.test.ts b/packages/cards-editor-middleware/test/unit/index.test.ts index 384814881a..ad470635ea 100644 --- a/packages/cards-editor-middleware/test/unit/index.test.ts +++ b/packages/cards-editor-middleware/test/unit/index.test.ts @@ -11,6 +11,7 @@ import path from 'path'; import os from 'os'; jest.mock('fs', () => ({ + ...jest.requireActual('fs'), promises: { ...jest.requireActual('fs').promises, writeFile: jest.fn(), @@ -62,6 +63,18 @@ async function getTestServer(fixture?: string, configuration: Partial = {}) } describe('sap-cards-generator', () => { + // beforeAll(() => { + // jest.mock('fs', () => ({ + // promises: { + // ...jest.requireActual('fs').promises, + // readFile: jest.fn(), + // writeFile: jest.fn(), + // access: jest.fn(), + // mkdir: jest.fn() + // } + // })); + // }); + describe('Middleware for serving static files', () => { test('GET /test/flpGeneratorSandbox.html', async () => { const server = await getTestServer('lrop-v4'); From b73fa300194b6f143b8f471d9bff6ff2bbf21fc4 Mon Sep 17 00:00:00 2001 From: Klaus Keller Date: Tue, 25 Feb 2025 12:33:42 -0800 Subject: [PATCH 16/17] fix: unit test for card, remove code to try --- .../cards-editor-middleware/test/unit/index.test.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/packages/cards-editor-middleware/test/unit/index.test.ts b/packages/cards-editor-middleware/test/unit/index.test.ts index ad470635ea..7ddafd7783 100644 --- a/packages/cards-editor-middleware/test/unit/index.test.ts +++ b/packages/cards-editor-middleware/test/unit/index.test.ts @@ -63,18 +63,6 @@ async function getTestServer(fixture?: string, configuration: Partial = {}) } describe('sap-cards-generator', () => { - // beforeAll(() => { - // jest.mock('fs', () => ({ - // promises: { - // ...jest.requireActual('fs').promises, - // readFile: jest.fn(), - // writeFile: jest.fn(), - // access: jest.fn(), - // mkdir: jest.fn() - // } - // })); - // }); - describe('Middleware for serving static files', () => { test('GET /test/flpGeneratorSandbox.html', async () => { const server = await getTestServer('lrop-v4'); From 93f2f9d4ab3f162a358f8d28981d820609d8c8eb Mon Sep 17 00:00:00 2001 From: D048415 Date: Wed, 26 Feb 2025 08:55:12 +0100 Subject: [PATCH 17/17] fix sonar issue --- packages/project-access/src/project/cap.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/project-access/src/project/cap.ts b/packages/project-access/src/project/cap.ts index 7ea99d831c..35a8d26a12 100644 --- a/packages/project-access/src/project/cap.ts +++ b/packages/project-access/src/project/cap.ts @@ -12,7 +12,8 @@ import type { Package, ServiceDefinitions, ServiceInfo, - CdsVersionInfo + CdsVersionInfo, + CdsUi5PluginInfo } from '../types'; import { deleteDirectory, @@ -26,7 +27,6 @@ import { } from '../file'; import { loadModuleFromProject } from './module-loader'; import { findCapProjectRoot } from './search'; -import type { CdsUi5PluginInfo } from '../types'; import { coerce, gte, satisfies } from 'semver'; import { create as createStorage } from 'mem-fs'; import { create } from 'mem-fs-editor';