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

feat: make SfProject optional #638

Merged
merged 11 commits into from
Aug 15, 2024
Merged

feat: make SfProject optional #638

merged 11 commits into from
Aug 15, 2024

Conversation

cristiand391
Copy link
Member

@cristiand391 cristiand391 commented Aug 12, 2024

This PR updates some packaging classes to make SfProject optional.

See: salesforcecli/plugin-packaging#771

Most of these classes were taking an SfProject instance along with a possible package ID or alias (defined in sfdx-project.json). By making SfProject optional, consumers of the library can call it without having to create a dummy sfdx-project.

Note for review:
there are classes/methods that do need a project b/c they write stuff on it after a package operation, most of these aren't affected by this change (PackageVersion.updateProjectWithPackageVersion was updated to throw if there's no project).

QA:

Check the plugin-packaging PR linked above, with this branch linked (or the prerelease) you should be able to use the listed commands outside a project.

@W-16286213@

@cristiand391 cristiand391 marked this pull request as ready for review August 13, 2024 14:01
@cristiand391 cristiand391 changed the title feat: allow to classes to run outside an sfdx project feat: make SfProject optional Aug 13, 2024
this.options.project.getPackageIdFromAlias(this.options.packageAliasOrId) ?? this.options.packageAliasOrId;
packageId = this.options.project
? this.options.project.getPackageIdFromAlias(this.options.packageAliasOrId) ?? this.options.packageAliasOrId
: this.options.packageAliasOrId;
if (packageId === this.options.packageAliasOrId) {
throw messages.createError('packageAliasNotFound', [this.options.packageAliasOrId]);
Copy link
Member Author

Choose a reason for hiding this comment

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

the constructor will fail if you pass an alias without project or an invalid alias with a project instance.

options?: PackageVersionListOptions
): Promise<PackageVersionListResult[]> {
// resolve/verify packages
const packages = options?.packages?.map((pkg) => {
const id = project.getPackageIdFromAlias(pkg) ?? pkg;
const id = project ? project.getPackageIdFromAlias(pkg) ?? pkg : pkg;
Copy link
Member Author

Choose a reason for hiding this comment

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

these IDs are validated below

@mshanemc
Copy link
Contributor

QA for that last commit: from the plugin using the prerel,

✅ ran with an alias and got the good helpful error message about the missing project
✅ ran with a valid Id and it worked fine

@mshanemc mshanemc merged commit 11c5afb into main Aug 15, 2024
7 checks passed
@mshanemc mshanemc deleted the cd/optional-project-refactor branch August 15, 2024 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants