@nomicfoundation/hardhat-utils 3.0.0-next.9 → 3.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.
- package/CHANGELOG.md +7 -5
- package/README.md +3 -3
- package/dist/src/ci.d.ts +4 -0
- package/dist/src/ci.d.ts.map +1 -1
- package/dist/src/ci.js +4 -0
- package/dist/src/ci.js.map +1 -1
- package/dist/src/crypto.d.ts +7 -0
- package/dist/src/crypto.d.ts.map +1 -1
- package/dist/src/crypto.js +10 -0
- package/dist/src/crypto.js.map +1 -1
- package/dist/src/debug.d.ts.map +1 -1
- package/dist/src/env.d.ts +19 -0
- package/dist/src/env.d.ts.map +1 -0
- package/dist/src/env.js +29 -0
- package/dist/src/env.js.map +1 -0
- package/dist/src/error.d.ts +2 -2
- package/dist/src/error.js +2 -2
- package/dist/src/fs.d.ts +7 -3
- package/dist/src/fs.d.ts.map +1 -1
- package/dist/src/fs.js +28 -5
- package/dist/src/fs.js.map +1 -1
- package/dist/src/internal/bytecode.d.ts +1 -1
- package/dist/src/internal/bytecode.d.ts.map +1 -1
- package/dist/src/lang.d.ts +7 -0
- package/dist/src/lang.d.ts.map +1 -1
- package/dist/src/lang.js +30 -0
- package/dist/src/lang.js.map +1 -1
- package/dist/src/package.d.ts +12 -0
- package/dist/src/package.d.ts.map +1 -1
- package/dist/src/package.js.map +1 -1
- package/dist/src/panic-errors.d.ts +2 -0
- package/dist/src/panic-errors.d.ts.map +1 -0
- package/dist/src/panic-errors.js +32 -0
- package/dist/src/panic-errors.js.map +1 -0
- package/dist/src/path.d.ts +2 -2
- package/dist/src/path.d.ts.map +1 -1
- package/dist/src/path.js +12 -3
- package/dist/src/path.js.map +1 -1
- package/dist/src/request.d.ts +26 -6
- package/dist/src/request.d.ts.map +1 -1
- package/dist/src/request.js +37 -4
- package/dist/src/request.js.map +1 -1
- package/dist/src/stream.d.ts +1 -1
- package/dist/src/stream.js +1 -1
- package/dist/src/subprocess.js +1 -1
- package/dist/src/subprocess.js.map +1 -1
- package/dist/src/synchronization.d.ts +17 -0
- package/dist/src/synchronization.d.ts.map +1 -1
- package/dist/src/synchronization.js +77 -1
- package/dist/src/synchronization.js.map +1 -1
- package/package.json +6 -4
- package/src/ci.ts +5 -0
- package/src/crypto.ts +11 -0
- package/src/env.ts +33 -0
- package/src/error.ts +2 -2
- package/src/fs.ts +43 -8
- package/src/internal/bytecode.ts +1 -1
- package/src/lang.ts +36 -0
- package/src/package.ts +26 -0
- package/src/panic-errors.ts +35 -0
- package/src/path.ts +16 -6
- package/src/request.ts +55 -8
- package/src/stream.ts +1 -1
- package/src/subprocess.ts +1 -1
- package/src/synchronization.ts +90 -1
package/dist/src/path.js
CHANGED
|
@@ -19,7 +19,7 @@ export function resolveFromRoot(root, target) {
|
|
|
19
19
|
* Tries to return a shorter version of the path if its inside the given folder.
|
|
20
20
|
*
|
|
21
21
|
* This is useful for displaying paths in the terminal, as they can be shorter
|
|
22
|
-
* when they are
|
|
22
|
+
* when they are inside the current working directory. For example, if the
|
|
23
23
|
* current working directory is `/home/user/project`, and the path is
|
|
24
24
|
* `/home/user/project/contracts/File.sol`, the shorter path is
|
|
25
25
|
* `contracts/File.sol`.
|
|
@@ -28,8 +28,17 @@ export function resolveFromRoot(root, target) {
|
|
|
28
28
|
* @param folder The absolute path to the folder.
|
|
29
29
|
* @returns The shorter path, if possible, or the original path.
|
|
30
30
|
*/
|
|
31
|
-
export function shortenPath(absolutePath
|
|
32
|
-
const
|
|
31
|
+
export function shortenPath(absolutePath) {
|
|
32
|
+
const cwd = process.cwd();
|
|
33
|
+
let relativePath = path.relative(cwd, absolutePath);
|
|
34
|
+
if (relativePath === "..") {
|
|
35
|
+
return ".." + path.sep;
|
|
36
|
+
}
|
|
37
|
+
if (!relativePath.startsWith(".." + path.sep) &&
|
|
38
|
+
!relativePath.startsWith("." + path.sep) &&
|
|
39
|
+
!path.isAbsolute(relativePath)) {
|
|
40
|
+
relativePath = "." + path.sep + relativePath;
|
|
41
|
+
}
|
|
33
42
|
if (relativePath.length < absolutePath.length) {
|
|
34
43
|
return relativePath;
|
|
35
44
|
}
|
package/dist/src/path.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.js","sourceRoot":"","sources":["../../src/path.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,MAAc;IAC1D,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,
|
|
1
|
+
{"version":3,"file":"path.js","sourceRoot":"","sources":["../../src/path.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,MAAc;IAC1D,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,YAAoB;IAC9C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1B,IAAI,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IAEpD,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;QAC1B,OAAO,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC;IACzB,CAAC;IAED,IACE,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC;QACzC,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACxC,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAC9B,CAAC;QACD,YAAY,GAAG,GAAG,GAAG,IAAI,CAAC,GAAG,GAAG,YAAY,CAAC;IAC/C,CAAC;IAED,IAAI,YAAY,CAAC,MAAM,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC;QAC9C,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
package/dist/src/request.d.ts
CHANGED
|
@@ -35,18 +35,26 @@ export interface RequestOptions {
|
|
|
35
35
|
extraHeaders?: Record<string, string>;
|
|
36
36
|
abortSignal?: AbortSignal | EventEmitter;
|
|
37
37
|
}
|
|
38
|
+
export interface HttpResponse {
|
|
39
|
+
statusCode: number;
|
|
40
|
+
body: {
|
|
41
|
+
json(): Promise<any>;
|
|
42
|
+
text(): Promise<string>;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
38
45
|
/**
|
|
39
46
|
* Performs a HTTP request.
|
|
40
47
|
*
|
|
41
48
|
* @param url The url to make the request to.
|
|
42
49
|
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
43
50
|
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
44
|
-
* @returns
|
|
51
|
+
* @returns An object containing the status code and the response body. The body can be accessed as JSON or text.
|
|
52
|
+
* `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`.
|
|
45
53
|
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
46
54
|
* @throws RequestTimeoutError If the request times out.
|
|
47
55
|
* @throws RequestError If the request fails for any other reason.
|
|
48
56
|
*/
|
|
49
|
-
export declare function getRequest(url: string, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise<
|
|
57
|
+
export declare function getRequest(url: string, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise<HttpResponse>;
|
|
50
58
|
/**
|
|
51
59
|
* Performs a POST request with a JSON body.
|
|
52
60
|
*
|
|
@@ -54,12 +62,13 @@ export declare function getRequest(url: string, requestOptions?: RequestOptions,
|
|
|
54
62
|
* @param body The body of the request, represented as an object.
|
|
55
63
|
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
56
64
|
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
57
|
-
* @returns
|
|
65
|
+
* @returns An object containing the status code and the response body. The body can be accessed as JSON or text.
|
|
66
|
+
* `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`.
|
|
58
67
|
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
59
68
|
* @throws RequestTimeoutError If the request times out.
|
|
60
69
|
* @throws RequestError If the request fails for any other reason.
|
|
61
70
|
*/
|
|
62
|
-
export declare function postJsonRequest(url: string, body: unknown, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise<
|
|
71
|
+
export declare function postJsonRequest(url: string, body: unknown, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise<HttpResponse>;
|
|
63
72
|
/**
|
|
64
73
|
* Performs a POST request with a form body.
|
|
65
74
|
*
|
|
@@ -67,12 +76,13 @@ export declare function postJsonRequest(url: string, body: unknown, requestOptio
|
|
|
67
76
|
* @param body The body of the request, represented as an object.
|
|
68
77
|
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
69
78
|
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
70
|
-
* @returns
|
|
79
|
+
* @returns An object containing the status code and the response body. The body can be accessed as JSON or text.
|
|
80
|
+
* `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`.
|
|
71
81
|
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
72
82
|
* @throws RequestTimeoutError If the request times out.
|
|
73
83
|
* @throws RequestError If the request fails for any other reason.
|
|
74
84
|
*/
|
|
75
|
-
export declare function postFormRequest(url: string, body: unknown, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise<
|
|
85
|
+
export declare function postFormRequest(url: string, body: unknown, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise<HttpResponse>;
|
|
76
86
|
/**
|
|
77
87
|
* Downloads a file from a url to a destination path.
|
|
78
88
|
*
|
|
@@ -114,5 +124,15 @@ export declare function shouldUseProxy(url: string): boolean;
|
|
|
114
124
|
* @returns `true` if the url is valid, `false` otherwise.
|
|
115
125
|
*/
|
|
116
126
|
export declare function isValidUrl(url: string): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Returns the proxy URL from environment variables based on the target URL.
|
|
129
|
+
* For HTTPS URLs, checks `https_proxy` then `HTTPS_PROXY`.
|
|
130
|
+
* For HTTP URLs, checks `http_proxy` then `HTTP_PROXY`.
|
|
131
|
+
* Falls back to the other protocol's proxy if none found.
|
|
132
|
+
*
|
|
133
|
+
* @param url The target URL to determine proxy for.
|
|
134
|
+
* @returns The proxy URL, or `undefined` if none are set.
|
|
135
|
+
*/
|
|
136
|
+
export declare function getProxyUrl(url: string): string | undefined;
|
|
117
137
|
export { ConnectionRefusedError, DispatcherError, DownloadError, RequestError, RequestTimeoutError, ResponseStatusCodeError, } from "./errors/request.js";
|
|
118
138
|
//# sourceMappingURL=request.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,aAAa,CAAC;AAE5C,OAAO,KAAK,OAAO,MAAM,QAAQ,CAAC;AAuBlC,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UAAU,GAAG,iBAAiB,GACrE,OAAO,CAAC,YAAY,CAAC,CA0BvB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,QAAQ,CAC5B,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM,EACnB,cAAc,GAAE,cAAmB,EACnC,6BAA6B,CAAC,EAAE,OAAO,CAAC,UAAU,GAAG,iBAAiB,GACrE,OAAO,CAAC,IAAI,CAAC,CAgCf;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,MAAM,EACX,EACE,OAAO,EACP,KAAK,EACL,IAAI,EACJ,cAAc,EACd,gBAAgB,GACjB,GAAE,iBAAsB,GACxB,OAAO,CAAC,UAAU,CAAC,CAyBrB;AAED,wBAAsB,iBAAiB,CACrC,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,MAAM,CAAC;CACb,GACL,OAAO,CAAC,cAAc,CAAC,CAKzB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAiBnD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAO/C;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAoB3D;AAED,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC"}
|
package/dist/src/request.js
CHANGED
|
@@ -15,7 +15,8 @@ export const DEFAULT_USER_AGENT = "Hardhat";
|
|
|
15
15
|
* @param url The url to make the request to.
|
|
16
16
|
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
17
17
|
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
18
|
-
* @returns
|
|
18
|
+
* @returns An object containing the status code and the response body. The body can be accessed as JSON or text.
|
|
19
|
+
* `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`.
|
|
19
20
|
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
20
21
|
* @throws RequestTimeoutError If the request times out.
|
|
21
22
|
* @throws RequestError If the request fails for any other reason.
|
|
@@ -42,7 +43,8 @@ export async function getRequest(url, requestOptions = {}, dispatcherOrDispatche
|
|
|
42
43
|
* @param body The body of the request, represented as an object.
|
|
43
44
|
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
44
45
|
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
45
|
-
* @returns
|
|
46
|
+
* @returns An object containing the status code and the response body. The body can be accessed as JSON or text.
|
|
47
|
+
* `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`.
|
|
46
48
|
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
47
49
|
* @throws RequestTimeoutError If the request times out.
|
|
48
50
|
* @throws RequestError If the request fails for any other reason.
|
|
@@ -74,7 +76,8 @@ export async function postJsonRequest(url, body, requestOptions = {}, dispatcher
|
|
|
74
76
|
* @param body The body of the request, represented as an object.
|
|
75
77
|
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
76
78
|
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
77
|
-
* @returns
|
|
79
|
+
* @returns An object containing the status code and the response body. The body can be accessed as JSON or text.
|
|
80
|
+
* `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`.
|
|
78
81
|
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
79
82
|
* @throws RequestTimeoutError If the request times out.
|
|
80
83
|
* @throws RequestError If the request fails for any other reason.
|
|
@@ -114,7 +117,12 @@ export async function postFormRequest(url, body, requestOptions = {}, dispatcher
|
|
|
114
117
|
export async function download(url, destination, requestOptions = {}, dispatcherOrDispatcherOptions) {
|
|
115
118
|
let statusCode;
|
|
116
119
|
try {
|
|
117
|
-
|
|
120
|
+
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
121
|
+
-- We need the full Dispatcher.ResponseData here for stream.pipeline,
|
|
122
|
+
but HttpResponse doesn’t expose the raw ReadableStream.
|
|
123
|
+
TODO: wrap undici's request so we can keep the public API
|
|
124
|
+
strictly typed without falling back to Undici types. */
|
|
125
|
+
const response = (await getRequest(url, requestOptions, dispatcherOrDispatcherOptions));
|
|
118
126
|
const { body } = response;
|
|
119
127
|
statusCode = response.statusCode;
|
|
120
128
|
if (statusCode < 200 || statusCode >= 300) {
|
|
@@ -204,5 +212,30 @@ export function isValidUrl(url) {
|
|
|
204
212
|
return false;
|
|
205
213
|
}
|
|
206
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Returns the proxy URL from environment variables based on the target URL.
|
|
217
|
+
* For HTTPS URLs, checks `https_proxy` then `HTTPS_PROXY`.
|
|
218
|
+
* For HTTP URLs, checks `http_proxy` then `HTTP_PROXY`.
|
|
219
|
+
* Falls back to the other protocol's proxy if none found.
|
|
220
|
+
*
|
|
221
|
+
* @param url The target URL to determine proxy for.
|
|
222
|
+
* @returns The proxy URL, or `undefined` if none are set.
|
|
223
|
+
*/
|
|
224
|
+
export function getProxyUrl(url) {
|
|
225
|
+
const { protocol } = new URL(url);
|
|
226
|
+
if (protocol === "https:") {
|
|
227
|
+
return (process.env.https_proxy ??
|
|
228
|
+
process.env.HTTPS_PROXY ??
|
|
229
|
+
process.env.http_proxy ??
|
|
230
|
+
process.env.HTTP_PROXY);
|
|
231
|
+
}
|
|
232
|
+
else if (protocol === "http:") {
|
|
233
|
+
return (process.env.http_proxy ??
|
|
234
|
+
process.env.HTTP_PROXY ??
|
|
235
|
+
process.env.https_proxy ??
|
|
236
|
+
process.env.HTTPS_PROXY);
|
|
237
|
+
}
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
207
240
|
export { ConnectionRefusedError, DispatcherError, DownloadError, RequestError, RequestTimeoutError, ResponseStatusCodeError, } from "./errors/request.js";
|
|
208
241
|
//# sourceMappingURL=request.js.map
|
package/dist/src/request.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,aAAa,EACb,YAAY,EACZ,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,GACZ,MAAM,uBAAuB,CAAC;AAE/B,MAAM,CAAC,MAAM,+BAA+B,GAAG,OAAO,CAAC,CAAC,uBAAuB;AAC/E,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACxC,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,CAAC;AAChD,MAAM,CAAC,MAAM,kBAAkB,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,aAAa,EACb,YAAY,EACZ,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,EA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GED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Writable } from "node:stream";
|
|
2
2
|
/**
|
|
3
|
-
* Creates a
|
|
3
|
+
* Creates a Transform that writes everything to actualWritable, without closing it
|
|
4
4
|
* when finished.
|
|
5
5
|
*
|
|
6
6
|
* This is useful to pipe things to stdout, without closing it, while being
|
package/dist/src/stream.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Writable } from "node:stream";
|
|
2
2
|
/**
|
|
3
|
-
* Creates a
|
|
3
|
+
* Creates a Transform that writes everything to actualWritable, without closing it
|
|
4
4
|
* when finished.
|
|
5
5
|
*
|
|
6
6
|
* This is useful to pipe things to stdout, without closing it, while being
|
package/dist/src/subprocess.js
CHANGED
|
@@ -21,7 +21,7 @@ export async function spawnDetachedSubProcess(absolutePathToSubProcessFile, args
|
|
|
21
21
|
}
|
|
22
22
|
const subprocessArgs = [absolutePathToSubProcessFile, ...args];
|
|
23
23
|
if (absolutePathToSubProcessFile.endsWith(".ts")) {
|
|
24
|
-
subprocessArgs.unshift("--import", "tsx/esm");
|
|
24
|
+
subprocessArgs.unshift("--import", import.meta.resolve("tsx/esm"));
|
|
25
25
|
}
|
|
26
26
|
const subprocess = spawn(process.execPath, subprocessArgs, {
|
|
27
27
|
detached: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subprocess.js","sourceRoot":"","sources":["../../src/subprocess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EACL,2BAA2B,EAC3B,8BAA8B,GAC/B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE9C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,4BAAoC,EACpC,OAAiB,EAAE,EACnB,MAA8B,EAAE;IAEhC,IAAI,CAAC,MAAM,MAAM,CAAC,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AAC,EAAE,CAAC;QACjD,cAAc,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IACrE,CAAC;IAED,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,cAAc,EAAE;QACzD,QAAQ,EAAE,IAAI;QACd,GAAG;QACH,KAAK,EAAE,QAAQ;KAChB,CAAC,CAAC;IAEH,UAAU,CAAC,KAAK,EAAE,CAAC;AACrB,CAAC"}
|
|
@@ -3,4 +3,21 @@ export declare class MultiProcessMutex {
|
|
|
3
3
|
constructor(mutexName: string, maxMutexLifespanInMs?: number);
|
|
4
4
|
use<T>(f: () => Promise<T>): Promise<T>;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* A class that implements an asynchronous mutex (mutual exclusion) lock.
|
|
8
|
+
*
|
|
9
|
+
* The mutex ensures that only one asynchronous operation can be executed at a time,
|
|
10
|
+
* providing exclusive access to a shared resource.
|
|
11
|
+
*/
|
|
12
|
+
export declare class AsyncMutex {
|
|
13
|
+
#private;
|
|
14
|
+
/**
|
|
15
|
+
* Acquires the mutex, running the provided function exclusively,
|
|
16
|
+
* and releasing it afterwards.
|
|
17
|
+
*
|
|
18
|
+
* @param f The function to run.
|
|
19
|
+
* @returns The result of the function.
|
|
20
|
+
*/
|
|
21
|
+
exclusiveRun<ReturnT>(f: () => ReturnT): Promise<Awaited<ReturnT>>;
|
|
22
|
+
}
|
|
6
23
|
//# sourceMappingURL=synchronization.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synchronization.d.ts","sourceRoot":"","sources":["../../src/synchronization.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"synchronization.d.ts","sourceRoot":"","sources":["../../src/synchronization.ts"],"names":[],"mappings":"AAwBA,qBAAa,iBAAiB;;gBAIhB,SAAS,EAAE,MAAM,EAAE,oBAAoB,CAAC,EAAE,MAAM;IAQ/C,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CA8HrD;AAED;;;;;GAKG;AACH,qBAAa,UAAU;;IAIrB;;;;;;OAMG;IACU,YAAY,CAAC,OAAO,EAC/B,CAAC,EAAE,MAAM,OAAO,GACf,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;CA+B7B"}
|
|
@@ -12,6 +12,7 @@ import path from "node:path";
|
|
|
12
12
|
import debug from "debug";
|
|
13
13
|
import { ensureNodeErrnoExceptionError } from "./error.js";
|
|
14
14
|
import { FileSystemAccessError } from "./errors/fs.js";
|
|
15
|
+
import { readUtf8File } from "./fs.js";
|
|
15
16
|
import { sleep } from "./lang.js";
|
|
16
17
|
const log = debug("hardhat:util:multi-process-mutex");
|
|
17
18
|
const DEFAULT_MAX_MUTEX_LIFESPAN_IN_MS = 60000;
|
|
@@ -38,6 +39,10 @@ export class MultiProcessMutex {
|
|
|
38
39
|
log(`Current mutex file is too old, removing it at path '${this.#mutexFilePath}'`);
|
|
39
40
|
this.#deleteMutexFile();
|
|
40
41
|
}
|
|
42
|
+
else if (await this.#isMutexProcessOwnerDead()) {
|
|
43
|
+
log(`The process owning the mutex file no longer exists. Removing mutex file at '${this.#mutexFilePath}'.`);
|
|
44
|
+
this.#deleteMutexFile();
|
|
45
|
+
}
|
|
41
46
|
else {
|
|
42
47
|
// wait
|
|
43
48
|
await sleep(MUTEX_LOOP_WAITING_TIME_IN_MS / 1000);
|
|
@@ -47,7 +52,9 @@ export class MultiProcessMutex {
|
|
|
47
52
|
async #tryToAcquireMutex() {
|
|
48
53
|
try {
|
|
49
54
|
// Create a file only if it does not exist
|
|
50
|
-
fs.writeFileSync(this.#mutexFilePath,
|
|
55
|
+
fs.writeFileSync(this.#mutexFilePath, process.pid.toString(), {
|
|
56
|
+
flag: "wx+",
|
|
57
|
+
});
|
|
51
58
|
return true;
|
|
52
59
|
}
|
|
53
60
|
catch (e) {
|
|
@@ -66,6 +73,8 @@ export class MultiProcessMutex {
|
|
|
66
73
|
}
|
|
67
74
|
finally {
|
|
68
75
|
// Release the mutex
|
|
76
|
+
// Note: if a process dies, its `finally` block never executes, and the process hangs indefinitely since no response is received.
|
|
77
|
+
// To handle this, we use the function `isMutexProcessOwnerDead`.
|
|
69
78
|
log(`Mutex released at path '${this.#mutexFilePath}'`);
|
|
70
79
|
this.#deleteMutexFile();
|
|
71
80
|
log(`Mutex released at path '${this.#mutexFilePath}'`);
|
|
@@ -103,5 +112,72 @@ export class MultiProcessMutex {
|
|
|
103
112
|
throw new FileSystemAccessError(e.message, e);
|
|
104
113
|
}
|
|
105
114
|
}
|
|
115
|
+
async #isMutexProcessOwnerDead() {
|
|
116
|
+
let mutexPid;
|
|
117
|
+
try {
|
|
118
|
+
// If the file doesn't exist, it means the owning process deleted it
|
|
119
|
+
mutexPid = await readUtf8File(this.#mutexFilePath);
|
|
120
|
+
}
|
|
121
|
+
catch (_e) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
process.kill(parseInt(mutexPid, 10), 0);
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
ensureNodeErrnoExceptionError(e);
|
|
129
|
+
if (e.code === "ESRCH") {
|
|
130
|
+
// The process owning the mutex no longer exists
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* A class that implements an asynchronous mutex (mutual exclusion) lock.
|
|
139
|
+
*
|
|
140
|
+
* The mutex ensures that only one asynchronous operation can be executed at a time,
|
|
141
|
+
* providing exclusive access to a shared resource.
|
|
142
|
+
*/
|
|
143
|
+
export class AsyncMutex {
|
|
144
|
+
#acquired = false;
|
|
145
|
+
#queue = [];
|
|
146
|
+
/**
|
|
147
|
+
* Acquires the mutex, running the provided function exclusively,
|
|
148
|
+
* and releasing it afterwards.
|
|
149
|
+
*
|
|
150
|
+
* @param f The function to run.
|
|
151
|
+
* @returns The result of the function.
|
|
152
|
+
*/
|
|
153
|
+
async exclusiveRun(f) {
|
|
154
|
+
const release = await this.#acquire();
|
|
155
|
+
try {
|
|
156
|
+
return await f();
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
await release();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Acquires the mutex, returning a function that releases it.
|
|
164
|
+
*/
|
|
165
|
+
async #acquire() {
|
|
166
|
+
if (!this.#acquired) {
|
|
167
|
+
this.#acquired = true;
|
|
168
|
+
return async () => {
|
|
169
|
+
this.#acquired = false;
|
|
170
|
+
const next = this.#queue.shift();
|
|
171
|
+
if (next !== undefined) {
|
|
172
|
+
next();
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
return new Promise((resolve) => {
|
|
177
|
+
this.#queue.push(() => {
|
|
178
|
+
resolve(this.#acquire());
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
}
|
|
106
182
|
}
|
|
107
183
|
//# sourceMappingURL=synchronization.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synchronization.js","sourceRoot":"","sources":["../../src/synchronization.ts"],"names":[],"mappings":"AAAA,4HAA4H;AAC5H,2FAA2F;AAC3F,mDAAmD;AACnD,0GAA0G;AAC1G,oFAAoF;AACpF,yGAAyG;AACzG,oJAAoJ;AACpJ,6GAA6G;AAE7G,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,KAAK,E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AQ,EAAE,CAAC,CAAC;YAC3B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nomicfoundation/hardhat-utils",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Utilities for Hardhat and its plugins",
|
|
5
5
|
"homepage": "https://github.com/nomicfoundation/hardhat/tree/v-next/v-next/hardhat-utils",
|
|
6
6
|
"repository": {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"./crypto": "./dist/src/crypto.js",
|
|
21
21
|
"./date": "./dist/src/date.js",
|
|
22
22
|
"./debug": "./dist/src/debug.js",
|
|
23
|
+
"./env": "./dist/src/env.js",
|
|
23
24
|
"./error": "./dist/src/error.js",
|
|
24
25
|
"./eth": "./dist/src/eth.js",
|
|
25
26
|
"./fs": "./dist/src/fs.js",
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
"./lang": "./dist/src/lang.js",
|
|
29
30
|
"./number": "./dist/src/number.js",
|
|
30
31
|
"./package": "./dist/src/package.js",
|
|
32
|
+
"./panic-errors": "./dist/src/panic-errors.js",
|
|
31
33
|
"./path": "./dist/src/path.js",
|
|
32
34
|
"./request": "./dist/src/request.js",
|
|
33
35
|
"./string": "./dist/src/string.js",
|
|
@@ -48,17 +50,17 @@
|
|
|
48
50
|
"README.md"
|
|
49
51
|
],
|
|
50
52
|
"devDependencies": {
|
|
51
|
-
"@nomicfoundation/hardhat-node-test-reporter": "^3.0.0
|
|
53
|
+
"@nomicfoundation/hardhat-node-test-reporter": "^3.0.0",
|
|
52
54
|
"@types/bn.js": "^5.1.5",
|
|
53
55
|
"@types/debug": "^4.1.7",
|
|
54
56
|
"@types/node": "^20.14.9",
|
|
55
57
|
"c8": "^9.1.0",
|
|
56
58
|
"eslint": "9.25.1",
|
|
57
|
-
"expect-type": "^
|
|
59
|
+
"expect-type": "^1.2.1",
|
|
58
60
|
"prettier": "3.2.5",
|
|
59
61
|
"rimraf": "^5.0.5",
|
|
60
62
|
"tsx": "^4.19.3",
|
|
61
|
-
"typescript": "~5.
|
|
63
|
+
"typescript": "~5.8.0"
|
|
62
64
|
},
|
|
63
65
|
"dependencies": {
|
|
64
66
|
"@streamparser/json-node": "^0.0.22",
|
package/src/ci.ts
CHANGED
package/src/crypto.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { keccak256 as keccak256Impl } from "ethereum-cryptography/keccak";
|
|
2
|
+
import { sha256 as sha256Impl } from "ethereum-cryptography/sha256";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Computes the Keccak-256 hash of the input bytes.
|
|
@@ -10,6 +11,16 @@ export async function keccak256(bytes: Uint8Array): Promise<Uint8Array> {
|
|
|
10
11
|
return keccak256Impl(bytes);
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Computes the SHA-256 hash of the input bytes.
|
|
16
|
+
*
|
|
17
|
+
* @param bytes The input bytes to hash.
|
|
18
|
+
* @returns The SHA-256 hash of the input bytes.
|
|
19
|
+
*/
|
|
20
|
+
export async function sha256(bytes: Uint8Array): Promise<Uint8Array> {
|
|
21
|
+
return sha256Impl(bytes);
|
|
22
|
+
}
|
|
23
|
+
|
|
13
24
|
/**
|
|
14
25
|
* Creates a non-cryptographic hash-based identifier for the given input.
|
|
15
26
|
*
|
package/src/env.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { camelToSnakeCase } from "./string.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sets the resolved global options as environment variables.
|
|
5
|
+
*
|
|
6
|
+
* @param globalOptions An object containing the resolved global options,
|
|
7
|
+
* with each option adhering to its definition in the globalOptionDefinitions.
|
|
8
|
+
*/
|
|
9
|
+
export function setGlobalOptionsAsEnvVariables<
|
|
10
|
+
T extends Record<keyof T, string | boolean>,
|
|
11
|
+
>(globalOptions: T): void {
|
|
12
|
+
for (const [name, value] of Object.entries(globalOptions)) {
|
|
13
|
+
const envName = getEnvVariableNameFromGlobalOption(name);
|
|
14
|
+
|
|
15
|
+
if (value !== undefined) {
|
|
16
|
+
process.env[envName] = String(value);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Converts a global option name to its corresponding environment variable name.
|
|
23
|
+
* The conversion involves transforming the option name from camelCase to
|
|
24
|
+
* SNAKE_CASE and prefixing it with "HARDHAT_".
|
|
25
|
+
*
|
|
26
|
+
* @param globalOptionName The name of the global option in camelCase.
|
|
27
|
+
*
|
|
28
|
+
* @returns The corresponding environment variable name in the format
|
|
29
|
+
* "HARDHAT_<OPTION_NAME_IN_SNAKE_CASE>".
|
|
30
|
+
*/
|
|
31
|
+
export function getEnvVariableNameFromGlobalOption(globalOptionName: string) {
|
|
32
|
+
return `HARDHAT_${camelToSnakeCase(globalOptionName).toUpperCase()}`;
|
|
33
|
+
}
|
package/src/error.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Abstract custom error class, which inherits from the built-in Error class,
|
|
3
|
-
* making sure that the standard
|
|
3
|
+
* making sure that the standard error properties are set, and the stack trace
|
|
4
4
|
* is not polluted with the custom error class' code.
|
|
5
5
|
*
|
|
6
6
|
* This class supports the `cause` property, which can be used to pass the
|
|
7
7
|
* original error that caused the custom error to be thrown. Note that it needs
|
|
8
8
|
* to be an instance of the built-in Error class, or a subclass of it. See `ensureError`
|
|
9
|
-
* for a
|
|
9
|
+
* for a convenient way of using it.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```ts
|