@salesforce/core 3.30.1 → 3.30.3

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.
@@ -25,6 +25,7 @@ export declare enum EnvironmentVariable {
25
25
  'SFDX_IMPROVED_CODE_COVERAGE' = "SFDX_IMPROVED_CODE_COVERAGE",
26
26
  'SFDX_INSTANCE_URL' = "SFDX_INSTANCE_URL",
27
27
  'SFDX_JSON_TO_STDOUT' = "SFDX_JSON_TO_STDOUT",
28
+ 'SFDX_DISABLE_LOG_FILE' = "SFDX_DISABLE_LOG_FILE",
28
29
  'SFDX_LOG_LEVEL' = "SFDX_LOG_LEVEL",
29
30
  'SFDX_LOG_ROTATION_COUNT' = "SFDX_LOG_ROTATION_COUNT",
30
31
  'SFDX_LOG_ROTATION_PERIOD' = "SFDX_LOG_ROTATION_PERIOD",
@@ -59,6 +60,7 @@ export declare enum EnvironmentVariable {
59
60
  'SF_IMPROVED_CODE_COVERAGE' = "SF_IMPROVED_CODE_COVERAGE",
60
61
  'SF_ORG_INSTANCE_URL' = "SF_ORG_INSTANCE_URL",
61
62
  'SF_JSON_TO_STDOUT' = "SF_JSON_TO_STDOUT",
63
+ 'SF_DISABLE_LOG_FILE' = "SF_DISABLE_LOG_FILE",
62
64
  'SF_LOG_LEVEL' = "SF_LOG_LEVEL",
63
65
  'SF_LOG_ROTATION_COUNT' = "SF_LOG_ROTATION_COUNT",
64
66
  'SF_LOG_ROTATION_PERIOD' = "SF_LOG_ROTATION_PERIOD",
@@ -39,6 +39,7 @@ var EnvironmentVariable;
39
39
  EnvironmentVariable["SFDX_IMPROVED_CODE_COVERAGE"] = "SFDX_IMPROVED_CODE_COVERAGE";
40
40
  EnvironmentVariable["SFDX_INSTANCE_URL"] = "SFDX_INSTANCE_URL";
41
41
  EnvironmentVariable["SFDX_JSON_TO_STDOUT"] = "SFDX_JSON_TO_STDOUT";
42
+ EnvironmentVariable["SFDX_DISABLE_LOG_FILE"] = "SFDX_DISABLE_LOG_FILE";
42
43
  EnvironmentVariable["SFDX_LOG_LEVEL"] = "SFDX_LOG_LEVEL";
43
44
  EnvironmentVariable["SFDX_LOG_ROTATION_COUNT"] = "SFDX_LOG_ROTATION_COUNT";
44
45
  EnvironmentVariable["SFDX_LOG_ROTATION_PERIOD"] = "SFDX_LOG_ROTATION_PERIOD";
@@ -73,6 +74,7 @@ var EnvironmentVariable;
73
74
  EnvironmentVariable["SF_IMPROVED_CODE_COVERAGE"] = "SF_IMPROVED_CODE_COVERAGE";
74
75
  EnvironmentVariable["SF_ORG_INSTANCE_URL"] = "SF_ORG_INSTANCE_URL";
75
76
  EnvironmentVariable["SF_JSON_TO_STDOUT"] = "SF_JSON_TO_STDOUT";
77
+ EnvironmentVariable["SF_DISABLE_LOG_FILE"] = "SF_DISABLE_LOG_FILE";
76
78
  EnvironmentVariable["SF_LOG_LEVEL"] = "SF_LOG_LEVEL";
77
79
  EnvironmentVariable["SF_LOG_ROTATION_COUNT"] = "SF_LOG_ROTATION_COUNT";
78
80
  EnvironmentVariable["SF_LOG_ROTATION_PERIOD"] = "SF_LOG_ROTATION_PERIOD";
@@ -186,6 +188,10 @@ exports.SUPPORTED_ENV_VARS = {
186
188
  description: getMessage(EnvironmentVariable.SFDX_JSON_TO_STDOUT),
187
189
  synonymOf: EnvironmentVariable.SF_JSON_TO_STDOUT,
188
190
  },
191
+ [EnvironmentVariable.SFDX_DISABLE_LOG_FILE]: {
192
+ description: getMessage(EnvironmentVariable.SFDX_DISABLE_LOG_FILE),
193
+ synonymOf: EnvironmentVariable.SF_DISABLE_LOG_FILE,
194
+ },
189
195
  [EnvironmentVariable.SFDX_LOG_LEVEL]: {
190
196
  description: getMessage(EnvironmentVariable.SFDX_LOG_LEVEL),
191
197
  synonymOf: EnvironmentVariable.SF_LOG_LEVEL,
@@ -323,6 +329,10 @@ exports.SUPPORTED_ENV_VARS = {
323
329
  description: getMessage(EnvironmentVariable.SF_JSON_TO_STDOUT),
324
330
  synonymOf: null,
325
331
  },
332
+ [EnvironmentVariable.SF_DISABLE_LOG_FILE]: {
333
+ description: getMessage(EnvironmentVariable.SF_DISABLE_LOG_FILE),
334
+ synonymOf: EnvironmentVariable.SFDX_DISABLE_LOG_FILE,
335
+ },
326
336
  [EnvironmentVariable.SF_LOG_LEVEL]: {
327
337
  description: getMessage(EnvironmentVariable.SF_LOG_LEVEL),
328
338
  synonymOf: null,
package/lib/logger.js CHANGED
@@ -155,7 +155,8 @@ class Logger {
155
155
  }
156
156
  const rootLogger = (this.rootLogger = new Logger(Logger.ROOT_NAME).setLevel());
157
157
  // disable log file writing, if applicable
158
- if (process.env.SFDX_DISABLE_LOG_FILE !== 'true' && global_1.Global.getEnvironmentMode() !== global_1.Mode.TEST) {
158
+ const disableLogFile = new kit_1.Env().getString('SF_DISABLE_LOG_FILE');
159
+ if (disableLogFile !== 'true' && global_1.Global.getEnvironmentMode() !== global_1.Mode.TEST) {
159
160
  await rootLogger.addLogFileStream(global_1.Global.LOG_FILE_PATH);
160
161
  }
161
162
  rootLogger.enableDEBUG();
@@ -353,7 +354,8 @@ class Logger {
353
354
  */
354
355
  setLevel(level) {
355
356
  if (level == null) {
356
- level = process.env.SFDX_LOG_LEVEL ? Logger.getLevelByName(process.env.SFDX_LOG_LEVEL) : Logger.DEFAULT_LEVEL;
357
+ const logLevelFromEnvVar = new kit_1.Env().getString('SF_LOG_LEVEL');
358
+ level = logLevelFromEnvVar ? Logger.getLevelByName(logLevelFromEnvVar) : Logger.DEFAULT_LEVEL;
357
359
  }
358
360
  this.bunyan.level(level);
359
361
  return this;
@@ -1,4 +1,4 @@
1
- import { JsonMap, Nullable, Optional } from '@salesforce/ts-types';
1
+ import { Dictionary, JsonMap, Nullable, Optional } from '@salesforce/ts-types';
2
2
  import { ConfigFile } from './config/configFile';
3
3
  import { ConfigContents } from './config/configStore';
4
4
  export declare type PackageDirDependency = {
@@ -127,6 +127,30 @@ export declare class SfProjectJson extends ConfigFile {
127
127
  * Has multiple package directories (MPD) defined in the project.
128
128
  */
129
129
  hasMultiplePackages(): boolean;
130
+ /**
131
+ * Has at least one package alias defined in the project.
132
+ */
133
+ hasPackageAliases(): Promise<boolean>;
134
+ /**
135
+ * Get package aliases defined in the project.
136
+ */
137
+ getPackageAliases(): Nullable<Dictionary<string>>;
138
+ /**
139
+ * Add a package alias to the project.
140
+ * If the alias already exists, it will be overwritten.
141
+ *
142
+ * @param alias
143
+ * @param id
144
+ */
145
+ addPackageAlias(alias: string, id: string): void;
146
+ /**
147
+ * Add a package directory to the project.
148
+ * If the package directory already exists, the new directory
149
+ * properties will be merged with the existing properties.
150
+ *
151
+ * @param packageDir
152
+ */
153
+ addPackageDirectory(packageDir: PackageDir): void;
130
154
  private doesPackageExist;
131
155
  private validateKeys;
132
156
  }
@@ -148,6 +172,7 @@ export declare class SfProject {
148
172
  private sfProjectJsonGlobal;
149
173
  private packageDirectories?;
150
174
  private activePackage;
175
+ private packageAliases;
151
176
  /**
152
177
  * Do not directly construct instances of this class -- use {@link SfProject.resolve} instead.
153
178
  *
@@ -284,7 +309,7 @@ export declare class SfProject {
284
309
  * Set the currently activated package on the project. This has no implication on sfdx-project.json
285
310
  * but is useful for keeping track of package and source specific options in a process.
286
311
  *
287
- * @param pkgName The package name to activate. E.g. 'force-app'
312
+ * @param packageName The package name to activate. E.g. 'force-app'
288
313
  */
289
314
  setActivePackage(packageName: Nullable<string>): void;
290
315
  /**
@@ -304,6 +329,15 @@ export declare class SfProject {
304
329
  * properties, including some 3rd party custom properties.
305
330
  */
306
331
  resolveProjectConfig(): Promise<JsonMap>;
332
+ hasPackageAliases(): Promise<boolean>;
333
+ /**
334
+ * Returns a read-only list of `packageDirectories` within sfdx-project.json, first reading
335
+ * and validating the file if necessary. i.e. modifying this array will not affect the
336
+ * sfdx-project.json file.
337
+ */
338
+ getPackageAliases(): Nullable<Dictionary<string>>;
339
+ getPackageIdFromAlias(alias: string): Optional<string>;
340
+ getAliasesFromPackageId(id: string): string[];
307
341
  }
308
342
  /**
309
343
  * @deprecated use SfProject instead
package/lib/sfProject.js CHANGED
@@ -27,6 +27,7 @@ const messages = messages_1.Messages.load('@salesforce/core', 'config', [
27
27
  'multipleDefaultPaths',
28
28
  'invalidPackageDirectory',
29
29
  'missingPackageDirectory',
30
+ 'invalidId',
30
31
  ]);
31
32
  const coreMessages = messages_1.Messages.load('@salesforce/core', 'core', ['invalidJsonCasing']);
32
33
  /**
@@ -241,13 +242,63 @@ class SfProjectJson extends configFile_1.ConfigFile {
241
242
  * Has package directories defined in the project.
242
243
  */
243
244
  hasPackages() {
244
- return this.getContents().packageDirectories && this.getContents().packageDirectories.length > 0;
245
+ return this.getContents()?.packageDirectories?.length > 0;
245
246
  }
246
247
  /**
247
248
  * Has multiple package directories (MPD) defined in the project.
248
249
  */
249
250
  hasMultiplePackages() {
250
- return this.getContents().packageDirectories && this.getContents().packageDirectories.length > 1;
251
+ return this.getContents()?.packageDirectories?.length > 1;
252
+ }
253
+ /**
254
+ * Has at least one package alias defined in the project.
255
+ */
256
+ async hasPackageAliases() {
257
+ return Object.keys(this.getContents().packageAliases || {}).length > 0;
258
+ }
259
+ /**
260
+ * Get package aliases defined in the project.
261
+ */
262
+ getPackageAliases() {
263
+ return this.getContents().packageAliases;
264
+ }
265
+ /**
266
+ * Add a package alias to the project.
267
+ * If the alias already exists, it will be overwritten.
268
+ *
269
+ * @param alias
270
+ * @param id
271
+ */
272
+ addPackageAlias(alias, id) {
273
+ // TODO: validate id (e.g. 04t, 0Ho)
274
+ if (!/^.{15,18}$/.test(id)) {
275
+ throw messages.createError('invalidId', [id]);
276
+ }
277
+ const contents = this.getContents();
278
+ if (!contents.packageAliases) {
279
+ contents.packageAliases = {};
280
+ }
281
+ contents.packageAliases[alias] = id;
282
+ this.setContents(contents);
283
+ }
284
+ /**
285
+ * Add a package directory to the project.
286
+ * If the package directory already exists, the new directory
287
+ * properties will be merged with the existing properties.
288
+ *
289
+ * @param packageDir
290
+ */
291
+ addPackageDirectory(packageDir) {
292
+ const dirIndex = this.getContents().packageDirectories.findIndex((pkgDir) => {
293
+ return pkgDir.package === packageDir.package;
294
+ });
295
+ const packageDirEntry = Object.assign({}, dirIndex > -1 ? this.getContents().packageDirectories[dirIndex] : packageDir, packageDir);
296
+ if (dirIndex > -1) {
297
+ this.getContents().packageDirectories[dirIndex] = packageDirEntry;
298
+ }
299
+ else {
300
+ this.getContents().packageDirectories.push(packageDirEntry);
301
+ }
251
302
  }
252
303
  doesPackageExist(packagePath) {
253
304
  return fs.existsSync(packagePath);
@@ -492,7 +543,7 @@ class SfProject {
492
543
  * Set the currently activated package on the project. This has no implication on sfdx-project.json
493
544
  * but is useful for keeping track of package and source specific options in a process.
494
545
  *
495
- * @param pkgName The package name to activate. E.g. 'force-app'
546
+ * @param packageName The package name to activate. E.g. 'force-app'
496
547
  */
497
548
  setActivePackage(packageName) {
498
549
  if (packageName == null) {
@@ -551,6 +602,32 @@ class SfProject {
551
602
  }
552
603
  return this.projectConfig;
553
604
  }
605
+ async hasPackageAliases() {
606
+ return this.getSfProjectJson().hasPackageAliases();
607
+ }
608
+ /**
609
+ * Returns a read-only list of `packageDirectories` within sfdx-project.json, first reading
610
+ * and validating the file if necessary. i.e. modifying this array will not affect the
611
+ * sfdx-project.json file.
612
+ */
613
+ getPackageAliases() {
614
+ if (!this.packageAliases) {
615
+ this.packageAliases = this.getSfProjectJson().getPackageAliases();
616
+ }
617
+ return this.packageAliases;
618
+ }
619
+ getPackageIdFromAlias(alias) {
620
+ const packageAliases = this.getPackageAliases();
621
+ return packageAliases ? packageAliases[alias] : undefined;
622
+ }
623
+ getAliasesFromPackageId(id) {
624
+ if (!/^.{15,18}$/.test(id)) {
625
+ throw messages.createError('invalidId', [id]);
626
+ }
627
+ return Object.entries(this.getPackageAliases() ?? {})
628
+ .filter(([, value]) => value?.startsWith(id))
629
+ .map(([key]) => key);
630
+ }
554
631
  }
555
632
  exports.SfProject = SfProject;
556
633
  // Cache of SfProject instances per path.
@@ -150,3 +150,7 @@ A valid repository URL or directory for the custom org metadata templates.
150
150
  # org-custom-metadata-templates
151
151
 
152
152
  A valid repository URL or directory for the custom org metadata templates.
153
+
154
+ # invalidId
155
+
156
+ The given id %s is not a valid 15 or 18 character Salesforce ID.
@@ -90,6 +90,10 @@ URL of the Salesforce instance that is hosting your org. Default value is https:
90
90
 
91
91
  Set to true to send messages resulting from failed Salesforce CLI commands to stdout instead of stderr.
92
92
 
93
+ # sfdxDisableLogFile
94
+
95
+ Set to true to disable log file writing
96
+
93
97
  # sfdxLogLevel
94
98
 
95
99
  Level of messages that the CLI writes to the log file. Valid values are trace, debug, info, warn, error, fatal. Default value is warn.
@@ -226,6 +230,10 @@ URL of the Salesforce instance that is hosting your org. Default value is https:
226
230
 
227
231
  Set to true to send messages resulting from failed Salesforce CLI commands to stdout instead of stderr.
228
232
 
233
+ # sfDisableLogFile
234
+
235
+ Set to true to disable log file writing
236
+
229
237
  # sfLogLevel
230
238
 
231
239
  Level of messages that the CLI writes to the log file. Valid values are trace, debug, info, warn, error, fatal. Default value is warn.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "3.30.1",
3
+ "version": "3.30.3",
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",
@@ -96,4 +96,4 @@
96
96
  "publishConfig": {
97
97
  "access": "public"
98
98
  }
99
- }
99
+ }