Skip to content

Commit

Permalink
fix: modify commands for packaging library refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
shetzel committed Sep 29, 2022
1 parent 9b71bcc commit e07d269
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 57 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@salesforce/command": "^5.2.10",
"@salesforce/core": "^3.30.8",
"@salesforce/kit": "^1.6.1",
"@salesforce/packaging": "0.0.42",
"@salesforce/packaging": "0.0.43",
"tslib": "^2",
"chalk": "^4.1.2"
},
Expand Down Expand Up @@ -188,4 +188,4 @@
"publishConfig": {
"access": "public"
}
}
}
10 changes: 7 additions & 3 deletions src/commands/force/package/beta/version/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,14 @@ export class PackageVersionCreateCommand extends SfdxCommand {

const packageId = getPackageIdFromAlias(packageName, this.project);

const pv = new PackageVersion({ project: this.project, connection: this.hubOrg.getConnection() });
this.ux.startSpinner(messages.getMessage('requestInProgress'));
const result = await pv.create(
{ ...this.flags, ...{ packageId } },
const result = await PackageVersion.create(
{
connection: this.hubOrg.getConnection(),
project: this.project,
...this.flags,
...{ packageId },
},
{
timeout: this.flags.wait as Duration,
frequency,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/force/package/beta/version/create/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export class PackageVersionCreateListCommand extends SfdxCommand {
};

public async run(): Promise<PackageVersionCreateRequestResult[]> {
const pv = new PackageVersion({ connection: this.hubOrg.getConnection(), project: undefined });
const results = await pv.createdList({ ...this.flags });
const connection = this.hubOrg.getConnection();
const results = await PackageVersion.createdList(connection, { ...this.flags });

if (results.length === 0) {
this.ux.log('No results found');
Expand Down
3 changes: 1 addition & 2 deletions src/commands/force/package/beta/version/create/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ export class PackageVersionCreateReportCommand extends SfdxCommand {
};

public async run(): Promise<PackageVersionCreateRequestResult> {
const packageVersion = new PackageVersion({ connection: this.hubOrg.getConnection(), project: undefined });
const result = await packageVersion.getCreateVersionReport(this.flags.packagecreaterequestid);
const result = await PackageVersion.getCreateStatus(this.flags.packagecreaterequestid, this.hubOrg.getConnection());
this.display(result);
return result;
}
Expand Down
10 changes: 6 additions & 4 deletions src/commands/force/package/beta/version/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ export class PackageVersionDeleteCommand extends SfdxCommand {
};

public async run(): Promise<PackageSaveResult> {
const packageVersion = new PackageVersion({ project: this.project, connection: this.hubOrg.getConnection() });
const packageVersion = new PackageVersion({
connection: this.hubOrg.getConnection(),
project: this.project,
idOrAlias: this.flags.package as string,
});
await this.confirmDelete();
const results = this.flags.undelete
? await packageVersion.undelete(this.flags.package)
: await packageVersion.delete(this.flags.package);
const results = this.flags.undelete ? await packageVersion.undelete() : await packageVersion.delete();
this.ux.log(this.getHumanSuccessMessage(results));
return results;
}
Expand Down
15 changes: 6 additions & 9 deletions src/commands/force/package/beta/version/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { CliUx } from '@oclif/core';
import {
getContainerOptions,
getPackageAliasesFromId,
getPackageIdFromAlias,
getPackageVersionStrings,
INSTALL_URL_BASE,
PackageVersion,
Expand Down Expand Up @@ -92,16 +91,14 @@ export class PackageVersionListCommand extends SfdxCommand {
};

public async run(): Promise<PackageVersionListCommandResult[]> {
const connection = this.hubOrg.getConnection();
const project = SfProject.getInstance();
const pv = new PackageVersion({ connection: this.hubOrg.getConnection(), project: undefined });
const packageIdOrAliases = (this.flags.packages as string[]) || [];
// resolve any passed in values from aliases or IDs
const packages = packageIdOrAliases.map((p) => getPackageIdFromAlias(p, project) ?? p);
const records = await pv.list({

const records = await PackageVersion.list(connection, project, {
createdLastDays: this.flags.createdlastdays as number,
concise: this.flags.concise as boolean,
modifiedLastDays: this.flags.modifiedlastdays as number,
packages,
packages: this.flags.packages as string[],
isReleased: this.flags.released as boolean,
orderBy: this.flags.orderby as string,
verbose: this.flags.verbose as boolean,
Expand All @@ -114,12 +111,12 @@ export class PackageVersionListCommand extends SfdxCommand {
// lookup ancestorVersions if ancestorIds are present
const ancestorIds = records.filter((record) => record.AncestorId).map((record) => record.AncestorId);
if (ancestorIds?.length > 0) {
ancestorVersionsMap = await getPackageVersionStrings(ancestorIds, this.hubOrg.getConnection());
ancestorVersionsMap = await getPackageVersionStrings(ancestorIds, connection);
}

// Get the container options for each package version. We need this for determining if the version is OrgDependent
const recordIds = [...new Set(records.map((record) => record.Package2Id))];
const containerOptionsMap = await getContainerOptions(recordIds, this.hubOrg.getConnection());
const containerOptionsMap = await getContainerOptions(recordIds, connection);

records.forEach((record) => {
const ids = [record.Id, record.SubscriberPackageVersionId];
Expand Down
34 changes: 10 additions & 24 deletions src/commands/force/package/beta/version/promote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@
import * as os from 'os';
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
import { Messages, SfError } from '@salesforce/core';
import {
BY_LABEL,
getHasMetadataRemoved,
getPackageIdFromAlias,
getPackageVersionId,
PackageSaveResult,
PackageVersion,
validateId,
} from '@salesforce/packaging';
import { PackageSaveResult, PackageVersion } from '@salesforce/packaging';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_version_promote');
Expand All @@ -42,21 +34,16 @@ export class PackageVersionPromoteCommand extends SfdxCommand {
};

public async run(): Promise<PackageSaveResult> {
const conn = this.hubOrg.getConnection();
const packageIdFromAlias =
getPackageIdFromAlias(this.flags.package, this.project) ?? (this.flags.package as string);
let packageId = packageIdFromAlias;
// ID can be 04t or 05i at this point
validateId([BY_LABEL.SUBSCRIBER_PACKAGE_VERSION_ID, BY_LABEL.PACKAGE_VERSION_ID], packageId);

if (packageId.startsWith('04t')) {
// lookup the 05i ID for getHasMetadataRemoved below
packageId = await getPackageVersionId(packageId, conn);
}
const packageVersion = new PackageVersion({
connection: this.hubOrg.getConnection(),
project: this.project,
idOrAlias: this.flags.package as string,
});
const packageVersionData = await packageVersion.getPackageVersionData();

if (!this.flags.json && !this.flags.noprompt) {
// Warn when a Managed package has removed metadata
if (await getHasMetadataRemoved(packageId, conn)) {
if (packageVersionData.HasMetadataRemoved) {
this.ux.warn(messages.getMessage('hasMetadataRemovedWarning'));
}

Expand All @@ -66,12 +53,11 @@ export class PackageVersionPromoteCommand extends SfdxCommand {
}
}

const pkg = new PackageVersion({ connection: conn, project: this.project });
let result: PackageSaveResult;

try {
result = await pkg.promote(packageId);
result.id = packageIdFromAlias.startsWith('04t') ? packageIdFromAlias : result.id;
result = await packageVersion.promote();
result.id = packageVersionData.SubscriberPackageVersionId;
} catch (e) {
const err = SfError.wrap(e);
if (err.name === 'DUPLICATE_VALUE' && err.message.includes('previously released')) {
Expand Down
8 changes: 6 additions & 2 deletions src/commands/force/package/beta/version/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ export class PackageVersionReportCommand extends SfdxCommand {
protected haveCodeCoverageData = false;

public async run(): Promise<PackageVersionReportResultModified> {
const packageVersion = new PackageVersion({ connection: this.hubOrg.getConnection(), project: this.project });
const results = await packageVersion.report(this.flags.package, this.flags.verbose);
const packageVersion = new PackageVersion({
connection: this.hubOrg.getConnection(),
project: this.project,
idOrAlias: this.flags.package as string,
});
const results = await packageVersion.report(this.flags.verbose);
const massagedResults = this.massageResultsForDisplay(results);
this.display(massagedResults);
return massagedResults;
Expand Down
11 changes: 7 additions & 4 deletions src/commands/force/package/beta/version/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import * as os from 'os';
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
import { Messages } from '@salesforce/core';
import { getPackageIdFromAlias, PackageSaveResult, PackageVersion } from '@salesforce/packaging';
import { PackageSaveResult, PackageVersion } from '@salesforce/packaging';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_version_update');
Expand Down Expand Up @@ -53,9 +53,12 @@ export class PackageVersionUpdateCommand extends SfdxCommand {
};

public async run(): Promise<PackageSaveResult> {
const pv = new PackageVersion({ connection: this.hubOrg.getConnection(), project: this.project });
const id = getPackageIdFromAlias(this.flags.package, this.project);
const result = await pv.update(id, {
const pv = new PackageVersion({
connection: this.hubOrg.getConnection(),
project: this.project,
idOrAlias: this.flags.package as string,
});
const result = await pv.update({
VersionDescription: this.flags.versiondescription as string,
Branch: this.flags.branch as string,
InstallKey: this.flags.installationkey as string,
Expand Down
6 changes: 3 additions & 3 deletions test/commands/force/package/version.delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ describe('force:package:version:delete', () => {
}
});

it('should error pkg version not found in project', async () => {
it('should error pkg version alias not found in project', async () => {
try {
await runCmd(['-p', '04t6A000002zgKSQAY', '-v', 'foor@bar.org'], true);
await runCmd(['-p', 'subscriberPV-alias', '-v', 'foor@bar.org'], true);
expect(false, 'Expected invalid id error').to.be.true;
} catch (err) {
const error = err as Error;
expect(error.name).to.equal('ErrorInvalidIdNoMatchingVersionIdError');
expect(error.name).to.equal('ErrorInvalidPackageVersionIdError');
}
});
it('should delete a package version', async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/commands/force/package/versionReport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const pkgVersionReportResultModified: PackageVersionReportResultModified = {
Description: '',
HasMetadataRemoved: 'N/A',
HasPassedCodeCoverageCheck: false,
Id: '',
Id: '05i3i000000Gmj6XXX',
InstallKey: '',
IsDeleted: false,
IsDeprecated: false,
Expand Down Expand Up @@ -88,7 +88,7 @@ const pkgVersionReportResult: PackageVersionReportResult = {
Description: '',
HasMetadataRemoved: false,
HasPassedCodeCoverageCheck: false,
Id: '',
Id: '05i3i000000Gmj6XXX',
InstallKey: '',
IsDeleted: false,
IsDeprecated: false,
Expand Down

0 comments on commit e07d269

Please sign in to comment.