@salesforce/core 4.0.0 → 4.1.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.
- package/LICENSE.txt +1 -1
- package/README.md +93 -44
- package/lib/config/authInfoConfig.d.ts +19 -0
- package/lib/config/authInfoConfig.js +35 -0
- package/lib/config/config.d.ts +87 -22
- package/lib/config/config.js +117 -65
- package/lib/config/configAggregator.d.ts +41 -35
- package/lib/config/configAggregator.js +102 -73
- package/lib/config/configFile.d.ts +2 -2
- package/lib/config/configFile.js +38 -29
- package/lib/config/configStore.d.ts +9 -9
- package/lib/config/configStore.js +17 -15
- package/lib/config/envVars.d.ts +15 -9
- package/lib/config/envVars.js +71 -47
- package/lib/config/orgUsersConfig.js +2 -0
- package/lib/config/sandboxOrgConfig.js +2 -0
- package/lib/config/sandboxProcessCache.d.ts +16 -0
- package/lib/config/sandboxProcessCache.js +38 -0
- package/lib/config/tokensConfig.d.ts +10 -0
- package/lib/config/tokensConfig.js +29 -0
- package/lib/config/ttlConfig.d.ts +34 -0
- package/lib/config/ttlConfig.js +50 -0
- package/lib/crypto/crypto.js +15 -22
- package/lib/crypto/keyChain.js +2 -3
- package/lib/crypto/keyChainImpl.d.ts +5 -3
- package/lib/crypto/keyChainImpl.js +58 -61
- package/lib/crypto/secureBuffer.d.ts +1 -1
- package/lib/deviceOauthService.d.ts +3 -3
- package/lib/deviceOauthService.js +27 -25
- package/lib/exported.d.ts +15 -12
- package/lib/exported.js +28 -16
- package/lib/global.d.ts +11 -3
- package/lib/global.js +39 -12
- package/lib/lifecycleEvents.d.ts +1 -1
- package/lib/lifecycleEvents.js +3 -0
- package/lib/logger.d.ts +19 -9
- package/lib/logger.js +112 -86
- package/lib/messages.d.ts +53 -36
- package/lib/messages.js +81 -91
- package/lib/org/authInfo.d.ts +56 -20
- package/lib/org/authInfo.js +232 -131
- package/lib/org/authRemover.d.ts +8 -7
- package/lib/org/authRemover.js +32 -28
- package/lib/org/connection.d.ts +13 -37
- package/lib/org/connection.js +78 -124
- package/lib/org/index.js +5 -1
- package/lib/org/org.d.ts +151 -48
- package/lib/org/org.js +468 -225
- package/lib/org/orgConfigProperties.d.ts +64 -3
- package/lib/org/orgConfigProperties.js +96 -4
- package/lib/org/permissionSetAssignment.js +4 -13
- package/lib/org/scratchOrgCache.d.ts +20 -0
- package/lib/org/scratchOrgCache.js +33 -0
- package/lib/org/scratchOrgCreate.d.ts +28 -17
- package/lib/org/scratchOrgCreate.js +125 -53
- package/lib/org/scratchOrgErrorCodes.d.ts +9 -3
- package/lib/org/scratchOrgErrorCodes.js +34 -17
- package/lib/org/scratchOrgFeatureDeprecation.js +1 -6
- package/lib/org/scratchOrgInfoApi.d.ts +21 -47
- package/lib/org/scratchOrgInfoApi.js +129 -63
- package/lib/org/scratchOrgInfoGenerator.d.ts +6 -5
- package/lib/org/scratchOrgInfoGenerator.js +76 -62
- package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -0
- package/lib/org/scratchOrgLifecycleEvents.js +41 -0
- package/lib/org/scratchOrgSettingsGenerator.d.ts +44 -21
- package/lib/org/scratchOrgSettingsGenerator.js +165 -98
- package/lib/org/scratchOrgTypes.d.ts +43 -0
- package/lib/org/scratchOrgTypes.js +9 -0
- package/lib/org/user.d.ts +1 -1
- package/lib/org/user.js +25 -34
- package/lib/schema/printer.d.ts +6 -0
- package/lib/schema/printer.js +34 -31
- package/lib/schema/validator.d.ts +12 -10
- package/lib/schema/validator.js +56 -76
- package/lib/{sfdxError.d.ts → sfError.d.ts} +12 -20
- package/lib/{sfdxError.js → sfError.js} +40 -30
- package/lib/{sfdxProject.d.ts → sfProject.d.ts} +75 -35
- package/lib/sfProject.js +651 -0
- package/lib/stateAggregator/accessors/aliasAccessor.d.ts +129 -0
- package/lib/stateAggregator/accessors/aliasAccessor.js +263 -0
- package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -0
- package/lib/stateAggregator/accessors/orgAccessor.js +240 -0
- package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -0
- package/lib/stateAggregator/accessors/sandboxAccessor.js +28 -0
- package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -0
- package/lib/stateAggregator/accessors/tokenAccessor.js +80 -0
- package/lib/stateAggregator/index.d.ts +4 -0
- package/lib/stateAggregator/index.js +27 -0
- package/lib/stateAggregator/stateAggregator.d.ts +25 -0
- package/lib/stateAggregator/stateAggregator.js +46 -0
- package/lib/status/myDomainResolver.d.ts +1 -1
- package/lib/status/myDomainResolver.js +4 -4
- package/lib/status/pollingClient.js +4 -4
- package/lib/status/streamingClient.d.ts +2 -2
- package/lib/status/streamingClient.js +58 -63
- package/lib/status/types.d.ts +2 -2
- package/lib/testSetup.d.ts +204 -75
- package/lib/testSetup.js +468 -164
- package/lib/util/cache.d.ts +2 -2
- package/lib/util/cache.js +6 -6
- package/lib/util/checkLightningDomain.js +3 -4
- package/lib/util/directoryWriter.d.ts +12 -0
- package/lib/util/directoryWriter.js +54 -0
- package/lib/util/getJwtAudienceUrl.js +1 -1
- package/lib/util/internal.d.ts +28 -2
- package/lib/util/internal.js +65 -8
- package/lib/util/jsonXmlTools.js +2 -4
- package/lib/util/mapKeys.d.ts +9 -9
- package/lib/util/mapKeys.js +13 -9
- package/lib/util/sfdc.d.ts +51 -51
- package/lib/util/sfdc.js +74 -79
- package/lib/util/sfdcUrl.d.ts +5 -19
- package/lib/util/sfdcUrl.js +40 -49
- package/lib/util/structuredWriter.d.ts +9 -0
- package/lib/util/structuredWriter.js +3 -0
- package/lib/util/zipWriter.d.ts +8 -6
- package/lib/util/zipWriter.js +13 -13
- package/lib/webOAuthServer.d.ts +20 -6
- package/lib/webOAuthServer.js +102 -56
- package/messageTransformer/messageTransformer.ts +93 -0
- package/messages/auth.md +9 -1
- package/messages/config.md +42 -6
- package/messages/connection.md +8 -0
- package/messages/core.md +10 -0
- package/messages/envVars.md +37 -3
- package/messages/org.md +21 -1
- package/messages/scratchOrgCreate.md +2 -6
- package/messages/scratchOrgErrorCodes.md +17 -1
- package/messages/scratchOrgInfoApi.md +9 -0
- package/messages/scratchOrgInfoGenerator.md +9 -1
- package/package.json +123 -46
- package/CHANGELOG.md +0 -1244
- package/lib/config/keychainConfig.d.ts +0 -19
- package/lib/config/keychainConfig.js +0 -43
- package/lib/globalInfo/accessors/aliasAccessor.d.ts +0 -83
- package/lib/globalInfo/accessors/aliasAccessor.js +0 -130
- package/lib/globalInfo/accessors/orgAccessor.d.ts +0 -13
- package/lib/globalInfo/accessors/orgAccessor.js +0 -45
- package/lib/globalInfo/accessors/tokenAccessor.d.ts +0 -13
- package/lib/globalInfo/accessors/tokenAccessor.js +0 -35
- package/lib/globalInfo/globalInfoConfig.d.ts +0 -36
- package/lib/globalInfo/globalInfoConfig.js +0 -105
- package/lib/globalInfo/index.d.ts +0 -6
- package/lib/globalInfo/index.js +0 -29
- package/lib/globalInfo/sfdxDataHandler.d.ts +0 -43
- package/lib/globalInfo/sfdxDataHandler.js +0 -217
- package/lib/globalInfo/types.d.ts +0 -39
- package/lib/globalInfo/types.js +0 -10
- package/lib/sfdxProject.js +0 -557
- package/lib/util/fs.d.ts +0 -201
- package/lib/util/fs.js +0 -378
package/lib/sfdxProject.js
DELETED
|
@@ -1,557 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SfdxProject = exports.SfdxProjectJson = void 0;
|
|
4
|
-
/*
|
|
5
|
-
* Copyright (c) 2020, salesforce.com, inc.
|
|
6
|
-
* All rights reserved.
|
|
7
|
-
* Licensed under the BSD 3-Clause license.
|
|
8
|
-
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
9
|
-
*/
|
|
10
|
-
const path_1 = require("path");
|
|
11
|
-
const kit_1 = require("@salesforce/kit");
|
|
12
|
-
const ts_types_1 = require("@salesforce/ts-types");
|
|
13
|
-
const sfdcUrl_1 = require("./util/sfdcUrl");
|
|
14
|
-
const configAggregator_1 = require("./config/configAggregator");
|
|
15
|
-
const configFile_1 = require("./config/configFile");
|
|
16
|
-
const validator_1 = require("./schema/validator");
|
|
17
|
-
const fs_1 = require("./util/fs");
|
|
18
|
-
const internal_1 = require("./util/internal");
|
|
19
|
-
const sfdxError_1 = require("./sfdxError");
|
|
20
|
-
const sfdc_1 = require("./util/sfdc");
|
|
21
|
-
const messages_1 = require("./messages");
|
|
22
|
-
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
23
|
-
const messages = messages_1.Messages.load('@salesforce/core', 'config', [
|
|
24
|
-
'schemaValidationError',
|
|
25
|
-
'singleNonDefaultPackage',
|
|
26
|
-
'missingDefaultPath',
|
|
27
|
-
'multipleDefaultPaths',
|
|
28
|
-
'invalidPackageDirectory',
|
|
29
|
-
'missingPackageDirectory',
|
|
30
|
-
]);
|
|
31
|
-
const coreMessages = messages_1.Messages.load('@salesforce/core', 'core', ['invalidJsonCasing']);
|
|
32
|
-
/**
|
|
33
|
-
* The sfdx-project.json config object. This file determines if a folder is a valid sfdx project.
|
|
34
|
-
*
|
|
35
|
-
* *Note:* Any non-standard (not owned by Salesforce) properties stored in sfdx-project.json should
|
|
36
|
-
* be in a top level property that represents your project or plugin.
|
|
37
|
-
*
|
|
38
|
-
* ```
|
|
39
|
-
* const project = await SfdxProject.resolve();
|
|
40
|
-
* const projectJson = await project.resolveProjectConfig();
|
|
41
|
-
* const myPluginProperties = projectJson.get('myplugin') || {};
|
|
42
|
-
* myPluginProperties.myprop = 'someValue';
|
|
43
|
-
* projectJson.set('myplugin', myPluginProperties);
|
|
44
|
-
* await projectJson.write();
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* **See** [force:project:create](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_create_new.htm)
|
|
48
|
-
*/
|
|
49
|
-
class SfdxProjectJson extends configFile_1.ConfigFile {
|
|
50
|
-
static getFileName() {
|
|
51
|
-
return internal_1.SFDX_PROJECT_JSON;
|
|
52
|
-
}
|
|
53
|
-
static getDefaultOptions(isGlobal = false) {
|
|
54
|
-
const options = configFile_1.ConfigFile.getDefaultOptions(isGlobal, SfdxProjectJson.getFileName());
|
|
55
|
-
options.isState = false;
|
|
56
|
-
return options;
|
|
57
|
-
}
|
|
58
|
-
async read() {
|
|
59
|
-
const contents = await super.read();
|
|
60
|
-
this.validateKeys();
|
|
61
|
-
await this.schemaValidate();
|
|
62
|
-
return contents;
|
|
63
|
-
}
|
|
64
|
-
readSync() {
|
|
65
|
-
const contents = super.readSync();
|
|
66
|
-
this.validateKeys();
|
|
67
|
-
this.schemaValidateSync();
|
|
68
|
-
return contents;
|
|
69
|
-
}
|
|
70
|
-
async write(newContents) {
|
|
71
|
-
this.setContents(newContents);
|
|
72
|
-
this.validateKeys();
|
|
73
|
-
await this.schemaValidate();
|
|
74
|
-
return super.write();
|
|
75
|
-
}
|
|
76
|
-
writeSync(newContents) {
|
|
77
|
-
this.setContents(newContents);
|
|
78
|
-
this.validateKeys();
|
|
79
|
-
this.schemaValidateSync();
|
|
80
|
-
return super.writeSync();
|
|
81
|
-
}
|
|
82
|
-
getContents() {
|
|
83
|
-
return super.getContents();
|
|
84
|
-
}
|
|
85
|
-
getDefaultOptions(options) {
|
|
86
|
-
const defaultOptions = {
|
|
87
|
-
isState: false,
|
|
88
|
-
};
|
|
89
|
-
Object.assign(defaultOptions, options || {});
|
|
90
|
-
return defaultOptions;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Validates sfdx-project.json against the schema.
|
|
94
|
-
*
|
|
95
|
-
* Set the `SFDX_PROJECT_JSON_VALIDATION` environment variable to `true` to throw an error when schema validation fails.
|
|
96
|
-
* A warning is logged by default when the file is invalid.
|
|
97
|
-
*
|
|
98
|
-
* ***See*** [sfdx-project.schema.json] (https://raw.githubusercontent.com/forcedotcom/schemas/master/schemas/sfdx-project.schema.json)
|
|
99
|
-
*/
|
|
100
|
-
async schemaValidate() {
|
|
101
|
-
if (!this.hasRead) {
|
|
102
|
-
// read calls back into this method after necessarily setting this.hasRead=true
|
|
103
|
-
await this.read();
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
try {
|
|
107
|
-
const projectJsonSchemaPath = require.resolve('@salesforce/schemas/sfdx-project.schema.json');
|
|
108
|
-
const validator = new validator_1.SchemaValidator(this.logger, projectJsonSchemaPath);
|
|
109
|
-
await validator.load();
|
|
110
|
-
await validator.validate(this.getContents());
|
|
111
|
-
}
|
|
112
|
-
catch (err) {
|
|
113
|
-
const error = err;
|
|
114
|
-
// Don't throw errors if the global isn't valid, but still warn the user.
|
|
115
|
-
if (kit_1.env.getBoolean('SFDX_PROJECT_JSON_VALIDATION', false) && !this.options.isGlobal) {
|
|
116
|
-
throw messages.createError('schemaValidationError', [this.getPath(), error.message], [this.getPath()], error);
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
this.logger.warn(messages.getMessage('schemaValidationError', [this.getPath(), error.message]));
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Returns the `packageDirectories` within sfdx-project.json, first reading
|
|
126
|
-
* and validating the file if necessary.
|
|
127
|
-
*/
|
|
128
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
129
|
-
async getPackageDirectories() {
|
|
130
|
-
return this.getPackageDirectoriesSync();
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Validates sfdx-project.json against the schema.
|
|
134
|
-
*
|
|
135
|
-
* Set the `SFDX_PROJECT_JSON_VALIDATION` environment variable to `true` to throw an error when schema validation fails.
|
|
136
|
-
* A warning is logged by default when the file is invalid.
|
|
137
|
-
*
|
|
138
|
-
* ***See*** [sfdx-project.schema.json] (https://raw.githubusercontent.com/forcedotcom/schemas/master/schemas/sfdx-project.schema.json)
|
|
139
|
-
*/
|
|
140
|
-
schemaValidateSync() {
|
|
141
|
-
if (!this.hasRead) {
|
|
142
|
-
// read calls back into this method after necessarily setting this.hasRead=true
|
|
143
|
-
this.readSync();
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
try {
|
|
147
|
-
const projectJsonSchemaPath = require.resolve('@salesforce/schemas/sfdx-project.schema.json');
|
|
148
|
-
const validator = new validator_1.SchemaValidator(this.logger, projectJsonSchemaPath);
|
|
149
|
-
validator.loadSync();
|
|
150
|
-
validator.validateSync(this.getContents());
|
|
151
|
-
}
|
|
152
|
-
catch (err) {
|
|
153
|
-
const error = err;
|
|
154
|
-
// Don't throw errors if the global isn't valid, but still warn the user.
|
|
155
|
-
if (kit_1.env.getBoolean('SFDX_PROJECT_JSON_VALIDATION', false) && !this.options.isGlobal) {
|
|
156
|
-
throw messages.createError('schemaValidationError', [this.getPath(), error.message], [this.getPath()], error);
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
this.logger.warn(messages.getMessage('schemaValidationError', [this.getPath(), error.message]));
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Returns a read-only list of `packageDirectories` within sfdx-project.json, first reading
|
|
166
|
-
* and validating the file if necessary. i.e. modifying this array will not affect the
|
|
167
|
-
* sfdx-project.json file.
|
|
168
|
-
*/
|
|
169
|
-
getPackageDirectoriesSync() {
|
|
170
|
-
const contents = this.getContents();
|
|
171
|
-
// This has to be done on the fly so it won't be written back to the file
|
|
172
|
-
// This is a fast operation so no need to cache it so it stays immutable.
|
|
173
|
-
const packageDirs = (contents.packageDirectories || []).map((packageDir) => {
|
|
174
|
-
if ((0, path_1.isAbsolute)(packageDir.path)) {
|
|
175
|
-
throw messages.createError('invalidPackageDirectory', [packageDir.path]);
|
|
176
|
-
}
|
|
177
|
-
const regex = path_1.sep === '/' ? /\\/g : /\//g;
|
|
178
|
-
// Change packageDir paths to have path separators that match the OS
|
|
179
|
-
const path = packageDir.path.replace(regex, path_1.sep);
|
|
180
|
-
// Normalize and remove any ending path separators
|
|
181
|
-
const name = (0, path_1.normalize)(path).replace(new RegExp(`\\${path_1.sep}$`), '');
|
|
182
|
-
// Always end in a path sep for standardization on folder paths
|
|
183
|
-
const fullPath = `${(0, path_1.dirname)(this.getPath())}${path_1.sep}${name}${path_1.sep}`;
|
|
184
|
-
if (!this.doesPackageExist(fullPath)) {
|
|
185
|
-
throw messages.createError('missingPackageDirectory', [packageDir.path]);
|
|
186
|
-
}
|
|
187
|
-
return Object.assign({}, packageDir, { name, path, fullPath });
|
|
188
|
-
});
|
|
189
|
-
// If we only have one package entry, it must be the default even if not explicitly labelled
|
|
190
|
-
if (packageDirs.length === 1) {
|
|
191
|
-
if (packageDirs[0].default === false) {
|
|
192
|
-
// we have one package but it is explicitly labelled as default=false
|
|
193
|
-
throw messages.createError('singleNonDefaultPackage');
|
|
194
|
-
}
|
|
195
|
-
// add default=true to the package
|
|
196
|
-
packageDirs[0].default = true;
|
|
197
|
-
}
|
|
198
|
-
const defaultDirs = packageDirs.filter((packageDir) => packageDir.default);
|
|
199
|
-
// Don't throw about a missing default path if we are in the global file.
|
|
200
|
-
// Package directories are not really meant to be set at the global level.
|
|
201
|
-
if (defaultDirs.length === 0 && !this.isGlobal()) {
|
|
202
|
-
throw messages.createError('missingDefaultPath');
|
|
203
|
-
}
|
|
204
|
-
else if (defaultDirs.length > 1) {
|
|
205
|
-
throw messages.createError('multipleDefaultPaths');
|
|
206
|
-
}
|
|
207
|
-
return packageDirs;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Returns a read-only list of `packageDirectories` within sfdx-project.json, first reading
|
|
211
|
-
* and validating the file if necessary. i.e. modifying this array will not affect the
|
|
212
|
-
* sfdx-project.json file.
|
|
213
|
-
*
|
|
214
|
-
* There can be multiple packages in packageDirectories that point to the same directory.
|
|
215
|
-
* This method only returns one packageDirectory entry per unique directory path. This is
|
|
216
|
-
* useful when doing source operations based on directories but probably not as useful
|
|
217
|
-
* for packaging operations that want to do something for each package entry.
|
|
218
|
-
*/
|
|
219
|
-
getUniquePackageDirectories() {
|
|
220
|
-
const visited = {};
|
|
221
|
-
const uniqueValues = [];
|
|
222
|
-
// Keep original order defined in sfdx-project.json
|
|
223
|
-
this.getPackageDirectoriesSync().forEach((packageDir) => {
|
|
224
|
-
if (!visited[packageDir.name]) {
|
|
225
|
-
visited[packageDir.name] = true;
|
|
226
|
-
uniqueValues.push(packageDir);
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
return uniqueValues;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Get a list of the unique package names from within sfdx-project.json. Use {@link SfdxProject.getUniquePackageDirectories}
|
|
233
|
-
* for data other than the names.
|
|
234
|
-
*/
|
|
235
|
-
getUniquePackageNames() {
|
|
236
|
-
return this.getUniquePackageDirectories().map((pkgDir) => pkgDir.name);
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Has package directories defined in the project.
|
|
240
|
-
*/
|
|
241
|
-
hasPackages() {
|
|
242
|
-
return this.getContents().packageDirectories && this.getContents().packageDirectories.length > 0;
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Has multiple package directories (MPD) defined in the project.
|
|
246
|
-
*/
|
|
247
|
-
hasMultiplePackages() {
|
|
248
|
-
return this.getContents().packageDirectories && this.getContents().packageDirectories.length > 1;
|
|
249
|
-
}
|
|
250
|
-
doesPackageExist(packagePath) {
|
|
251
|
-
return fs_1.fs.existsSync(packagePath);
|
|
252
|
-
}
|
|
253
|
-
validateKeys() {
|
|
254
|
-
// Verify that the configObject does not have upper case keys; throw if it does. Must be heads down camel case.
|
|
255
|
-
const upperCaseKey = sfdc_1.sfdc.findUpperCaseKeys(this.toObject(), SfdxProjectJson.BLOCKLIST);
|
|
256
|
-
if (upperCaseKey) {
|
|
257
|
-
throw coreMessages.createError('invalidJsonCasing', [upperCaseKey, this.getPath()]);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
exports.SfdxProjectJson = SfdxProjectJson;
|
|
262
|
-
SfdxProjectJson.BLOCKLIST = ['packageAliases'];
|
|
263
|
-
/**
|
|
264
|
-
* Represents an SFDX project directory. This directory contains a {@link SfdxProjectJson} config file as well as
|
|
265
|
-
* a hidden .sfdx folder that contains all the other local project config files.
|
|
266
|
-
*
|
|
267
|
-
* ```
|
|
268
|
-
* const project = await SfdxProject.resolve();
|
|
269
|
-
* const projectJson = await project.resolveProjectConfig();
|
|
270
|
-
* console.log(projectJson.sfdcLoginUrl);
|
|
271
|
-
* ```
|
|
272
|
-
*/
|
|
273
|
-
class SfdxProject {
|
|
274
|
-
/**
|
|
275
|
-
* Do not directly construct instances of this class -- use {@link SfdxProject.resolve} instead.
|
|
276
|
-
*
|
|
277
|
-
* @ignore
|
|
278
|
-
*/
|
|
279
|
-
constructor(path) {
|
|
280
|
-
this.path = path;
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Get a Project from a given path or from the working directory.
|
|
284
|
-
*
|
|
285
|
-
* @param path The path of the project.
|
|
286
|
-
*
|
|
287
|
-
* **Throws** *{@link SfdxError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace.
|
|
288
|
-
*/
|
|
289
|
-
static async resolve(path) {
|
|
290
|
-
path = await this.resolveProjectPath(path || process.cwd());
|
|
291
|
-
if (!SfdxProject.instances.has(path)) {
|
|
292
|
-
const project = new SfdxProject(path);
|
|
293
|
-
SfdxProject.instances.set(path, project);
|
|
294
|
-
}
|
|
295
|
-
return (0, ts_types_1.ensure)(SfdxProject.instances.get(path));
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Get a Project from a given path or from the working directory.
|
|
299
|
-
*
|
|
300
|
-
* @param path The path of the project.
|
|
301
|
-
*
|
|
302
|
-
* **Throws** *{@link SfdxError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace.
|
|
303
|
-
*/
|
|
304
|
-
static getInstance(path) {
|
|
305
|
-
// Store instance based on the path of the actual project.
|
|
306
|
-
path = this.resolveProjectPathSync(path || process.cwd());
|
|
307
|
-
if (!SfdxProject.instances.has(path)) {
|
|
308
|
-
const project = new SfdxProject(path);
|
|
309
|
-
SfdxProject.instances.set(path, project);
|
|
310
|
-
}
|
|
311
|
-
return (0, ts_types_1.ensure)(SfdxProject.instances.get(path));
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Performs an upward directory search for an sfdx project file. Returns the absolute path to the project.
|
|
315
|
-
*
|
|
316
|
-
* @param dir The directory path to start traversing from.
|
|
317
|
-
*
|
|
318
|
-
* **Throws** *{@link SfdxError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace.
|
|
319
|
-
*
|
|
320
|
-
* **See** {@link traverseForFile}
|
|
321
|
-
*
|
|
322
|
-
* **See** [process.cwd()](https://nodejs.org/api/process.html#process_process_cwd)
|
|
323
|
-
*/
|
|
324
|
-
static async resolveProjectPath(dir) {
|
|
325
|
-
return (0, internal_1.resolveProjectPath)(dir);
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Performs a synchronous upward directory search for an sfdx project file. Returns the absolute path to the project.
|
|
329
|
-
*
|
|
330
|
-
* @param dir The directory path to start traversing from.
|
|
331
|
-
*
|
|
332
|
-
* **Throws** *{@link SfdxError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace.
|
|
333
|
-
*
|
|
334
|
-
* **See** {@link traverseForFileSync}
|
|
335
|
-
*
|
|
336
|
-
* **See** [process.cwd()](https://nodejs.org/api/process.html#process_process_cwd)
|
|
337
|
-
*/
|
|
338
|
-
static resolveProjectPathSync(dir) {
|
|
339
|
-
return (0, internal_1.resolveProjectPathSync)(dir);
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Returns the project path.
|
|
343
|
-
*/
|
|
344
|
-
getPath() {
|
|
345
|
-
return this.path;
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Get the sfdx-project.json config. The global sfdx-project.json is used for user defaults
|
|
349
|
-
* that are not checked in to the project specific file.
|
|
350
|
-
*
|
|
351
|
-
* *Note:* When reading values from {@link SfdxProjectJson}, it is recommended to use
|
|
352
|
-
* {@link SfdxProject.resolveProjectConfig} instead.
|
|
353
|
-
*
|
|
354
|
-
* @param isGlobal True to get the global project file, otherwise the local project config.
|
|
355
|
-
*/
|
|
356
|
-
async retrieveSfdxProjectJson(isGlobal = false) {
|
|
357
|
-
const options = SfdxProjectJson.getDefaultOptions(isGlobal);
|
|
358
|
-
if (isGlobal) {
|
|
359
|
-
if (!this.sfdxProjectJsonGlobal) {
|
|
360
|
-
this.sfdxProjectJsonGlobal = await SfdxProjectJson.create(options);
|
|
361
|
-
}
|
|
362
|
-
return this.sfdxProjectJsonGlobal;
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
options.rootFolder = this.getPath();
|
|
366
|
-
if (!this.sfdxProjectJson) {
|
|
367
|
-
this.sfdxProjectJson = await SfdxProjectJson.create(options);
|
|
368
|
-
}
|
|
369
|
-
return this.sfdxProjectJson;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Get the sfdx-project.json config. The global sfdx-project.json is used for user defaults
|
|
374
|
-
* that are not checked in to the project specific file.
|
|
375
|
-
*
|
|
376
|
-
* *Note:* When reading values from {@link SfdxProjectJson}, it is recommended to use
|
|
377
|
-
* {@link SfdxProject.resolveProjectConfig} instead.
|
|
378
|
-
*
|
|
379
|
-
* This is the sync method of {@link SfdxProject.resolveSfdxProjectJson}
|
|
380
|
-
*
|
|
381
|
-
* @param isGlobal True to get the global project file, otherwise the local project config.
|
|
382
|
-
*/
|
|
383
|
-
getSfdxProjectJson(isGlobal = false) {
|
|
384
|
-
const options = SfdxProjectJson.getDefaultOptions(isGlobal);
|
|
385
|
-
if (isGlobal) {
|
|
386
|
-
if (!this.sfdxProjectJsonGlobal) {
|
|
387
|
-
this.sfdxProjectJsonGlobal = new SfdxProjectJson(options);
|
|
388
|
-
this.sfdxProjectJsonGlobal.readSync();
|
|
389
|
-
}
|
|
390
|
-
return this.sfdxProjectJsonGlobal;
|
|
391
|
-
}
|
|
392
|
-
else {
|
|
393
|
-
options.rootFolder = this.getPath();
|
|
394
|
-
if (!this.sfdxProjectJson) {
|
|
395
|
-
this.sfdxProjectJson = new SfdxProjectJson(options);
|
|
396
|
-
this.sfdxProjectJson.readSync();
|
|
397
|
-
}
|
|
398
|
-
return this.sfdxProjectJson;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* Returns a read-only list of `packageDirectories` within sfdx-project.json, first reading
|
|
403
|
-
* and validating the file if necessary. i.e. modifying this array will not affect the
|
|
404
|
-
* sfdx-project.json file.
|
|
405
|
-
*/
|
|
406
|
-
getPackageDirectories() {
|
|
407
|
-
if (!this.packageDirectories) {
|
|
408
|
-
this.packageDirectories = this.getSfdxProjectJson().getPackageDirectoriesSync();
|
|
409
|
-
}
|
|
410
|
-
return this.packageDirectories;
|
|
411
|
-
}
|
|
412
|
-
/**
|
|
413
|
-
* Returns a read-only list of `packageDirectories` within sfdx-project.json, first reading
|
|
414
|
-
* and validating the file if necessary. i.e. modifying this array will not affect the
|
|
415
|
-
* sfdx-project.json file.
|
|
416
|
-
*
|
|
417
|
-
* There can be multiple packages in packageDirectories that point to the same directory.
|
|
418
|
-
* This method only returns one packageDirectory entry per unique directory path. This is
|
|
419
|
-
* useful when doing source operations based on directories but probably not as useful
|
|
420
|
-
* for packaging operations that want to do something for each package entry.
|
|
421
|
-
*/
|
|
422
|
-
getUniquePackageDirectories() {
|
|
423
|
-
return this.getSfdxProjectJson().getUniquePackageDirectories();
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* Get a list of the unique package names from within sfdx-project.json. Use {@link SfdxProject.getUniquePackageDirectories}
|
|
427
|
-
* for data other than the names.
|
|
428
|
-
*/
|
|
429
|
-
getUniquePackageNames() {
|
|
430
|
-
return this.getSfdxProjectJson().getUniquePackageNames();
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* Returns the package from a file path.
|
|
434
|
-
*
|
|
435
|
-
* @param path A file path. E.g. /Users/jsmith/projects/ebikes-lwc/force-app/apex/my-cls.cls
|
|
436
|
-
*/
|
|
437
|
-
getPackageFromPath(path) {
|
|
438
|
-
const packageDirs = this.getPackageDirectories();
|
|
439
|
-
const match = packageDirs.find((packageDir) => (0, path_1.basename)(path) === packageDir.name || path.includes(packageDir.fullPath));
|
|
440
|
-
return match;
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* Returns the package name, E.g. 'force-app', from a file path.
|
|
444
|
-
*
|
|
445
|
-
* @param path A file path. E.g. /Users/jsmith/projects/ebikes-lwc/force-app/apex/my-cls.cls
|
|
446
|
-
*/
|
|
447
|
-
getPackageNameFromPath(path) {
|
|
448
|
-
const packageDir = this.getPackageFromPath(path);
|
|
449
|
-
return packageDir ? packageDir.name : undefined;
|
|
450
|
-
}
|
|
451
|
-
/**
|
|
452
|
-
* Returns the package directory.
|
|
453
|
-
*
|
|
454
|
-
* @param packageName Name of the package directory. E.g., 'force-app'
|
|
455
|
-
*/
|
|
456
|
-
getPackage(packageName) {
|
|
457
|
-
const packageDirs = this.getPackageDirectories();
|
|
458
|
-
return packageDirs.find((packageDir) => packageDir.name === packageName);
|
|
459
|
-
}
|
|
460
|
-
/**
|
|
461
|
-
* Returns the absolute path of the package directory ending with the path separator.
|
|
462
|
-
* E.g., /Users/jsmith/projects/ebikes-lwc/force-app/
|
|
463
|
-
*
|
|
464
|
-
* @param packageName Name of the package directory. E.g., 'force-app'
|
|
465
|
-
*/
|
|
466
|
-
getPackagePath(packageName) {
|
|
467
|
-
const packageDir = this.getPackage(packageName);
|
|
468
|
-
return packageDir && packageDir.fullPath;
|
|
469
|
-
}
|
|
470
|
-
/**
|
|
471
|
-
* Has package directories defined in the project.
|
|
472
|
-
*/
|
|
473
|
-
hasPackages() {
|
|
474
|
-
return this.getSfdxProjectJson().hasPackages();
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Has multiple package directories (MPD) defined in the project.
|
|
478
|
-
*/
|
|
479
|
-
hasMultiplePackages() {
|
|
480
|
-
return this.getSfdxProjectJson().hasMultiplePackages();
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* Get the currently activated package on the project. This has no implication on sfdx-project.json
|
|
484
|
-
* but is useful for keeping track of package and source specific options in a process.
|
|
485
|
-
*/
|
|
486
|
-
getActivePackage() {
|
|
487
|
-
return this.activePackage;
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Set the currently activated package on the project. This has no implication on sfdx-project.json
|
|
491
|
-
* but is useful for keeping track of package and source specific options in a process.
|
|
492
|
-
*
|
|
493
|
-
* @param pkgName The package name to activate. E.g. 'force-app'
|
|
494
|
-
*/
|
|
495
|
-
setActivePackage(packageName) {
|
|
496
|
-
if (packageName == null) {
|
|
497
|
-
this.activePackage = null;
|
|
498
|
-
}
|
|
499
|
-
else {
|
|
500
|
-
this.activePackage = this.getPackage(packageName);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* Get the project's default package directory defined in sfdx-project.json using first 'default: true'
|
|
505
|
-
* found. The first entry is returned if no default is specified.
|
|
506
|
-
*/
|
|
507
|
-
getDefaultPackage() {
|
|
508
|
-
if (!this.hasPackages()) {
|
|
509
|
-
throw new sfdxError_1.SfdxError('The sfdx-project.json does not have any packageDirectories defined.');
|
|
510
|
-
}
|
|
511
|
-
const defaultPackage = this.getPackageDirectories().find((packageDir) => packageDir.default === true);
|
|
512
|
-
return defaultPackage || this.getPackageDirectories()[0];
|
|
513
|
-
}
|
|
514
|
-
/**
|
|
515
|
-
* The project config is resolved from local and global {@link SfdxProjectJson},
|
|
516
|
-
* {@link ConfigAggregator}, and a set of defaults. It is recommended to use
|
|
517
|
-
* this when reading values from SfdxProjectJson.
|
|
518
|
-
*
|
|
519
|
-
* The global {@link SfdxProjectJson} is used to allow the user to provide default values they
|
|
520
|
-
* may not want checked into their project's source.
|
|
521
|
-
*
|
|
522
|
-
* @returns A resolved config object that contains a bunch of different
|
|
523
|
-
* properties, including some 3rd party custom properties.
|
|
524
|
-
*/
|
|
525
|
-
async resolveProjectConfig() {
|
|
526
|
-
var _a;
|
|
527
|
-
if (!this.projectConfig) {
|
|
528
|
-
// Do fs operations in parallel
|
|
529
|
-
const [global, local, configAggregator] = await Promise.all([
|
|
530
|
-
this.retrieveSfdxProjectJson(true),
|
|
531
|
-
this.retrieveSfdxProjectJson(),
|
|
532
|
-
configAggregator_1.ConfigAggregator.create(),
|
|
533
|
-
]);
|
|
534
|
-
await Promise.all([global.read(), local.read()]);
|
|
535
|
-
this.projectConfig = (0, kit_1.defaults)(local.toObject(), global.toObject());
|
|
536
|
-
// Add fields in sfdx-config.json
|
|
537
|
-
Object.assign(this.projectConfig, configAggregator.getConfig());
|
|
538
|
-
// we don't have a login url yet, so use instanceUrl from config or default
|
|
539
|
-
if (!this.projectConfig.sfdcLoginUrl) {
|
|
540
|
-
this.projectConfig.sfdcLoginUrl = (_a = configAggregator.getConfig().instanceUrl) !== null && _a !== void 0 ? _a : sfdcUrl_1.SfdcUrl.PRODUCTION;
|
|
541
|
-
}
|
|
542
|
-
// LEGACY - Allow override of sfdcLoginUrl via env var FORCE_SFDC_LOGIN_URL
|
|
543
|
-
if (process.env.FORCE_SFDC_LOGIN_URL) {
|
|
544
|
-
this.projectConfig.sfdcLoginUrl = process.env.FORCE_SFDC_LOGIN_URL;
|
|
545
|
-
}
|
|
546
|
-
// Allow override of signupTargetLoginUrl via env var SFDX_SCRATCH_ORG_CREATION_LOGIN_URL
|
|
547
|
-
if (process.env.SFDX_SCRATCH_ORG_CREATION_LOGIN_URL) {
|
|
548
|
-
this.projectConfig.signupTargetLoginUrl = process.env.SFDX_SCRATCH_ORG_CREATION_LOGIN_URL;
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
return this.projectConfig;
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
exports.SfdxProject = SfdxProject;
|
|
555
|
-
// Cache of SfdxProject instances per path.
|
|
556
|
-
SfdxProject.instances = new Map();
|
|
557
|
-
//# sourceMappingURL=sfdxProject.js.map
|