@salesforce/core 3.30.8 → 3.30.10

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.
@@ -26,6 +26,7 @@ const messages = messages_1.Messages.load('@salesforce/core', 'connection', [
26
26
  'incorrectAPIVersionError',
27
27
  'domainNotFoundError',
28
28
  'noInstanceUrlError',
29
+ 'noApiVersionsError',
29
30
  ]);
30
31
  const clientId = `sfdx toolbelt:${process.env.SFDX_SET_CLIENT_IDS || ''}`;
31
32
  exports.SFDX_HTTP_HEADERS = {
@@ -178,6 +179,11 @@ class Connection extends jsforce_1.Connection {
178
179
  async retrieveMaxApiVersion() {
179
180
  await this.isResolvable();
180
181
  const versions = await this.request(`${this.instanceUrl}/services/data`);
182
+ // if the server doesn't return a list of versions, it's possibly a instanceUrl issue where the local file is out of date.
183
+ if (!Array.isArray(versions)) {
184
+ this.logger.debug(`server response for retrieveMaxApiVersion: ${versions}`);
185
+ throw messages.createError('noApiVersionsError');
186
+ }
181
187
  this.logger.debug(`response for org versions: ${versions.map((item) => item.version).join(',')}`);
182
188
  const max = (0, ts_types_1.ensure)((0, kit_1.maxBy)(versions, (version) => version.version));
183
189
  return max.version;
@@ -150,7 +150,7 @@ export declare class SfProjectJson extends ConfigFile {
150
150
  *
151
151
  * @param packageDir
152
152
  */
153
- addPackageDirectory(packageDir: PackageDir): void;
153
+ addPackageDirectory(packageDir: NamedPackageDir): void;
154
154
  private doesPackageExist;
155
155
  private validateKeys;
156
156
  }
@@ -285,6 +285,12 @@ export declare class SfProject {
285
285
  * @param packageName Name of the package directory. E.g., 'force-app'
286
286
  */
287
287
  getPackage(packageName: string): Optional<NamedPackageDir>;
288
+ /**
289
+ * Returns the package directory.
290
+ *
291
+ * @param packageName Name of the package directory. E.g., 'force-app'
292
+ */
293
+ findPackage(predicate: (packageDir: NamedPackageDir) => boolean): Optional<NamedPackageDir>;
288
294
  /**
289
295
  * Returns the absolute path of the package directory ending with the path separator.
290
296
  * E.g., /Users/jsmith/projects/ebikes-lwc/force-app/
package/lib/sfProject.js CHANGED
@@ -220,12 +220,12 @@ class SfProjectJson extends configFile_1.ConfigFile {
220
220
  * for packaging operations that want to do something for each package entry.
221
221
  */
222
222
  getUniquePackageDirectories() {
223
- const visited = {};
223
+ const visited = new Set();
224
224
  const uniqueValues = [];
225
225
  // Keep original order defined in sfdx-project.json
226
226
  this.getPackageDirectoriesSync().forEach((packageDir) => {
227
- if (!visited[packageDir.name]) {
228
- visited[packageDir.name] = true;
227
+ if (!visited.has(packageDir.name)) {
228
+ visited.add(packageDir.name);
229
229
  uniqueValues.push(packageDir);
230
230
  }
231
231
  });
@@ -289,10 +289,19 @@ class SfProjectJson extends configFile_1.ConfigFile {
289
289
  * @param packageDir
290
290
  */
291
291
  addPackageDirectory(packageDir) {
292
- const dirIndex = this.getContents().packageDirectories.findIndex((pkgDir) => {
293
- return pkgDir.package === packageDir.package;
292
+ // there is no notion of uniqueness in package directory entries
293
+ // so an attempt of matching an existing entry is a bit convoluted
294
+ // an entry w/o a package or id is considered a directory entry for which a package has yet to be created
295
+ // so first attempt is to find a matching dir entry that where path is the same and id and package are not present
296
+ // if that fails, then find a matching dir entry package is present and is same as the new entry
297
+ const dirIndex = this.getContents().packageDirectories.findIndex((pd) => {
298
+ const withId = pd;
299
+ return ((withId.path === packageDir.path && !withId.id && !withId.package) ||
300
+ (!!packageDir.package && packageDir.package === withId.package));
294
301
  });
302
+ // merge new package dir with existing entry, if present
295
303
  const packageDirEntry = Object.assign({}, dirIndex > -1 ? this.getContents().packageDirectories[dirIndex] : packageDir, packageDir);
304
+ // update package dir entries
296
305
  if (dirIndex > -1) {
297
306
  this.getContents().packageDirectories[dirIndex] = packageDirEntry;
298
307
  }
@@ -489,7 +498,7 @@ class SfProject {
489
498
  */
490
499
  getPackageFromPath(path) {
491
500
  const packageDirs = this.getPackageDirectories();
492
- const match = packageDirs.find((packageDir) => (0, path_1.basename)(path) === packageDir.name || path.includes(packageDir.fullPath));
501
+ const match = packageDirs.find((packageDir) => (0, path_1.basename)(path) === packageDir.path || path.includes(packageDir.fullPath));
493
502
  return match;
494
503
  }
495
504
  /**
@@ -499,7 +508,7 @@ class SfProject {
499
508
  */
500
509
  getPackageNameFromPath(path) {
501
510
  const packageDir = this.getPackageFromPath(path);
502
- return packageDir ? packageDir.name : undefined;
511
+ return packageDir ? packageDir.package || packageDir.path : undefined;
503
512
  }
504
513
  /**
505
514
  * Returns the package directory.
@@ -510,6 +519,14 @@ class SfProject {
510
519
  const packageDirs = this.getPackageDirectories();
511
520
  return packageDirs.find((packageDir) => packageDir.name === packageName);
512
521
  }
522
+ /**
523
+ * Returns the package directory.
524
+ *
525
+ * @param packageName Name of the package directory. E.g., 'force-app'
526
+ */
527
+ findPackage(predicate) {
528
+ return this.getPackageDirectories().find(predicate);
529
+ }
513
530
  /**
514
531
  * Returns the absolute path of the package directory ending with the path separator.
515
532
  * E.g., /Users/jsmith/projects/ebikes-lwc/force-app/
@@ -518,7 +535,7 @@ class SfProject {
518
535
  */
519
536
  getPackagePath(packageName) {
520
537
  const packageDir = this.getPackage(packageName);
521
- return packageDir && packageDir.fullPath;
538
+ return packageDir?.fullPath;
522
539
  }
523
540
  /**
524
541
  * Has package directories defined in the project.
@@ -561,7 +578,7 @@ class SfProject {
561
578
  if (!this.hasPackages()) {
562
579
  throw new sfError_1.SfError('The sfdx-project.json does not have any packageDirectories defined.');
563
580
  }
564
- const defaultPackage = this.getPackageDirectories().find((packageDir) => packageDir.default === true);
581
+ const defaultPackage = this.findPackage((packageDir) => packageDir.default === true);
565
582
  return defaultPackage || this.getPackageDirectories()[0];
566
583
  }
567
584
  /**
@@ -20,3 +20,11 @@ Connection has no instanceUrl.
20
20
  # noInstanceUrlError.actions
21
21
 
22
22
  Make sure the instanceUrl is set in your command or config.
23
+
24
+ # noApiVersionsError
25
+
26
+ Org failed to respond with its list of API versions. This is usually the result of domain changes like activating MyDomain or Enhanced Domains
27
+
28
+ # noApiVersionsError.actions
29
+
30
+ Re-authenticate to the org.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "3.30.8",
3
+ "version": "3.30.10",
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",