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: update imports to focus on main classes #121

Merged
merged 5 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@salesforce/packaging",
"version": "0.1.20",
"version": "1.0.0",
"description": "packing libraries to Salesforce packaging platform",
"main": "lib/exported",
"types": "lib/exported.d.ts",
Expand Down Expand Up @@ -90,4 +90,4 @@
"publishConfig": {
"access": "public"
}
}
}
44 changes: 0 additions & 44 deletions src/constants.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/interfaces/packagingInterfacesAndType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SaveResult } from 'jsforce';
import { Attributes } from 'graphology-types';
import { Optional } from '@salesforce/ts-types';
import { PackageProfileApi } from '../package/packageProfileApi';
import { PackageAncestryNode } from '../package';
import { PackageAncestryNode } from '../package/packageAncestry';
import { PackagingSObjects } from './packagingSObjects';
import Package2VersionStatus = PackagingSObjects.Package2VersionStatus;
import PackageInstallRequest = PackagingSObjects.PackageInstallRequest;
Expand Down
6 changes: 1 addition & 5 deletions src/package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
export * from './package';
export * from './packageInstall';
export * from './packageVersion';
export * from './packageVersionCreateRequest';
export * from './packageInstalledList';
export * from './packageVersionCreateRequestReport';
export * from './packageAncestry';
export * from './subscriberPackageVersion';
export { VersionNumber } from './versionNumber';
37 changes: 25 additions & 12 deletions src/package/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,12 @@ import {
PackageVersionListResult,
PackagingSObjects,
} from '../interfaces';
import {
applyErrorAction,
BY_LABEL,
getPackageAliasesFromId,
getPackageIdFromAlias,
massageErrorMessage,
validateId,
} from '../utils';
import { applyErrorAction, BY_LABEL, massageErrorMessage, validateId } from '../utils/packageUtils';
import { createPackage } from './packageCreate';

import { convertPackage } from './packageConvert';
import { listPackageVersions } from './packageVersionList';
import { deletePackage } from './packageDelete';
import { PackageAncestry } from './packageAncestry';

