UNPKG

12.8 kBTypeScriptView Raw
1import { JsonMap, Nullable, Optional } from '@salesforce/ts-types';
2import { ConfigFile } from './config/configFile';
3import { ConfigContents } from './config/configStore';
4export declare type PackageDirDependency = {
5 [k: string]: unknown;
6 package: string;
7 versionNumber?: string;
8};
9export declare type PackageDir = {
10 ancestorId?: string;
11 ancestorVersion?: string;
12 default?: boolean;
13 definitionFile?: string;
14 dependencies?: PackageDirDependency[];
15 includeProfileUserLicenses?: boolean;
16 package?: string;
17 path: string;
18 postInstallScript?: string;
19 postInstallUrl?: string;
20 releaseNotesUrl?: string;
21 uninstallScript?: string;
22 versionDescription?: string;
23 versionName?: string;
24 versionNumber?: string;
25};
26export declare type NamedPackageDir = PackageDir & {
27 /**
28 * The [normalized](https://nodejs.org/api/path.html#path_path_normalize_path) path used as the package name.
29 */
30 name: string;
31 /**
32 * The absolute path of the package.
33 */
34 fullPath: string;
35};
36export declare type ProjectJson = ConfigContents & {
37 packageDirectories: PackageDir[];
38 namespace?: string;
39 sourceApiVersion?: string;
40 sfdcLoginUrl?: string;
41 signupTargetLoginUrl?: string;
42 oauthLocalPort?: number;
43 plugins?: {
44 [k: string]: unknown;
45 };
46 packageAliases?: {
47 [k: string]: string;
48 };
49};
50/**
51 * The sfdx-project.json config object. This file determines if a folder is a valid sfdx project.
52 *
53 * *Note:* Any non-standard (not owned by Salesforce) properties stored in sfdx-project.json should
54 * be in a top level property that represents your project or plugin.
55 *
56 * ```
57 * const project = await SfProject.resolve();
58 * const projectJson = await project.resolveProjectConfig();
59 * const myPluginProperties = projectJson.get('myplugin') || {};
60 * myPluginProperties.myprop = 'someValue';
61 * projectJson.set('myplugin', myPluginProperties);
62 * await projectJson.write();
63 * ```
64 *
65 * **See** [force:project:create](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_create_new.htm)
66 */
67export declare class SfProjectJson extends ConfigFile {
68 static BLOCKLIST: string[];
69 static getFileName(): string;
70 static getDefaultOptions(isGlobal?: boolean): ConfigFile.Options;
71 read(): Promise<ConfigContents>;
72 readSync(): ConfigContents;
73 write(newContents?: ConfigContents): Promise<ConfigContents>;
74 writeSync(newContents?: ConfigContents): ConfigContents;
75 getContents(): ProjectJson;
76 getDefaultOptions(options?: ConfigFile.Options): ConfigFile.Options;
77 /**
78 * Validates sfdx-project.json against the schema.
79 *
80 * Set the `SFDX_PROJECT_JSON_VALIDATION` environment variable to `true` to throw an error when schema validation fails.
81 * A warning is logged by default when the file is invalid.
82 *
83 * ***See*** [sfdx-project.schema.json] ((https://github.com/forcedotcom/schemas/blob/main/sfdx-project.schema.json)
84 */
85 schemaValidate(): Promise<void>;
86 /**
87 * Returns the `packageDirectories` within sfdx-project.json, first reading
88 * and validating the file if necessary.
89 */
90 getPackageDirectories(): Promise<PackageDir[]>;
91 /**
92 * Validates sfdx-project.json against the schema.
93 *
94 * Set the `SFDX_PROJECT_JSON_VALIDATION` environment variable to `true` to throw an error when schema validation fails.
95 * A warning is logged by default when the file is invalid.
96 *
97 * ***See*** [sfdx-project.schema.json] ((https://github.com/forcedotcom/schemas/blob/main/sfdx-project.schema.json)
98 */
99 schemaValidateSync(): void;
100 /**
101 * Returns a read-only list of `packageDirectories` within sfdx-project.json, first reading
102 * and validating the file if necessary. i.e. modifying this array will not affect the
103 * sfdx-project.json file.
104 */
105 getPackageDirectoriesSync(): NamedPackageDir[];
106 /**
107 * Returns a read-only list of `packageDirectories` within sfdx-project.json, first reading
108 * and validating the file if necessary. i.e. modifying this array will not affect the
109 * sfdx-project.json file.
110 *
111 * There can be multiple packages in packageDirectories that point to the same directory.
112 * This method only returns one packageDirectory entry per unique directory path. This is
113 * useful when doing source operations based on directories but probably not as useful
114 * for packaging operations that want to do something for each package entry.
115 */
116 getUniquePackageDirectories(): NamedPackageDir[];
117 /**
118 * Get a list of the unique package names from within sfdx-project.json. Use {@link SfProject.getUniquePackageDirectories}
119 * for data other than the names.
120 */
121 getUniquePackageNames(): string[];
122 /**
123 * Has package directories defined in the project.
124 */
125 hasPackages(): boolean;
126 /**
127 * Has multiple package directories (MPD) defined in the project.
128 */
129 hasMultiplePackages(): boolean;
130 private doesPackageExist;
131 private validateKeys;
132}
133/**
134 * Represents an SFDX project directory. This directory contains a {@link SfProjectJson} config file as well as
135 * a hidden .sfdx folder that contains all the other local project config files.
136 *
137 * ```
138 * const project = await SfProject.resolve();
139 * const projectJson = await project.resolveProjectConfig();
140 * console.log(projectJson.sfdcLoginUrl);
141 * ```
142 */
143export declare class SfProject {
144 private path;
145 private static instances;
146 private projectConfig;
147 private sfProjectJson;
148 private sfProjectJsonGlobal;
149 private packageDirectories?;
150 private activePackage;
151 /**
152 * Do not directly construct instances of this class -- use {@link SfProject.resolve} instead.
153 *
154 * @ignore
155 */
156 protected constructor(path: string);
157 /**
158 * Get a Project from a given path or from the working directory.
159 *
160 * @param path The path of the project.
161 *
162 * **Throws** *{@link SfError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace.
163 */
164 static resolve(path?: string): Promise<SfProject>;
165 /**
166 * Get a Project from a given path or from the working directory.
167 *
168 * @param path The path of the project.
169 *
170 * **Throws** *{@link SfError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace.
171 */
172 static getInstance(path?: string): SfProject;
173 /**
174 * Performs an upward directory search for an sfdx project file. Returns the absolute path to the project.
175 *
176 * @param dir The directory path to start traversing from.
177 *
178 * **Throws** *{@link SfError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace.
179 *
180 * **See** {@link traverseForFile}
181 *
182 * **See** [process.cwd()](https://nodejs.org/api/process.html#process_process_cwd)
183 */
184 static resolveProjectPath(dir?: string): Promise<string>;
185 /**
186 * Performs a synchronous upward directory search for an sfdx project file. Returns the absolute path to the project.
187 *
188 * @param dir The directory path to start traversing from.
189 *
190 * **Throws** *{@link SfError}{ name: 'InvalidProjectWorkspaceError' }* If the current folder is not located in a workspace.
191 *
192 * **See** {@link traverseForFileSync}
193 *
194 * **See** [process.cwd()](https://nodejs.org/api/process.html#process_process_cwd)
195 */
196 static resolveProjectPathSync(dir?: string): string;
197 /**
198 * Returns the project path.
199 */
200 getPath(): string;
201 /**
202 * Get the sfdx-project.json config. The global sfdx-project.json is used for user defaults
203 * that are not checked in to the project specific file.
204 *
205 * *Note:* When reading values from {@link SfProjectJson}, it is recommended to use
206 * {@link SfProject.resolveProjectConfig} instead.
207 *
208 * @param isGlobal True to get the global project file, otherwise the local project config.
209 */
210 retrieveSfProjectJson(isGlobal?: boolean): Promise<SfProjectJson>;
211 /**
212 * Get the sfdx-project.json config. The global sfdx-project.json is used for user defaults
213 * that are not checked in to the project specific file.
214 *
215 * *Note:* When reading values from {@link SfProjectJson}, it is recommended to use
216 * {@link SfProject.resolveProjectConfig} instead.
217 *
218 * This is the sync method of {@link SfProject.resolveSfProjectJson}
219 *
220 * @param isGlobal True to get the global project file, otherwise the local project config.
221 */
222 getSfProjectJson(isGlobal?: boolean): SfProjectJson;
223 /**
224 * Returns a read-only list of `packageDirectories` within sfdx-project.json, first reading
225 * and validating the file if necessary. i.e. modifying this array will not affect the
226 * sfdx-project.json file.
227 */
228 getPackageDirectories(): NamedPackageDir[];
229 /**
230 * Returns a read-only list of `packageDirectories` within sfdx-project.json, first reading
231 * and validating the file if necessary. i.e. modifying this array will not affect the
232 * sfdx-project.json file.
233 *
234 * There can be multiple packages in packageDirectories that point to the same directory.
235 * This method only returns one packageDirectory entry per unique directory path. This is
236 * useful when doing source operations based on directories but probably not as useful
237 * for packaging operations that want to do something for each package entry.
238 */
239 getUniquePackageDirectories(): NamedPackageDir[];
240 /**
241 * Get a list of the unique package names from within sfdx-project.json. Use {@link SfProject.getUniquePackageDirectories}
242 * for data other than the names.
243 */
244 getUniquePackageNames(): string[];
245 /**
246 * Returns the package from a file path.
247 *
248 * @param path A file path. E.g. /Users/jsmith/projects/ebikes-lwc/force-app/apex/my-cls.cls
249 */
250 getPackageFromPath(path: string): Optional<NamedPackageDir>;
251 /**
252 * Returns the package name, E.g. 'force-app', from a file path.
253 *
254 * @param path A file path. E.g. /Users/jsmith/projects/ebikes-lwc/force-app/apex/my-cls.cls
255 */
256 getPackageNameFromPath(path: string): Optional<string>;
257 /**
258 * Returns the package directory.
259 *
260 * @param packageName Name of the package directory. E.g., 'force-app'
261 */
262 getPackage(packageName: string): Optional<NamedPackageDir>;
263 /**
264 * Returns the absolute path of the package directory ending with the path separator.
265 * E.g., /Users/jsmith/projects/ebikes-lwc/force-app/
266 *
267 * @param packageName Name of the package directory. E.g., 'force-app'
268 */
269 getPackagePath(packageName: string): Optional<string>;
270 /**
271 * Has package directories defined in the project.
272 */
273 hasPackages(): boolean;
274 /**
275 * Has multiple package directories (MPD) defined in the project.
276 */
277 hasMultiplePackages(): boolean;
278 /**
279 * Get the currently activated package on the project. This has no implication on sfdx-project.json
280 * but is useful for keeping track of package and source specific options in a process.
281 */
282 getActivePackage(): Nullable<NamedPackageDir>;
283 /**
284 * Set the currently activated package on the project. This has no implication on sfdx-project.json
285 * but is useful for keeping track of package and source specific options in a process.
286 *
287 * @param pkgName The package name to activate. E.g. 'force-app'
288 */
289 setActivePackage(packageName: Nullable<string>): void;
290 /**
291 * Get the project's default package directory defined in sfdx-project.json using first 'default: true'
292 * found. The first entry is returned if no default is specified.
293 */
294 getDefaultPackage(): NamedPackageDir;
295 /**
296 * The project config is resolved from local and global {@link SfProjectJson},
297 * {@link ConfigAggregator}, and a set of defaults. It is recommended to use
298 * this when reading values from SfProjectJson.
299 *
300 * The global {@link SfProjectJson} is used to allow the user to provide default values they
301 * may not want checked into their project's source.
302 *
303 * @returns A resolved config object that contains a bunch of different
304 * properties, including some 3rd party custom properties.
305 */
306 resolveProjectConfig(): Promise<JsonMap>;
307}
308/**
309 * @deprecated use SfProject instead
310 */
311export declare class SfdxProject extends SfProject {
312}
313/**
314 * @deprecated use SfProjectJson instead
315 */
316export declare class SfdxProjectJson extends SfProjectJson {
317}