@salesforce/core 3.30.2 → 3.30.4
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/lib/sfProject.d.ts +36 -2
- package/lib/sfProject.js +87 -10
- package/messages/config.md +4 -0
- package/package.json +2 -2
- package/CHANGELOG.md +0 -1671
package/lib/sfProject.d.ts
CHANGED
|
@@ -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: NamedPackageDir): 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
|
|
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
|
/**
|
|
@@ -223,8 +224,8 @@ class SfProjectJson extends configFile_1.ConfigFile {
|
|
|
223
224
|
const uniqueValues = [];
|
|
224
225
|
// Keep original order defined in sfdx-project.json
|
|
225
226
|
this.getPackageDirectoriesSync().forEach((packageDir) => {
|
|
226
|
-
if (!visited[packageDir.
|
|
227
|
-
visited[packageDir.
|
|
227
|
+
if (!visited[packageDir.path]) {
|
|
228
|
+
visited[packageDir.path] = true;
|
|
228
229
|
uniqueValues.push(packageDir);
|
|
229
230
|
}
|
|
230
231
|
});
|
|
@@ -235,19 +236,69 @@ class SfProjectJson extends configFile_1.ConfigFile {
|
|
|
235
236
|
* for data other than the names.
|
|
236
237
|
*/
|
|
237
238
|
getUniquePackageNames() {
|
|
238
|
-
return this.getUniquePackageDirectories().map((pkgDir) => pkgDir.
|
|
239
|
+
return this.getUniquePackageDirectories().map((pkgDir) => pkgDir.package || pkgDir.path);
|
|
239
240
|
}
|
|
240
241
|
/**
|
|
241
242
|
* Has package directories defined in the project.
|
|
242
243
|
*/
|
|
243
244
|
hasPackages() {
|
|
244
|
-
return this.getContents()
|
|
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()
|
|
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);
|
|
@@ -438,7 +489,7 @@ class SfProject {
|
|
|
438
489
|
*/
|
|
439
490
|
getPackageFromPath(path) {
|
|
440
491
|
const packageDirs = this.getPackageDirectories();
|
|
441
|
-
const match = packageDirs.find((packageDir) => (0, path_1.basename)(path) === packageDir.
|
|
492
|
+
const match = packageDirs.find((packageDir) => (0, path_1.basename)(path) === packageDir.path || path.includes(packageDir.fullPath));
|
|
442
493
|
return match;
|
|
443
494
|
}
|
|
444
495
|
/**
|
|
@@ -448,7 +499,7 @@ class SfProject {
|
|
|
448
499
|
*/
|
|
449
500
|
getPackageNameFromPath(path) {
|
|
450
501
|
const packageDir = this.getPackageFromPath(path);
|
|
451
|
-
return packageDir ? packageDir.
|
|
502
|
+
return packageDir ? packageDir.package || packageDir.path : undefined;
|
|
452
503
|
}
|
|
453
504
|
/**
|
|
454
505
|
* Returns the package directory.
|
|
@@ -457,7 +508,7 @@ class SfProject {
|
|
|
457
508
|
*/
|
|
458
509
|
getPackage(packageName) {
|
|
459
510
|
const packageDirs = this.getPackageDirectories();
|
|
460
|
-
return packageDirs.find((packageDir) => packageDir.
|
|
511
|
+
return packageDirs.find((packageDir) => packageDir.package === packageName || packageDir.path === packageName);
|
|
461
512
|
}
|
|
462
513
|
/**
|
|
463
514
|
* Returns the absolute path of the package directory ending with the path separator.
|
|
@@ -467,7 +518,7 @@ class SfProject {
|
|
|
467
518
|
*/
|
|
468
519
|
getPackagePath(packageName) {
|
|
469
520
|
const packageDir = this.getPackage(packageName);
|
|
470
|
-
return packageDir
|
|
521
|
+
return packageDir?.fullPath;
|
|
471
522
|
}
|
|
472
523
|
/**
|
|
473
524
|
* Has package directories defined in the project.
|
|
@@ -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
|
|
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.
|
package/messages/config.md
CHANGED
|
@@ -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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/core",
|
|
3
|
-
"version": "3.30.
|
|
3
|
+
"version": "3.30.4",
|
|
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
|
+
}
|