const packagePrefixes = {
PackageId: '0Ho',
Expand Down Expand Up @@ -72,7 +65,8 @@ export class Package {
public constructor(private options: PackageOptions) {
let packageId = this.options.packageAliasOrId;
if (!packageId.startsWith(packagePrefixes.PackageId)) {
packageId = getPackageIdFromAlias(this.options.packageAliasOrId, this.options.project);
packageId =
this.options.project.getPackageIdFromAlias(this.options.packageAliasOrId) ?? this.options.packageAliasOrId;
if (packageId === this.options.packageAliasOrId) {
throw messages.createError('packageAliasNotFound', [this.options.packageAliasOrId]);
}
Expand Down Expand Up @@ -128,7 +122,7 @@ export class Package {
): Promise<PackageVersionListResult[]> {
// resolve/verify packages
const packages = options?.packages?.map((pkg) => {
const id = getPackageIdFromAlias(pkg, project);
const id = project.getPackageIdFromAlias(pkg) ?? pkg;

// validate ID
if (id.startsWith('0Ho')) {
Expand All @@ -144,6 +138,25 @@ export class Package {
return (await listPackageVersions({ ...opts, ...{ connection } })).records;
}

/**
* create a PackageAncestry instance
*
* @param packageId to get version information for
* @param project SfProject instance
* @param connection Hub Org Connection
*/
public static async getAncestry(
packageId: string,
project: SfProject,
connection: Connection
): Promise<PackageAncestry> {
return PackageAncestry.create({
packageId,
project,
connection,
});
}

/**
* Convert a 1st generation package to a 2nd generation package.
* See {@link ConvertPackageOptions} for conversion options.
Expand Down Expand Up @@ -250,7 +263,7 @@ export class Package {
}

private verifyAliasForId(): void {
if (getPackageAliasesFromId(this.packageId, this.options.project).length === 0) {
if (this.options.project.getAliasesFromPackageId(this.packageId).length === 0) {
throw new SfError(messages.getMessage('couldNotFindAliasForId', [this.packageId]));
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/package/packageAncestry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import {
PackageType,
} from '../interfaces';
import * as pkgUtils from '../utils/packageUtils';
import { VersionNumber } from '../utils';
import { PackageVersion } from './packageVersion';
import { Package } from './package';
import { VersionNumber } from './versionNumber';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/packaging', 'package_ancestry');
Expand Down Expand Up @@ -204,7 +204,8 @@ export class PackageAncestry extends AsyncCreatable<PackageAncestryOptions> {

private async getRoots(): Promise<PackageAncestryNode[]> {
let roots: PackageAncestryNode[] = [];
this.#requestedPackageId = pkgUtils.getPackageIdFromAlias(this.options.packageId, this.options.project);
this.#requestedPackageId =
this.options.project.getPackageIdFromAlias(this.options.packageId) ?? this.options.packageId;
switch (this.requestedPackageId.slice(0, 3)) {
case '0Ho':
pkgUtils.validateId(pkgUtils.BY_LABEL.PACKAGE_ID, this.requestedPackageId);
Expand Down
28 changes: 12 additions & 16 deletions src/package/packageConvert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
import { camelCaseToTitleCase, Duration } from '@salesforce/kit';
import { Many } from '@salesforce/ts-types';
import SettingsGenerator from '@salesforce/core/lib/org/scratchOrgSettingsGenerator';
import { uniqid } from '../utils/uniqid';
import * as pkgUtils from '../utils/packageUtils';
import {
PackagingSObjects,
Expand All @@ -31,9 +30,7 @@ import {
PackageVersionCreateEventData,
PackageEvents,
} from '../interfaces';
import { consts } from '../constants';
import * as srcDevUtil from '../utils/srcDevUtils';
import { generatePackageAliasEntry } from '../utils';
import { generatePackageAliasEntry, uniqid } from '../utils/packageUtils';
import { byId } from './packageVersionCreateRequest';
import * as pvcr from './packageVersionCreateRequest';
import Package2VersionStatus = PackagingSObjects.Package2VersionStatus;
Expand Down Expand Up @@ -94,7 +91,7 @@ export async function convertPackage(

const packageId = await findOrCreatePackage2(pkg, connection);

const apiVersion = pkgUtils.getSourceApiVersion(project);
const apiVersion = project?.getSfProjectJson()?.get('sourceApiVersion') as string;

const request = await createPackageVersionCreateRequest(
{
Expand All @@ -107,7 +104,6 @@ export async function convertPackage(
);

// TODO: a lot of this is duplicated from PC, PVC, and PVCR.

const createResult = await connection.tooling.create('Package2VersionCreateRequest', request);
if (!createResult.success) {
const errStr = createResult?.errors.length ? createResult.errors.join(', ') : createResult.errors;
Expand Down Expand Up @@ -154,7 +150,7 @@ export async function createPackageVersionCreateRequest(
const packageVersBlobDirectory = path.join(packageVersTmpRoot, 'package-version-info');
const settingsZipFile = path.join(packageVersBlobDirectory, 'settings.zip');
const metadataZipFile = path.join(packageVersBlobDirectory, 'package.zip');
const packageVersBlobZipFile = path.join(packageVersTmpRoot, consts.PACKAGE_VERSION_INFO_FILE_ZIP);
const packageVersBlobZipFile = path.join(packageVersTmpRoot, 'package-version-info.zip');

const packageDescriptorJson = {
id: packageId,
Expand Down Expand Up @@ -194,7 +190,7 @@ export async function createPackageVersionCreateRequest(

await settingsGenerator.createDeploy();
await settingsGenerator.createDeployPackageContents(apiVersion);
await srcDevUtil.zipDir(
await pkgUtils.zipDir(
`${settingsGenerator.getDestinationPath()}${path.sep}${settingsGenerator.getShapeDirName()}`,
settingsZipFile
);
Expand All @@ -203,13 +199,13 @@ export async function createPackageVersionCreateRequest(
const currentPackageXml = await fs.promises.readFile(path.join(shapeDirectory, 'package.xml'), 'utf8');
await fs.promises.writeFile(path.join(packageVersMetadataFolder, 'package.xml'), currentPackageXml, 'utf-8');
// Zip the packageVersMetadataFolder folder and put the zip in {packageVersBlobDirectory}/package.zip
await srcDevUtil.zipDir(packageVersMetadataFolder, metadataZipFile);
await pkgUtils.zipDir(packageVersMetadataFolder, metadataZipFile);
await fs.promises.writeFile(
path.join(packageVersBlobDirectory, consts.PACKAGE2_DESCRIPTOR_FILE),
path.join(packageVersBlobDirectory, 'package2-descriptor.json'),
JSON.stringify(packageDescriptorJson, undefined, 2)
);
// Zip the Version Info and package.zip files into another zip
await srcDevUtil.zipDir(packageVersBlobDirectory, packageVersBlobZipFile);
await pkgUtils.zipDir(packageVersBlobDirectory, packageVersBlobZipFile);
return createRequestObject(packageId, context, packageVersTmpRoot, packageVersBlobZipFile);
}

Expand All @@ -236,7 +232,7 @@ async function pollForStatusWithInterval(
retries: number,
packageId: string,
branch: string,
withProject: SfProject,
project: SfProject,
connection: Connection,
interval: Duration
): Promise<PackageVersionCreateRequestResult> {
Expand All @@ -250,7 +246,7 @@ async function pollForStatusWithInterval(
if (isStatusEqualTo(results, [Package2VersionStatus.success])) {
// update sfdx-project.json
let projectUpdated = false;
if (withProject && !process.env.SFDX_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_VERSION_CREATE) {
if (project && !process.env.SFDX_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_VERSION_CREATE) {
projectUpdated = true;
const query = `SELECT MajorVersion, MinorVersion, PatchVersion, BuildNumber FROM Package2Version WHERE Id = '${results[0].Package2VersionId}'`;
const packageVersionVersionString: string = await connection.tooling
Expand All @@ -261,14 +257,14 @@ async function pollForStatusWithInterval(
});
const [alias, writtenId] = await generatePackageAliasEntry(
connection,
withProject,
project,
results[0].SubscriberPackageVersionId,
packageVersionVersionString,
branch,
packageId
);
withProject.getSfProjectJson().addPackageAlias(alias, writtenId);
await withProject.getSfProjectJson().write();
project.getSfProjectJson().addPackageAlias(alias, writtenId);
await project.getSfProjectJson().write();
}
await Lifecycle.getInstance().emit(PackageEvents.convert.success, {
id,
Expand Down
8 changes: 3 additions & 5 deletions src/package/packageDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@
*/

import { Connection, SfProject } from '@salesforce/core';
import * as pkgUtils from '../utils/packageUtils';
import { combineSaveErrors } from '../utils';
import { combineSaveErrors, applyErrorAction, massageErrorMessage, validateId, BY_LABEL } from '../utils/packageUtils';
import { PackageSaveResult } from '../interfaces';
import { applyErrorAction, massageErrorMessage } from '../utils/packageUtils';

export async function deletePackage(
idOrAlias: string,
project: SfProject,
connection: Connection,
undelete: boolean
): Promise<PackageSaveResult> {
const packageId = pkgUtils.getPackageIdFromAlias(idOrAlias, project);
pkgUtils.validateId(pkgUtils.BY_LABEL.PACKAGE_ID, packageId);
const packageId = project.getPackageIdFromAlias(idOrAlias) ?? idOrAlias;
validateId(BY_LABEL.PACKAGE_ID, packageId);

const request = {} as { Id: string; IsDeprecated: boolean };
request.Id = packageId;
Expand Down
7 changes: 3 additions & 4 deletions src/package/packageInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import { Connection, Lifecycle, Logger, Messages, PollingClient, SfError, Status
import { isString } from '@salesforce/ts-types';
import { QueryResult } from 'jsforce';
import { Duration } from '@salesforce/kit';
import { escapeInstallationKey, numberToDuration } from '../utils';
import { escapeInstallationKey, numberToDuration } from '../utils/packageUtils';
import {
PackagingSObjects,
PackageInstallCreateRequest,
PackageEvents,
PackageType,
PackageInstallOptions,
} from '../interfaces';
import { consts } from '../constants';
import SubscriberPackageVersion = PackagingSObjects.SubscriberPackageVersion;
import PackageInstallRequest = PackagingSObjects.PackageInstallRequest;

Expand Down Expand Up @@ -179,9 +178,9 @@ export async function pollStatus(
let packageInstallRequest: PackageInstallRequest;

const { pollingFrequency, pollingTimeout } = options;
const frequency = numberToDuration(pollingFrequency || consts.PACKAGE_INSTALL_POLL_FREQUENCY);
const frequency = numberToDuration(pollingFrequency || 5000);

const timeout = numberToDuration(pollingTimeout || consts.PACKAGE_INSTALL_POLL_TIMEOUT);
const timeout = numberToDuration(pollingTimeout || 300000);

const pollingOptions: Partial<PollingClient.Options> = {
frequency,
Expand Down
19 changes: 0 additions & 19 deletions src/package/packageInstalledList.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/package/packageUninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as os from 'os';
import { Connection, Lifecycle, Messages, PollingClient, SfError } from '@salesforce/core';
import { Duration } from '@salesforce/kit';
import { PackageEvents, PackagingSObjects } from '../interfaces';
import { applyErrorAction, massageErrorMessage } from '../utils';
import { applyErrorAction, massageErrorMessage } from '../utils/packageUtils';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/packaging', 'package_uninstall');
Expand Down
14 changes: 3 additions & 11 deletions src/package/packageVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,7 @@ import {
PackageVersionUpdateOptions,
PackagingSObjects,
} from '../interfaces';
import {
applyErrorAction,
BY_LABEL,
combineSaveErrors,
getPackageAliasesFromId,
getPackageIdFromAlias,
massageErrorMessage,
validateId,
} from '../utils';
import { applyErrorAction, BY_LABEL, combineSaveErrors, massageErrorMessage, validateId } from '../utils/packageUtils';
import { PackageVersionCreate } from './packageVersionCreate';
import { getPackageVersionReport } from './packageVersionReport';
import { getCreatePackageVersionCreateRequestReport } from './packageVersionCreateRequestReport';
Expand Down Expand Up @@ -547,7 +539,7 @@ export class PackageVersion {
`SELECT Branch, MajorVersion, MinorVersion, PatchVersion, BuildNumber FROM Package2Version WHERE SubscriberPackageVersionId='${results.SubscriberPackageVersionId}'`
)
).records[0];
const version = `${getPackageAliasesFromId(results.Package2Id, this.project).join()}@${
const version = `${this.project.getAliasesFromPackageId(results.Package2Id).join()}@${
versionResult.MajorVersion ?? 0
}.${versionResult.MinorVersion ?? 0}.${versionResult.PatchVersion ?? 0}`;
const build = versionResult.BuildNumber ? `-${versionResult.BuildNumber}` : '';
Expand All @@ -559,6 +551,6 @@ export class PackageVersion {
}
}
private resolveId(): string {
return getPackageIdFromAlias(this.options.idOrAlias, this.project);
return this.project.getPackageIdFromAlias(this.options.idOrAlias) ?? this.options.idOrAlias;
}
}
Loading