@salesforce/core 4.3.4 → 4.3.6

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/README.md CHANGED
@@ -69,3 +69,13 @@ In your plugin or library,
69
69
  }
70
70
 
71
71
  ```
72
+
73
+ ## Performance Testing
74
+
75
+ There are some benchmark.js checks to get a baseline for Logger performance.
76
+ https://forcedotcom.github.io/sfdx-core/perf-Linux
77
+ https://forcedotcom.github.io/sfdx-core/perf-Windows
78
+
79
+ You can add more test cases in test/perf/logger/main.js
80
+
81
+ If you add tests for new parts of sfdx-core outside of Logger, add new test Suites and create new jobs in the GHA `perf.yml`
@@ -57,8 +57,8 @@ export declare class ConfigAggregator extends AsyncOptionalCreatable<ConfigAggre
57
57
  protected static instance: AsyncOptionalCreatable;
58
58
  protected static encrypted: boolean;
59
59
  private allowedProperties;
60
- private localConfig?;
61
- private globalConfig;
60
+ private readonly localConfig?;
61
+ private readonly globalConfig;
62
62
  private envVars;
63
63
  /**
64
64
  * **Do not directly construct instances of this class -- use {@link ConfigAggregator.create} instead.**
@@ -161,6 +161,7 @@ export declare class ConfigAggregator extends AsyncOptionalCreatable<ConfigAggre
161
161
  * Get the resolved config object from the local, global and environment config instances.
162
162
  */
163
163
  getConfig(): JsonMap;
164
+ unsetByValue(key: string): Promise<void>;
164
165
  /**
165
166
  * Get the config properties that are environment variables.
166
167
  */
@@ -260,6 +260,20 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
260
260
  getConfig() {
261
261
  return this.config;
262
262
  }
263
+ async unsetByValue(key) {
264
+ const hasLocalWrites = this.localConfig
265
+ ?.getKeysByValue(key)
266
+ .map((k) => this.localConfig?.unset(k))
267
+ .some(Boolean);
268
+ if (hasLocalWrites)
269
+ await this.localConfig?.write();
270
+ const hasGlobalWrites = this.globalConfig
271
+ ?.getKeysByValue(key)
272
+ .map((k) => this.globalConfig?.unset(k))
273
+ .some(Boolean);
274
+ if (hasGlobalWrites)
275
+ await this.globalConfig?.write();
276
+ }
263
277
  /**
264
278
  * Get the config properties that are environment variables.
265
279
  */
@@ -328,8 +342,7 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
328
342
  }
329
343
  configs.push(this.envVars);
330
344
  const json = {};
331
- const reduced = configs.filter(ts_types_1.isJsonMap).reduce((acc, el) => (0, kit_1.merge)(acc, el), json);
332
- return reduced;
345
+ return configs.filter(ts_types_1.isJsonMap).reduce((acc, el) => (0, kit_1.merge)(acc, el), json);
333
346
  }
334
347
  }
335
348
  exports.ConfigAggregator = ConfigAggregator;
@@ -192,6 +192,11 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
192
192
  * Find all dev hubs available in the local environment.
193
193
  */
194
194
  static getDevHubAuthInfos(): Promise<OrgAuthorization[]>;
195
+ /**
196
+ * Checks active scratch orgs to match by the ScratchOrg field (the 15-char org id)
197
+ * if you pass an 18-char scratchOrgId, it will be trimmed to 15-char for query purposes
198
+ * Throws is no matching scratch org is found
199
+ */
195
200
  private static queryScratchOrg;
196
201
  /**
197
202
  * Get the username.
@@ -270,11 +270,22 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
270
270
  static async getDevHubAuthInfos() {
271
271
  return AuthInfo.listAllAuthorizations((possibleHub) => possibleHub?.isDevHub ?? false);
272
272
  }
273
+ /**
274
+ * Checks active scratch orgs to match by the ScratchOrg field (the 15-char org id)
275
+ * if you pass an 18-char scratchOrgId, it will be trimmed to 15-char for query purposes
276
+ * Throws is no matching scratch org is found
277
+ */
273
278
  static async queryScratchOrg(devHubUsername, scratchOrgId) {
274
279
  const devHubOrg = await org_1.Org.create({ aliasOrUsername: devHubUsername });
280
+ const trimmedId = (0, sfdc_1.trimTo15)(scratchOrgId);
275
281
  const conn = devHubOrg.getConnection();
276
- const data = await conn.singleRecordQuery(`select Id, ExpirationDate from ScratchOrgInfo where ScratchOrg = '${(0, sfdc_1.trimTo15)(scratchOrgId)}'`);
277
- return data;
282
+ const data = await conn.query(`select Id, ExpirationDate, ScratchOrg from ScratchOrgInfo where ScratchOrg = '${trimmedId}' and Status = 'Active'`);
283
+ // where ScratchOrg='00DDE00000485Lg' will return a record for both 00DDE00000485Lg and 00DDE00000485LG.
284
+ // this is our way of enforcing case sensitivity on a 15-char Id (which is unfortunately how ScratchOrgInfo stores it)
285
+ const result = data.records.filter((r) => r.ScratchOrg === trimmedId)[0];
286
+ if (result)
287
+ return result;
288
+ throw new sfError_1.SfError(`DevHub ${devHubUsername} has no active scratch orgs that match ${trimmedId}`, 'NoActiveScratchOrgFound');
278
289
  }
279
290
  /**
280
291
  * Get the username.
package/lib/org/org.js CHANGED
@@ -355,6 +355,13 @@ class Org extends kit_1.AsyncOptionalCreatable {
355
355
  * Will delete 'this' instance remotely and any files locally
356
356
  */
357
357
  async delete() {
358
+ const username = (0, ts_types_1.ensureString)(this.getUsername());
359
+ // unset any aliases referencing this org
360
+ const stateAgg = await stateAggregator_1.StateAggregator.getInstance();
361
+ const existingAliases = stateAgg.aliases.getAll(username);
362
+ await stateAgg.aliases.unsetValuesAndSave(existingAliases);
363
+ // unset any configs referencing this org
364
+ [...existingAliases, username].flatMap((name) => this.configAggregator.unsetByValue(name));
358
365
  if (await this.isSandbox()) {
359
366
  await this.deleteSandbox();
360
367
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "4.3.4",
3
+ "version": "4.3.6",
4
4
  "description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",
@@ -22,7 +22,8 @@
22
22
  "prepack": "sf-prepack",
23
23
  "prepare": "sf-install",
24
24
  "test": "wireit",
25
- "test:only": "wireit"
25
+ "test:only": "wireit",
26
+ "test:perf": "ts-node test/perf/logger/main.test.ts"
26
27
  },
27
28
  "keywords": [
28
29
  "force",
@@ -60,14 +61,16 @@
60
61
  "@salesforce/dev-scripts": "^5.4.2",
61
62
  "@salesforce/prettier-config": "^0.0.3",
62
63
  "@salesforce/ts-sinon": "^1.4.8",
64
+ "@types/benchmark": "^2.1.2",
63
65
  "@types/chai-string": "^1.4.2",
64
66
  "@types/debug": "0.0.31",
65
67
  "@types/jsonwebtoken": "9.0.2",
66
68
  "@types/lodash": "^4.14.195",
67
69
  "@types/proper-lockfile": "^4.1.2",
68
70
  "@types/shelljs": "0.8.12",
69
- "@typescript-eslint/eslint-plugin": "^5.59.9",
70
- "@typescript-eslint/parser": "^5.59.11",
71
+ "@typescript-eslint/eslint-plugin": "^5.60.1",
72
+ "@typescript-eslint/parser": "^5.60.1",
73
+ "benchmark": "^2.1.4",
71
74
  "chai": "^4.3.7",
72
75
  "chai-string": "^1.5.0",
73
76
  "eslint": "^8.43.0",