@salesforce/core 4.0.0-v3.0 → 4.0.1

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.
Files changed (160) hide show
  1. package/LICENSE.txt +1 -1
  2. package/README.md +93 -44
  3. package/lib/config/aliasesConfig.d.ts +12 -0
  4. package/lib/config/aliasesConfig.js +28 -0
  5. package/lib/config/authInfoConfig.d.ts +19 -0
  6. package/lib/config/authInfoConfig.js +35 -0
  7. package/lib/config/config.d.ts +181 -48
  8. package/lib/config/config.js +382 -159
  9. package/lib/config/configAggregator.d.ts +59 -42
  10. package/lib/config/configAggregator.js +135 -82
  11. package/lib/config/configFile.d.ts +2 -2
  12. package/lib/config/configFile.js +40 -31
  13. package/lib/config/configGroup.d.ts +9 -9
  14. package/lib/config/configGroup.js +13 -11
  15. package/lib/config/configStore.d.ts +9 -9
  16. package/lib/config/configStore.js +29 -26
  17. package/lib/config/envVars.d.ts +102 -0
  18. package/lib/config/envVars.js +457 -0
  19. package/lib/config/orgUsersConfig.d.ts +8 -0
  20. package/lib/config/orgUsersConfig.js +12 -0
  21. package/lib/config/sandboxOrgConfig.d.ts +8 -0
  22. package/lib/config/sandboxOrgConfig.js +12 -0
  23. package/lib/config/sandboxProcessCache.d.ts +16 -0
  24. package/lib/config/sandboxProcessCache.js +38 -0
  25. package/lib/config/tokensConfig.d.ts +10 -0
  26. package/lib/config/tokensConfig.js +29 -0
  27. package/lib/config/ttlConfig.d.ts +34 -0
  28. package/lib/config/ttlConfig.js +50 -0
  29. package/lib/crypto/crypto.js +29 -16
  30. package/lib/crypto/keyChain.js +4 -4
  31. package/lib/crypto/keyChainImpl.d.ts +5 -3
  32. package/lib/crypto/keyChainImpl.js +65 -66
  33. package/lib/crypto/secureBuffer.d.ts +1 -1
  34. package/lib/crypto/secureBuffer.js +1 -1
  35. package/lib/deviceOauthService.d.ts +5 -5
  36. package/lib/deviceOauthService.js +37 -33
  37. package/lib/exported.d.ts +22 -15
  38. package/lib/exported.js +49 -25
  39. package/lib/global.d.ts +17 -3
  40. package/lib/global.js +46 -13
  41. package/lib/lifecycleEvents.d.ts +39 -2
  42. package/lib/lifecycleEvents.js +77 -3
  43. package/lib/logger.d.ts +21 -11
  44. package/lib/logger.js +121 -105
  45. package/lib/messages.d.ts +53 -36
  46. package/lib/messages.js +89 -97
  47. package/lib/org/authInfo.d.ts +84 -72
  48. package/lib/org/authInfo.js +326 -320
  49. package/lib/org/authRemover.d.ts +16 -23
  50. package/lib/org/authRemover.js +62 -60
  51. package/lib/org/connection.d.ts +33 -59
  52. package/lib/org/connection.js +129 -190
  53. package/lib/org/index.js +6 -2
  54. package/lib/org/org.d.ts +263 -38
  55. package/lib/org/org.js +734 -149
  56. package/lib/org/orgConfigProperties.d.ts +69 -0
  57. package/lib/org/orgConfigProperties.js +121 -0
  58. package/lib/org/permissionSetAssignment.js +6 -15
  59. package/lib/org/scratchOrgCache.d.ts +20 -0
  60. package/lib/org/scratchOrgCache.js +33 -0
  61. package/lib/org/scratchOrgCreate.d.ts +54 -0
  62. package/lib/org/scratchOrgCreate.js +214 -0
  63. package/lib/org/scratchOrgErrorCodes.d.ts +10 -0
  64. package/lib/org/scratchOrgErrorCodes.js +79 -0
  65. package/lib/org/scratchOrgFeatureDeprecation.d.ts +26 -0
  66. package/lib/org/scratchOrgFeatureDeprecation.js +105 -0
  67. package/lib/org/scratchOrgInfoApi.d.ts +68 -0
  68. package/lib/org/scratchOrgInfoApi.js +416 -0
  69. package/lib/org/scratchOrgInfoGenerator.d.ts +64 -0
  70. package/lib/org/scratchOrgInfoGenerator.js +237 -0
  71. package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -0
  72. package/lib/org/scratchOrgLifecycleEvents.js +41 -0
  73. package/lib/org/scratchOrgSettingsGenerator.d.ts +79 -0
  74. package/lib/org/scratchOrgSettingsGenerator.js +277 -0
  75. package/lib/org/scratchOrgTypes.d.ts +43 -0
  76. package/lib/{status/client.js → org/scratchOrgTypes.js} +1 -1
  77. package/lib/org/user.d.ts +7 -2
  78. package/lib/org/user.js +78 -54
  79. package/lib/schema/printer.d.ts +6 -0
  80. package/lib/schema/printer.js +49 -46
  81. package/lib/schema/validator.d.ts +12 -10
  82. package/lib/schema/validator.js +56 -76
  83. package/lib/{sfdxError.d.ts → sfError.d.ts} +12 -15
  84. package/lib/{sfdxError.js → sfError.js} +42 -24
  85. package/lib/{sfdxProject.d.ts → sfProject.d.ts} +75 -35
  86. package/lib/sfProject.js +651 -0
  87. package/lib/stateAggregator/accessors/aliasAccessor.d.ts +98 -0
  88. package/lib/stateAggregator/accessors/aliasAccessor.js +146 -0
  89. package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -0
  90. package/lib/stateAggregator/accessors/orgAccessor.js +240 -0
  91. package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -0
  92. package/lib/stateAggregator/accessors/sandboxAccessor.js +28 -0
  93. package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -0
  94. package/lib/stateAggregator/accessors/tokenAccessor.js +80 -0
  95. package/lib/stateAggregator/index.d.ts +4 -0
  96. package/lib/stateAggregator/index.js +27 -0
  97. package/lib/stateAggregator/stateAggregator.d.ts +25 -0
  98. package/lib/stateAggregator/stateAggregator.js +46 -0
  99. package/lib/status/myDomainResolver.d.ts +1 -1
  100. package/lib/status/myDomainResolver.js +10 -10
  101. package/lib/status/pollingClient.d.ts +2 -6
  102. package/lib/status/pollingClient.js +38 -64
  103. package/lib/status/streamingClient.d.ts +5 -80
  104. package/lib/status/streamingClient.js +74 -94
  105. package/lib/status/types.d.ts +89 -0
  106. package/lib/status/types.js +18 -0
  107. package/lib/testSetup.d.ts +212 -79
  108. package/lib/testSetup.js +478 -182
  109. package/lib/util/cache.d.ts +11 -0
  110. package/lib/util/cache.js +70 -0
  111. package/lib/util/checkLightningDomain.d.ts +1 -0
  112. package/lib/util/checkLightningDomain.js +29 -0
  113. package/lib/util/directoryWriter.d.ts +12 -0
  114. package/lib/util/directoryWriter.js +54 -0
  115. package/lib/util/getJwtAudienceUrl.d.ts +4 -0
  116. package/lib/util/getJwtAudienceUrl.js +19 -0
  117. package/lib/util/internal.d.ts +28 -2
  118. package/lib/util/internal.js +65 -8
  119. package/lib/util/jsonXmlTools.d.ts +14 -0
  120. package/lib/util/jsonXmlTools.js +39 -0
  121. package/lib/util/mapKeys.d.ts +14 -0
  122. package/lib/util/mapKeys.js +52 -0
  123. package/lib/util/sfdc.d.ts +51 -63
  124. package/lib/util/sfdc.js +75 -127
  125. package/lib/util/sfdcUrl.d.ts +64 -0
  126. package/lib/util/sfdcUrl.js +197 -0
  127. package/lib/util/structuredWriter.d.ts +9 -0
  128. package/lib/util/structuredWriter.js +3 -0
  129. package/lib/util/zipWriter.d.ts +16 -0
  130. package/lib/util/zipWriter.js +68 -0
  131. package/lib/webOAuthServer.d.ts +20 -7
  132. package/lib/webOAuthServer.js +107 -60
  133. package/messageTransformer/messageTransformer.ts +93 -0
  134. package/messages/auth.md +11 -3
  135. package/messages/config.md +94 -6
  136. package/messages/connection.md +8 -0
  137. package/messages/core.json +3 -3
  138. package/messages/core.md +11 -1
  139. package/messages/envVars.md +313 -0
  140. package/messages/org.md +64 -0
  141. package/messages/scratchOrgCreate.md +23 -0
  142. package/messages/scratchOrgErrorCodes.md +115 -0
  143. package/messages/scratchOrgFeatureDeprecation.md +11 -0
  144. package/messages/scratchOrgInfoApi.md +20 -0
  145. package/messages/scratchOrgInfoGenerator.md +27 -0
  146. package/messages/user.md +12 -0
  147. package/package.json +138 -66
  148. package/CHANGELOG.md +0 -699
  149. package/lib/config/aliases.d.ts +0 -56
  150. package/lib/config/aliases.js +0 -96
  151. package/lib/config/globalInfoConfig.d.ts +0 -74
  152. package/lib/config/globalInfoConfig.js +0 -144
  153. package/lib/config/keychainConfig.d.ts +0 -19
  154. package/lib/config/keychainConfig.js +0 -43
  155. package/lib/config/sfdxDataHandler.d.ts +0 -36
  156. package/lib/config/sfdxDataHandler.js +0 -165
  157. package/lib/sfdxProject.js +0 -546
  158. package/lib/status/client.d.ts +0 -15
  159. package/lib/util/fs.d.ts +0 -198
  160. package/lib/util/fs.js +0 -374
