From e7002f16b288037605e4e9256f3fdc18938babec Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Mon, 7 Nov 2022 08:54:50 -0700 Subject: [PATCH 1/5] fix: update imports to use 4 main classes --- src/commands/force/package/beta/installed/list.ts | 4 ++-- .../force/package/beta/version/displayancestry.ts | 12 ++++++------ test/commands/force/package/install.test.ts | 3 +++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/commands/force/package/beta/installed/list.ts b/src/commands/force/package/beta/installed/list.ts index 7d9366c2..68e2040d 100644 --- a/src/commands/force/package/beta/installed/list.ts +++ b/src/commands/force/package/beta/installed/list.ts @@ -8,8 +8,8 @@ import * as os from 'os'; import { Messages } from '@salesforce/core'; import { SfdxCommand } from '@salesforce/command'; -import { packageInstalledList } from '@salesforce/packaging'; import { CliUx } from '@oclif/core'; +import { Package } from '@salesforce/packaging'; Messages.importMessagesDirectory(__dirname); const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_installed_list'); @@ -31,7 +31,7 @@ export class PackageInstalledListCommand extends SfdxCommand { public static readonly requiresProject = true; public async run(): Promise { - const result = await packageInstalledList(this.org.getConnection()); + const result = await Package.installedList(this.org.getConnection()); const records = result.map((record) => ({ Id: record.Id, diff --git a/src/commands/force/package/beta/version/displayancestry.ts b/src/commands/force/package/beta/version/displayancestry.ts index 5dd7a332..5bae0879 100644 --- a/src/commands/force/package/beta/version/displayancestry.ts +++ b/src/commands/force/package/beta/version/displayancestry.ts @@ -8,7 +8,7 @@ import * as os from 'os'; import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command'; import { Messages } from '@salesforce/core'; -import { PackageAncestry, PackageAncestryNodeData } from '@salesforce/packaging'; +import { PackageAncestryNodeData, PackageVersion } from '@salesforce/packaging'; // Import i18n messages Messages.importMessagesDirectory(__dirname); @@ -41,11 +41,11 @@ export class PackageVersionDisplayAncestryCommand extends SfdxCommand { }; public async run(): Promise { - const packageAncestry = await PackageAncestry.create({ - packageId: this.flags.package as string, - project: this.project, - connection: this.hubOrg.getConnection(), - }); + const packageAncestry = await PackageVersion.getAncestry( + this.flags.package as string, + this.project, + this.hubOrg.getConnection() + ); const jsonProducer = packageAncestry.getJsonProducer(); if (this.flags.dotcode) { const dotProducer = packageAncestry.getDotProducer(); diff --git a/test/commands/force/package/install.test.ts b/test/commands/force/package/install.test.ts index 90d769a5..6de91365 100644 --- a/test/commands/force/package/install.test.ts +++ b/test/commands/force/package/install.test.ts @@ -245,6 +245,9 @@ describe('force:package:install', () => { } }); + // TODO: It seems that while linking @salesforce/packaging into the plugin + // we cannot stub the library calls of `SfProject.getInstance` e.g. "SfProject, 'getInstance'" + // once the library has been published, the stubs resume to work and this test will pass it('should print SUCCESS status correctly for package alias', async () => { // Stubs SfProject.getInstance, SfProject.getSfProjectJson, and SfProjectJson.getContents // in a way that makes TS happy... all to test package aliases. From 32d27094553ccf29472adc0b717dcc652be103aa Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Mon, 7 Nov 2022 13:51:49 -0700 Subject: [PATCH 2/5] refactor: update for changes in library --- src/commands/force/package/beta/list.ts | 8 ++++---- src/commands/force/package/beta/version/list.ts | 11 +++++------ test/commands/force/package/packageVersion.nut.ts | 12 ++++++------ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/commands/force/package/beta/list.ts b/src/commands/force/package/beta/list.ts index 54be321a..f8ed48c3 100644 --- a/src/commands/force/package/beta/list.ts +++ b/src/commands/force/package/beta/list.ts @@ -6,9 +6,9 @@ */ import * as os from 'os'; -import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command'; -import { Messages } from '@salesforce/core'; -import { getPackageAliasesFromId, Package, PackagingSObjects } from '@salesforce/packaging'; +import {flags, FlagsConfig, SfdxCommand} from '@salesforce/command'; +import {Messages} from '@salesforce/core'; +import {Package, PackagingSObjects} from '@salesforce/packaging'; import * as chalk from 'chalk'; Messages.importMessagesDirectory(__dirname); @@ -77,7 +77,7 @@ export class PackageListCommand extends SfdxCommand { NamespacePrefix, ContainerOptions, ConvertedFromPackageId, - Alias: getPackageAliasesFromId(Id, this.project).join(), + Alias: this.project.getAliasesFromPackageId(Id).join(), IsOrgDependent: ContainerOptions === 'Managed' ? 'N/A' : IsOrgDependent ? 'Yes' : 'No', PackageErrorUsername, CreatedBy: CreatedById, diff --git a/src/commands/force/package/beta/version/list.ts b/src/commands/force/package/beta/version/list.ts index 56018291..9c47f711 100644 --- a/src/commands/force/package/beta/version/list.ts +++ b/src/commands/force/package/beta/version/list.ts @@ -6,18 +6,17 @@ */ import * as os from 'os'; -import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command'; -import { Messages, SfProject } from '@salesforce/core'; -import { CliUx } from '@oclif/core'; +import {flags, FlagsConfig, SfdxCommand} from '@salesforce/command'; +import {Messages, SfProject} from '@salesforce/core'; +import {CliUx} from '@oclif/core'; import { getContainerOptions, - getPackageAliasesFromId, getPackageVersionStrings, INSTALL_URL_BASE, Package, PackageVersionListResult, } from '@salesforce/packaging'; -import { Optional } from '@salesforce/ts-types'; +import {Optional} from '@salesforce/ts-types'; Messages.importMessagesDirectory(__dirname); const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_version_list'); @@ -122,7 +121,7 @@ export class PackageVersionListCommand extends SfdxCommand { const ids = [record.Id, record.SubscriberPackageVersionId]; const aliases = []; ids.forEach((id) => { - const matches = getPackageAliasesFromId(id, project); + const matches = project.getAliasesFromPackageId(id); if (matches.length > 0) { aliases.push(matches); } diff --git a/test/commands/force/package/packageVersion.nut.ts b/test/commands/force/package/packageVersion.nut.ts index 084ba01d..ed5feb2b 100644 --- a/test/commands/force/package/packageVersion.nut.ts +++ b/test/commands/force/package/packageVersion.nut.ts @@ -5,18 +5,18 @@ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ -import { execCmd, genUniqueString, TestSession } from '@salesforce/cli-plugins-testkit'; -import { ConfigAggregator, Org, SfProject } from '@salesforce/core'; -import { expect } from 'chai'; +import {execCmd, genUniqueString, TestSession} from '@salesforce/cli-plugins-testkit'; +import {ConfigAggregator, Org, SfProject} from '@salesforce/core'; +import {expect} from 'chai'; +import {Duration} from '@salesforce/kit'; import { PackageAncestryNodeData, PackageSaveResult, PackageVersionCreateRequestResult, PackagingSObjects, - VersionNumber, + VersionNumber } from '@salesforce/packaging'; -import { Duration } from '@salesforce/kit'; -import { PackageVersionListCommandResult } from '../../../../src/commands/force/package/beta/version/list'; +import {PackageVersionListCommandResult} from '../../../../src/commands/force/package/beta/version/list'; describe('package:version:*', () => { let session: TestSession; From 4b31c8f0560b6dc92d685d35d3942f4883eb052c Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Tue, 8 Nov 2022 10:25:15 -0700 Subject: [PATCH 3/5] refactor: update for library changes --- src/commands/force/package/beta/installed/list.ts | 4 ++-- src/commands/force/package/beta/version/displayancestry.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/force/package/beta/installed/list.ts b/src/commands/force/package/beta/installed/list.ts index 68e2040d..70356634 100644 --- a/src/commands/force/package/beta/installed/list.ts +++ b/src/commands/force/package/beta/installed/list.ts @@ -9,7 +9,7 @@ import * as os from 'os'; import { Messages } from '@salesforce/core'; import { SfdxCommand } from '@salesforce/command'; import { CliUx } from '@oclif/core'; -import { Package } from '@salesforce/packaging'; +import { SubscriberPackageVersion } from '@salesforce/packaging'; Messages.importMessagesDirectory(__dirname); const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_installed_list'); @@ -31,7 +31,7 @@ export class PackageInstalledListCommand extends SfdxCommand { public static readonly requiresProject = true; public async run(): Promise { - const result = await Package.installedList(this.org.getConnection()); + const result = await SubscriberPackageVersion.installedList(this.org.getConnection()); const records = result.map((record) => ({ Id: record.Id, diff --git a/src/commands/force/package/beta/version/displayancestry.ts b/src/commands/force/package/beta/version/displayancestry.ts index 5bae0879..5fb95eec 100644 --- a/src/commands/force/package/beta/version/displayancestry.ts +++ b/src/commands/force/package/beta/version/displayancestry.ts @@ -8,7 +8,7 @@ import * as os from 'os'; import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command'; import { Messages } from '@salesforce/core'; -import { PackageAncestryNodeData, PackageVersion } from '@salesforce/packaging'; +import { Package, PackageAncestryNodeData } from '@salesforce/packaging'; // Import i18n messages Messages.importMessagesDirectory(__dirname); @@ -41,7 +41,7 @@ export class PackageVersionDisplayAncestryCommand extends SfdxCommand { }; public async run(): Promise { - const packageAncestry = await PackageVersion.getAncestry( + const packageAncestry = await Package.getAncestry( this.flags.package as string, this.project, this.hubOrg.getConnection() From 559781d88c6561c0406454fb982df7be89cb303c Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Tue, 8 Nov 2022 13:37:52 -0700 Subject: [PATCH 4/5] chore: bump packaging, fix date format --- package.json | 4 ++-- src/commands/force/package/beta/version/list.ts | 14 ++++++-------- yarn.lock | 8 ++++---- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 1e42d1c3..33214328 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "@salesforce/command": "^5.2.17", "@salesforce/core": "^3.31.15", "@salesforce/kit": "^1.7.0", - "@salesforce/packaging": "^0.1.18", + "@salesforce/packaging": "^1.0.1", "chalk": "^4.1.2", "tslib": "^2" }, @@ -181,4 +181,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/src/commands/force/package/beta/version/list.ts b/src/commands/force/package/beta/version/list.ts index 9c47f711..239a863f 100644 --- a/src/commands/force/package/beta/version/list.ts +++ b/src/commands/force/package/beta/version/list.ts @@ -6,9 +6,9 @@ */ import * as os from 'os'; -import {flags, FlagsConfig, SfdxCommand} from '@salesforce/command'; -import {Messages, SfProject} from '@salesforce/core'; -import {CliUx} from '@oclif/core'; +import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command'; +import { Messages, SfProject } from '@salesforce/core'; +import { CliUx } from '@oclif/core'; import { getContainerOptions, getPackageVersionStrings, @@ -16,7 +16,7 @@ import { Package, PackageVersionListResult, } from '@salesforce/packaging'; -import {Optional} from '@salesforce/ts-types'; +import { Optional } from '@salesforce/ts-types'; Messages.importMessagesDirectory(__dirname); const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_version_list'); @@ -179,10 +179,8 @@ export class PackageVersionListCommand extends SfdxCommand { // Table output needs string false to display 'false' IsPasswordProtected: this.flags.json ? record.IsPasswordProtected : record.IsPasswordProtected.toString(), IsReleased: this.flags.json ? record.IsReleased : record.IsReleased.toString(), - CreatedDate: record.CreatedDate, // (record.CreatedDate).format('YYYY-MM-DD HH:mm'), - LastModifiedDate: record.LastModifiedDate, // moment(record.LastModifiedDate).format('YYYY-MM-DD HH:mm'), - // CreatedDate: moment(record.CreatedDate).format('YYYY-MM-DD HH:mm'), - // LastModifiedDate: moment(record.LastModifiedDate).format('YYYY-MM-DD HH:mm'), + CreatedDate: new Date(record.CreatedDate).toISOString().replace('T', ' ').substring(0, 16), + LastModifiedDate: new Date(record.LastModifiedDate).toISOString().replace('T', ' ').substring(0, 16), InstallUrl: INSTALL_URL_BASE.toString() + record.SubscriberPackageVersionId, CodeCoverage: codeCoverage, HasPassedCodeCoverageCheck: hasPassedCodeCoverageCheck, diff --git a/yarn.lock b/yarn.lock index 39ce65a6..8a88d4bb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1143,10 +1143,10 @@ shx "^0.3.3" tslib "^2.2.0" -"@salesforce/packaging@^0.1.18": - version "0.1.18" - resolved "https://registry.yarnpkg.com/@salesforce/packaging/-/packaging-0.1.18.tgz#d76d59611d4b940600a49963a18c71e2ade6088c" - integrity sha512-GaxqayvbA88vtCBMJn8TX+cnrw6jbPMJuQVypOWDcnROGXUEfA4GZJBuf5oAimVnuhGFmXNpbloMx3fat0i1PQ== +"@salesforce/packaging@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@salesforce/packaging/-/packaging-1.0.1.tgz#14b73d9078064ac2ff07b9f319fac034c3f8fdfd" + integrity sha512-KJWGapdEddiUq73/15RQaefzjxi6njYWRcFxM7Dr1ANGdK5nigRkaB3SJzaT1xhOscmZhuob4Gq7y267EIINrg== dependencies: "@oclif/core" "^1.19.1" "@salesforce/core" "^3.31.16" From 895efa500eb82214aa6b82cff887b312898d5e3d Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Tue, 8 Nov 2022 13:50:35 -0700 Subject: [PATCH 5/5] chore: fix spaces on imports --- src/commands/force/package/beta/list.ts | 6 +++--- test/commands/force/package/packageVersion.nut.ts | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/commands/force/package/beta/list.ts b/src/commands/force/package/beta/list.ts index f8ed48c3..a5165132 100644 --- a/src/commands/force/package/beta/list.ts +++ b/src/commands/force/package/beta/list.ts @@ -6,9 +6,9 @@ */ import * as os from 'os'; -import {flags, FlagsConfig, SfdxCommand} from '@salesforce/command'; -import {Messages} from '@salesforce/core'; -import {Package, PackagingSObjects} from '@salesforce/packaging'; +import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command'; +import { Messages } from '@salesforce/core'; +import { Package, PackagingSObjects } from '@salesforce/packaging'; import * as chalk from 'chalk'; Messages.importMessagesDirectory(__dirname); diff --git a/test/commands/force/package/packageVersion.nut.ts b/test/commands/force/package/packageVersion.nut.ts index ed5feb2b..305cce25 100644 --- a/test/commands/force/package/packageVersion.nut.ts +++ b/test/commands/force/package/packageVersion.nut.ts @@ -5,18 +5,18 @@ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ -import {execCmd, genUniqueString, TestSession} from '@salesforce/cli-plugins-testkit'; -import {ConfigAggregator, Org, SfProject} from '@salesforce/core'; -import {expect} from 'chai'; -import {Duration} from '@salesforce/kit'; +import { execCmd, genUniqueString, TestSession } from '@salesforce/cli-plugins-testkit'; +import { ConfigAggregator, Org, SfProject } from '@salesforce/core'; +import { expect } from 'chai'; +import { Duration } from '@salesforce/kit'; import { PackageAncestryNodeData, PackageSaveResult, PackageVersionCreateRequestResult, PackagingSObjects, - VersionNumber + VersionNumber, } from '@salesforce/packaging'; -import {PackageVersionListCommandResult} from '../../../../src/commands/force/package/beta/version/list'; +import { PackageVersionListCommandResult } from '../../../../src/commands/force/package/beta/version/list'; describe('package:version:*', () => { let session: TestSession;