Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app-config-writer): wrong prerequisites check in convert preview-config #2922

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

heimwege
Copy link
Contributor

@heimwege heimwege commented Feb 14, 2025

cds-plugin-ui5 is currently being searched in package.json of the app to be converted but must be searched for in CAP root package.json.

This fix currently leads to an exception in project-access checkFilesInSrvFolder in case the CAP srv folder contains sub folders. (fixed in #2923)

Depends on #2926 being merged ✅

Copy link

changeset-bot bot commented Feb 14, 2025

🦋 Changeset detected

Latest commit: f63da1f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@sap-ux/app-config-writer Patch
@sap-ux/create Patch
@sap-ux/flp-config-sub-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@heimwege
Copy link
Contributor Author

The new sonar issue seems to be a false positive because casting to Package | undefined is for sure a different type than the inferred JSONSchema7Object | undefined

@heimwege heimwege marked this pull request as ready for review February 17, 2025 08:06
@@ -35,6 +45,26 @@ function isLowerThanMinimalVersion(
return !satisfies(minVersionInfo, versionInfo);
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @heimwege, there is already a check for cds plugin in module @sap-ux/cap-config-writer checkCdsUi5PluginEnabled(), see:

export async function checkCdsUi5PluginEnabled(
basePath: string,
fs?: Editor,
moreInfo?: boolean,
cdsVersionInfo?: CdsVersionInfo
): Promise<boolean | CdsUi5PluginInfo> {
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 };

I don't think it is a good idea to have a dependency from @sap-ux/app-config-writer to @sap-ux/cap-config-writer, my proposal would be to move the function to @sap-ux/project-access and call it from there in all places.

Copy link
Contributor Author

@heimwege heimwege Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Klaus-Keller done in 104f694 ff. Please check carefully as it was a lot of methods and tests to be adjusted

@heimwege heimwege requested a review from a team as a code owner February 21, 2025 16:21
@@ -1,4 +1,4 @@
export { checkCdsUi5PluginEnabled, enableCdsUi5Plugin, satisfiesMinCdsVersion } from './cap-config';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@heimwege, I'm wondering whether we should keep the export checkCdsUi5PluginEnabled for backward compatibility reasons. We would then import and re-export the function. I know of other modules that use the function, search in tools suite for checkCdsUi5PluginEnabled. From a semver perspective this would be breaking changes and require a major version increase, but as we are on a 0.x.y version here we could do such incompatible changes. We just need to be careful and adjust all consumers, not only in this repo.
Let me know what you think.

@@ -0,0 +1,5 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sap-ux/project-access and @sap-ux/ui5-application-inquirer are missing in changeset

@@ -47,7 +47,13 @@ export {
readUi5Yaml,
refreshSpecificationDistTags,
toReferenceUri,
updatePackageScript
updatePackageScript,
hasCdsPluginUi5,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to export this? Is it not also part of checkCdsUi5PluginEnabled?

Comment on lines +52 to +53
getWorkspaceInfo,
getWorkspacePackages,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we combine getWorkspaceInfo and getWorkspacePackages or add them to results to checkCdsUi5PluginEnabled?

hasCdsPluginUi5,
getWorkspaceInfo,
getWorkspacePackages,
minCdsVersion,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we add this to constants.ts and change it to Uppercase? Also a more speakable name might help, like MinCdsVersionUi5Plugin?

getWorkspaceInfo,
getWorkspacePackages,
minCdsVersion,
hasMinCdsVersion,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a separate export for this, info is also included in checkCdsUi5PluginEnabled

* @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'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have already

export const hasDependency = (packageJson: Package, dependency: string): boolean =>
!!(packageJson.dependencies?.[dependency] ?? packageJson.devDependencies?.[dependency]);

which checks for both: dependencies and devDependencies which I think is even better, if someone decides to have cds-plgin-ui5 as dependency we still should enable tooling for it

Co-authored-by: Klaus Keller <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app-config-writer @sap-ux/app-config-writer bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants