Skip to content

Commit

Permalink
feat: automatically update sfdx-project.json after package conversion…
Browse files Browse the repository at this point in the history
… / retrieval
  • Loading branch information
andrewslater committed Sep 22, 2023
1 parent a7cc401 commit 9b021df
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/package/packageConvert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
SfProject,
StatusResult,
} from '@salesforce/core';
import { camelCaseToTitleCase, Duration } from '@salesforce/kit';
import { camelCaseToTitleCase, Duration, env } from '@salesforce/kit';
import { Many } from '@salesforce/ts-types';
import SettingsGenerator from '@salesforce/core/lib/org/scratchOrgSettingsGenerator';
import * as pkgUtils from '../utils/packageUtils';
Expand Down Expand Up @@ -272,7 +272,7 @@ async function pollForStatusWithInterval(
if (isStatusEqualTo(results, [Package2VersionStatus.success])) {
// update sfdx-project.json
let projectUpdated = false;
if (project && !process.env.SF_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_VERSION_CREATE) {
if (project && !env.getBoolean('SF_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 Down Expand Up @@ -345,7 +345,7 @@ async function pollForStatusWithInterval(
}

async function addPackageAlias(project: SfProject, packageName: string, packageId: string): Promise<void> {
if (!process.env.SF_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_CREATE) {
if (!env.getBoolean('SF_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_CREATE')) {
project.getSfProjectJson().addPackageAlias(packageName, packageId);
await project.getSfProjectJson().write();
}
Expand Down
3 changes: 2 additions & 1 deletion src/package/packageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { Connection, NamedPackageDir, PackageDir, SfError, SfProject } from '@salesforce/core';
import { env } from '@salesforce/kit';
import * as pkgUtils from '../utils/packageUtils';
import { applyErrorAction, massageErrorMessage, replaceIfEmpty } from '../utils/packageUtils';
import { PackageCreateOptions, PackagingSObjects } from '../interfaces';
Expand Down Expand Up @@ -87,7 +88,7 @@ export async function createPackage(
throw pkgUtils.combineSaveErrors('Package2', 'create', createResult.errors);
}

if (!process.env.SF_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_CREATE) {
if (!env.getBoolean('SF_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_CREATE')) {
const packageDirectory = createPackageDirEntry(project, options);
project.getSfProjectJson().addPackageDirectory(packageDirectory as NamedPackageDir);
project.getSfProjectJson().addPackageAlias(options.name, createResult.id);
Expand Down
4 changes: 2 additions & 2 deletions src/package/packageVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { Connection, Lifecycle, Messages, PollingClient, SfProject, StatusResult } from '@salesforce/core';
import { Duration } from '@salesforce/kit';
import { Duration, env } from '@salesforce/kit';
import { Optional } from '@salesforce/ts-types';
import {
PackageSaveResult,
Expand Down Expand Up @@ -611,7 +611,7 @@ export class PackageVersion {
}

private async updateProjectWithPackageVersion(results: PackageVersionCreateRequestResult): Promise<void> {
if (!process.env.SF_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_VERSION_CREATE) {
if (!env.getBoolean('SF_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_VERSION_CREATE')) {
// get the newly created package version from the server
const versionResult = (
await this.connection.tooling.query<{
Expand Down
4 changes: 2 additions & 2 deletions src/package/packageVersionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
} from '@salesforce/source-deploy-retrieve';
import SettingsGenerator from '@salesforce/core/lib/org/scratchOrgSettingsGenerator';
import { PackageDirDependency } from '@salesforce/core/lib/sfProject';
import { cloneJson, ensureArray } from '@salesforce/kit';
import { cloneJson, ensureArray, env } from '@salesforce/kit';
import { XMLParser, XMLBuilder } from 'fast-xml-parser';
import * as pkgUtils from '../utils/packageUtils';
import {
Expand Down Expand Up @@ -308,7 +308,7 @@ export class PackageVersionCreate {
* @private
*/
private async createPackageVersionCreateRequestFromOptions(): Promise<PackageVersionCreateRequest> {
const preserveFiles = !!(this.options.preserve ?? process.env.SFDX_PACKAGE2_VERSION_CREATE_PRESERVE);
const preserveFiles = !!(this.options.preserve ?? env.getBoolean('SFDX_PACKAGE2_VERSION_CREATE_PRESERVE'));
const uniqueHash = uniqid({ template: `${this.packageId}-%s` });
const packageVersTmpRoot = path.join(os.tmpdir(), `${uniqueHash}`);
const packageVersMetadataFolder = path.join(packageVersTmpRoot, 'md-files');
Expand Down
3 changes: 2 additions & 1 deletion src/package/packageVersionRetrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as path from 'path';
import * as fs from 'fs';
import { Connection, Logger, Messages, NamedPackageDir, PackageDirDependency, SfProject } from '@salesforce/core';
import { ComponentSet, MetadataConverter, ZipTreeContainer } from '@salesforce/source-deploy-retrieve';
import { env } from '@salesforce/kit';
import {
PackagingSObjects,
PackageVersionMetadataDownloadOptions,
Expand Down Expand Up @@ -131,7 +132,7 @@ async function attemptToUpdateProjectJson(
dependencyIds: string[],
destinationFolder: string
): Promise<void> {
if (process.env.SF_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_VERSION_RETRIEVE) {
if (env.getBoolean('SF_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_VERSION_RETRIEVE')) {
getLogger().info(
'Skipping sfdx-project.json updates because SF_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_VERSION_RETRIEVE is set'
);
Expand Down

0 comments on commit 9b021df

Please sign in to comment.