@salesforce/core 3.7.7 → 3.7.8

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.
@@ -8,11 +8,11 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.SchemaValidator = void 0;
10
10
  const path = require("path");
11
+ const fs = require("fs");
11
12
  const kit_1 = require("@salesforce/kit");
12
13
  const ts_types_1 = require("@salesforce/ts-types");
13
14
  const validator = require("jsen");
14
15
  const sfError_1 = require("../sfError");
15
- const fs_1 = require("../util/fs");
16
16
  /**
17
17
  * Loads a JSON schema and performs validations against JSON objects.
18
18
  */
@@ -33,7 +33,7 @@ class SchemaValidator {
33
33
  */
34
34
  async load() {
35
35
  if (!this.schema) {
36
- this.schema = await fs_1.fs.readJsonMap(this.schemaPath);
36
+ this.schema = (0, kit_1.parseJsonMap)(await fs.promises.readFile(this.schemaPath, 'utf8'));
37
37
  this.logger.debug(`Schema loaded for ${this.schemaPath}`);
38
38
  }
39
39
  return this.schema;
@@ -43,7 +43,7 @@ class SchemaValidator {
43
43
  */
44
44
  loadSync() {
45
45
  if (!this.schema) {
46
- this.schema = fs_1.fs.readJsonMapSync(this.schemaPath);
46
+ this.schema = (0, kit_1.parseJsonMap)(fs.readFileSync(this.schemaPath, 'utf8'));
47
47
  this.logger.debug(`Schema loaded for ${this.schemaPath}`);
48
48
  }
49
49
  return this.schema;
@@ -125,7 +125,7 @@ class SchemaValidator {
125
125
  loadExternalSchema(uri) {
126
126
  const schemaPath = path.join(this.schemasDir, `${uri}.json`);
127
127
  try {
128
- return fs_1.fs.readJsonMapSync(schemaPath);
128
+ return (0, kit_1.parseJsonMap)(fs.readFileSync(schemaPath, 'utf8'));
129
129
  }
130
130
  catch (err) {
131
131
  if (err.code === 'ENOENT') {
package/lib/sfError.d.ts CHANGED
@@ -68,11 +68,6 @@ export declare class SfError extends NamedError {
68
68
  * Convert an {@link SfError} state to an object. Returns a plain object representing the state of this error.
69
69
  */
70
70
  toObject(): JsonMap;
71
- /**
72
- * @deprecated Does nothing. Do not use. This is kept around to support older versions of SfdxCommand.
73
- * @param commandName
74
- */
75
- setCommandName(): void;
76
71
  }
77
72
  /**
78
73
  * @deprecated use SfError instead
package/lib/sfError.js CHANGED
@@ -109,13 +109,6 @@ class SfError extends kit_1.NamedError {
109
109
  }
110
110
  return obj;
111
111
  }
112
- /**
113
- * @deprecated Does nothing. Do not use. This is kept around to support older versions of SfdxCommand.
114
- * @param commandName
115
- */
116
- setCommandName() {
117
- /** Do nothing. */
118
- }
119
112
  }
120
113
  exports.SfError = SfError;
121
114
  /**
package/lib/sfProject.js CHANGED
@@ -8,13 +8,13 @@ exports.SfdxProjectJson = exports.SfdxProject = exports.SfProject = exports.SfPr
8
8
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
9
  */
10
10
  const path_1 = require("path");
11
+ const fs = require("fs");
11
12
  const kit_1 = require("@salesforce/kit");
12
13
  const ts_types_1 = require("@salesforce/ts-types");
13
14
  const sfdcUrl_1 = require("./util/sfdcUrl");
14
15
  const configAggregator_1 = require("./config/configAggregator");
15
16
  const configFile_1 = require("./config/configFile");
16
17
  const validator_1 = require("./schema/validator");
17
- const fs_1 = require("./util/fs");
18
18
  const internal_1 = require("./util/internal");
19
19
  const sfError_1 = require("./sfError");
20
20
  const sfdc_1 = require("./util/sfdc");
@@ -248,7 +248,7 @@ class SfProjectJson extends configFile_1.ConfigFile {
248
248
  return this.getContents().packageDirectories && this.getContents().packageDirectories.length > 1;
249
249
  }
250
250
  doesPackageExist(packagePath) {
251
- return fs_1.fs.existsSync(packagePath);
251
+ return fs.existsSync(packagePath);
252
252
  }
253
253
  validateKeys() {
254
254
  // Verify that the configObject does not have upper case keys; throw if it does. Must be heads down camel case.
@@ -1,3 +1,4 @@
1
+ import { Optional } from '@salesforce/ts-types';
1
2
  /**
2
3
  * The name of the project config file.
3
4
  *
@@ -30,3 +31,28 @@ export declare function resolveProjectPath(dir?: string): Promise<string>;
30
31
  * @ignore
31
32
  */
32
33
  export declare function resolveProjectPathSync(dir?: string): string;
34
+ /**
35
+ * These methods were moved from the deprecated 'fs' module in v2 and are only used in sfdx-core above
36
+ *
37
+ * They were migrated into the 'traverse' constant in order to stub them in unit tests
38
+ */
39
+ export declare const traverse: {
40
+ /**
41
+ * Searches a file path in an ascending manner (until reaching the filesystem root) for the first occurrence a
42
+ * specific file name. Resolves with the directory path containing the located file, or `null` if the file was
43
+ * not found.
44
+ *
45
+ * @param dir The directory path in which to start the upward search.
46
+ * @param file The file name to look for.
47
+ */
48
+ forFile: (dir: string, file: string) => Promise<Optional<string>>;
49
+ /**
50
+ * Searches a file path synchronously in an ascending manner (until reaching the filesystem root) for the first occurrence a
51
+ * specific file name. Resolves with the directory path containing the located file, or `null` if the file was
52
+ * not found.
53
+ *
54
+ * @param dir The directory path in which to start the upward search.
55
+ * @param file The file name to look for.
56
+ */
57
+ forFileSync: (dir: string, file: string) => Optional<string>;
58
+ };
@@ -6,9 +6,10 @@
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.resolveProjectPathSync = exports.resolveProjectPath = exports.SFDX_PROJECT_JSON = void 0;
9
+ exports.traverse = exports.resolveProjectPathSync = exports.resolveProjectPath = exports.SFDX_PROJECT_JSON = void 0;
10
+ const fs = require("fs");
11
+ const path_1 = require("path");
10
12
  const messages_1 = require("../messages");
11
- const fs_1 = require("./fs");
12
13
  messages_1.Messages.importMessagesDirectory(__dirname);
13
14
  const messages = messages_1.Messages.load('@salesforce/core', 'config', ['invalidProjectWorkspace']);
14
15
  /**
@@ -31,7 +32,7 @@ exports.SFDX_PROJECT_JSON = 'sfdx-project.json';
31
32
  * @ignore
32
33
  */
33
34
  async function resolveProjectPath(dir = process.cwd()) {
34
- const projectPath = await fs_1.fs.traverseForFile(dir, exports.SFDX_PROJECT_JSON);
35
+ const projectPath = await exports.traverse.forFile(dir, exports.SFDX_PROJECT_JSON);
35
36
  if (!projectPath) {
36
37
  throw messages.createError('invalidProjectWorkspace');
37
38
  }
@@ -51,11 +52,68 @@ exports.resolveProjectPath = resolveProjectPath;
51
52
  * @ignore
52
53
  */
53
54
  function resolveProjectPathSync(dir = process.cwd()) {
54
- const projectPath = fs_1.fs.traverseForFileSync(dir, exports.SFDX_PROJECT_JSON);
55
+ const projectPath = exports.traverse.forFileSync(dir, exports.SFDX_PROJECT_JSON);
55
56
  if (!projectPath) {
56
57
  throw messages.createError('invalidProjectWorkspace');
57
58
  }
58
59
  return projectPath;
59
60
  }
60
61
  exports.resolveProjectPathSync = resolveProjectPathSync;
62
+ /**
63
+ * These methods were moved from the deprecated 'fs' module in v2 and are only used in sfdx-core above
64
+ *
65
+ * They were migrated into the 'traverse' constant in order to stub them in unit tests
66
+ */
67
+ exports.traverse = {
68
+ /**
69
+ * Searches a file path in an ascending manner (until reaching the filesystem root) for the first occurrence a
70
+ * specific file name. Resolves with the directory path containing the located file, or `null` if the file was
71
+ * not found.
72
+ *
73
+ * @param dir The directory path in which to start the upward search.
74
+ * @param file The file name to look for.
75
+ */
76
+ forFile: async (dir, file) => {
77
+ let foundProjectDir;
78
+ try {
79
+ fs.statSync((0, path_1.join)(dir, file));
80
+ foundProjectDir = dir;
81
+ }
82
+ catch (err) {
83
+ if (err && err.code === 'ENOENT') {
84
+ const nextDir = (0, path_1.resolve)(dir, '..');
85
+ if (nextDir !== dir) {
86
+ // stop at root
87
+ foundProjectDir = await exports.traverse.forFile(nextDir, file);
88
+ }
89
+ }
90
+ }
91
+ return foundProjectDir;
92
+ },
93
+ /**
94
+ * Searches a file path synchronously in an ascending manner (until reaching the filesystem root) for the first occurrence a
95
+ * specific file name. Resolves with the directory path containing the located file, or `null` if the file was
96
+ * not found.
97
+ *
98
+ * @param dir The directory path in which to start the upward search.
99
+ * @param file The file name to look for.
100
+ */
101
+ forFileSync: (dir, file) => {
102
+ let foundProjectDir;
103
+ try {
104
+ fs.statSync((0, path_1.join)(dir, file));
105
+ foundProjectDir = dir;
106
+ }
107
+ catch (err) {
108
+ if (err && err.code === 'ENOENT') {
109
+ const nextDir = (0, path_1.resolve)(dir, '..');
110
+ if (nextDir !== dir) {
111
+ // stop at root
112
+ foundProjectDir = exports.traverse.forFileSync(nextDir, file);
113
+ }
114
+ }
115
+ }
116
+ return foundProjectDir;
117
+ },
118
+ };
61
119
  //# sourceMappingURL=internal.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "3.7.7",
3
+ "version": "3.7.8",
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",
package/lib/util/fs.d.ts DELETED
@@ -1,201 +0,0 @@
1
- /// <reference types="node" />
2
- import { AnyJson, JsonMap, Optional } from '@salesforce/ts-types';
3
- import * as fsLib from 'graceful-fs';
4
- import * as mkdirpLib from 'mkdirp';
5
- declare type PerformFunction = (filePath: string, file?: string, dir?: string) => Promise<void>;
6
- declare type PerformFunctionSync = (filePath: string, file?: string, dir?: string) => void;
7
- export declare type WriteJsonOptions = {
8
- /**
9
- * The number of indent spaces
10
- */
11
- space?: number;
12
- };
13
- /**
14
- * @deprecated Use fs/promises instead
15
- */
16
- export declare const fs: typeof fsLib & {
17
- /**
18
- * The default file system mode to use when creating directories.
19
- */
20
- DEFAULT_USER_DIR_MODE: string;
21
- /**
22
- * The default file system mode to use when creating files.
23
- */
24
- DEFAULT_USER_FILE_MODE: string;
25
- /**
26
- * A convenience reference to {@link https://nodejs.org/api/fsLib.html#fs_fs_constants}
27
- * to reduce the need to import multiple `fs` modules.
28
- */
29
- constants: typeof fsLib.constants;
30
- /**
31
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_readfile_path_options_callback|fsLib.readFile}.
32
- */
33
- readFile: typeof fsLib.readFile.__promisify__;
34
- /**
35
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_readdir_path_options_callback|fsLib.readdir}.
36
- */
37
- readdir: typeof fsLib.readdir.__promisify__;
38
- /**
39
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_writefile_file_data_options_callback|fsLib.writeFile}.
40
- */
41
- writeFile: typeof fsLib.writeFile.__promisify__;
42
- /**
43
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_access_path_mode_callback|fsLib.access}.
44
- */
45
- access: typeof fsLib.access.__promisify__;
46
- /**
47
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_open_path_flags_mode_callback|fsLib.open}.
48
- */
49
- open: typeof fsLib.open.__promisify__;
50
- /**
51
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_unlink_path_callback|fsLib.unlink}.
52
- */
53
- unlink: typeof fsLib.unlink.__promisify__;
54
- /**
55
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_readdir_path_options_callback|fsLib.rmdir}.
56
- */
57
- rmdir: typeof fsLib.rmdir.__promisify__;
58
- /**
59
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_fstat_fd_callback|fsLib.stat}.
60
- */
61
- stat: typeof fsLib.stat.__promisify__;
62
- /**
63
- * Promisified version of {@link https://npmjs.com/package/mkdirp|mkdirp}.
64
- */
65
- mkdirp: (folderPath: string, mode?: string | object | undefined) => Promise<string | undefined>;
66
- mkdirpSync: typeof mkdirpLib.sync;
67
- /**
68
- * Deletes a folder recursively, removing all descending files and folders.
69
- *
70
- * **Throws** *PathIsNullOrUndefined* The path is not defined.
71
- * **Throws** *DirMissingOrNoAccess* The folder or any sub-folder is missing or has no access.
72
- *
73
- * @param {string} dirPath The path to remove.
74
- */
75
- remove: (dirPath: string) => Promise<void>;
76
- /**
77
- * Deletes a folder recursively, removing all descending files and folders.
78
- *
79
- * NOTE: It is recommended to call the asynchronous `remove` when possible as it will remove all files in parallel rather than serially.
80
- *
81
- * **Throws** *PathIsNullOrUndefined* The path is not defined.
82
- * **Throws** *DirMissingOrNoAccess* The folder or any sub-folder is missing or has no access.
83
- *
84
- * @param {string} dirPath The path to remove.
85
- */
86
- removeSync: (dirPath: string) => void;
87
- /**
88
- * Searches a file path in an ascending manner (until reaching the filesystem root) for the first occurrence a
89
- * specific file name. Resolves with the directory path containing the located file, or `null` if the file was
90
- * not found.
91
- *
92
- * @param dir The directory path in which to start the upward search.
93
- * @param file The file name to look for.
94
- */
95
- traverseForFile: (dir: string, file: string) => Promise<Optional<string>>;
96
- /**
97
- * Searches a file path synchronously in an ascending manner (until reaching the filesystem root) for the first occurrence a
98
- * specific file name. Resolves with the directory path containing the located file, or `null` if the file was
99
- * not found.
100
- *
101
- * @param dir The directory path in which to start the upward search.
102
- * @param file The file name to look for.
103
- */
104
- traverseForFileSync: (dir: string, file: string) => Optional<string>;
105
- /**
106
- * Read a file and convert it to JSON. Returns the contents of the file as a JSON object
107
- *
108
- * @param jsonPath The path of the file.
109
- * @param throwOnEmpty Whether to throw an error if the JSON file is empty.
110
- */
111
- readJson: (jsonPath: string, throwOnEmpty?: boolean | undefined) => Promise<AnyJson>;
112
- /**
113
- * Read a file and convert it to JSON. Returns the contents of the file as a JSON object
114
- *
115
- * @param jsonPath The path of the file.
116
- * @param throwOnEmpty Whether to throw an error if the JSON file is empty.
117
- */
118
- readJsonSync: (jsonPath: string, throwOnEmpty?: boolean | undefined) => AnyJson;
119
- /**
120
- * Read a file and convert it to JSON, throwing an error if the parsed contents are not a `JsonMap`.
121
- *
122
- * @param jsonPath The path of the file.
123
- * @param throwOnEmpty Whether to throw an error if the JSON file is empty.
124
- */
125
- readJsonMap: <T extends JsonMap = JsonMap>(jsonPath: string, throwOnEmpty?: boolean | undefined) => Promise<T>;
126
- /**
127
- * Read a file and convert it to JSON, throwing an error if the parsed contents are not a `JsonMap`.
128
- *
129
- * @param jsonPath The path of the file.
130
- * @param throwOnEmpty Whether to throw an error if the JSON file is empty.
131
- */
132
- readJsonMapSync: <T_1 extends JsonMap = JsonMap>(jsonPath: string, throwOnEmpty?: boolean | undefined) => T_1;
133
- /**
134
- * Convert a JSON-compatible object to a `string` and write it to a file.
135
- *
136
- * @param jsonPath The path of the file to write.
137
- * @param data The JSON object to write.
138
- */
139
- writeJson: (jsonPath: string, data: AnyJson, options?: WriteJsonOptions) => Promise<void>;
140
- /**
141
- * Convert a JSON-compatible object to a `string` and write it to a file.
142
- *
143
- * @param jsonPath The path of the file to write.
144
- * @param data The JSON object to write.
145
- */
146
- writeJsonSync: (jsonPath: string, data: AnyJson, options?: WriteJsonOptions) => void;
147
- /**
148
- * Checks if a file path exists
149
- *
150
- * @param filePath the file path to check the existence of
151
- */
152
- fileExists: (filePath: string) => Promise<boolean>;
153
- /**
154
- * Checks if a file path exists
155
- *
156
- * @param filePath the file path to check the existence of
157
- */
158
- fileExistsSync: (filePath: string) => boolean;
159
- /**
160
- * Recursively act on all files or directories in a directory
161
- *
162
- * @param dir path to directory
163
- * @param perform function to be run on contents of dir
164
- * @param onType optional parameter to specify type to actOn
165
- * @returns void
166
- */
167
- actOn: (dir: string, perform: PerformFunction, onType?: 'file' | 'dir' | 'all') => Promise<void>;
168
- /**
169
- * Recursively act on all files or directories in a directory
170
- *
171
- * @param dir path to directory
172
- * @param perform function to be run on contents of dir
173
- * @param onType optional parameter to specify type to actOn
174
- * @returns void
175
- */
176
- actOnSync: (dir: string, perform: PerformFunctionSync, onType?: 'file' | 'dir' | 'all') => void;
177
- /**
178
- * Checks if files are the same
179
- *
180
- * @param file1Path the first file path to check
181
- * @param file2Path the second file path to check
182
- * @returns boolean
183
- */
184
- areFilesEqual: (file1Path: string, file2Path: string) => Promise<boolean>;
185
- /**
186
- * Checks if files are the same
187
- *
188
- * @param file1Path the first file path to check
189
- * @param file2Path the second file path to check
190
- * @returns boolean
191
- */
192
- areFilesEqualSync: (file1Path: string, file2Path: string) => boolean;
193
- /**
194
- * Creates a hash for the string that's passed in
195
- *
196
- * @param contents The string passed into the function
197
- * @returns string
198
- */
199
- getContentHash(contents: string | Buffer): string;
200
- };
201
- export {};