@nomicfoundation/hardhat-utils 3.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +5 -0
- package/dist/src/bigint.d.ts +32 -0
- package/dist/src/bigint.d.ts.map +1 -0
- package/dist/src/bigint.js +54 -0
- package/dist/src/bigint.js.map +1 -0
- package/dist/src/bytecode.d.ts +27 -0
- package/dist/src/bytecode.d.ts.map +1 -0
- package/dist/src/bytecode.js +60 -0
- package/dist/src/bytecode.js.map +1 -0
- package/dist/src/bytes.d.ts +34 -0
- package/dist/src/bytes.d.ts.map +1 -0
- package/dist/src/bytes.js +47 -0
- package/dist/src/bytes.js.map +1 -0
- package/dist/src/ci.d.ts +7 -0
- package/dist/src/ci.d.ts.map +1 -0
- package/dist/src/ci.js +18 -0
- package/dist/src/ci.js.map +1 -0
- package/dist/src/common-errors.d.ts +5 -0
- package/dist/src/common-errors.d.ts.map +1 -0
- package/dist/src/common-errors.js +7 -0
- package/dist/src/common-errors.js.map +1 -0
- package/dist/src/crypto.d.ts +25 -0
- package/dist/src/crypto.d.ts.map +1 -0
- package/dist/src/crypto.js +32 -0
- package/dist/src/crypto.js.map +1 -0
- package/dist/src/date.d.ts +21 -0
- package/dist/src/date.d.ts.map +1 -0
- package/dist/src/date.js +27 -0
- package/dist/src/date.js.map +1 -0
- package/dist/src/debug.d.ts +16 -0
- package/dist/src/debug.d.ts.map +1 -0
- package/dist/src/debug.js +28 -0
- package/dist/src/debug.js.map +1 -0
- package/dist/src/error.d.ts +80 -0
- package/dist/src/error.d.ts.map +1 -0
- package/dist/src/error.js +97 -0
- package/dist/src/error.js.map +1 -0
- package/dist/src/errors/bytecode.d.ts +18 -0
- package/dist/src/errors/bytecode.d.ts.map +1 -0
- package/dist/src/errors/bytecode.js +59 -0
- package/dist/src/errors/bytecode.js.map +1 -0
- package/dist/src/errors/fs.d.ts +25 -0
- package/dist/src/errors/fs.d.ts.map +1 -0
- package/dist/src/errors/fs.js +41 -0
- package/dist/src/errors/fs.js.map +1 -0
- package/dist/src/errors/package.d.ts +8 -0
- package/dist/src/errors/package.d.ts.map +1 -0
- package/dist/src/errors/package.js +12 -0
- package/dist/src/errors/package.js.map +1 -0
- package/dist/src/errors/request.d.ts +25 -0
- package/dist/src/errors/request.d.ts.map +1 -0
- package/dist/src/errors/request.js +64 -0
- package/dist/src/errors/request.js.map +1 -0
- package/dist/src/errors/subprocess.d.ts +8 -0
- package/dist/src/errors/subprocess.d.ts.map +1 -0
- package/dist/src/errors/subprocess.js +12 -0
- package/dist/src/errors/subprocess.js.map +1 -0
- package/dist/src/eth.d.ts +56 -0
- package/dist/src/eth.d.ts.map +1 -0
- package/dist/src/eth.js +78 -0
- package/dist/src/eth.js.map +1 -0
- package/dist/src/fs.d.ts +241 -0
- package/dist/src/fs.d.ts.map +1 -0
- package/dist/src/fs.js +581 -0
- package/dist/src/fs.js.map +1 -0
- package/dist/src/global-dir.d.ts +28 -0
- package/dist/src/global-dir.d.ts.map +1 -0
- package/dist/src/global-dir.js +42 -0
- package/dist/src/global-dir.js.map +1 -0
- package/dist/src/hex.d.ts +117 -0
- package/dist/src/hex.d.ts.map +1 -0
- package/dist/src/hex.js +187 -0
- package/dist/src/hex.js.map +1 -0
- package/dist/src/internal/bytecode.d.ts +45 -0
- package/dist/src/internal/bytecode.d.ts.map +1 -0
- package/dist/src/internal/bytecode.js +73 -0
- package/dist/src/internal/bytecode.js.map +1 -0
- package/dist/src/internal/eth.d.ts +21 -0
- package/dist/src/internal/eth.d.ts.map +1 -0
- package/dist/src/internal/eth.js +58 -0
- package/dist/src/internal/eth.js.map +1 -0
- package/dist/src/internal/global-dir.d.ts +4 -0
- package/dist/src/internal/global-dir.d.ts.map +1 -0
- package/dist/src/internal/global-dir.js +6 -0
- package/dist/src/internal/global-dir.js.map +1 -0
- package/dist/src/internal/hex.d.ts +2 -0
- package/dist/src/internal/hex.d.ts.map +1 -0
- package/dist/src/internal/hex.js +16 -0
- package/dist/src/internal/hex.js.map +1 -0
- package/dist/src/internal/lang.d.ts +2 -0
- package/dist/src/internal/lang.d.ts.map +1 -0
- package/dist/src/internal/lang.js +9 -0
- package/dist/src/internal/lang.js.map +1 -0
- package/dist/src/internal/package.d.ts +2 -0
- package/dist/src/internal/package.d.ts.map +1 -0
- package/dist/src/internal/package.js +15 -0
- package/dist/src/internal/package.js.map +1 -0
- package/dist/src/internal/request.d.ts +20 -0
- package/dist/src/internal/request.d.ts.map +1 -0
- package/dist/src/internal/request.js +101 -0
- package/dist/src/internal/request.js.map +1 -0
- package/dist/src/lang.d.ts +30 -0
- package/dist/src/lang.d.ts.map +1 -0
- package/dist/src/lang.js +41 -0
- package/dist/src/lang.js.map +1 -0
- package/dist/src/number.d.ts +23 -0
- package/dist/src/number.d.ts.map +1 -0
- package/dist/src/number.js +30 -0
- package/dist/src/number.js.map +1 -0
- package/dist/src/package.d.ts +75 -0
- package/dist/src/package.d.ts.map +1 -0
- package/dist/src/package.js +97 -0
- package/dist/src/package.js.map +1 -0
- package/dist/src/path.d.ts +26 -0
- package/dist/src/path.d.ts.map +1 -0
- package/dist/src/path.js +38 -0
- package/dist/src/path.js.map +1 -0
- package/dist/src/request.d.ts +118 -0
- package/dist/src/request.d.ts.map +1 -0
- package/dist/src/request.js +208 -0
- package/dist/src/request.js.map +1 -0
- package/dist/src/stream.d.ts +10 -0
- package/dist/src/stream.d.ts.map +1 -0
- package/dist/src/stream.js +16 -0
- package/dist/src/stream.js.map +1 -0
- package/dist/src/string.d.ts +45 -0
- package/dist/src/string.d.ts.map +1 -0
- package/dist/src/string.js +60 -0
- package/dist/src/string.js.map +1 -0
- package/dist/src/subprocess.d.ts +13 -0
- package/dist/src/subprocess.d.ts.map +1 -0
- package/dist/src/subprocess.js +33 -0
- package/dist/src/subprocess.js.map +1 -0
- package/dist/src/synchronization.d.ts +6 -0
- package/dist/src/synchronization.d.ts.map +1 -0
- package/dist/src/synchronization.js +107 -0
- package/dist/src/synchronization.js.map +1 -0
- package/package.json +90 -0
- package/src/bigint.ts +61 -0
- package/src/bytecode.ts +90 -0
- package/src/bytes.ts +51 -0
- package/src/ci.ts +19 -0
- package/src/common-errors.ts +7 -0
- package/src/crypto.ts +35 -0
- package/src/date.ts +28 -0
- package/src/debug.ts +38 -0
- package/src/error.ts +105 -0
- package/src/errors/bytecode.ts +75 -0
- package/src/errors/fs.ts +47 -0
- package/src/errors/package.ts +13 -0
- package/src/errors/request.ts +84 -0
- package/src/errors/subprocess.ts +17 -0
- package/src/eth.ts +91 -0
- package/src/fs.ts +678 -0
- package/src/global-dir.ts +51 -0
- package/src/hex.ts +232 -0
- package/src/internal/bytecode.ts +129 -0
- package/src/internal/eth.ts +71 -0
- package/src/internal/global-dir.ts +10 -0
- package/src/internal/hex.ts +21 -0
- package/src/internal/lang.ts +12 -0
- package/src/internal/package.ts +15 -0
- package/src/internal/request.ts +165 -0
- package/src/lang.ts +48 -0
- package/src/number.ts +38 -0
- package/src/package.ts +143 -0
- package/src/path.ts +45 -0
- package/src/request.ts +341 -0
- package/src/stream.ts +16 -0
- package/src/string.ts +69 -0
- package/src/subprocess.ts +46 -0
- package/src/synchronization.ts +126 -0
package/dist/src/fs.js
ADDED
|
@@ -0,0 +1,581 @@
|
|
|
1
|
+
import fsPromises from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { ensureError } from "./error.js";
|
|
4
|
+
import { FileNotFoundError, FileSystemAccessError, InvalidFileFormatError, JsonSerializationError, FileAlreadyExistsError, NotADirectoryError, IsDirectoryError, DirectoryNotEmptyError, } from "./errors/fs.js";
|
|
5
|
+
/**
|
|
6
|
+
* Determines the canonical pathname for a given path, resolving any symbolic
|
|
7
|
+
* links, and returns it.
|
|
8
|
+
*
|
|
9
|
+
* @throws FileNotFoundError if absolutePath doesn't exist.
|
|
10
|
+
* @throws FileSystemAccessError for any other error.
|
|
11
|
+
*/
|
|
12
|
+
export async function getRealPath(absolutePath) {
|
|
13
|
+
try {
|
|
14
|
+
return await fsPromises.realpath(path.normalize(absolutePath));
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
ensureError(e);
|
|
18
|
+
if (e.code === "ENOENT") {
|
|
19
|
+
throw new FileNotFoundError(absolutePath, e);
|
|
20
|
+
}
|
|
21
|
+
throw new FileSystemAccessError(e.message, e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Recursively searches a directory and its subdirectories for files that
|
|
26
|
+
* satisfy the specified condition, returning their absolute paths.
|
|
27
|
+
*
|
|
28
|
+
* @param dirFrom The absolute path of the directory to start the search from.
|
|
29
|
+
* @param matches A function to filter files (not directories).
|
|
30
|
+
* @returns An array of absolute paths. Each file has its true case, except
|
|
31
|
+
* for the initial dirFrom part, which preserves the given casing.
|
|
32
|
+
* No order is guaranteed. If dirFrom doesn't exist `[]` is returned.
|
|
33
|
+
* @throws NotADirectoryError if dirFrom is not a directory.
|
|
34
|
+
* @throws FileSystemAccessError for any other error.
|
|
35
|
+
*/
|
|
36
|
+
export async function getAllFilesMatching(dirFrom, matches) {
|
|
37
|
+
const dirContent = await readdirOrEmpty(dirFrom);
|
|
38
|
+
const results = await Promise.all(dirContent.map(async (file) => {
|
|
39
|
+
const absolutePathToFile = path.join(dirFrom, file);
|
|
40
|
+
if (await isDirectory(absolutePathToFile)) {
|
|
41
|
+
return getAllFilesMatching(absolutePathToFile, matches);
|
|
42
|
+
}
|
|
43
|
+
else if (matches === undefined || matches(absolutePathToFile)) {
|
|
44
|
+
return absolutePathToFile;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
}));
|
|
50
|
+
return results.flat();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Recursively searches a directory and its subdirectories for directories that
|
|
54
|
+
* satisfy the specified condition, returning their absolute paths. Once a
|
|
55
|
+
* directory is found, its subdirectories are not searched.
|
|
56
|
+
*
|
|
57
|
+
* Note: dirFrom is never returned, nor `matches` is called on it.
|
|
58
|
+
*
|
|
59
|
+
* @param dirFrom The absolute path of the directory to start the search from.
|
|
60
|
+
* @param matches A function to filter directories (not files).
|
|
61
|
+
* @returns An array of absolute paths. Each path has its true case, except
|
|
62
|
+
* for the initial dirFrom part, which preserves the given casing.
|
|
63
|
+
* No order is guaranteed. If dirFrom doesn't exist `[]` is returned.
|
|
64
|
+
* @throws NotADirectoryError if dirFrom is not a directory.
|
|
65
|
+
* @throws FileSystemAccessError for any other error.
|
|
66
|
+
*/
|
|
67
|
+
export async function getAllDirectoriesMatching(dirFrom, matches) {
|
|
68
|
+
const dirContent = await readdirOrEmpty(dirFrom);
|
|
69
|
+
const results = await Promise.all(dirContent.map(async (file) => {
|
|
70
|
+
const absolutePathToFile = path.join(dirFrom, file);
|
|
71
|
+
if (!(await isDirectory(absolutePathToFile))) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
if (matches === undefined || matches(absolutePathToFile)) {
|
|
75
|
+
return absolutePathToFile;
|
|
76
|
+
}
|
|
77
|
+
return getAllDirectoriesMatching(absolutePathToFile, matches);
|
|
78
|
+
}));
|
|
79
|
+
return results.flat();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Determines the true case path of a given relative path from a specified
|
|
83
|
+
* directory, without resolving symbolic links, and returns it.
|
|
84
|
+
*
|
|
85
|
+
* @param from The absolute path of the directory to start the search from.
|
|
86
|
+
* @param relativePath The relative path to get the true case of.
|
|
87
|
+
* @returns The true case of the relative path.
|
|
88
|
+
* @throws FileNotFoundError if the starting directory or the relative path doesn't exist.
|
|
89
|
+
* @throws NotADirectoryError if the starting directory is not a directory.
|
|
90
|
+
* @throws FileSystemAccessError for any other error.
|
|
91
|
+
*/
|
|
92
|
+
export async function getFileTrueCase(from, relativePath) {
|
|
93
|
+
const dirEntries = await readdirOrEmpty(from);
|
|
94
|
+
const segments = relativePath.split(path.sep);
|
|
95
|
+
const nextDir = segments[0];
|
|
96
|
+
const nextDirLowerCase = nextDir.toLowerCase();
|
|
97
|
+
for (const dirEntry of dirEntries) {
|
|
98
|
+
if (dirEntry.toLowerCase() === nextDirLowerCase) {
|
|
99
|
+
if (segments.length === 1) {
|
|
100
|
+
return dirEntry;
|
|
101
|
+
}
|
|
102
|
+
return path.join(dirEntry, await getFileTrueCase(path.join(from, dirEntry), path.relative(nextDir, relativePath)));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
throw new FileNotFoundError(path.join(from, relativePath));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Checks if a given path is a directory.
|
|
109
|
+
*
|
|
110
|
+
* @param absolutePath The path to check.
|
|
111
|
+
* @returns `true` if the path is a directory, `false` otherwise.
|
|
112
|
+
* @throws FileNotFoundError if the path doesn't exist.
|
|
113
|
+
* @throws FileSystemAccessError for any other error.
|
|
114
|
+
*/
|
|
115
|
+
export async function isDirectory(absolutePath) {
|
|
116
|
+
try {
|
|
117
|
+
return (await fsPromises.lstat(absolutePath)).isDirectory();
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
ensureError(e);
|
|
121
|
+
if (e.code === "ENOENT") {
|
|
122
|
+
throw new FileNotFoundError(absolutePath, e);
|
|
123
|
+
}
|
|
124
|
+
throw new FileSystemAccessError(e.message, e);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Reads a JSON file and parses it. The encoding used is "utf8".
|
|
129
|
+
*
|
|
130
|
+
* @param absolutePathToFile The path to the file.
|
|
131
|
+
* @returns The parsed JSON object.
|
|
132
|
+
* @throws FileNotFoundError if the file doesn't exist.
|
|
133
|
+
* @throws InvalidFileFormatError if the file is not a valid JSON file.
|
|
134
|
+
* @throws IsDirectoryError if the path is a directory instead of a file.
|
|
135
|
+
* @throws FileSystemAccessError for any other error.
|
|
136
|
+
*/
|
|
137
|
+
export async function readJsonFile(absolutePathToFile) {
|
|
138
|
+
const content = await readUtf8File(absolutePathToFile);
|
|
139
|
+
try {
|
|
140
|
+
return JSON.parse(content.toString());
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
ensureError(e);
|
|
144
|
+
throw new InvalidFileFormatError(absolutePathToFile, e);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Writes an object to a JSON file. The encoding used is "utf8" and the file is overwritten.
|
|
149
|
+
* If part of the path doesn't exist, it will be created.
|
|
150
|
+
*
|
|
151
|
+
* @param absolutePathToFile The path to the file. If the file exists, it will be overwritten.
|
|
152
|
+
* @param object The object to write.
|
|
153
|
+
* @throws JsonSerializationError if the object can't be serialized to JSON.
|
|
154
|
+
* @throws FileSystemAccessError for any other error.
|
|
155
|
+
*/
|
|
156
|
+
export async function writeJsonFile(absolutePathToFile, object) {
|
|
157
|
+
let content;
|
|
158
|
+
try {
|
|
159
|
+
content = JSON.stringify(object, null, 2);
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
ensureError(e);
|
|
163
|
+
throw new JsonSerializationError(absolutePathToFile, e);
|
|
164
|
+
}
|
|
165
|
+
await writeUtf8File(absolutePathToFile, content);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Reads a file and returns its content as a string. The encoding used is "utf8".
|
|
169
|
+
*
|
|
170
|
+
* @param absolutePathToFile The path to the file.
|
|
171
|
+
* @returns The content of the file as a string.
|
|
172
|
+
* @throws FileNotFoundError if the file doesn't exist.
|
|
173
|
+
* @throws IsDirectoryError if the path is a directory instead of a file.
|
|
174
|
+
* @throws FileSystemAccessError for any other error.
|
|
175
|
+
*/
|
|
176
|
+
export async function readUtf8File(absolutePathToFile) {
|
|
177
|
+
try {
|
|
178
|
+
return await fsPromises.readFile(absolutePathToFile, { encoding: "utf8" });
|
|
179
|
+
}
|
|
180
|
+
catch (e) {
|
|
181
|
+
ensureError(e);
|
|
182
|
+
if (e.code === "ENOENT") {
|
|
183
|
+
throw new FileNotFoundError(absolutePathToFile, e);
|
|
184
|
+
}
|
|
185
|
+
if (e.code === "EISDIR") {
|
|
186
|
+
throw new IsDirectoryError(absolutePathToFile, e);
|
|
187
|
+
}
|
|
188
|
+
throw new FileSystemAccessError(e.message, e);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Writes a string to a file. The encoding used is "utf8" and the file is overwritten by default.
|
|
193
|
+
* If part of the path doesn't exist, it will be created.
|
|
194
|
+
*
|
|
195
|
+
* @param absolutePathToFile The path to the file.
|
|
196
|
+
* @param data The data to write.
|
|
197
|
+
* @param flag The flag to use when writing the file. If not provided, the file will be overwritten.
|
|
198
|
+
* See https://nodejs.org/docs/latest-v20.x/api/fs.html#file-system-flags for more information.
|
|
199
|
+
* @throws FileAlreadyExistsError if the file already exists and the flag "x" is used.
|
|
200
|
+
* @throws FileSystemAccessError for any other error.
|
|
201
|
+
*/
|
|
202
|
+
export async function writeUtf8File(absolutePathToFile, data, flag) {
|
|
203
|
+
const dirPath = path.dirname(absolutePathToFile);
|
|
204
|
+
const dirExists = await exists(dirPath);
|
|
205
|
+
if (!dirExists) {
|
|
206
|
+
await mkdir(dirPath);
|
|
207
|
+
}
|
|
208
|
+
try {
|
|
209
|
+
await fsPromises.writeFile(absolutePathToFile, data, {
|
|
210
|
+
encoding: "utf8",
|
|
211
|
+
flag,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
catch (e) {
|
|
215
|
+
ensureError(e);
|
|
216
|
+
// if the directory was created, we should remove it
|
|
217
|
+
if (dirExists === false) {
|
|
218
|
+
try {
|
|
219
|
+
await remove(dirPath);
|
|
220
|
+
// we don't want to override the original error
|
|
221
|
+
}
|
|
222
|
+
catch (err) { }
|
|
223
|
+
}
|
|
224
|
+
if (e.code === "ENOENT") {
|
|
225
|
+
throw new FileNotFoundError(absolutePathToFile, e);
|
|
226
|
+
}
|
|
227
|
+
// flag "x" has been used and the file already exists
|
|
228
|
+
if (e.code === "EEXIST") {
|
|
229
|
+
throw new FileAlreadyExistsError(absolutePathToFile, e);
|
|
230
|
+
}
|
|
231
|
+
throw new FileSystemAccessError(e.message, e);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Reads a file and returns its content as a Uint8Array.
|
|
236
|
+
*
|
|
237
|
+
* @param absolutePathToFile The path to the file.
|
|
238
|
+
* @returns The content of the file as a Uint8Array.
|
|
239
|
+
* @throws FileNotFoundError if the file doesn't exist.
|
|
240
|
+
* @throws IsDirectoryError if the path is a directory instead of a file.
|
|
241
|
+
* @throws FileSystemAccessError for any other error.
|
|
242
|
+
*/
|
|
243
|
+
export async function readBinaryFile(absolutePathToFile) {
|
|
244
|
+
try {
|
|
245
|
+
const buffer = await fsPromises.readFile(absolutePathToFile);
|
|
246
|
+
return new Uint8Array(buffer);
|
|
247
|
+
}
|
|
248
|
+
catch (e) {
|
|
249
|
+
ensureError(e);
|
|
250
|
+
if (e.code === "ENOENT") {
|
|
251
|
+
throw new FileNotFoundError(absolutePathToFile, e);
|
|
252
|
+
}
|
|
253
|
+
if (e.code === "EISDIR") {
|
|
254
|
+
throw new IsDirectoryError(absolutePathToFile, e);
|
|
255
|
+
}
|
|
256
|
+
throw new FileSystemAccessError(e.message, e);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Reads a directory and returns its content as an array of strings.
|
|
261
|
+
*
|
|
262
|
+
* @param absolutePathToDir The path to the directory.
|
|
263
|
+
* @returns An array of strings with the names of the files and directories in the directory.
|
|
264
|
+
* @throws FileNotFoundError if the directory doesn't exist.
|
|
265
|
+
* @throws NotADirectoryError if the path is not a directory.
|
|
266
|
+
* @throws FileSystemAccessError for any other error.
|
|
267
|
+
*/
|
|
268
|
+
export async function readdir(absolutePathToDir) {
|
|
269
|
+
try {
|
|
270
|
+
return await fsPromises.readdir(absolutePathToDir);
|
|
271
|
+
}
|
|
272
|
+
catch (e) {
|
|
273
|
+
ensureError(e);
|
|
274
|
+
if (e.code === "ENOENT") {
|
|
275
|
+
throw new FileNotFoundError(absolutePathToDir, e);
|
|
276
|
+
}
|
|
277
|
+
if (e.code === "ENOTDIR") {
|
|
278
|
+
throw new NotADirectoryError(absolutePathToDir, e);
|
|
279
|
+
}
|
|
280
|
+
throw new FileSystemAccessError(e.message, e);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Wrapper around `readdir` that returns an empty array if the directory doesn't exist.
|
|
285
|
+
*
|
|
286
|
+
* @see readdir
|
|
287
|
+
*/
|
|
288
|
+
async function readdirOrEmpty(dirFrom) {
|
|
289
|
+
try {
|
|
290
|
+
return await readdir(dirFrom);
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
if (error instanceof FileNotFoundError) {
|
|
294
|
+
return [];
|
|
295
|
+
}
|
|
296
|
+
throw error;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Creates a directory and any necessary directories along the way. If the directory already exists,
|
|
301
|
+
* nothing is done.
|
|
302
|
+
*
|
|
303
|
+
* @param absolutePath The path to the directory to create.
|
|
304
|
+
* @throws FileSystemAccessError for any error.
|
|
305
|
+
*/
|
|
306
|
+
export async function mkdir(absolutePath) {
|
|
307
|
+
try {
|
|
308
|
+
await fsPromises.mkdir(absolutePath, { recursive: true });
|
|
309
|
+
}
|
|
310
|
+
catch (e) {
|
|
311
|
+
ensureError(e);
|
|
312
|
+
throw new FileSystemAccessError(e.message, e);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Alias for `mkdir`.
|
|
317
|
+
* @see mkdir
|
|
318
|
+
*/
|
|
319
|
+
export const ensureDir = mkdir;
|
|
320
|
+
/**
|
|
321
|
+
* Retrieves the last change time of a file or directory's properties.
|
|
322
|
+
* This includes changes to the file's metadata or contents.
|
|
323
|
+
*
|
|
324
|
+
* @param absolutePath The absolute path to the file or directory.
|
|
325
|
+
* @returns The time of the last change as a Date object.
|
|
326
|
+
* @throws FileNotFoundError if the path does not exist.
|
|
327
|
+
* @throws FileSystemAccessError for any other error.
|
|
328
|
+
*/
|
|
329
|
+
export async function getChangeTime(absolutePath) {
|
|
330
|
+
try {
|
|
331
|
+
const stats = await fsPromises.stat(absolutePath);
|
|
332
|
+
return stats.ctime;
|
|
333
|
+
}
|
|
334
|
+
catch (e) {
|
|
335
|
+
ensureError(e);
|
|
336
|
+
if (e.code === "ENOENT") {
|
|
337
|
+
throw new FileNotFoundError(absolutePath, e);
|
|
338
|
+
}
|
|
339
|
+
throw new FileSystemAccessError(e.message, e);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Retrieves the last access time of a file or directory's properties.
|
|
344
|
+
*
|
|
345
|
+
* @param absolutePath The absolute path to the file or directory.
|
|
346
|
+
* @returns The time of the last access as a Date object.
|
|
347
|
+
* @throws FileNotFoundError if the path does not exist.
|
|
348
|
+
* @throws FileSystemAccessError for any other error.
|
|
349
|
+
*/
|
|
350
|
+
export async function getAccessTime(absolutePath) {
|
|
351
|
+
try {
|
|
352
|
+
const stats = await fsPromises.stat(absolutePath);
|
|
353
|
+
return stats.atime;
|
|
354
|
+
}
|
|
355
|
+
catch (e) {
|
|
356
|
+
ensureError(e);
|
|
357
|
+
if (e.code === "ENOENT") {
|
|
358
|
+
throw new FileNotFoundError(absolutePath, e);
|
|
359
|
+
}
|
|
360
|
+
throw new FileSystemAccessError(e.message, e);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Retrieves the size of a file.
|
|
365
|
+
*
|
|
366
|
+
* @param absolutePath The absolute path to the file.
|
|
367
|
+
* @returns The size of the file in bytes.
|
|
368
|
+
* @throws FileNotFoundError if the path does not exist.
|
|
369
|
+
* @throws FileSystemAccessError for any other error.
|
|
370
|
+
*/
|
|
371
|
+
export async function getFileSize(absolutePath) {
|
|
372
|
+
try {
|
|
373
|
+
const stats = await fsPromises.stat(absolutePath);
|
|
374
|
+
return stats.size;
|
|
375
|
+
}
|
|
376
|
+
catch (e) {
|
|
377
|
+
ensureError(e);
|
|
378
|
+
if (e.code === "ENOENT") {
|
|
379
|
+
throw new FileNotFoundError(absolutePath, e);
|
|
380
|
+
}
|
|
381
|
+
throw new FileSystemAccessError(e.message, e);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Checks if a file or directory exists.
|
|
386
|
+
*
|
|
387
|
+
* @param absolutePath The absolute path to the file or directory.
|
|
388
|
+
* @returns A boolean indicating whether the file or directory exists.
|
|
389
|
+
*/
|
|
390
|
+
export async function exists(absolutePath) {
|
|
391
|
+
try {
|
|
392
|
+
await fsPromises.access(absolutePath);
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
catch (e) {
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Copies a file from a source to a destination.
|
|
401
|
+
* If the destination file already exists, it will be overwritten.
|
|
402
|
+
*
|
|
403
|
+
* @param source The path to the source file. It can't be a directory.
|
|
404
|
+
* @param destination The path to the destination file. It can't be a directory.
|
|
405
|
+
* @throws FileNotFoundError if the source path or the destination path doesn't exist.
|
|
406
|
+
* @throws IsDirectoryError if the source path or the destination path is a directory.
|
|
407
|
+
* @throws FileSystemAccessError for any other error.
|
|
408
|
+
*/
|
|
409
|
+
export async function copy(source, destination) {
|
|
410
|
+
try {
|
|
411
|
+
await fsPromises.copyFile(source, destination);
|
|
412
|
+
}
|
|
413
|
+
catch (e) {
|
|
414
|
+
ensureError(e);
|
|
415
|
+
if (e.code === "ENOENT") {
|
|
416
|
+
if (!(await exists(source))) {
|
|
417
|
+
throw new FileNotFoundError(source, e);
|
|
418
|
+
}
|
|
419
|
+
if (!(await exists(destination))) {
|
|
420
|
+
throw new FileNotFoundError(destination, e);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
// On linux, trying to copy a directory will throw EISDIR,
|
|
424
|
+
// on Windows it will throw EPERM, and on macOS it will throw ENOTSUP.
|
|
425
|
+
if (e.code === "EISDIR" || e.code === "EPERM" || e.code === "ENOTSUP") {
|
|
426
|
+
if (await isDirectory(source)) {
|
|
427
|
+
throw new IsDirectoryError(source, e);
|
|
428
|
+
}
|
|
429
|
+
if (await isDirectory(destination)) {
|
|
430
|
+
throw new IsDirectoryError(destination, e);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
throw new FileSystemAccessError(e.message, e);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Moves a file or directory from a source to a destination. If the source is a
|
|
438
|
+
* file and the destination is a file that already exists, it will be overwritten.
|
|
439
|
+
* If the source is a directory and the destination is a directory, it needs to be empty.
|
|
440
|
+
*
|
|
441
|
+
* Note: This method may not work when moving files between different mount points
|
|
442
|
+
* or file systems, as the underlying `fsPromises.rename` method may not support it.
|
|
443
|
+
*
|
|
444
|
+
* @param source The path to the source file or directory.
|
|
445
|
+
* @param destination The path to the destination file or directory.
|
|
446
|
+
* @throws FileNotFoundError if the source path or the destination path doesn't exist.
|
|
447
|
+
* @throws DirectoryNotEmptyError if the source path is a directory and the destination
|
|
448
|
+
* path is a directory that is not empty.
|
|
449
|
+
* @throws FileSystemAccessError for any other error.
|
|
450
|
+
*/
|
|
451
|
+
export async function move(source, destination) {
|
|
452
|
+
try {
|
|
453
|
+
await fsPromises.rename(source, destination);
|
|
454
|
+
}
|
|
455
|
+
catch (e) {
|
|
456
|
+
ensureError(e);
|
|
457
|
+
if (e.code === "ENOENT") {
|
|
458
|
+
if (!(await exists(source))) {
|
|
459
|
+
throw new FileNotFoundError(source, e);
|
|
460
|
+
}
|
|
461
|
+
if (!(await exists(path.dirname(destination)))) {
|
|
462
|
+
throw new FileNotFoundError(destination, e);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
// On linux, trying to move a non-empty directory will throw ENOTEMPTY,
|
|
466
|
+
// while on Windows it will throw EPERM.
|
|
467
|
+
if (e.code === "ENOTEMPTY" || e.code === "EPERM") {
|
|
468
|
+
throw new DirectoryNotEmptyError(destination, e);
|
|
469
|
+
}
|
|
470
|
+
throw new FileSystemAccessError(e.message, e);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Removes a file or directory recursively.
|
|
475
|
+
* Exceptions are ignored for non-existent paths.
|
|
476
|
+
*
|
|
477
|
+
* @param absolutePath The path to the file or directory to remove.
|
|
478
|
+
* @throws FileSystemAccessError for any error, except for non-existent path errors.
|
|
479
|
+
*/
|
|
480
|
+
export async function remove(absolutePath) {
|
|
481
|
+
try {
|
|
482
|
+
await fsPromises.rm(absolutePath, {
|
|
483
|
+
recursive: true,
|
|
484
|
+
force: true,
|
|
485
|
+
maxRetries: 3,
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
catch (e) {
|
|
489
|
+
ensureError(e);
|
|
490
|
+
throw new FileSystemAccessError(e.message, e);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Changes the permissions of a file or directory.
|
|
495
|
+
*
|
|
496
|
+
* @param absolutePath The path to the file or directory.
|
|
497
|
+
* @param mode The permissions to set. It can be a string or a number representing the octal mode.
|
|
498
|
+
* @throws FileNotFoundError if the path doesn't exist.
|
|
499
|
+
* @throws FileSystemAccessError for any other error.
|
|
500
|
+
*/
|
|
501
|
+
export async function chmod(absolutePath, mode) {
|
|
502
|
+
try {
|
|
503
|
+
await fsPromises.chmod(absolutePath, mode);
|
|
504
|
+
}
|
|
505
|
+
catch (e) {
|
|
506
|
+
ensureError(e);
|
|
507
|
+
if (e.code === "ENOENT") {
|
|
508
|
+
throw new FileNotFoundError(absolutePath, e);
|
|
509
|
+
}
|
|
510
|
+
throw new FileSystemAccessError(e.message, e);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Creates a file with an empty content. If the file already exists, it will be overwritten.
|
|
515
|
+
* If part of the path doesn't exist, it will be created.
|
|
516
|
+
*
|
|
517
|
+
* @param absolutePath The path to the file to create.
|
|
518
|
+
* @throws FileSystemAccessError for any other error.
|
|
519
|
+
*/
|
|
520
|
+
export async function createFile(absolutePath) {
|
|
521
|
+
await writeUtf8File(absolutePath, "");
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Empties a directory by recursively removing all its content. If the
|
|
525
|
+
* directory doesn't exist, it will be created. The directory itself is
|
|
526
|
+
* not removed.
|
|
527
|
+
*
|
|
528
|
+
* @param absolutePath The path to the directory to empty.
|
|
529
|
+
* @throws NotADirectoryError if the path is not a directory.
|
|
530
|
+
* @throws FileSystemAccessError for any other error.
|
|
531
|
+
*/
|
|
532
|
+
export async function emptyDir(absolutePath) {
|
|
533
|
+
let isDir;
|
|
534
|
+
let mode;
|
|
535
|
+
try {
|
|
536
|
+
const stats = await fsPromises.stat(absolutePath);
|
|
537
|
+
isDir = stats.isDirectory();
|
|
538
|
+
mode = stats.mode;
|
|
539
|
+
}
|
|
540
|
+
catch (e) {
|
|
541
|
+
ensureError(e);
|
|
542
|
+
if (e.code === "ENOENT") {
|
|
543
|
+
await mkdir(absolutePath);
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
throw new FileSystemAccessError(e.message, e);
|
|
547
|
+
}
|
|
548
|
+
if (!isDir) {
|
|
549
|
+
throw new NotADirectoryError(absolutePath, new Error());
|
|
550
|
+
}
|
|
551
|
+
await remove(absolutePath);
|
|
552
|
+
await mkdir(absolutePath);
|
|
553
|
+
// eslint-disable-next-line no-bitwise -- Bitwise as common in fs permissions
|
|
554
|
+
await chmod(absolutePath, mode & 0o777);
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Looks for a file in the current directory and its parents.
|
|
558
|
+
*
|
|
559
|
+
* @param fileName The name of the file to look for.
|
|
560
|
+
* @param from The directory to start the search from. Defaults to the current working directory.
|
|
561
|
+
* @returns The absolute path to the file, or `undefined` if it wasn't found.
|
|
562
|
+
*/
|
|
563
|
+
export async function findUp(fileName, from) {
|
|
564
|
+
if (from === undefined) {
|
|
565
|
+
from = process.cwd();
|
|
566
|
+
}
|
|
567
|
+
let currentDir = from;
|
|
568
|
+
while (true) {
|
|
569
|
+
const absolutePath = path.join(currentDir, fileName);
|
|
570
|
+
if (await exists(absolutePath)) {
|
|
571
|
+
return absolutePath;
|
|
572
|
+
}
|
|
573
|
+
const parentDir = path.dirname(currentDir);
|
|
574
|
+
if (parentDir === currentDir) {
|
|
575
|
+
return undefined;
|
|
576
|
+
}
|
|
577
|
+
currentDir = parentDir;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
export { FileNotFoundError, FileSystemAccessError, InvalidFileFormatError, JsonSerializationError, FileAlreadyExistsError, NotADirectoryError, IsDirectoryError, DirectoryNotEmptyError, } from "./errors/fs.js";
|
|
581
|
+
//# sourceMappingURL=fs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/fs.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,gBAAgB,CAAC;AAExB;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,YAAoB;IACpD,IAAI,CAAC;QACH,OAAO,MAAM,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;IACjE,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,WAAW,CAAwB,CAAC,CAAC,CAAC;QACtC,IAAI,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M,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC3C,IAAI,SAAS,KAAK,UAAU,EAAE,CAAC;YAC7B,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,UAAU,GAAG,SAAS,CAAC;IACzB,CAAC;AACH,CAAC;AAED,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the configuration directory path for a given package (defaults to "hardhat").
|
|
3
|
+
* Ensures that the directory exists before returning the path.
|
|
4
|
+
*
|
|
5
|
+
* @param packageName The name of the package for which to generate paths. Defaults to "hardhat" if no package name is provided.
|
|
6
|
+
* @returns The path to the hardhat configuration directory.
|
|
7
|
+
* @throws FileSystemAccessError for any error.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getConfigDir(packageName?: string): Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the cache directory path for a given package (defaults to "hardhat").
|
|
12
|
+
* Ensures that the directory exists before returning the path.
|
|
13
|
+
*
|
|
14
|
+
* @param packageName The name of the package for which to generate paths. Defaults to "hardhat" if no package name is provided.
|
|
15
|
+
* @returns The path to the hardhat cache directory.
|
|
16
|
+
* @throws FileSystemAccessError for any error.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getCacheDir(packageName?: string): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the telemetry directory path for a given package (defaults to "hardhat").
|
|
21
|
+
* Ensures that the directory exists before returning the path.
|
|
22
|
+
*
|
|
23
|
+
* @param packageName The name of the package for which to generate paths. Defaults to "hardhat" if no package name is provided.
|
|
24
|
+
* @returns A promise that resolves to the path of the telemetry directory.
|
|
25
|
+
* @throws FileSystemAccessError for any error.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getTelemetryDir(packageName?: string): Promise<string>;
|
|
28
|
+
//# sourceMappingURL=global-dir.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-dir.d.ts","sourceRoot":"","sources":["../../src/global-dir.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,WAAW,GAAE,MAA6B,GACzC,OAAO,CAAC,MAAM,CAAC,CAIjB;AAED;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,WAAW,GAAE,MAA6B,GACzC,OAAO,CAAC,MAAM,CAAC,CAIjB;AAED;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,WAAW,GAAE,MAA6B,GACzC,OAAO,CAAC,MAAM,CAAC,CAIjB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { generatePaths, HARDHAT_PACKAGE_NAME } from "./internal/global-dir.js";
|
|
2
|
+
import { ensureDir } from "@nomicfoundation/hardhat-utils/fs";
|
|
3
|
+
/**
|
|
4
|
+
* Returns the configuration directory path for a given package (defaults to "hardhat").
|
|
5
|
+
* Ensures that the directory exists before returning the path.
|
|
6
|
+
*
|
|
7
|
+
* @param packageName The name of the package for which to generate paths. Defaults to "hardhat" if no package name is provided.
|
|
8
|
+
* @returns The path to the hardhat configuration directory.
|
|
9
|
+
* @throws FileSystemAccessError for any error.
|
|
10
|
+
*/
|
|
11
|
+
export async function getConfigDir(packageName = HARDHAT_PACKAGE_NAME) {
|
|
12
|
+
const { config } = await generatePaths(packageName);
|
|
13
|
+
await ensureDir(config);
|
|
14
|
+
return config;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns the cache directory path for a given package (defaults to "hardhat").
|
|
18
|
+
* Ensures that the directory exists before returning the path.
|
|
19
|
+
*
|
|
20
|
+
* @param packageName The name of the package for which to generate paths. Defaults to "hardhat" if no package name is provided.
|
|
21
|
+
* @returns The path to the hardhat cache directory.
|
|
22
|
+
* @throws FileSystemAccessError for any error.
|
|
23
|
+
*/
|
|
24
|
+
export async function getCacheDir(packageName = HARDHAT_PACKAGE_NAME) {
|
|
25
|
+
const { cache } = await generatePaths(packageName);
|
|
26
|
+
await ensureDir(cache);
|
|
27
|
+
return cache;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Returns the telemetry directory path for a given package (defaults to "hardhat").
|
|
31
|
+
* Ensures that the directory exists before returning the path.
|
|
32
|
+
*
|
|
33
|
+
* @param packageName The name of the package for which to generate paths. Defaults to "hardhat" if no package name is provided.
|
|
34
|
+
* @returns A promise that resolves to the path of the telemetry directory.
|
|
35
|
+
* @throws FileSystemAccessError for any error.
|
|
36
|
+
*/
|
|
37
|
+
export async function getTelemetryDir(packageName = HARDHAT_PACKAGE_NAME) {
|
|
38
|
+
const { data } = await generatePaths(packageName);
|
|
39
|
+
await ensureDir(data);
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=global-dir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-dir.js","sourceRoot":"","sources":["../../src/global-dir.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAE/E,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAE9D;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,cAAsB,oBAAoB;IAE1C,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,aAAa,CAAC,WAAW,CAAC,CAAC;IACpD,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC;IACxB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,cAAsB,oBAAoB;IAE1C,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,aAAa,CAAC,WAAW,CAAC,CAAC;IACnD,MAAM,SAAS,CAAC,KAAK,CAAC,CAAC;IACvB,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,cAAsB,oBAAoB;IAE1C,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,aAAa,CAAC,WAAW,CAAC,CAAC;IAClD,MAAM,SAAS,CAAC,IAAI,CAAC,CAAC;IACtB,OAAO,IAAI,CAAC;AACd,CAAC"}
|