package/lib/util/fs.d.ts DELETED
@@ -1,198 +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
- export declare const fs: typeof fsLib & {
14
- /**
15
- * The default file system mode to use when creating directories.
16
- */
17
- DEFAULT_USER_DIR_MODE: string;
18
- /**
19
- * The default file system mode to use when creating files.
20
- */
21
- DEFAULT_USER_FILE_MODE: string;
22
- /**
23
- * A convenience reference to {@link https://nodejs.org/api/fsLib.html#fs_fs_constants}
24
- * to reduce the need to import multiple `fs` modules.
25
- */
26
- constants: typeof fsLib.constants;
27
- /**
28
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_readfile_path_options_callback|fsLib.readFile}.
29
- */
30
- readFile: typeof fsLib.readFile.__promisify__;
31
- /**
32
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_readdir_path_options_callback|fsLib.readdir}.
33
- */
34
- readdir: typeof fsLib.readdir.__promisify__;
35
- /**
36
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_writefile_file_data_options_callback|fsLib.writeFile}.
37
- */
38
- writeFile: typeof fsLib.writeFile.__promisify__;
39
- /**
40
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_access_path_mode_callback|fsLib.access}.
41
- */
42
- access: typeof fsLib.access.__promisify__;
43
- /**
44
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_open_path_flags_mode_callback|fsLib.open}.
45
- */
46
- open: typeof fsLib.open.__promisify__;
47
- /**
48
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_unlink_path_callback|fsLib.unlink}.
49
- */
50
- unlink: typeof fsLib.unlink.__promisify__;
51
- /**
52
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_readdir_path_options_callback|fsLib.rmdir}.
53
- */
54
- rmdir: typeof fsLib.rmdir.__promisify__;
55
- /**
56
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_fstat_fd_callback|fsLib.stat}.
57
- */
58
- stat: typeof fsLib.stat.__promisify__;
59
- /**
60
- * Promisified version of {@link https://npmjs.com/package/mkdirp|mkdirp}.
61
- */
62
- mkdirp: (folderPath: string, mode?: string | object | undefined) => Promise<string | undefined>;
63
- mkdirpSync: typeof mkdirpLib.sync;
64
- /**
65
- * Deletes a folder recursively, removing all descending files and folders.
66
- *
67
- * **Throws** *PathIsNullOrUndefined* The path is not defined.
68
- * **Throws** *DirMissingOrNoAccess* The folder or any sub-folder is missing or has no access.
69
- *
70
- * @param {string} dirPath The path to remove.
71
- */
72
- remove: (dirPath: string) => Promise<void>;
73
- /**
74
- * Deletes a folder recursively, removing all descending files and folders.
75
- *
76
- * NOTE: It is recommended to call the asynchronous `remove` when possible as it will remove all files in parallel rather than serially.
77
- *
78
- * **Throws** *PathIsNullOrUndefined* The path is not defined.
79
- * **Throws** *DirMissingOrNoAccess* The folder or any sub-folder is missing or has no access.
80
- *
81
- * @param {string} dirPath The path to remove.
82
- */
83
- removeSync: (dirPath: string) => void;
84
- /**
85
- * Searches a file path in an ascending manner (until reaching the filesystem root) for the first occurrence a
86
- * specific file name. Resolves with the directory path containing the located file, or `null` if the file was
87
- * not found.
88
- *
89
- * @param dir The directory path in which to start the upward search.
90
- * @param file The file name to look for.
91
- */
92
- traverseForFile: (dir: string, file: string) => Promise<Optional<string>>;
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
- traverseForFileSync: (dir: string, file: string) => Optional<string>;
102
- /**
103
- * Read a file and convert it to JSON. Returns the contents of the file as a JSON object
104
- *
105
- * @param jsonPath The path of the file.
106
- * @param throwOnEmpty Whether to throw an error if the JSON file is empty.
107
- */
108
- readJson: (jsonPath: string, throwOnEmpty?: boolean | undefined) => Promise<AnyJson>;
109
- /**
110
- * Read a file and convert it to JSON. Returns the contents of the file as a JSON object
111
- *
112
- * @param jsonPath The path of the file.
113
- * @param throwOnEmpty Whether to throw an error if the JSON file is empty.
114
- */
115
- readJsonSync: (jsonPath: string, throwOnEmpty?: boolean | undefined) => AnyJson;
116
- /**
117
- * Read a file and convert it to JSON, throwing an error if the parsed contents are not a `JsonMap`.
118
- *
119
- * @param jsonPath The path of the file.
120
- * @param throwOnEmpty Whether to throw an error if the JSON file is empty.
121
- */
122
- readJsonMap: <T extends JsonMap = JsonMap>(jsonPath: string, throwOnEmpty?: boolean | undefined) => Promise<T>;
123
- /**
124
- * Read a file and convert it to JSON, throwing an error if the parsed contents are not a `JsonMap`.
125
- *
126
- * @param jsonPath The path of the file.
127
- * @param throwOnEmpty Whether to throw an error if the JSON file is empty.
128
- */
129
- readJsonMapSync: <T_1 extends JsonMap = JsonMap>(jsonPath: string, throwOnEmpty?: boolean | undefined) => T_1;
130
- /**
131
- * Convert a JSON-compatible object to a `string` and write it to a file.
132
- *
133
- * @param jsonPath The path of the file to write.
134
- * @param data The JSON object to write.
135
- */
136
- writeJson: (jsonPath: string, data: AnyJson, options?: WriteJsonOptions) => Promise<void>;
137
- /**
138
- * Convert a JSON-compatible object to a `string` and write it to a file.
139
- *
140
- * @param jsonPath The path of the file to write.
141
- * @param data The JSON object to write.
142
- */
143
- writeJsonSync: (jsonPath: string, data: AnyJson, options?: WriteJsonOptions) => void;
144
- /**
145
- * Checks if a file path exists
146
- *
147
- * @param filePath the file path to check the existence of
148
- */
149
- fileExists: (filePath: string) => Promise<boolean>;
150
- /**
151
- * Checks if a file path exists
152
- *
153
- * @param filePath the file path to check the existence of
154
- */
155
- fileExistsSync: (filePath: string) => boolean;
156
- /**
157
- * Recursively act on all files or directories in a directory
158
- *
159
- * @param dir path to directory
160
- * @param perform function to be run on contents of dir
161
- * @param onType optional parameter to specify type to actOn
162
- * @returns void
163
- */
164
- actOn: (dir: string, perform: PerformFunction, onType?: 'file' | 'dir' | 'all') => Promise<void>;
165
- /**
166
- * Recursively act on all files or directories in a directory
167
- *
168
- * @param dir path to directory
169
- * @param perform function to be run on contents of dir
170
- * @param onType optional parameter to specify type to actOn
171
- * @returns void
172
- */
173
- actOnSync: (dir: string, perform: PerformFunctionSync, onType?: 'file' | 'dir' | 'all') => void;
174
- /**
175
- * Checks if files are the same
176
- *
177
- * @param file1Path the first file path to check
178
- * @param file2Path the second file path to check
179
- * @returns boolean
180
- */
181
- areFilesEqual: (file1Path: string, file2Path: string) => Promise<boolean>;
182
- /**
183
- * Checks if files are the same
184
- *
185
- * @param file1Path the first file path to check
186
- * @param file2Path the second file path to check
187
- * @returns boolean
188
- */
189
- areFilesEqualSync: (file1Path: string, file2Path: string) => boolean;
190
- /**
191
- * Creates a hash for the string that's passed in
192
- *
193
- * @param contents The string passed into the function
194
- * @returns string
195
- */
196
- getContentHash(contents: string | Buffer): string;
197
- };
198
- export {};
package/lib/util/fs.js DELETED
@@ -1,374 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2020, salesforce.com, inc.
4
- * All rights reserved.
5
- * Licensed under the BSD 3-Clause license.
6
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.fs = void 0;
10
- const crypto = require("crypto");
11
- const path = require("path");
12
- const util_1 = require("util");
13
- const kit_1 = require("@salesforce/kit");
14
- const fsLib = require("graceful-fs");
15
- const mkdirpLib = require("mkdirp");
16
- const sfdxError_1 = require("../sfdxError");
17
- exports.fs = Object.assign({}, fsLib, {
18
- /**
19
- * The default file system mode to use when creating directories.
20
- */
21
- DEFAULT_USER_DIR_MODE: '700',
22
- /**
23
- * The default file system mode to use when creating files.
24
- */
25
- DEFAULT_USER_FILE_MODE: '600',
26
- /**
27
- * A convenience reference to {@link https://nodejs.org/api/fsLib.html#fs_fs_constants}
28
- * to reduce the need to import multiple `fs` modules.
29
- */
30
- constants: fsLib.constants,
31
- /**
32
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_readfile_path_options_callback|fsLib.readFile}.
33
- */
34
- readFile: util_1.promisify(fsLib.readFile),
35
- /**
36
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_readdir_path_options_callback|fsLib.readdir}.
37
- */
38
- readdir: util_1.promisify(fsLib.readdir),
39
- /**
40
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_writefile_file_data_options_callback|fsLib.writeFile}.
41
- */
42
- writeFile: util_1.promisify(fsLib.writeFile),
43
- /**
44
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_access_path_mode_callback|fsLib.access}.
45
- */
46
- access: util_1.promisify(fsLib.access),
47
- /**
48
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_open_path_flags_mode_callback|fsLib.open}.
49
- */
50
- open: util_1.promisify(fsLib.open),
51
- /**
52
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_unlink_path_callback|fsLib.unlink}.
53
- */
54
- unlink: util_1.promisify(fsLib.unlink),
55
- /**
56
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_readdir_path_options_callback|fsLib.rmdir}.
57
- */
58
- rmdir: util_1.promisify(fsLib.rmdir),
59
- /**
60
- * Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_fstat_fd_callback|fsLib.stat}.
61
- */
62
- stat: util_1.promisify(fsLib.stat),
63
- /**
64
- * Promisified version of {@link https://npmjs.com/package/mkdirp|mkdirp}.
65
- */
66
- mkdirp: (folderPath, mode) => mkdirpLib(folderPath, mode),
67
- mkdirpSync: mkdirpLib.sync,
68
- /**
69
- * Deletes a folder recursively, removing all descending files and folders.
70
- *
71
- * **Throws** *PathIsNullOrUndefined* The path is not defined.
72
- * **Throws** *DirMissingOrNoAccess* The folder or any sub-folder is missing or has no access.
73
- *
74
- * @param {string} dirPath The path to remove.
75
- */
76
- remove: async (dirPath) => {
77
- if (!dirPath) {
78
- throw new sfdxError_1.SfdxError('Path is null or undefined.', 'PathIsNullOrUndefined');
79
- }
80
- try {
81
- await exports.fs.access(dirPath, fsLib.constants.R_OK);
82
- }
83
- catch (err) {
84
- throw new sfdxError_1.SfdxError(`The path: ${dirPath} doesn't exist or access is denied.`, 'DirMissingOrNoAccess');
85
- }
86
- const files = await exports.fs.readdir(dirPath);
87
- const stats = await Promise.all(files.map((file) => exports.fs.stat(path.join(dirPath, file))));
88
- const metas = stats.map((value, index) => Object.assign(value, { path: path.join(dirPath, files[index]) }));
89
- await Promise.all(metas.map((meta) => (meta.isDirectory() ? exports.fs.remove(meta.path) : exports.fs.unlink(meta.path))));
90
- await exports.fs.rmdir(dirPath);
91
- },
92
- /**
93
- * Deletes a folder recursively, removing all descending files and folders.
94
- *
95
- * NOTE: It is recommended to call the asynchronous `remove` when possible as it will remove all files in parallel rather than serially.
96
- *
97
- * **Throws** *PathIsNullOrUndefined* The path is not defined.
98
- * **Throws** *DirMissingOrNoAccess* The folder or any sub-folder is missing or has no access.
99
- *
100
- * @param {string} dirPath The path to remove.
101
- */
102
- removeSync: (dirPath) => {
103
- if (!dirPath) {
104
- throw new sfdxError_1.SfdxError('Path is null or undefined.', 'PathIsNullOrUndefined');
105
- }
106
- try {
107
- exports.fs.accessSync(dirPath, fsLib.constants.R_OK);
108
- }
109
- catch (err) {
110
- throw new sfdxError_1.SfdxError(`The path: ${dirPath} doesn't exist or access is denied.`, 'DirMissingOrNoAccess');
111
- }
112
- exports.fs.actOnSync(dirPath, (fullPath, file) => {
113
- if (file) {
114
- exports.fs.unlinkSync(fullPath);
115
- }
116
- else {
117
- // All files in this directory will be acted on before the directory.
118
- exports.fs.rmdirSync(fullPath);
119
- }
120
- }, 'all');
121
- // Remove the top level
122
- exports.fs.rmdirSync(dirPath);
123
- },
124
- /**
125
- * Searches a file path in an ascending manner (until reaching the filesystem root) for the first occurrence a
126
- * specific file name. Resolves with the directory path containing the located file, or `null` if the file was
127
- * not found.
128
- *
129
- * @param dir The directory path in which to start the upward search.
130
- * @param file The file name to look for.
131
- */
132
- traverseForFile: async (dir, file) => {
133
- let foundProjectDir;
134
- try {
135
- await exports.fs.stat(path.join(dir, file));
136
- foundProjectDir = dir;
137
- }
138
- catch (err) {
139
- if (err && err.code === 'ENOENT') {
140
- const nextDir = path.resolve(dir, '..');
141
- if (nextDir !== dir) {
142
- // stop at root
143
- foundProjectDir = await exports.fs.traverseForFile(nextDir, file);
144
- }
145
- }
146
- }
147
- return foundProjectDir;
148
- },
149
- /**
150
- * Searches a file path synchronously in an ascending manner (until reaching the filesystem root) for the first occurrence a
151
- * specific file name. Resolves with the directory path containing the located file, or `null` if the file was
152
- * not found.
153
- *
154
- * @param dir The directory path in which to start the upward search.
155
- * @param file The file name to look for.
156
- */
157
- traverseForFileSync: (dir, file) => {
158
- let foundProjectDir;
159
- try {
160
- exports.fs.statSync(path.join(dir, file));
161
- foundProjectDir = dir;
162
- }
163
- catch (err) {
164
- if (err && err.code === 'ENOENT') {
165
- const nextDir = path.resolve(dir, '..');
166
- if (nextDir !== dir) {
167
- // stop at root
168
- foundProjectDir = exports.fs.traverseForFileSync(nextDir, file);
169
- }
170
- }
171
- }
172
- return foundProjectDir;
173
- },
174
- /**
175
- * Read a file and convert it to JSON. Returns the contents of the file as a JSON object
176
- *
177
- * @param jsonPath The path of the file.
178
- * @param throwOnEmpty Whether to throw an error if the JSON file is empty.
179
- */
180
- readJson: async (jsonPath, throwOnEmpty) => {
181
- const fileData = await exports.fs.readFile(jsonPath, 'utf8');
182
- return kit_1.parseJson(fileData, jsonPath, throwOnEmpty);
183
- },
184
- /**
185
- * Read a file and convert it to JSON. Returns the contents of the file as a JSON object
186
- *
187
- * @param jsonPath The path of the file.
188
- * @param throwOnEmpty Whether to throw an error if the JSON file is empty.
189
- */
190
- readJsonSync: (jsonPath, throwOnEmpty) => {
191
- const fileData = exports.fs.readFileSync(jsonPath, 'utf8');
192
- return kit_1.parseJson(fileData, jsonPath, throwOnEmpty);
193
- },
194
- /**
195
- * Read a file and convert it to JSON, throwing an error if the parsed contents are not a `JsonMap`.
196
- *
197
- * @param jsonPath The path of the file.
198
- * @param throwOnEmpty Whether to throw an error if the JSON file is empty.
199
- */
200
- readJsonMap: async (jsonPath, throwOnEmpty) => {
201
- const fileData = await exports.fs.readFile(jsonPath, 'utf8');
202
- return kit_1.parseJsonMap(fileData, jsonPath, throwOnEmpty);
203
- },
204
- /**
205
- * Read a file and convert it to JSON, throwing an error if the parsed contents are not a `JsonMap`.
206
- *
207
- * @param jsonPath The path of the file.
208
- * @param throwOnEmpty Whether to throw an error if the JSON file is empty.
209
- */
210
- readJsonMapSync: (jsonPath, throwOnEmpty) => {
211
- const fileData = exports.fs.readFileSync(jsonPath, 'utf8');
212
- return kit_1.parseJsonMap(fileData, jsonPath, throwOnEmpty);
213
- },
214
- /**
215
- * Convert a JSON-compatible object to a `string` and write it to a file.
216
- *
217
- * @param jsonPath The path of the file to write.
218
- * @param data The JSON object to write.
219
- */
220
- writeJson: async (jsonPath, data, options = {}) => {
221
- options = Object.assign({ space: 2 }, options);
222
- const fileData = JSON.stringify(data, null, options.space);
223
- await exports.fs.writeFile(jsonPath, fileData, {
224
- encoding: 'utf8',
225
- mode: exports.fs.DEFAULT_USER_FILE_MODE,
226
- });
227
- },
228
- /**
229
- * Convert a JSON-compatible object to a `string` and write it to a file.
230
- *
231
- * @param jsonPath The path of the file to write.
232
- * @param data The JSON object to write.
233
- */
234
- writeJsonSync: (jsonPath, data, options = {}) => {
235
- options = Object.assign({ space: 2 }, options);
236
- const fileData = JSON.stringify(data, null, options.space);
237
- exports.fs.writeFileSync(jsonPath, fileData, {
238
- encoding: 'utf8',
239
- mode: exports.fs.DEFAULT_USER_FILE_MODE,
240
- });
241
- },
242
- /**
243
- * Checks if a file path exists
244
- *
245
- * @param filePath the file path to check the existence of
246
- */
247
- fileExists: async (filePath) => {
248
- try {
249
- await exports.fs.access(filePath);
250
- return true;
251
- }
252
- catch (err) {
253
- return false;
254
- }
255
- },
256
- /**
257
- * Checks if a file path exists
258
- *
259
- * @param filePath the file path to check the existence of
260
- */
261
- fileExistsSync: (filePath) => {
262
- try {
263
- exports.fs.accessSync(filePath);
264
- return true;
265
- }
266
- catch (err) {
267
- return false;
268
- }
269
- },
270
- /**
271
- * Recursively act on all files or directories in a directory
272
- *
273
- * @param dir path to directory
274
- * @param perform function to be run on contents of dir
275
- * @param onType optional parameter to specify type to actOn
276
- * @returns void
277
- */
278
- actOn: async (dir, perform, onType = 'file') => {
279
- for (const file of await exports.fs.readdir(dir)) {
280
- const filePath = path.join(dir, file);
281
- const stat = await exports.fs.stat(filePath);
282
- if (stat) {
283
- if (stat.isDirectory()) {
284
- await exports.fs.actOn(filePath, perform, onType);
285
- if (onType === 'dir' || onType === 'all') {
286
- await perform(filePath);
287
- }
288
- }
289
- else if (stat.isFile() && (onType === 'file' || onType === 'all')) {
290
- await perform(filePath, file, dir);
291
- }
292
- }
293
- }
294
- },
295
- /**
296
- * Recursively act on all files or directories in a directory
297
- *
298
- * @param dir path to directory
299
- * @param perform function to be run on contents of dir
300
- * @param onType optional parameter to specify type to actOn
301
- * @returns void
302
- */
303
- actOnSync: (dir, perform, onType = 'file') => {
304
- for (const file of exports.fs.readdirSync(dir)) {
305
- const filePath = path.join(dir, file);
306
- const stat = exports.fs.statSync(filePath);
307
- if (stat) {
308
- if (stat.isDirectory()) {
309
- exports.fs.actOnSync(filePath, perform, onType);
310
- if (onType === 'dir' || onType === 'all') {
311
- perform(filePath);
312
- }
313
- }
314
- else if (stat.isFile() && (onType === 'file' || onType === 'all')) {
315
- perform(filePath, file, dir);
316
- }
317
- }
318
- }
319
- },
320
- /**
321
- * Checks if files are the same
322
- *
323
- * @param file1Path the first file path to check
324
- * @param file2Path the second file path to check
325
- * @returns boolean
326
- */
327
- areFilesEqual: async (file1Path, file2Path) => {
328
- try {
329
- const file1Size = (await exports.fs.stat(file1Path)).size;
330
- const file2Size = (await exports.fs.stat(file2Path)).size;
331
- if (file1Size !== file2Size) {
332
- return false;
333
- }
334
- const contentA = await exports.fs.readFile(file1Path);
335
- const contentB = await exports.fs.readFile(file2Path);
336
- return exports.fs.getContentHash(contentA) === exports.fs.getContentHash(contentB);
337
- }
338
- catch (err) {
339
- throw new sfdxError_1.SfdxError(`The path: ${err.path} doesn't exist or access is denied.`, 'DirMissingOrNoAccess');
340
- }
341
- },
342
- /**
343
- * Checks if files are the same
344
- *
345
- * @param file1Path the first file path to check
346
- * @param file2Path the second file path to check
347
- * @returns boolean
348
- */
349
- areFilesEqualSync: (file1Path, file2Path) => {
350
- try {
351
- const file1Size = exports.fs.statSync(file1Path).size;
352
- const file2Size = exports.fs.statSync(file2Path).size;
353
- if (file1Size !== file2Size) {
354
- return false;
355
- }
356
- const contentA = exports.fs.readFileSync(file1Path);
357
- const contentB = exports.fs.readFileSync(file2Path);
358
- return exports.fs.getContentHash(contentA) === exports.fs.getContentHash(contentB);
359
- }
360
- catch (err) {
361
- throw new sfdxError_1.SfdxError(`The path: ${err.path} doesn't exist or access is denied.`, 'DirMissingOrNoAccess');
362
- }
363
- },
364
- /**
365
- * Creates a hash for the string that's passed in
366
- *
367
- * @param contents The string passed into the function
368
- * @returns string
369
- */
370
- getContentHash(contents) {
371
- return crypto.createHash('sha1').update(contents).digest('hex');
372
- },
373
- });
374
- //# sourceMappingURL=fs.js.map