@salesforce/core 7.3.12-qa.1 → 7.4.0

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.
@@ -1,5 +1,7 @@
1
1
  import { AnyJson } from '@salesforce/ts-types';
2
- type callback = (data: any) => Promise<void>;
2
+ export type callback = (data: any) => Promise<void>;
3
+ type ListenerMap = Map<string, callback>;
4
+ export type UniqueListenerMap = Map<string, ListenerMap>;
3
5
  /**
4
6
  * An asynchronous event listener and emitter that follows the singleton pattern. The singleton pattern allows lifecycle
5
7
  * events to be emitted from deep within a library and still be consumed by any other library or tool. It allows other
@@ -92,4 +94,5 @@ export declare class Lifecycle {
92
94
  */
93
95
  emit<T = AnyJson>(eventName: string, data: T): Promise<void>;
94
96
  }
97
+ export declare const cloneUniqueListeners: (uniqueListeners: UniqueListenerMap) => UniqueListenerMap;
95
98
  export {};
@@ -29,7 +29,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
29
29
  return result;
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.Lifecycle = void 0;
32
+ exports.cloneUniqueListeners = exports.Lifecycle = void 0;
33
33
  const semver_1 = require("semver");
34
34
  // needed for TS to not put everything inside /lib/src
35
35
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -102,8 +102,8 @@ class Lifecycle {
102
102
  (0, semver_1.compare)(global.salesforceCoreLifecycle.version(), Lifecycle.staticVersion()) === -1) {
103
103
  const oldInstance = global.salesforceCoreLifecycle;
104
104
  // use the newer version and transfer any listeners from the old version
105
- // object spread keeps them from being references
106
- global.salesforceCoreLifecycle = new Lifecycle({ ...oldInstance.listeners }, oldInstance.uniqueListeners);
105
+ // object spread and the clone fn keep them from being references
106
+ global.salesforceCoreLifecycle = new Lifecycle({ ...oldInstance.listeners }, (0, exports.cloneUniqueListeners)(oldInstance.uniqueListeners));
107
107
  // clean up any listeners on the old version
108
108
  Object.keys(oldInstance.listeners).map((eventName) => {
109
109
  oldInstance.removeAllListeners(eventName);
@@ -232,4 +232,7 @@ class Lifecycle {
232
232
  }
233
233
  }
234
234
  exports.Lifecycle = Lifecycle;
235
+ const cloneListeners = (listeners) => new Map(Array.from(listeners.entries()));
236
+ const cloneUniqueListeners = (uniqueListeners) => new Map(Array.from(uniqueListeners.entries()).map(([key, value]) => [key, cloneListeners(value)]));
237
+ exports.cloneUniqueListeners = cloneUniqueListeners;
235
238
  //# sourceMappingURL=lifecycleEvents.js.map
@@ -53,7 +53,6 @@ const getAncestorIds = async (scratchOrgInfo, projectJson, hubOrg) => {
53
53
  throw new sfError_1.SfError(messages.getMessage('Package2AncestorsIdsKeyNotSupportedError'), 'DeprecationError');
54
54
  }
55
55
  const packagesWithAncestors = (await projectJson.getPackageDirectories())
56
- .filter(sfProject_1.isPackagingDirectory)
57
56
  // check that the package has any ancestor types (id or version)
58
57
  .filter((packageDir) => packageDir.ancestorId ?? packageDir.ancestorVersion);
59
58
  if (packagesWithAncestors.length === 0) {
@@ -1,9 +1,40 @@
1
1
  import { Dictionary, JsonMap, Nullable, Optional } from '@salesforce/ts-types';
2
- import { PackageDir as PackageDirSchema, PackageDirDependency as PackageDirDependencySchema, ProjectJson as ProjectJsonSchema, PackagePackageDir } from '@salesforce/schemas';
3
2
  import { ConfigFile } from './config/configFile';
4
3
  import { ConfigContents } from './config/configStackTypes';
5
- export type PackageDirDependency = PackageDirDependencySchema;
6
- type NamedDirAdditions = {
4
+ export type PackageDirDependency = {
5
+ [k: string]: unknown;
6
+ package: string;
7
+ versionNumber?: string;
8
+ };
9
+ export type PackageDir = {
10
+ ancestorId?: string;
11
+ ancestorVersion?: string;
12
+ default?: boolean;
13
+ definitionFile?: string;
14
+ dependencies?: PackageDirDependency[];
15
+ includeProfileUserLicenses?: boolean;
16
+ package?: string;
17
+ packageMetadataAccess?: {
18
+ permissionSets: string | string[];
19
+ permissionSetLicenses: string | string[];
20
+ };
21
+ path: string;
22
+ postInstallScript?: string;
23
+ postInstallUrl?: string;
24
+ releaseNotesUrl?: string;
25
+ scopeProfiles?: boolean;
26
+ uninstallScript?: string;
27
+ versionDescription?: string;
28
+ versionName?: string;
29
+ versionNumber?: string;
30
+ unpackagedMetadata?: {
31
+ path: string;
32
+ };
33
+ seedMetadata?: {
34
+ path: string;
35
+ };
36
+ };
37
+ export type NamedPackageDir = PackageDir & {
7
38
  /**
8
39
  * The [normalized](https://nodejs.org/api/path.html#path_path_normalize_path) path used as the package name.
9
40
  */
@@ -13,10 +44,20 @@ type NamedDirAdditions = {
13
44
  */
14
45
  fullPath: string;
15
46
  };
16
- export type PackageDir = PackageDirSchema;
17
- export type NamedPackagingDir = PackagePackageDir & NamedDirAdditions;
18
- export type NamedPackageDir = PackageDir & NamedDirAdditions;
19
- export type ProjectJson = ConfigContents & ProjectJsonSchema;
47
+ export type ProjectJson = ConfigContents & {
48
+ packageDirectories: PackageDir[];
49
+ namespace?: string;
50
+ sourceApiVersion?: string;
51
+ sfdcLoginUrl?: string;
52
+ signupTargetLoginUrl?: string;
53
+ oauthLocalPort?: number;
54
+ plugins?: {
55
+ [k: string]: unknown;
56
+ };
57
+ packageAliases?: {
58
+ [k: string]: string;
59
+ };
60
+ };
20
61
  /**
21
62
  * The sfdx-project.json config object. This file determines if a folder is a valid sfdx project.
22
63
  *
@@ -119,7 +160,7 @@ export declare class SfProjectJson extends ConfigFile<ConfigFile.Options, Projec
119
160
  *
120
161
  * @param packageDir
121
162
  */
122
- addPackageDirectory(packageDir: PackageDir): void;
163
+ addPackageDirectory(packageDir: NamedPackageDir): void;
123
164
  private doesPackageExist;
124
165
  private validateKeys;
125
166
  }
@@ -317,7 +358,3 @@ export declare class SfProject {
317
358
  getPackageIdFromAlias(alias: string): Optional<string>;
318
359
  getAliasesFromPackageId(id: string): string[];
319
360
  }
320
- /** differentiate between the Base PackageDir (path, maybe default) and the Packaging version (package and maybe a LOT of other fields) by whether is has the `package` property */
321
- export declare const isPackagingDirectory: (packageDir: PackageDir) => packageDir is PackagePackageDir;
322
- export declare const isNamedPackagingDirectory: (packageDir: NamedPackageDir) => packageDir is NamedPackagingDir;
323
- export {};
package/lib/sfProject.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isNamedPackagingDirectory = exports.isPackagingDirectory = exports.SfProject = exports.SfProjectJson = void 0;
26
+ exports.SfProject = exports.SfProjectJson = void 0;
27
27
  /*
28
28
  * Copyright (c) 2020, salesforce.com, inc.
29
29
  * All rights reserved.
@@ -282,7 +282,16 @@ class SfProjectJson extends configFile_1.ConfigFile {
282
282
  * @param packageDir
283
283
  */
284
284
  addPackageDirectory(packageDir) {
285
- const dirIndex = this.getContents().packageDirectories.findIndex(findPackageDir(packageDir));
285
+ // there is no notion of uniqueness in package directory entries
286
+ // so an attempt of matching an existing entry is a bit convoluted
287
+ // an entry w/o a package or id is considered a directory entry for which a package has yet to be created
288
+ // so first attempt is to find a matching dir entry that where path is the same and id and package are not present
289
+ // if that fails, then find a matching dir entry package is present and is same as the new entry
290
+ const dirIndex = this.getContents().packageDirectories.findIndex((pd) => {
291
+ const withId = pd;
292
+ return ((withId.path === packageDir.path && !withId.id && !withId.package) ||
293
+ (!!packageDir.package && packageDir.package === withId.package));
294
+ });
286
295
  // merge new package dir with existing entry, if present
287
296
  const packageDirEntry = Object.assign({}, dirIndex > -1 ? this.getContents().packageDirectories[dirIndex] : packageDir, packageDir);
288
297
  const modifiedPackagesDirs = dirIndex > -1
@@ -292,7 +301,6 @@ class SfProjectJson extends configFile_1.ConfigFile {
292
301
  [...(this.getContents()?.packageDirectories ?? []), packageDirEntry];
293
302
  this.set('packageDirectories', modifiedPackagesDirs);
294
303
  }
295
- // keep it because testSetup stubs it!
296
304
  // eslint-disable-next-line class-methods-use-this
297
305
  doesPackageExist(packagePath) {
298
306
  return fs.existsSync(packagePath);
@@ -512,9 +520,7 @@ class SfProject {
512
520
  */
513
521
  getPackageNameFromPath(path) {
514
522
  const packageDir = this.getPackageFromPath(path);
515
- if (!packageDir)
516
- return undefined;
517
- return (0, exports.isNamedPackagingDirectory)(packageDir) ? packageDir.package : packageDir.path;
523
+ return packageDir ? packageDir.package ?? packageDir.path : undefined;
518
524
  }
519
525
  /**
520
526
  * Returns the package directory.
@@ -582,7 +588,9 @@ class SfProject {
582
588
  */
583
589
  getDefaultPackage() {
584
590
  if (!this.hasPackages()) {
585
- throw new sfError_1.SfError('The sfdx-project.json does not have any packageDirectories defined.');
591
+ throw new sfError_1.SfError('The sfdx-project.json does not have any packageDirectories defined.', 'NoPackageDirectories', [
592
+ `Check ${this.getPath()} for packageDirectories.`,
593
+ ]);
586
594
  }
587
595
  const defaultPackage = this.findPackage((packageDir) => packageDir.default === true);
588
596
  return defaultPackage ?? this.getPackageDirectories()[0];
@@ -658,19 +666,4 @@ class SfProject {
658
666
  }
659
667
  }
660
668
  exports.SfProject = SfProject;
661
- /** differentiate between the Base PackageDir (path, maybe default) and the Packaging version (package and maybe a LOT of other fields) by whether is has the `package` property */
662
- const isPackagingDirectory = (packageDir) => 'package' in packageDir && typeof packageDir.package === 'string';
663
- exports.isPackagingDirectory = isPackagingDirectory;
664
- const isNamedPackagingDirectory = (packageDir) => 'package' in packageDir && typeof packageDir.package === 'string';
665
- exports.isNamedPackagingDirectory = isNamedPackagingDirectory;
666
- /**
667
- * there is no notion of uniqueness in package directory entries
668
- * so an attempt of matching an existing entry is a bit convoluted
669
- */
670
- const findPackageDir = (target) => (potentialMatch) =>
671
- // an entry w/o a package or id is considered a directory entry for which a package has yet to be created
672
- // find a matching dir entry that where path is the same and id and package are not present
673
- (potentialMatch.path === target.path && !('id' in potentialMatch) && !(0, exports.isPackagingDirectory)(potentialMatch)) ||
674
- // if that fails, then find a matching dir entry package is present and is same as the new entry
675
- ((0, exports.isPackagingDirectory)(target) && (0, exports.isPackagingDirectory)(potentialMatch) && target.package === potentialMatch.package);
676
669
  //# sourceMappingURL=sfProject.js.map
package/lib/testSetup.js CHANGED
@@ -532,6 +532,8 @@ const restoreContext = (testContext) => {
532
532
  testContext.configStubs = {};
533
533
  // Give each test run a clean StateAggregator
534
534
  stateAggregator_1.StateAggregator.clearInstance();
535
+ // @ts-expect-error accessing a private property
536
+ sfProject_1.SfProject.instances.clear();
535
537
  // Allow each test to have their own config aggregator
536
538
  // @ts-ignore clear for testing.
537
539
  delete configAggregator_1.ConfigAggregator.instance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "7.3.12-qa.1",
3
+ "version": "7.4.0",
4
4
  "description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
5
5
  "main": "lib/index",
6
6
  "types": "lib/index.d.ts",
@@ -83,7 +83,7 @@
83
83
  "benchmark": "^2.1.4",
84
84
  "chai-string": "^1.5.0",
85
85
  "ts-node": "^10.9.2",
86
- "ts-patch": "^3.1.1",
86
+ "ts-patch": "^3.2.0",
87
87
  "typescript": "^5.4.5"
88
88
  },
89
89
  "repository": {