Skip to content

Commit 11c5afb

Browse files
cristiand391svc-cli-botmshanemc
authored
feat: make SfProject optional (#638)
* feat make `SfProject` optional * fix(pv): validate id --------- Co-authored-by: svc-cli-bot <Svc_cli_bot@salesforce.com> Co-authored-by: mshanemc <shane.mclaughlin@salesforce.com>
1 parent 3e14f9b commit 11c5afb

11 files changed

+804
-1734
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
externalProjectGitUrl: 'https://github.com/salesforcecli/plugin-packaging'
3737
command: 'yarn test:nuts:package'
3838
os: ${{ matrix.os }}
39-
preSwapCommands: 'yarn upgrade @salesforce/core; npx yarn-deduplicate; yarn install'
39+
preSwapCommands: 'yarn upgrade @salesforce/core; yarn upgrade @jsforce/jsforce-node@latest; npx yarn-deduplicate; yarn install'
4040
preExternalBuildCommands: 'npm why @salesforce/core --json'
4141
useCache: false
4242
secrets: inherit

CHANGELOG.md

+725-1,670
Large diffs are not rendered by default.

messages/package_version.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@ The %s %s is invalid, as a corresponding %s was not found
66

77
The provided alias or ID: [%s] could not be resolved to a valid package version ID (05i) or subscriber package version ID (04t).
88

9+
# errorInvalidPackageVersionIdNoProject
10+
11+
The provided alias or ID: [%s] could not be resolved to a valid package version ID (05i) or subscriber package version ID (04t).
12+
13+
# errorInvalidPackageVersionIdNoProject.actions
14+
15+
If you are using a package alias, make sure you are inside your sfdx project and it's defined in the `packageDirectories` section in `sfdx-project.json`
16+
917
# packageAliasNotFound
1018

11-
The provided package id: [%s] could not be resolved to an alias.
19+
The provided package ID: [%s] could not be resolved to an alias.
1220

1321
# createResultIdCannotBeEmpty
1422

@@ -21,3 +29,9 @@ Could not fetch the subscriber package version ID (04t).
2129
# maxPackage2VersionRecords
2230

2331
The maximum result size (2000) was reached when querying the Package2Version SObject. This means there could be more records that were not returned by the query. If all records are required you may have to break the query into multiple requests filtered by date, then aggregate the results.
32+
33+
# errors.RequiresProject
34+
35+
This method expects an sfdx project to be available to write the new package version data in it.
36+
Make sure to pass `options.project` when instantiating `PackageVersion`.
37+
https://forcedotcom.github.io/packaging/classes/package_packageVersion.PackageVersion.html#constructor

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
],
4343
"dependencies": {
4444
"@jsforce/jsforce-node": "^3.4.1",
45-
"@salesforce/core": "^8.3.0",
45+
"@salesforce/core": "^8.4.0",
4646
"@salesforce/kit": "^3.2.1",
4747
"@salesforce/schemas": "^1.9.0",
48-
"@salesforce/source-deploy-retrieve": "^12.1.12",
48+
"@salesforce/source-deploy-retrieve": "^12.4.0",
4949
"@salesforce/ts-types": "^2.0.11",
5050
"@salesforce/types": "^1.2.0",
5151
"fast-xml-parser": "^4.4.1",
@@ -61,7 +61,7 @@
6161
"@salesforce/dev-scripts": "^10.2.9",
6262
"@types/globby": "^9.1.0",
6363
"@types/jszip": "^3.4.1",
64-
"eslint-plugin-sf-plugin": "^1.20.1",
64+
"eslint-plugin-sf-plugin": "^1.20.4",
6565
"shelljs": "0.8.5",
6666
"ts-node": "^10.9.2",
6767
"typescript": "^5.5.4"

src/interfaces/packagingInterfacesAndType.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export type IPackageVersion2GP = {
4242

4343
export type PackageOptions = {
4444
connection: Connection;
45-
project: SfProject;
45+
project?: SfProject;
4646
packageAliasOrId: string;
4747
};
4848

@@ -288,7 +288,7 @@ export type PackageVersionOptions = {
288288
* 3. Alias for a 04t or 05i, defined in sfdx-project.json
289289
*/
290290
idOrAlias: string;
291-
project: SfProject;
291+
project?: SfProject;
292292
};
293293

294294
export type SubscriberPackageVersionOptions = {
@@ -431,7 +431,7 @@ export type PackageAncestryNodeData = {
431431

432432
export type PackageAncestryOptions = {
433433
packageId: string;
434-
project: SfProject;
434+
project?: SfProject;
435435
connection: Connection;
436436
};
437437

src/package/package.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ export class Package {
8383
public constructor(private options: PackageOptions) {
8484
let packageId = this.options.packageAliasOrId;
8585
if (!packageId.startsWith(packagePrefixes.PackageId)) {
86-
packageId =
87-
this.options.project.getPackageIdFromAlias(this.options.packageAliasOrId) ?? this.options.packageAliasOrId;
86+
packageId = this.options.project
87+
? this.options.project.getPackageIdFromAlias(this.options.packageAliasOrId) ?? this.options.packageAliasOrId
88+
: this.options.packageAliasOrId;
8889
if (packageId === this.options.packageAliasOrId) {
8990
throw messages.createError('packageAliasNotFound', [this.options.packageAliasOrId]);
9091
}
@@ -136,12 +137,12 @@ export class Package {
136137
*/
137138
public static async listVersions(
138139
connection: Connection,
139-
project: SfProject,
140+
project?: SfProject,
140141
options?: PackageVersionListOptions
141142
): Promise<PackageVersionListResult[]> {
142143
// resolve/verify packages
143144
const packages = options?.packages?.map((pkg) => {
144-
const id = project.getPackageIdFromAlias(pkg) ?? pkg;
145+
const id = project ? project.getPackageIdFromAlias(pkg) ?? pkg : pkg;
145146

146147
// validate ID
147148
if (id.startsWith('0Ho')) {
@@ -166,7 +167,7 @@ export class Package {
166167
*/
167168
public static async getAncestry(
168169
packageId: string,
169-
project: SfProject,
170+
project: SfProject | undefined,
170171
connection: Connection
171172
): Promise<PackageAncestry> {
172173
return PackageAncestry.create({

src/package/packageAncestry.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ export class PackageAncestry extends AsyncCreatable<PackageAncestryOptions> {
231231

232232
private async getRootsFromRequestedId(): Promise<PackageAncestryNode[]> {
233233
let roots: PackageAncestryNode[] = [];
234-
this.packageId = this.options.project.getPackageIdFromAlias(this.options.packageId) ?? this.options.packageId;
234+
this.packageId = this.options.project
235+
? this.options.project.getPackageIdFromAlias(this.options.packageId) ?? this.options.packageId
236+
: this.options.packageId;
235237
switch (this.requestedPackageId?.slice(0, 3)) {
236238
case '0Ho':
237239
pkgUtils.validateId(pkgUtils.BY_LABEL.PACKAGE_ID, this.requestedPackageId);

src/package/packageDelete.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import { PackageSaveResult } from '../interfaces';
1111

1212
export async function deletePackage(
1313
idOrAlias: string,
14-
project: SfProject,
14+
project: SfProject | undefined,
1515
connection: Connection,
1616
undelete: boolean
1717
): Promise<PackageSaveResult> {
18-
const packageId = project.getPackageIdFromAlias(idOrAlias) ?? idOrAlias;
18+
const packageId = project ? project.getPackageIdFromAlias(idOrAlias) ?? idOrAlias : idOrAlias;
1919
validateId(BY_LABEL.PACKAGE_ID, packageId);
2020

2121
const request = { Id: packageId, IsDeprecated: !undelete };

src/package/packageVersion.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export type Package2VersionQueryOptions = {
117117
* `new PackageVersion({connection, project, idOrAlias}).promote();`
118118
*/
119119
export class PackageVersion {
120-
private readonly project: SfProject;
120+
private readonly project?: SfProject;
121121
private readonly connection: Connection;
122122

123123
private data?: Package2Version;
@@ -619,6 +619,9 @@ export class PackageVersion {
619619
}
620620

621621
private async updateProjectWithPackageVersion(results: PackageVersionCreateRequestResult): Promise<void> {
622+
if (!this.project) {
623+
throw new SfError('errors.RequiresProject');
624+
}
622625
if (!env.getBoolean('SF_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_VERSION_CREATE')) {
623626
// get the newly created package version from the server
624627
const versionResult = (
@@ -659,6 +662,26 @@ export class PackageVersion {
659662
}
660663

661664
private resolveId(): string {
662-
return this.project.getPackageIdFromAlias(this.options.idOrAlias) ?? this.options.idOrAlias;
665+
let packageId = this.options.idOrAlias;
666+
667+
if (packageId.startsWith('04t') || packageId.startsWith('05i')) {
668+
return packageId;
669+
}
670+
671+
if (!this.options.project) {
672+
throw messages.createError('errorInvalidPackageVersionIdNoProject', [this.options.idOrAlias]);
673+
}
674+
675+
packageId = this.options.project.getPackageIdFromAlias(this.options.idOrAlias) ?? this.options.idOrAlias;
676+
677+
if (packageId === this.options.idOrAlias) {
678+
throw messages.createError('packageAliasNotFound', [this.options.idOrAlias]);
679+
}
680+
// validate the resolved alias value from sfdx-project is a valid ID
681+
if (packageId.startsWith('04t') || packageId.startsWith('05i')) {
682+
return packageId;
683+
} else {
684+
throw messages.createError('errorInvalidPackageVersionId', [this.options.idOrAlias]);
685+
}
663686
}
664687
}

src/package/packageVersionReport.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function constructQuery(connectionVersion: number, verbose: boolean): string {
7474
export async function getPackageVersionReport(options: {
7575
packageVersionId: string;
7676
connection: Connection;
77-
project: SfProject;
77+
project?: SfProject;
7878
verbose: boolean;
7979
}): Promise<PackageVersionReportResult[]> {
8080
getLogger().debug(`entering getPackageVersionReport(${util.inspect(options, { depth: null })})`);

yarn.lock

+20-45
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,10 @@
523523
strip-ansi "6.0.1"
524524
ts-retry-promise "^0.8.1"
525525

526-
"@salesforce/core@^8.2.3", "@salesforce/core@^8.2.8", "@salesforce/core@^8.3.0":
527-
version "8.3.0"
528-
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-8.3.0.tgz#b61fb6c0c0dec5664ce12ba62ebe35136ae33878"
529-
integrity sha512-HZchC42oGJ5RQsG9HpAb1bT7ohjB31ATDz46ryMvLngMmrfHnyzv2mlIi6UdYkJ/2meH2BJkibHi8paPrtF+/A==
526+
"@salesforce/core@^8.2.3", "@salesforce/core@^8.3.0", "@salesforce/core@^8.4.0":
527+
version "8.4.0"
528+
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-8.4.0.tgz#d2ddfe07994c42b1e917e581e9cf47ad27b97a93"
529+
integrity sha512-P+n0+Sp+v6voLTShW2E5sdF7gCUxEXJjNcc9Jtto0ZMyQesmQJ6WGpWmAuRoi+BVYc8OPSlEffndaYDAo/u73g==
530530
dependencies:
531531
"@jsforce/jsforce-node" "^3.4.0"
532532
"@salesforce/kit" "^3.1.6"
@@ -601,13 +601,13 @@
601601
resolved "https://registry.yarnpkg.com/@salesforce/schemas/-/schemas-1.9.0.tgz#ba477a112653a20b4edcf989c61c57bdff9aa3ca"
602602
integrity sha512-LiN37zG5ODT6z70sL1fxF7BQwtCX9JOWofSU8iliSNIM+WDEeinnoFtVqPInRSNt8I0RiJxIKCrqstsmQRBNvA==
603603

604-
"@salesforce/source-deploy-retrieve@^12.1.12":
605-
version "12.1.12"
606-
resolved "https://registry.yarnpkg.com/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-12.1.12.tgz#1a8b1cc54daa16ecb8c5abbbbb67c3bd367d8a41"
607-
integrity sha512-+Kbc62eB4epGBB6rr+EXzrSTmtBOXD1RNc5AIhnhnYSwL+WNIln5GOAmtZWVa/YOihjc1jTQF1/uHG4dKGCG9w==
604+
"@salesforce/source-deploy-retrieve@^12.4.0":
605+
version "12.4.0"
606+
resolved "https://registry.yarnpkg.com/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-12.4.0.tgz#7e5a72b1d7b559eaa7f6f333ee212380b6316542"
607+
integrity sha512-gvTEjLPbNRt62GEKvejt/f1TtG6Zx8JPd/5BYjnXyEJu8BeOy5kL4zJm9GD3ZiTzBnPGHLzfVL09JjWfNBbo0A==
608608
dependencies:
609-
"@salesforce/core" "^8.2.8"
610-
"@salesforce/kit" "^3.1.6"
609+
"@salesforce/core" "^8.4.0"
610+
"@salesforce/kit" "^3.2.1"
611611
"@salesforce/ts-types" "^2.0.12"
612612
fast-levenshtein "^3.0.0"
613613
fast-xml-parser "^4.4.1"
@@ -966,7 +966,7 @@
966966
"@typescript-eslint/typescript-estree" "6.21.0"
967967
semver "^7.5.4"
968968

969-
"@typescript-eslint/utils@^7.17.0":
969+
"@typescript-eslint/utils@^7.18.0":
970970
version "7.18.0"
971971
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-7.18.0.tgz#bca01cde77f95fc6a8d5b0dbcbfb3d6ca4be451f"
972972
integrity sha512-kK0/rNa2j74XuHVcoCZxdFBMF+aq/vH83CXAOHieC+2Gis4mF8jJXT5eAfyD3K0sAxtPuwxaIOIOvhwzVDt/kw==
@@ -2151,13 +2151,13 @@ eslint-plugin-jsdoc@^46.10.1:
21512151
semver "^7.5.4"
21522152
spdx-expression-parse "^4.0.0"
21532153

2154-
eslint-plugin-sf-plugin@^1.20.1:
2155-
version "1.20.1"
2156-
resolved "https://registry.yarnpkg.com/eslint-plugin-sf-plugin/-/eslint-plugin-sf-plugin-1.20.1.tgz#bdde7cd6b62df1f707770273768a4fecdf901cfa"
2157-
integrity sha512-Mf4gC4I87h+coOpwh2uIRbhCzTGDGX7QskLGzst7fktzXkCwsIXMVic6NHPWSWIA6U8IU4g5MwMiZjuXqJTwdA==
2154+
eslint-plugin-sf-plugin@^1.20.4:
2155+
version "1.20.4"
2156+
resolved "https://registry.yarnpkg.com/eslint-plugin-sf-plugin/-/eslint-plugin-sf-plugin-1.20.4.tgz#9d99f76cd316939222231f74bb65fc76ddd7fee4"
2157+
integrity sha512-lpuF4XGVenrQotd0cUZhgZ4rLDubytWPJBzmMCIovZdqyGYzgD68MGofDSLFzmbhKfa2fX1Pndljru6/GjVyGQ==
21582158
dependencies:
2159-
"@salesforce/core" "^8.2.3"
2160-
"@typescript-eslint/utils" "^7.17.0"
2159+
"@salesforce/core" "^8.3.0"
2160+
"@typescript-eslint/utils" "^7.18.0"
21612161

21622162
eslint-plugin-unicorn@^50.0.1:
21632163
version "50.0.1"
@@ -5048,16 +5048,7 @@ srcset@^5.0.0:
50485048
resolved "https://registry.yarnpkg.com/srcset/-/srcset-5.0.0.tgz#9df6c3961b5b44a02532ce6ae4544832609e2e3f"
50495049
integrity sha512-SqEZaAEhe0A6ETEa9O1IhSPC7MdvehZtCnTR0AftXk3QhY2UNgb+NApFOUPZILXk/YTDfFxMTNJOBpzrJsEdIA==
50505050

5051-
"string-width-cjs@npm:string-width@^4.2.0":
5052-
version "4.2.3"
5053-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
5054-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
5055-
dependencies:
5056-
emoji-regex "^8.0.0"
5057-
is-fullwidth-code-point "^3.0.0"
5058-
strip-ansi "^6.0.1"
5059-
5060-
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
5051+
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
50615052
version "4.2.3"
50625053
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
50635054
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -5116,14 +5107,7 @@ string_decoder@~1.1.1:
51165107
dependencies:
51175108
safe-buffer "~5.1.0"
51185109

5119-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
5120-
version "6.0.1"
5121-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
5122-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
5123-
dependencies:
5124-
ansi-regex "^5.0.1"
5125-
5126-
strip-ansi@6.0.1, strip-ansi@^6.0.0, strip-ansi@^6.0.1:
5110+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@6.0.1, strip-ansi@^6.0.0, strip-ansi@^6.0.1:
51275111
version "6.0.1"
51285112
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
51295113
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -5589,7 +5573,7 @@ workerpool@^6.5.1:
55895573
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.5.1.tgz#060f73b39d0caf97c6db64da004cd01b4c099544"
55905574
integrity sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA==
55915575

5592-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
5576+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
55935577
version "7.0.0"
55945578
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
55955579
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -5607,15 +5591,6 @@ wrap-ansi@^6.2.0:
56075591
string-width "^4.1.0"
56085592
strip-ansi "^6.0.0"
56095593

5610-
wrap-ansi@^7.0.0:
5611-
version "7.0.0"
5612-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
5613-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
5614-
dependencies:
5615-
ansi-styles "^4.0.0"
5616-
string-width "^4.1.0"
5617-
strip-ansi "^6.0.0"
5618-
56195594
wrap-ansi@^8.1.0:
56205595
version "8.1.0"
56215596
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)