@salesforce/core 8.0.5 → 8.1.1

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.
@@ -94,5 +94,5 @@ export declare class Lifecycle {
94
94
  */
95
95
  emit<T = AnyJson>(eventName: string, data: T): Promise<void>;
96
96
  }
97
- export declare const cloneUniqueListeners: (uniqueListeners: UniqueListenerMap) => UniqueListenerMap;
97
+ export declare const cloneUniqueListeners: (uniqueListeners: UniqueListenerMap | undefined) => UniqueListenerMap;
98
98
  export {};
@@ -233,6 +233,8 @@ class Lifecycle {
233
233
  }
234
234
  exports.Lifecycle = Lifecycle;
235
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)]));
236
+ const cloneUniqueListeners = (uniqueListeners) =>
237
+ // in case we're crossing major sfdx-core versions where uniqueListeners might be undefined
238
+ new Map(Array.from(uniqueListeners?.entries() ?? []).map(([key, value]) => [key, cloneListeners(value)]));
237
239
  exports.cloneUniqueListeners = cloneUniqueListeners;
238
240
  //# sourceMappingURL=lifecycleEvents.js.map
@@ -19,14 +19,21 @@ export type ProjectJson = ConfigContents & ProjectJsonSchema;
19
19
  * The sfdx-project.json config object. This file determines if a folder is a valid sfdx project.
20
20
  *
21
21
  * *Note:* Any non-standard (not owned by Salesforce) properties stored in sfdx-project.json should
22
- * be in a top level property that represents your project or plugin.
22
+ * be in a top level property that represents your project.
23
+ * Plugins should store their configuration @see SfProject.getPluginConfiguration and @see SfProject.setPluginConfiguration
23
24
  *
25
+ * @example reading a standard property
24
26
  * ```
25
27
  * const project = await SfProject.resolve();
26
28
  * const projectJson = await project.resolveProjectConfig();
27
- * const myPluginProperties = projectJson.get('myplugin') || {};
28
- * myPluginProperties.myprop = 'someValue';
29
- * projectJson.set('myplugin', myPluginProperties);
29
+ * const namespace = projectJson.get('namespace');
30
+ * ```
31
+ *
32
+ * ```
33
+ * @example writing
34
+ * const project = await SfProject.resolve();
35
+ * const projectJson = await project.resolveProjectConfig();
36
+ * projectJson.set('namespace', 'new');
30
37
  * await projectJson.write();
31
38
  * ```
32
39
  *
@@ -315,6 +322,30 @@ export declare class SfProject {
315
322
  getPackageAliases(): Nullable<Dictionary<string>>;
316
323
  getPackageIdFromAlias(alias: string): Optional<string>;
317
324
  getAliasesFromPackageId(id: string): string[];
325
+ /**
326
+ * retrieve the configuration for a named plugin from sfdx-project.json.plugins.pluginName
327
+ *
328
+ * @example
329
+ * ```
330
+ * const project = await SfProject.resolve();
331
+ * const pluginConfig = await project.getPluginConfiguration('myPlugin');
332
+ * ```
333
+ *
334
+ * optionally pass a type parameter for your plugin configuration's schema
335
+ * */
336
+ getPluginConfiguration<T extends Record<string, unknown>>(pluginName: string): Promise<Readonly<T>>;
337
+ /**
338
+ * set the configuration for a named plugin from sfdx-project.json.plugins.pluginName, overwriting existing configuration
339
+ *
340
+ * @example
341
+ * ```
342
+ * const project = await SfProject.resolve();
343
+ * const pluginConfig = await project.setPluginConfiguration('myPlugin', {foo: 'bar', myLimit: 25});
344
+ * ```
345
+ *
346
+ * optionally pass a type parameter for your plugin configuration's schema
347
+ * */
348
+ setPluginConfiguration<T extends Record<string, unknown>>(pluginName: string, config: T): Promise<void>;
318
349
  }
319
350
  /** 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 */
320
351
  export declare const isPackagingDirectory: (packageDir: PackageDir) => packageDir is PackagePackageDir;
package/lib/sfProject.js CHANGED
@@ -48,14 +48,21 @@ const messages = new messages_1.Messages('@salesforce/core', 'config', new Map([
48
48
  * The sfdx-project.json config object. This file determines if a folder is a valid sfdx project.
49
49
  *
50
50
  * *Note:* Any non-standard (not owned by Salesforce) properties stored in sfdx-project.json should
51
- * be in a top level property that represents your project or plugin.
51
+ * be in a top level property that represents your project.
52
+ * Plugins should store their configuration @see SfProject.getPluginConfiguration and @see SfProject.setPluginConfiguration
52
53
  *
54
+ * @example reading a standard property
53
55
  * ```
54
56
  * const project = await SfProject.resolve();
55
57
  * const projectJson = await project.resolveProjectConfig();
56
- * const myPluginProperties = projectJson.get('myplugin') || {};
57
- * myPluginProperties.myprop = 'someValue';
58
- * projectJson.set('myplugin', myPluginProperties);
58
+ * const namespace = projectJson.get('namespace');
59
+ * ```
60
+ *
61
+ * ```
62
+ * @example writing
63
+ * const project = await SfProject.resolve();
64
+ * const projectJson = await project.resolveProjectConfig();
65
+ * projectJson.set('namespace', 'new');
59
66
  * await projectJson.write();
60
67
  * ```
61
68
  *
@@ -654,6 +661,46 @@ class SfProject {
654
661
  .filter(([, value]) => value?.startsWith(id))
655
662
  .map(([key]) => key);
656
663
  }
664
+ /**
665
+ * retrieve the configuration for a named plugin from sfdx-project.json.plugins.pluginName
666
+ *
667
+ * @example
668
+ * ```
669
+ * const project = await SfProject.resolve();
670
+ * const pluginConfig = await project.getPluginConfiguration('myPlugin');
671
+ * ```
672
+ *
673
+ * optionally pass a type parameter for your plugin configuration's schema
674
+ * */
675
+ async getPluginConfiguration(pluginName) {
676
+ await this.retrieveSfProjectJson();
677
+ const plugins = this.sfProjectJson.get('plugins');
678
+ if (!plugins) {
679
+ throw new sfError_1.SfError('No plugins defined in sfdx-project.json', 'NoPluginsDefined');
680
+ }
681
+ if (!plugins[pluginName]) {
682
+ throw new sfError_1.SfError(`No configuration defined in sfdx-project.json for plugin ${pluginName}`, 'PluginNotFound');
683
+ }
684
+ return plugins[pluginName];
685
+ }
686
+ /**
687
+ * set the configuration for a named plugin from sfdx-project.json.plugins.pluginName, overwriting existing configuration
688
+ *
689
+ * @example
690
+ * ```
691
+ * const project = await SfProject.resolve();
692
+ * const pluginConfig = await project.setPluginConfiguration('myPlugin', {foo: 'bar', myLimit: 25});
693
+ * ```
694
+ *
695
+ * optionally pass a type parameter for your plugin configuration's schema
696
+ * */
697
+ async setPluginConfiguration(pluginName, config) {
698
+ await this.retrieveSfProjectJson();
699
+ const plugins = this.getSfProjectJson().get('plugins') ?? {};
700
+ const modified = { ...plugins, [pluginName]: config };
701
+ this.sfProjectJson.set('plugins', modified);
702
+ this.sfProjectJson.writeSync();
703
+ }
657
704
  }
658
705
  exports.SfProject = SfProject;
659
706
  /** 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 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "8.0.5",
3
+ "version": "8.1.1",
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",