@salesforce/packaging 0.0.21 → 0.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.0.24](https://github.com/forcedotcom/packaging/compare/v0.0.23...v0.0.24) (2022-08-24)
6
+
7
+ ### Bug Fixes
8
+
9
+ - correct package alias generation ([c4617bd](https://github.com/forcedotcom/packaging/commit/c4617bd16eac1f2bfe5efadafc1062ea78ee352c))
10
+
11
+ ### [0.0.23](https://github.com/forcedotcom/packaging/compare/v0.0.22...v0.0.23) (2022-08-22)
12
+
13
+ ### Bug Fixes
14
+
15
+ - increase pvc ut timeout to 10 secs ([08e667f](https://github.com/forcedotcom/packaging/commit/08e667f574abf5a3de0686c5dcfd654d9fa4c0fa))
16
+ - remove ref to dev dep ([a51323a](https://github.com/forcedotcom/packaging/commit/a51323aaf699eb82fc515722681c6f1b56edb5f4))
17
+
18
+ ### [0.0.22](https://github.com/forcedotcom/packaging/compare/v0.0.21...v0.0.22) (2022-08-22)
19
+
20
+ ### Bug Fixes
21
+
22
+ - add package.promote method ([de5867b](https://github.com/forcedotcom/packaging/commit/de5867bc45850ca2040e4e929a2149a7a146c93f))
23
+
5
24
  ### [0.0.21](https://github.com/forcedotcom/packaging/compare/v0.0.20...v0.0.21) (2022-08-19)
6
25
 
7
26
  ### Bug Fixes
@@ -1,8 +1,7 @@
1
1
  import { AsyncCreatable, Duration } from '@salesforce/kit';
2
2
  import { QueryResult } from 'jsforce';
3
3
  import { Optional } from '@salesforce/ts-types';
4
- import { IPackage, PackageOptions, PackagingSObjects } from '../interfaces';
5
- import { PackageInstallOptions, PackageInstallCreateRequest, PackageIdType } from '../interfaces/packagingInterfacesAndType';
4
+ import { IPackage, PackageOptions, PackagingSObjects, PackageInstallOptions, PackageInstallCreateRequest, PackageIdType } from '../interfaces';
6
5
  declare type PackageInstallRequest = PackagingSObjects.PackageInstallRequest;
7
6
  /**
8
7
  * Package class.
@@ -13,7 +13,7 @@ const os = require("os");
13
13
  const fs = require("fs");
14
14
  const core_1 = require("@salesforce/core");
15
15
  const kit_1 = require("@salesforce/kit");
16
- const testSetup_1 = require("@salesforce/core/lib/testSetup");
16
+ const uniqid_1 = require("../utils/uniqid");
17
17
  const pkgUtils = require("../utils/packageUtils");
18
18
  const constants_1 = require("../constants");
19
19
  const srcDevUtil = require("../utils/srcDevUtils");
@@ -55,7 +55,7 @@ exports.convertPackage = convertPackage;
55
55
  * @private
56
56
  */
57
57
  async function createPackageVersionCreateRequest(context, packageId) {
58
- const uniqueId = (0, testSetup_1.uniqid)({ template: `${packageId}-%s` });
58
+ const uniqueId = (0, uniqid_1.uniqid)({ template: `${packageId}-%s` });
59
59
  const packageVersTmpRoot = path.join(os.tmpdir(), uniqueId);
60
60
  const packageVersBlobDirectory = path.join(packageVersTmpRoot, 'package-version-info');
61
61
  const packageVersBlobZipFile = path.join(packageVersTmpRoot, constants_1.consts.PACKAGE_VERSION_INFO_FILE_ZIP);
@@ -46,6 +46,7 @@ export declare class PackageVersion {
46
46
  * This function emits LifeCycle events, "enqueued", "in-progress", "success", "error" and "timed-out" to
47
47
  * progress and current status. Events also carry a payload of type PackageVersionCreateRequestResult.
48
48
  *
49
+ * @param packageId - The package id to wait for
49
50
  * @param createPackageVersionRequestId
50
51
  * @param polling frequency and timeout Durations to be used in polling
51
52
  * */
@@ -57,6 +58,7 @@ export declare class PackageVersion {
57
58
  install(): Promise<void>;
58
59
  list(): Promise<void>;
59
60
  uninstall(): Promise<void>;
61
+ promote(id: string): Promise<PackageSaveResult>;
60
62
  update(): Promise<void>;
61
63
  private updateDeprecation;
62
64
  private updateProjectWithPackageVersion;
@@ -9,8 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.PackageVersion = void 0;
10
10
  const core_1 = require("@salesforce/core");
11
11
  const kit_1 = require("@salesforce/kit");
12
- const pkgUtils = require("../utils/packageUtils");
13
- const packageUtils_1 = require("../utils/packageUtils");
12
+ const utils_1 = require("../utils");
14
13
  const packageVersionCreate_1 = require("./packageVersionCreate");
15
14
  const packageVersionReport_1 = require("./packageVersionReport");
16
15
  const packageVersionCreateRequestReport_1 = require("./packageVersionCreateRequestReport");
@@ -37,7 +36,7 @@ class PackageVersion {
37
36
  return await this.waitForCreateVersion(createResult.Id, polling).catch((err) => {
38
37
  // TODO
39
38
  // until package2 is GA, wrap perm-based errors w/ 'contact sfdc' action (REMOVE once package2 is GA'd)
40
- throw pkgUtils.applyErrorAction(err);
39
+ throw (0, utils_1.applyErrorAction)(err);
41
40
  });
42
41
  }
43
42
  /**
@@ -71,7 +70,7 @@ class PackageVersion {
71
70
  }).catch((err) => {
72
71
  // TODO
73
72
  // until package2 is GA, wrap perm-based errors w/ 'contact sfdc' action (REMOVE once package2 is GA'd)
74
- throw pkgUtils.applyErrorAction(err);
73
+ throw (0, utils_1.applyErrorAction)(err);
75
74
  });
76
75
  return results[0];
77
76
  }
@@ -87,7 +86,7 @@ class PackageVersion {
87
86
  }).catch((err) => {
88
87
  // TODO
89
88
  // until package2 is GA, wrap perm-based errors w/ 'contact sfdc' action (REMOVE once package2 is GA'd)
90
- throw pkgUtils.applyErrorAction(err);
89
+ throw (0, utils_1.applyErrorAction)(err);
91
90
  });
92
91
  }
93
92
  /**
@@ -96,6 +95,7 @@ class PackageVersion {
96
95
  * This function emits LifeCycle events, "enqueued", "in-progress", "success", "error" and "timed-out" to
97
96
  * progress and current status. Events also carry a payload of type PackageVersionCreateRequestResult.
98
97
  *
98
+ * @param packageId - The package id to wait for
99
99
  * @param createPackageVersionRequestId
100
100
  * @param polling frequency and timeout Durations to be used in polling
101
101
  * */
@@ -134,7 +134,7 @@ class PackageVersion {
134
134
  if (!process.env.SFDX_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_CREATE) {
135
135
  // get the newly created package version from the server
136
136
  const versionResult = (await this.connection.tooling.query(`SELECT Branch, MajorVersion, MinorVersion, PatchVersion, BuildNumber FROM Package2Version WHERE SubscriberPackageVersionId='${report.SubscriberPackageVersionId}'`)).records[0];
137
- const version = `${(0, packageUtils_1.getPackageAliasesFromId)(report.Package2Id, this.project).join()}@${versionResult.MajorVersion ?? 0}.${versionResult.MinorVersion ?? 0}.${versionResult.PatchVersion ?? 0}`;
137
+ const version = `${(0, utils_1.getPackageAliasesFromId)(report.Package2Id, this.project).join()}@${versionResult.MajorVersion ?? 0}.${versionResult.MinorVersion ?? 0}.${versionResult.PatchVersion ?? 0}`;
138
138
  const build = versionResult.BuildNumber ? `-${versionResult.BuildNumber}` : '';
139
139
  const branch = versionResult.Branch ? `-${versionResult.Branch}` : '';
140
140
  // set packageAliases entry '<package>@<major>.<minor>.<patch>-<build>-<branch>: <result.subscriberPackageVersionId>'
@@ -156,7 +156,7 @@ class PackageVersion {
156
156
  }
157
157
  catch (err) {
158
158
  await core_1.Lifecycle.getInstance().emit('timed-out', report);
159
- throw pkgUtils.applyErrorAction(err);
159
+ throw (0, utils_1.applyErrorAction)(err);
160
160
  }
161
161
  }
162
162
  convert() {
@@ -171,15 +171,22 @@ class PackageVersion {
171
171
  uninstall() {
172
172
  return Promise.resolve(undefined);
173
173
  }
174
+ async promote(id) {
175
+ // lookup the 05i ID, if needed
176
+ if (id.startsWith('04t')) {
177
+ id = await (0, utils_1.getPackageVersionId)(id, this.connection);
178
+ }
179
+ return await this.options.connection.tooling.update('Package2Version', { IsReleased: true, Id: id });
180
+ }
174
181
  update() {
175
182
  return Promise.resolve(undefined);
176
183
  }
177
184
  async updateDeprecation(idOrAlias, IsDeprecated) {
178
- const packageVersionId = pkgUtils.getPackageIdFromAlias(idOrAlias, this.project);
185
+ const packageVersionId = (0, utils_1.getPackageIdFromAlias)(idOrAlias, this.project);
179
186
  // ID can be an 04t or 05i
180
- pkgUtils.validateId([pkgUtils.BY_LABEL.SUBSCRIBER_PACKAGE_VERSION_ID, pkgUtils.BY_LABEL.PACKAGE_VERSION_ID], packageVersionId);
187
+ (0, utils_1.validateId)([utils_1.BY_LABEL.SUBSCRIBER_PACKAGE_VERSION_ID, utils_1.BY_LABEL.PACKAGE_VERSION_ID], packageVersionId);
181
188
  // lookup the 05i ID, if needed
182
- const packageId = await pkgUtils.getPackageVersionId(packageVersionId, this.connection);
189
+ const packageId = await (0, utils_1.getPackageVersionId)(packageVersionId, this.connection);
183
190
  // setup the request
184
191
  const request = {
185
192
  Id: packageId,
@@ -187,9 +194,9 @@ class PackageVersion {
187
194
  };
188
195
  const updateResult = await this.connection.tooling.update('Package2Version', request);
189
196
  if (!updateResult.success) {
190
- throw (0, packageUtils_1.combineSaveErrors)('Package2', 'update', updateResult.errors);
197
+ throw (0, utils_1.combineSaveErrors)('Package2', 'update', updateResult.errors);
191
198
  }
192
- updateResult.id = await pkgUtils.getSubscriberPackageVersionId(packageVersionId, this.connection);
199
+ updateResult.id = await (0, utils_1.getSubscriberPackageVersionId)(packageVersionId, this.connection);
193
200
  return updateResult;
194
201
  }
195
202
  async updateProjectWithPackageVersion(withProject, results) {
@@ -200,14 +207,14 @@ class PackageVersion {
200
207
  });
201
208
  const packageVersionVersionString = `${packageVersion.MajorVersion}.${packageVersion.MinorVersion}.${packageVersion.PatchVersion}.${packageVersion.BuildNumber}`;
202
209
  await this.generatePackageDirectory(packageVersion, withProject, packageVersionVersionString);
203
- const newConfig = await (0, packageUtils_1.generatePackageAliasEntry)(this.connection, withProject, packageVersion.SubscriberPackageVersionId, packageVersionVersionString, packageVersion.Branch, packageVersion.Package2Id);
210
+ const newConfig = await (0, utils_1.generatePackageAliasEntry)(this.connection, withProject, packageVersion.SubscriberPackageVersionId, packageVersionVersionString, packageVersion.Branch, packageVersion.Package2Id);
204
211
  withProject.getSfProjectJson().set('packageAliases', newConfig);
205
212
  await withProject.getSfProjectJson().write();
206
213
  }
207
214
  }
208
215
  async generatePackageDirectory(packageVersion, withProject, packageVersionVersionString) {
209
216
  const pkg = await (await package_1.Package.create({ connection: this.connection })).getPackage(packageVersion.Package2Id);
210
- const pkgDir = (0, packageUtils_1.getConfigPackageDirectory)(withProject.getPackageDirectories(), 'id', pkg.Id) ?? {};
217
+ const pkgDir = (0, utils_1.getConfigPackageDirectory)(withProject.getPackageDirectories(), 'id', pkg.Id) ?? {};
211
218
  pkgDir.versionNumber = packageVersionVersionString;
212
219
  pkgDir.versionDescription = packageVersion.Description;
213
220
  const packageDirs = withProject.getPackageDirectories().map((pd) => (pkgDir['id'] === pd['id'] ? pkgDir : pd));
@@ -12,10 +12,10 @@ const os = require("os");
12
12
  const fs = require("fs");
13
13
  const core_1 = require("@salesforce/core");
14
14
  const source_deploy_retrieve_1 = require("@salesforce/source-deploy-retrieve");
15
- const testSetup_1 = require("@salesforce/core/lib/testSetup");
16
15
  const scratchOrgSettingsGenerator_1 = require("@salesforce/core/lib/org/scratchOrgSettingsGenerator");
17
16
  const xml2js = require("xml2js");
18
17
  const scratchOrgInfoGenerator_1 = require("@salesforce/core/lib/org/scratchOrgInfoGenerator");
18
+ const uniqid_1 = require("../utils/uniqid");
19
19
  const pkgUtils = require("../utils/packageUtils");
20
20
  const versionNumber_1 = require("../utils/versionNumber");
21
21
  const utils_1 = require("../utils");
@@ -221,7 +221,7 @@ class PackageVersionCreate {
221
221
  */
222
222
  async createPackageVersionCreateRequestFromOptions() {
223
223
  const preserveFiles = !!(this.options.preserve || process.env.SFDX_PACKAGE2_VERSION_CREATE_PRESERVE);
224
- const uniqueHash = (0, testSetup_1.uniqid)({ template: `${this.packageId}-%s` });
224
+ const uniqueHash = (0, uniqid_1.uniqid)({ template: `${this.packageId}-%s` });
225
225
  const packageVersTmpRoot = path.join(os.tmpdir(), `${uniqueHash}`);
226
226
  const packageVersMetadataFolder = path.join(packageVersTmpRoot, 'md-files');
227
227
  const unpackagedMetadataFolder = path.join(packageVersTmpRoot, 'unpackaged-md-files');
@@ -148,9 +148,7 @@ export declare function pollForStatusWithInterval(id: string, retries: number, p
148
148
  * @private
149
149
  */
150
150
  export declare function generatePackageAliasEntry(connection: Connection, project: SfProject, packageVersionId: string, packageVersionNumber: string, branch: string, packageId: string): Promise<{
151
- packageAliases: {
152
- [p: string]: string;
153
- };
151
+ [p: string]: string;
154
152
  }>;
155
153
  export declare function formatDate(date: Date): string;
156
154
  export declare function combineSaveErrors(sObject: string, crudOperation: string, errors: SaveError[]): SfError;
@@ -653,7 +653,7 @@ async function generatePackageAliasEntry(connection, project, packageVersionId,
653
653
  ? `${packageName}@${packageVersionNumber}-${branch}`
654
654
  : `${packageName}@${packageVersionNumber}`;
655
655
  packageAliases[packageAlias] = packageVersionId;
656
- return { packageAliases };
656
+ return packageAliases;
657
657
  }
658
658
  exports.generatePackageAliasEntry = generatePackageAliasEntry;
659
659
  /**
@@ -0,0 +1,14 @@
1
+ /**
2
+ * A function to generate a unique id and return it in the context of a template, if supplied.
3
+ *
4
+ * A template is a string that can contain `${%s}` to be replaced with a unique id.
5
+ * If the template contains the "%s" placeholder, it will be replaced with the unique id otherwise the id will be appended to the template.
6
+ *
7
+ * @param options an object with the following properties:
8
+ * - template: a template string.
9
+ * - length: the length of the unique id as presented in hexadecimal.
10
+ */
11
+ export declare function uniqid(options?: {
12
+ template?: string;
13
+ length?: number;
14
+ }): string;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uniqid = void 0;
4
+ /*
5
+ * Copyright (c) 2022, salesforce.com, inc.
6
+ * All rights reserved.
7
+ * Licensed under the BSD 3-Clause license.
8
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
+ */
10
+ const crypto_1 = require("crypto");
11
+ const util = require("util");
12
+ /**
13
+ * A function to generate a unique id and return it in the context of a template, if supplied.
14
+ *
15
+ * A template is a string that can contain `${%s}` to be replaced with a unique id.
16
+ * If the template contains the "%s" placeholder, it will be replaced with the unique id otherwise the id will be appended to the template.
17
+ *
18
+ * @param options an object with the following properties:
19
+ * - template: a template string.
20
+ * - length: the length of the unique id as presented in hexadecimal.
21
+ */
22
+ function uniqid(options) {
23
+ const uniqueString = (0, crypto_1.randomBytes)(Math.ceil((options?.length ?? 32) / 2.0))
24
+ .toString('hex')
25
+ .slice(0, options?.length ?? 32);
26
+ if (!options?.template) {
27
+ return uniqueString;
28
+ }
29
+ return options.template.includes('%s')
30
+ ? util.format(options.template, uniqueString)
31
+ : `${options.template}${uniqueString}`;
32
+ }
33
+ exports.uniqid = uniqid;
34
+ //# sourceMappingURL=uniqid.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/packaging",
3
- "version": "0.0.21",
3
+ "version": "0.0.24",
4
4
  "description": "packing libraries to Salesforce packaging platform",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",
@@ -35,8 +35,8 @@
35
35
  "!lib/**/*.map"
36
36
  ],
37
37
  "dependencies": {
38
- "@salesforce/core": "^3.26.1",
39
- "@salesforce/kit": "^1.5.44",
38
+ "@salesforce/core": "^3.26.2",
39
+ "@salesforce/kit": "^1.6.0",
40
40
  "@salesforce/schemas": "^1.2.0",
41
41
  "@salesforce/source-deploy-retrieve": "^6.2.0",
42
42
  "@salesforce/ts-types": "^1.5.20",