@salesforce/core 3.7.5 → 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.
- package/CHANGELOG.md +219 -0
- package/README.md +4 -4
- package/lib/config/config.d.ts +7 -5
- package/lib/config/config.js +14 -9
- package/lib/config/configAggregator.d.ts +2 -2
- package/lib/config/configAggregator.js +2 -2
- package/lib/config/configFile.d.ts +2 -2
- package/lib/config/configFile.js +22 -20
- package/lib/config/configStore.js +7 -6
- package/lib/config/keychainConfig.js +4 -3
- package/lib/crypto/keyChainImpl.js +12 -11
- package/lib/deviceOauthService.js +2 -2
- package/lib/exported.d.ts +6 -5
- package/lib/exported.js +11 -7
- package/lib/global.js +2 -2
- package/lib/globalInfo/accessors/aliasAccessor.js +2 -2
- package/lib/globalInfo/sfdxDataHandler.d.ts +1 -1
- package/lib/globalInfo/sfdxDataHandler.js +5 -4
- package/lib/lifecycleEvents.js +1 -1
- package/lib/logger.d.ts +3 -3
- package/lib/logger.js +20 -19
- package/lib/messages.d.ts +42 -3
- package/lib/messages.js +55 -12
- package/lib/org/authInfo.d.ts +1 -1
- package/lib/org/authInfo.js +8 -9
- package/lib/org/authRemover.d.ts +2 -2
- package/lib/org/authRemover.js +2 -2
- package/lib/org/connection.d.ts +7 -2
- package/lib/org/connection.js +17 -4
- package/lib/org/org.d.ts +16 -6
- package/lib/org/org.js +54 -51
- package/lib/org/permissionSetAssignment.js +2 -2
- package/lib/org/scratchOrgCreate.d.ts +43 -0
- package/lib/org/scratchOrgCreate.js +142 -0
- package/lib/org/scratchOrgErrorCodes.d.ts +4 -0
- package/lib/org/scratchOrgErrorCodes.js +62 -0
- package/lib/org/scratchOrgFeatureDeprecation.d.ts +26 -0
- package/lib/org/scratchOrgFeatureDeprecation.js +110 -0
- package/lib/org/scratchOrgInfoApi.d.ts +94 -0
- package/lib/org/scratchOrgInfoApi.js +350 -0
- package/lib/org/scratchOrgInfoGenerator.d.ts +63 -0
- package/lib/org/scratchOrgInfoGenerator.js +223 -0
- package/lib/org/scratchOrgSettingsGenerator.d.ts +56 -0
- package/lib/org/scratchOrgSettingsGenerator.js +210 -0
- package/lib/org/user.js +8 -7
- package/lib/schema/printer.js +2 -2
- package/lib/schema/validator.d.ts +4 -4
- package/lib/schema/validator.js +13 -13
- package/lib/{sfdxError.d.ts → sfError.d.ts} +14 -14
- package/lib/{sfdxError.js → sfError.js} +20 -21
- package/lib/{sfdxProject.d.ts → sfProject.d.ts} +37 -27
- package/lib/{sfdxProject.js → sfProject.js} +77 -65
- package/lib/status/pollingClient.d.ts +2 -2
- package/lib/status/pollingClient.js +10 -4
- package/lib/status/streamingClient.d.ts +1 -1
- package/lib/status/streamingClient.js +6 -6
- package/lib/testSetup.d.ts +4 -4
- package/lib/testSetup.js +8 -8
- package/lib/util/internal.d.ts +28 -2
- package/lib/util/internal.js +64 -6
- package/lib/util/jsonXmlTools.d.ts +14 -0
- package/lib/util/jsonXmlTools.js +41 -0
- package/lib/util/mapKeys.d.ts +14 -0
- package/lib/util/mapKeys.js +48 -0
- package/lib/util/sfdcUrl.d.ts +2 -2
- package/lib/util/sfdcUrl.js +2 -2
- package/lib/util/zipWriter.d.ts +14 -0
- package/lib/util/zipWriter.js +68 -0
- package/lib/webOAuthServer.js +11 -11
- package/messages/org.md +4 -0
- package/messages/scratchOrgCreate.md +27 -0
- package/messages/scratchOrgErrorCodes.md +99 -0
- package/messages/scratchOrgFeatureDeprecation.md +11 -0
- package/messages/scratchOrgInfoApi.md +11 -0
- package/messages/scratchOrgInfoGenerator.md +19 -0
- package/messages/user.md +4 -0
- package/package.json +4 -1
- package/lib/util/fs.d.ts +0 -201
- package/lib/util/fs.js +0 -378
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# quantifiedFeatureWithoutQuantityWarning
|
|
2
|
+
|
|
3
|
+
The feature %s will be deprecated in a future release. It's been replaced by %s:<value>, which requires you to specify a quantity.
|
|
4
|
+
|
|
5
|
+
# mappedFeatureWarning
|
|
6
|
+
|
|
7
|
+
The feature %s has been deprecated. It has been replaced with %s in this scratch org create request.
|
|
8
|
+
|
|
9
|
+
# deprecatedFeatureWarning
|
|
10
|
+
|
|
11
|
+
The feature %s has been deprecated. It has been removed from the list of requested features.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# SignupFieldsMissingError
|
|
2
|
+
|
|
3
|
+
Required fields are missing for org creation: [%s]
|
|
4
|
+
|
|
5
|
+
# SignupDuplicateSettingsSpecifiedError
|
|
6
|
+
|
|
7
|
+
You cannot use 'settings' and `'orgPreferences' in your scratch definition file, please specify one or the other.
|
|
8
|
+
|
|
9
|
+
# DeprecatedPrefFormat
|
|
10
|
+
|
|
11
|
+
We've deprecated OrgPreferences. Update the scratch org definition file to replace OrgPreferences with their corresponding settings.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Package2AncestorsIdsKeyNotSupportedError
|
|
2
|
+
|
|
3
|
+
The package2AncestorIds key is no longer supported in a scratch org definition. Ancestors defined in sfdx-project.json will be included in the scratch org.",
|
|
4
|
+
|
|
5
|
+
# InvalidAncestorVersionFormatError
|
|
6
|
+
|
|
7
|
+
The ancestor versionNumber must be in the format major.minor.patch but the value found is %s",
|
|
8
|
+
|
|
9
|
+
# NoMatchingAncestorError
|
|
10
|
+
|
|
11
|
+
The ancestorId for ancestorVersion %s can't be found. Package ID %s.",
|
|
12
|
+
|
|
13
|
+
# AncestorNotReleasedError
|
|
14
|
+
|
|
15
|
+
The ancestor package version [%s] specified in the sfdx-project.json file may exist hasn’t been promoted and released. Release the ancestor package version before specifying it as the ancestor in a new package or patch version.",
|
|
16
|
+
|
|
17
|
+
# AncestorIdVersionMismatchError
|
|
18
|
+
|
|
19
|
+
The ancestorVersion in sfdx-project.json is not the version expected for the ancestorId you supplied. ancestorVersion %s. ancestorID %s."
|
package/messages/user.md
CHANGED
|
@@ -29,3 +29,7 @@ Invalid complexity value. Specify a value between 0 and 5, inclusive.
|
|
|
29
29
|
# lengthOutOfBound
|
|
30
30
|
|
|
31
31
|
Invalid length value. Specify a value between 8 and 1000, inclusive.
|
|
32
|
+
|
|
33
|
+
# problemsDescribingTheUserObject
|
|
34
|
+
|
|
35
|
+
Problems occurred while attempting to describe the user object.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/core",
|
|
3
|
-
"version": "3.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",
|
|
@@ -42,6 +42,8 @@
|
|
|
42
42
|
"@types/graceful-fs": "^4.1.5",
|
|
43
43
|
"@types/mkdirp": "^1.0.2",
|
|
44
44
|
"@types/semver": "^7.3.9",
|
|
45
|
+
"archiver": "^5.3.0",
|
|
46
|
+
"js2xmlparser": "^4.0.1",
|
|
45
47
|
"change-case": "^4.1.2",
|
|
46
48
|
"debug": "^3.2.7",
|
|
47
49
|
"faye": "^1.4.0",
|
|
@@ -58,6 +60,7 @@
|
|
|
58
60
|
"@salesforce/dev-scripts": "^2.0.0",
|
|
59
61
|
"@salesforce/prettier-config": "^0.0.2",
|
|
60
62
|
"@salesforce/ts-sinon": "^1.3.21",
|
|
63
|
+
"@types/archiver": "^5.3.1",
|
|
61
64
|
"@types/debug": "0.0.31",
|
|
62
65
|
"@types/jsen": "0.0.21",
|
|
63
66
|
"@types/jsonwebtoken": "8.5.7",
|
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 {};
|
package/lib/util/fs.js
DELETED
|
@@ -1,378 +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
|
-
/**
|
|
18
|
-
* @deprecated Use fs/promises instead
|
|
19
|
-
*/
|
|
20
|
-
exports.fs = Object.assign({}, fsLib, {
|
|
21
|
-
/**
|
|
22
|
-
* The default file system mode to use when creating directories.
|
|
23
|
-
*/
|
|
24
|
-
DEFAULT_USER_DIR_MODE: '700',
|
|
25
|
-
/**
|
|
26
|
-
* The default file system mode to use when creating files.
|
|
27
|
-
*/
|
|
28
|
-
DEFAULT_USER_FILE_MODE: '600',
|
|
29
|
-
/**
|
|
30
|
-
* A convenience reference to {@link https://nodejs.org/api/fsLib.html#fs_fs_constants}
|
|
31
|
-
* to reduce the need to import multiple `fs` modules.
|
|
32
|
-
*/
|
|
33
|
-
constants: fsLib.constants,
|
|
34
|
-
/**
|
|
35
|
-
* Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_readfile_path_options_callback|fsLib.readFile}.
|
|
36
|
-
*/
|
|
37
|
-
readFile: (0, util_1.promisify)(fsLib.readFile),
|
|
38
|
-
/**
|
|
39
|
-
* Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_readdir_path_options_callback|fsLib.readdir}.
|
|
40
|
-
*/
|
|
41
|
-
readdir: (0, util_1.promisify)(fsLib.readdir),
|
|
42
|
-
/**
|
|
43
|
-
* Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_writefile_file_data_options_callback|fsLib.writeFile}.
|
|
44
|
-
*/
|
|
45
|
-
writeFile: (0, util_1.promisify)(fsLib.writeFile),
|
|
46
|
-
/**
|
|
47
|
-
* Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_access_path_mode_callback|fsLib.access}.
|
|
48
|
-
*/
|
|
49
|
-
access: (0, util_1.promisify)(fsLib.access),
|
|
50
|
-
/**
|
|
51
|
-
* Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_open_path_flags_mode_callback|fsLib.open}.
|
|
52
|
-
*/
|
|
53
|
-
open: (0, util_1.promisify)(fsLib.open),
|
|
54
|
-
/**
|
|
55
|
-
* Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_unlink_path_callback|fsLib.unlink}.
|
|
56
|
-
*/
|
|
57
|
-
unlink: (0, util_1.promisify)(fsLib.unlink),
|
|
58
|
-
/**
|
|
59
|
-
* Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_readdir_path_options_callback|fsLib.rmdir}.
|
|
60
|
-
*/
|
|
61
|
-
rmdir: (0, util_1.promisify)(fsLib.rmdir),
|
|
62
|
-
/**
|
|
63
|
-
* Promisified version of {@link https://nodejs.org/api/fsLib.html#fs_fs_fstat_fd_callback|fsLib.stat}.
|
|
64
|
-
*/
|
|
65
|
-
stat: (0, util_1.promisify)(fsLib.stat),
|
|
66
|
-
/**
|
|
67
|
-
* Promisified version of {@link https://npmjs.com/package/mkdirp|mkdirp}.
|
|
68
|
-
*/
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
70
|
-
mkdirp: (folderPath, mode) => mkdirpLib(folderPath, mode),
|
|
71
|
-
mkdirpSync: mkdirpLib.sync,
|
|
72
|
-
/**
|
|
73
|
-
* Deletes a folder recursively, removing all descending files and folders.
|
|
74
|
-
*
|
|
75
|
-
* **Throws** *PathIsNullOrUndefined* The path is not defined.
|
|
76
|
-
* **Throws** *DirMissingOrNoAccess* The folder or any sub-folder is missing or has no access.
|
|
77
|
-
*
|
|
78
|
-
* @param {string} dirPath The path to remove.
|
|
79
|
-
*/
|
|
80
|
-
remove: async (dirPath) => {
|
|
81
|
-
if (!dirPath) {
|
|
82
|
-
throw new sfdxError_1.SfdxError('Path is null or undefined.', 'PathIsNullOrUndefined');
|
|
83
|
-
}
|
|
84
|
-
try {
|
|
85
|
-
await exports.fs.access(dirPath, fsLib.constants.R_OK);
|
|
86
|
-
}
|
|
87
|
-
catch (err) {
|
|
88
|
-
throw new sfdxError_1.SfdxError(`The path: ${dirPath} doesn't exist or access is denied.`, 'DirMissingOrNoAccess');
|
|
89
|
-
}
|
|
90
|
-
const files = await exports.fs.readdir(dirPath);
|
|
91
|
-
const stats = await Promise.all(files.map((file) => exports.fs.stat(path.join(dirPath, file))));
|
|
92
|
-
const metas = stats.map((value, index) => Object.assign(value, { path: path.join(dirPath, files[index]) }));
|
|
93
|
-
await Promise.all(metas.map((meta) => (meta.isDirectory() ? exports.fs.remove(meta.path) : exports.fs.unlink(meta.path))));
|
|
94
|
-
await exports.fs.rmdir(dirPath);
|
|
95
|
-
},
|
|
96
|
-
/**
|
|
97
|
-
* Deletes a folder recursively, removing all descending files and folders.
|
|
98
|
-
*
|
|
99
|
-
* NOTE: It is recommended to call the asynchronous `remove` when possible as it will remove all files in parallel rather than serially.
|
|
100
|
-
*
|
|
101
|
-
* **Throws** *PathIsNullOrUndefined* The path is not defined.
|
|
102
|
-
* **Throws** *DirMissingOrNoAccess* The folder or any sub-folder is missing or has no access.
|
|
103
|
-
*
|
|
104
|
-
* @param {string} dirPath The path to remove.
|
|
105
|
-
*/
|
|
106
|
-
removeSync: (dirPath) => {
|
|
107
|
-
if (!dirPath) {
|
|
108
|
-
throw new sfdxError_1.SfdxError('Path is null or undefined.', 'PathIsNullOrUndefined');
|
|
109
|
-
}
|
|
110
|
-
try {
|
|
111
|
-
exports.fs.accessSync(dirPath, fsLib.constants.R_OK);
|
|
112
|
-
}
|
|
113
|
-
catch (err) {
|
|
114
|
-
throw new sfdxError_1.SfdxError(`The path: ${dirPath} doesn't exist or access is denied.`, 'DirMissingOrNoAccess');
|
|
115
|
-
}
|
|
116
|
-
exports.fs.actOnSync(dirPath, (fullPath, file) => {
|
|
117
|
-
if (file) {
|
|
118
|
-
exports.fs.unlinkSync(fullPath);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
// All files in this directory will be acted on before the directory.
|
|
122
|
-
exports.fs.rmdirSync(fullPath);
|
|
123
|
-
}
|
|
124
|
-
}, 'all');
|
|
125
|
-
// Remove the top level
|
|
126
|
-
exports.fs.rmdirSync(dirPath);
|
|
127
|
-
},
|
|
128
|
-
/**
|
|
129
|
-
* Searches a file path in an ascending manner (until reaching the filesystem root) for the first occurrence a
|
|
130
|
-
* specific file name. Resolves with the directory path containing the located file, or `null` if the file was
|
|
131
|
-
* not found.
|
|
132
|
-
*
|
|
133
|
-
* @param dir The directory path in which to start the upward search.
|
|
134
|
-
* @param file The file name to look for.
|
|
135
|
-
*/
|
|
136
|
-
traverseForFile: async (dir, file) => {
|
|
137
|
-
let foundProjectDir;
|
|
138
|
-
try {
|
|
139
|
-
await exports.fs.stat(path.join(dir, file));
|
|
140
|
-
foundProjectDir = dir;
|
|
141
|
-
}
|
|
142
|
-
catch (err) {
|
|
143
|
-
if (err && err.code === 'ENOENT') {
|
|
144
|
-
const nextDir = path.resolve(dir, '..');
|
|
145
|
-
if (nextDir !== dir) {
|
|
146
|
-
// stop at root
|
|
147
|
-
foundProjectDir = await exports.fs.traverseForFile(nextDir, file);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return foundProjectDir;
|
|
152
|
-
},
|
|
153
|
-
/**
|
|
154
|
-
* Searches a file path synchronously in an ascending manner (until reaching the filesystem root) for the first occurrence a
|
|
155
|
-
* specific file name. Resolves with the directory path containing the located file, or `null` if the file was
|
|
156
|
-
* not found.
|
|
157
|
-
*
|
|
158
|
-
* @param dir The directory path in which to start the upward search.
|
|
159
|
-
* @param file The file name to look for.
|
|
160
|
-
*/
|
|
161
|
-
traverseForFileSync: (dir, file) => {
|
|
162
|
-
let foundProjectDir;
|
|
163
|
-
try {
|
|
164
|
-
exports.fs.statSync(path.join(dir, file));
|
|
165
|
-
foundProjectDir = dir;
|
|
166
|
-
}
|
|
167
|
-
catch (err) {
|
|
168
|
-
if (err && err.code === 'ENOENT') {
|
|
169
|
-
const nextDir = path.resolve(dir, '..');
|
|
170
|
-
if (nextDir !== dir) {
|
|
171
|
-
// stop at root
|
|
172
|
-
foundProjectDir = exports.fs.traverseForFileSync(nextDir, file);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return foundProjectDir;
|
|
177
|
-
},
|
|
178
|
-
/**
|
|
179
|
-
* Read a file and convert it to JSON. Returns the contents of the file as a JSON object
|
|
180
|
-
*
|
|
181
|
-
* @param jsonPath The path of the file.
|
|
182
|
-
* @param throwOnEmpty Whether to throw an error if the JSON file is empty.
|
|
183
|
-
*/
|
|
184
|
-
readJson: async (jsonPath, throwOnEmpty) => {
|
|
185
|
-
const fileData = await exports.fs.readFile(jsonPath, 'utf8');
|
|
186
|
-
return (0, kit_1.parseJson)(fileData, jsonPath, throwOnEmpty);
|
|
187
|
-
},
|
|
188
|
-
/**
|
|
189
|
-
* Read a file and convert it to JSON. Returns the contents of the file as a JSON object
|
|
190
|
-
*
|
|
191
|
-
* @param jsonPath The path of the file.
|
|
192
|
-
* @param throwOnEmpty Whether to throw an error if the JSON file is empty.
|
|
193
|
-
*/
|
|
194
|
-
readJsonSync: (jsonPath, throwOnEmpty) => {
|
|
195
|
-
const fileData = exports.fs.readFileSync(jsonPath, 'utf8');
|
|
196
|
-
return (0, kit_1.parseJson)(fileData, jsonPath, throwOnEmpty);
|
|
197
|
-
},
|
|
198
|
-
/**
|
|
199
|
-
* Read a file and convert it to JSON, throwing an error if the parsed contents are not a `JsonMap`.
|
|
200
|
-
*
|
|
201
|
-
* @param jsonPath The path of the file.
|
|
202
|
-
* @param throwOnEmpty Whether to throw an error if the JSON file is empty.
|
|
203
|
-
*/
|
|
204
|
-
readJsonMap: async (jsonPath, throwOnEmpty) => {
|
|
205
|
-
const fileData = await exports.fs.readFile(jsonPath, 'utf8');
|
|
206
|
-
return (0, kit_1.parseJsonMap)(fileData, jsonPath, throwOnEmpty);
|
|
207
|
-
},
|
|
208
|
-
/**
|
|
209
|
-
* Read a file and convert it to JSON, throwing an error if the parsed contents are not a `JsonMap`.
|
|
210
|
-
*
|
|
211
|
-
* @param jsonPath The path of the file.
|
|
212
|
-
* @param throwOnEmpty Whether to throw an error if the JSON file is empty.
|
|
213
|
-
*/
|
|
214
|
-
readJsonMapSync: (jsonPath, throwOnEmpty) => {
|
|
215
|
-
const fileData = exports.fs.readFileSync(jsonPath, 'utf8');
|
|
216
|
-
return (0, kit_1.parseJsonMap)(fileData, jsonPath, throwOnEmpty);
|
|
217
|
-
},
|
|
218
|
-
/**
|
|
219
|
-
* Convert a JSON-compatible object to a `string` and write it to a file.
|
|
220
|
-
*
|
|
221
|
-
* @param jsonPath The path of the file to write.
|
|
222
|
-
* @param data The JSON object to write.
|
|
223
|
-
*/
|
|
224
|
-
writeJson: async (jsonPath, data, options = {}) => {
|
|
225
|
-
options = Object.assign({ space: 2 }, options);
|
|
226
|
-
const fileData = JSON.stringify(data, null, options.space);
|
|
227
|
-
await exports.fs.writeFile(jsonPath, fileData, {
|
|
228
|
-
encoding: 'utf8',
|
|
229
|
-
mode: exports.fs.DEFAULT_USER_FILE_MODE,
|
|
230
|
-
});
|
|
231
|
-
},
|
|
232
|
-
/**
|
|
233
|
-
* Convert a JSON-compatible object to a `string` and write it to a file.
|
|
234
|
-
*
|
|
235
|
-
* @param jsonPath The path of the file to write.
|
|
236
|
-
* @param data The JSON object to write.
|
|
237
|
-
*/
|
|
238
|
-
writeJsonSync: (jsonPath, data, options = {}) => {
|
|
239
|
-
options = Object.assign({ space: 2 }, options);
|
|
240
|
-
const fileData = JSON.stringify(data, null, options.space);
|
|
241
|
-
exports.fs.writeFileSync(jsonPath, fileData, {
|
|
242
|
-
encoding: 'utf8',
|
|
243
|
-
mode: exports.fs.DEFAULT_USER_FILE_MODE,
|
|
244
|
-
});
|
|
245
|
-
},
|
|
246
|
-
/**
|
|
247
|
-
* Checks if a file path exists
|
|
248
|
-
*
|
|
249
|
-
* @param filePath the file path to check the existence of
|
|
250
|
-
*/
|
|
251
|
-
fileExists: async (filePath) => {
|
|
252
|
-
try {
|
|
253
|
-
await exports.fs.access(filePath);
|
|
254
|
-
return true;
|
|
255
|
-
}
|
|
256
|
-
catch (err) {
|
|
257
|
-
return false;
|
|
258
|
-
}
|
|
259
|
-
},
|
|
260
|
-
/**
|
|
261
|
-
* Checks if a file path exists
|
|
262
|
-
*
|
|
263
|
-
* @param filePath the file path to check the existence of
|
|
264
|
-
*/
|
|
265
|
-
fileExistsSync: (filePath) => {
|
|
266
|
-
try {
|
|
267
|
-
exports.fs.accessSync(filePath);
|
|
268
|
-
return true;
|
|
269
|
-
}
|
|
270
|
-
catch (err) {
|
|
271
|
-
return false;
|
|
272
|
-
}
|
|
273
|
-
},
|
|
274
|
-
/**
|
|
275
|
-
* Recursively act on all files or directories in a directory
|
|
276
|
-
*
|
|
277
|
-
* @param dir path to directory
|
|
278
|
-
* @param perform function to be run on contents of dir
|
|
279
|
-
* @param onType optional parameter to specify type to actOn
|
|
280
|
-
* @returns void
|
|
281
|
-
*/
|
|
282
|
-
actOn: async (dir, perform, onType = 'file') => {
|
|
283
|
-
for (const file of await exports.fs.readdir(dir)) {
|
|
284
|
-
const filePath = path.join(dir, file);
|
|
285
|
-
const stat = await exports.fs.stat(filePath);
|
|
286
|
-
if (stat) {
|
|
287
|
-
if (stat.isDirectory()) {
|
|
288
|
-
await exports.fs.actOn(filePath, perform, onType);
|
|
289
|
-
if (onType === 'dir' || onType === 'all') {
|
|
290
|
-
await perform(filePath);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
else if (stat.isFile() && (onType === 'file' || onType === 'all')) {
|
|
294
|
-
await perform(filePath, file, dir);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
},
|
|
299
|
-
/**
|
|
300
|
-
* Recursively act on all files or directories in a directory
|
|
301
|
-
*
|
|
302
|
-
* @param dir path to directory
|
|
303
|
-
* @param perform function to be run on contents of dir
|
|
304
|
-
* @param onType optional parameter to specify type to actOn
|
|
305
|
-
* @returns void
|
|
306
|
-
*/
|
|
307
|
-
actOnSync: (dir, perform, onType = 'file') => {
|
|
308
|
-
for (const file of exports.fs.readdirSync(dir)) {
|
|
309
|
-
const filePath = path.join(dir, file);
|
|
310
|
-
const stat = exports.fs.statSync(filePath);
|
|
311
|
-
if (stat) {
|
|
312
|
-
if (stat.isDirectory()) {
|
|
313
|
-
exports.fs.actOnSync(filePath, perform, onType);
|
|
314
|
-
if (onType === 'dir' || onType === 'all') {
|
|
315
|
-
perform(filePath);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
else if (stat.isFile() && (onType === 'file' || onType === 'all')) {
|
|
319
|
-
perform(filePath, file, dir);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
},
|
|
324
|
-
/**
|
|
325
|
-
* Checks if files are the same
|
|
326
|
-
*
|
|
327
|
-
* @param file1Path the first file path to check
|
|
328
|
-
* @param file2Path the second file path to check
|
|
329
|
-
* @returns boolean
|
|
330
|
-
*/
|
|
331
|
-
areFilesEqual: async (file1Path, file2Path) => {
|
|
332
|
-
try {
|
|
333
|
-
const file1Size = (await exports.fs.stat(file1Path)).size;
|
|
334
|
-
const file2Size = (await exports.fs.stat(file2Path)).size;
|
|
335
|
-
if (file1Size !== file2Size) {
|
|
336
|
-
return false;
|
|
337
|
-
}
|
|
338
|
-
const contentA = await exports.fs.readFile(file1Path);
|
|
339
|
-
const contentB = await exports.fs.readFile(file2Path);
|
|
340
|
-
return exports.fs.getContentHash(contentA) === exports.fs.getContentHash(contentB);
|
|
341
|
-
}
|
|
342
|
-
catch (err) {
|
|
343
|
-
throw new sfdxError_1.SfdxError(`The path: ${err.path} doesn't exist or access is denied.`, 'DirMissingOrNoAccess');
|
|
344
|
-
}
|
|
345
|
-
},
|
|
346
|
-
/**
|
|
347
|
-
* Checks if files are the same
|
|
348
|
-
*
|
|
349
|
-
* @param file1Path the first file path to check
|
|
350
|
-
* @param file2Path the second file path to check
|
|
351
|
-
* @returns boolean
|
|
352
|
-
*/
|
|
353
|
-
areFilesEqualSync: (file1Path, file2Path) => {
|
|
354
|
-
try {
|
|
355
|
-
const file1Size = exports.fs.statSync(file1Path).size;
|
|
356
|
-
const file2Size = exports.fs.statSync(file2Path).size;
|
|
357
|
-
if (file1Size !== file2Size) {
|
|
358
|
-
return false;
|
|
359
|
-
}
|
|
360
|
-
const contentA = exports.fs.readFileSync(file1Path);
|
|
361
|
-
const contentB = exports.fs.readFileSync(file2Path);
|
|
362
|
-
return exports.fs.getContentHash(contentA) === exports.fs.getContentHash(contentB);
|
|
363
|
-
}
|
|
364
|
-
catch (err) {
|
|
365
|
-
throw new sfdxError_1.SfdxError(`The path: ${err.path} doesn't exist or access is denied.`, 'DirMissingOrNoAccess');
|
|
366
|
-
}
|
|
367
|
-
},
|
|
368
|
-
/**
|
|
369
|
-
* Creates a hash for the string that's passed in
|
|
370
|
-
*
|
|
371
|
-
* @param contents The string passed into the function
|
|
372
|
-
* @returns string
|
|
373
|
-
*/
|
|
374
|
-
getContentHash(contents) {
|
|
375
|
-
return crypto.createHash('sha1').update(contents).digest('hex');
|
|
376
|
-
},
|
|
377
|
-
});
|
|
378
|
-
//# sourceMappingURL=fs.js.map
|