@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
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type EventEmitter from "node:events";
|
|
2
|
+
import type UndiciT from "undici";
|
|
3
|
+
export declare const DEFAULT_TIMEOUT_IN_MILLISECONDS = 30000;
|
|
4
|
+
export declare const DEFAULT_MAX_REDIRECTS = 10;
|
|
5
|
+
export declare const DEFAULT_POOL_MAX_CONNECTIONS = 128;
|
|
6
|
+
export declare const DEFAULT_USER_AGENT = "Hardhat";
|
|
7
|
+
export type Dispatcher = UndiciT.Dispatcher;
|
|
8
|
+
export type TestDispatcher = UndiciT.MockAgent;
|
|
9
|
+
export type Interceptable = UndiciT.Interceptable;
|
|
10
|
+
/**
|
|
11
|
+
* Options to configure the dispatcher.
|
|
12
|
+
*
|
|
13
|
+
* @param timeout The timeout in milliseconds. Defaults to {@link DEFAULT_TIMEOUT_IN_MILLISECONDS}.
|
|
14
|
+
* @param proxy The proxy to use. If not provided, no proxy is used.
|
|
15
|
+
* @param pool Whether to use a pool dispatcher. Defaults to `false`.
|
|
16
|
+
* @param maxConnections The maximum number of connections to use in the pool. Defaults to {@link DEFAULT_POOL_MAX_CONNECTIONS}.
|
|
17
|
+
* @param isTestDispatcher Whether to use a test dispatcher. Defaults to `false`. It's highly recommended to use a test dispatcher in tests to avoid hanging tests.
|
|
18
|
+
*/
|
|
19
|
+
export interface DispatcherOptions {
|
|
20
|
+
timeout?: number;
|
|
21
|
+
proxy?: string;
|
|
22
|
+
pool?: boolean;
|
|
23
|
+
maxConnections?: number;
|
|
24
|
+
isTestDispatcher?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Options to configure a request.
|
|
28
|
+
*
|
|
29
|
+
* @param queryParams The query parameters to append to the url.
|
|
30
|
+
* @param extraHeaders Additional headers to include in the request.
|
|
31
|
+
* @param abortSignal The signal to abort the request.
|
|
32
|
+
*/
|
|
33
|
+
export interface RequestOptions {
|
|
34
|
+
queryParams?: Record<string, any>;
|
|
35
|
+
extraHeaders?: Record<string, string>;
|
|
36
|
+
abortSignal?: AbortSignal | EventEmitter;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Performs a HTTP request.
|
|
40
|
+
*
|
|
41
|
+
* @param url The url to make the request to.
|
|
42
|
+
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
43
|
+
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
44
|
+
* @returns The response data object. See {@link https://undici.nodejs.org/#/docs/api/Dispatcher?id=parameter-responsedata}.
|
|
45
|
+
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
46
|
+
* @throws RequestTimeoutError If the request times out.
|
|
47
|
+
* @throws RequestError If the request fails for any other reason.
|
|
48
|
+
*/
|
|
49
|
+
export declare function getRequest(url: string, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise<UndiciT.Dispatcher.ResponseData>;
|
|
50
|
+
/**
|
|
51
|
+
* Performs a POST request with a JSON body.
|
|
52
|
+
*
|
|
53
|
+
* @param url The url to make the request to.
|
|
54
|
+
* @param body The body of the request, represented as an object.
|
|
55
|
+
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
56
|
+
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
57
|
+
* @returns The response data object. See {@link https://undici.nodejs.org/#/docs/api/Dispatcher?id=parameter-responsedata}.
|
|
58
|
+
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
59
|
+
* @throws RequestTimeoutError If the request times out.
|
|
60
|
+
* @throws RequestError If the request fails for any other reason.
|
|
61
|
+
*/
|
|
62
|
+
export declare function postJsonRequest(url: string, body: unknown, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise<UndiciT.Dispatcher.ResponseData>;
|
|
63
|
+
/**
|
|
64
|
+
* Performs a POST request with a form body.
|
|
65
|
+
*
|
|
66
|
+
* @param url The url to make the request to.
|
|
67
|
+
* @param body The body of the request, represented as an object.
|
|
68
|
+
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
69
|
+
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
70
|
+
* @returns The response data object. See {@link https://undici.nodejs.org/#/docs/api/Dispatcher?id=parameter-responsedata}.
|
|
71
|
+
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
72
|
+
* @throws RequestTimeoutError If the request times out.
|
|
73
|
+
* @throws RequestError If the request fails for any other reason.
|
|
74
|
+
*/
|
|
75
|
+
export declare function postFormRequest(url: string, body: unknown, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise<UndiciT.Dispatcher.ResponseData>;
|
|
76
|
+
/**
|
|
77
|
+
* Downloads a file from a url to a destination path.
|
|
78
|
+
*
|
|
79
|
+
* @param url The url to download from.
|
|
80
|
+
* @param destination The absolute path to save the file to.
|
|
81
|
+
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
82
|
+
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
83
|
+
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
84
|
+
* @throws RequestTimeoutError If the request times out.
|
|
85
|
+
* @throws DownloadFailedError If the download fails for any other reason.
|
|
86
|
+
*/
|
|
87
|
+
export declare function download(url: string, destination: string, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Creates a dispatcher based on the provided options.
|
|
90
|
+
* If the `proxy` option is set, it creates a {@link UndiciT.ProxyAgent} dispatcher.
|
|
91
|
+
* If the `pool` option is set to `true`, it creates a {@link UndiciT.Pool} dispatcher.
|
|
92
|
+
* Otherwise, it creates a basic {@link UndiciT.Agent} dispatcher.
|
|
93
|
+
*
|
|
94
|
+
* @param url The url to make requests to.
|
|
95
|
+
* @param options The options to configure the dispatcher. See {@link DispatcherOptions}.
|
|
96
|
+
* @returns The configured dispatcher instance.
|
|
97
|
+
* @throws DispatcherError If the dispatcher can't be created.
|
|
98
|
+
*/
|
|
99
|
+
export declare function getDispatcher(url: string, { timeout, proxy, pool, maxConnections, isTestDispatcher, }?: DispatcherOptions): Promise<Dispatcher>;
|
|
100
|
+
export declare function getTestDispatcher(options?: {
|
|
101
|
+
timeout?: number;
|
|
102
|
+
}): Promise<TestDispatcher>;
|
|
103
|
+
/**
|
|
104
|
+
* Determines whether a proxy should be used for a given url.
|
|
105
|
+
*
|
|
106
|
+
* @param url The url to check.
|
|
107
|
+
* @returns `true` if a proxy should be used for the url, `false` otherwise.
|
|
108
|
+
*/
|
|
109
|
+
export declare function shouldUseProxy(url: string): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Determines whether an absolute url is valid.
|
|
112
|
+
*
|
|
113
|
+
* @param url The url to check.
|
|
114
|
+
* @returns `true` if the url is valid, `false` otherwise.
|
|
115
|
+
*/
|
|
116
|
+
export declare function isValidUrl(url: string): boolean;
|
|
117
|
+
export { ConnectionRefusedError, DispatcherError, DownloadError, RequestError, RequestTimeoutError, ResponseStatusCodeError, } from "./errors/request.js";
|
|
118
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -0,0 +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,eAAO,MAAM,+BAA+B,QAAS,CAAC;AACtD,eAAO,MAAM,qBAAqB,KAAK,CAAC;AACxC,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAChD,eAAO,MAAM,kBAAkB,YAAY,CAAC;AAE5C,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;AAC5C,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC;AAC/C,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;AAElD;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAA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L,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,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import querystring from "node:querystring";
|
|
3
|
+
import stream from "node:stream/promises";
|
|
4
|
+
import { ensureError } from "./error.js";
|
|
5
|
+
import { DownloadError, RequestError, DispatcherError, } from "./errors/request.js";
|
|
6
|
+
import { move } from "./fs.js";
|
|
7
|
+
import { generateTempFilePath, getBaseDispatcherOptions, getBaseRequestOptions, getBasicDispatcher, getPoolDispatcher, getProxyDispatcher, handleError, } from "./internal/request.js";
|
|
8
|
+
export const DEFAULT_TIMEOUT_IN_MILLISECONDS = 30_000;
|
|
9
|
+
export const DEFAULT_MAX_REDIRECTS = 10;
|
|
10
|
+
export const DEFAULT_POOL_MAX_CONNECTIONS = 128;
|
|
11
|
+
export const DEFAULT_USER_AGENT = "Hardhat";
|
|
12
|
+
/**
|
|
13
|
+
* Performs a HTTP request.
|
|
14
|
+
*
|
|
15
|
+
* @param url The url to make the request to.
|
|
16
|
+
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
17
|
+
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
18
|
+
* @returns The response data object. See {@link https://undici.nodejs.org/#/docs/api/Dispatcher?id=parameter-responsedata}.
|
|
19
|
+
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
20
|
+
* @throws RequestTimeoutError If the request times out.
|
|
21
|
+
* @throws RequestError If the request fails for any other reason.
|
|
22
|
+
*/
|
|
23
|
+
export async function getRequest(url, requestOptions = {}, dispatcherOrDispatcherOptions) {
|
|
24
|
+
const { request } = await import("undici");
|
|
25
|
+
try {
|
|
26
|
+
const baseRequestOptions = await getBaseRequestOptions(url, requestOptions, dispatcherOrDispatcherOptions);
|
|
27
|
+
return await request(url, {
|
|
28
|
+
method: "GET",
|
|
29
|
+
...baseRequestOptions,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
ensureError(e);
|
|
34
|
+
handleError(e, url);
|
|
35
|
+
throw new RequestError(url, "GET", e);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Performs a POST request with a JSON body.
|
|
40
|
+
*
|
|
41
|
+
* @param url The url to make the request to.
|
|
42
|
+
* @param body The body of the request, represented as an object.
|
|
43
|
+
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
44
|
+
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
45
|
+
* @returns The response data object. See {@link https://undici.nodejs.org/#/docs/api/Dispatcher?id=parameter-responsedata}.
|
|
46
|
+
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
47
|
+
* @throws RequestTimeoutError If the request times out.
|
|
48
|
+
* @throws RequestError If the request fails for any other reason.
|
|
49
|
+
*/
|
|
50
|
+
export async function postJsonRequest(url, body, requestOptions = {}, dispatcherOrDispatcherOptions) {
|
|
51
|
+
const { request } = await import("undici");
|
|
52
|
+
try {
|
|
53
|
+
const { headers, ...baseRequestOptions } = await getBaseRequestOptions(url, requestOptions, dispatcherOrDispatcherOptions);
|
|
54
|
+
return await request(url, {
|
|
55
|
+
method: "POST",
|
|
56
|
+
...baseRequestOptions,
|
|
57
|
+
headers: {
|
|
58
|
+
...headers,
|
|
59
|
+
"Content-Type": "application/json",
|
|
60
|
+
},
|
|
61
|
+
body: JSON.stringify(body),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
ensureError(e);
|
|
66
|
+
handleError(e, url);
|
|
67
|
+
throw new RequestError(url, "POST", e);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Performs a POST request with a form body.
|
|
72
|
+
*
|
|
73
|
+
* @param url The url to make the request to.
|
|
74
|
+
* @param body The body of the request, represented as an object.
|
|
75
|
+
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
76
|
+
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
77
|
+
* @returns The response data object. See {@link https://undici.nodejs.org/#/docs/api/Dispatcher?id=parameter-responsedata}.
|
|
78
|
+
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
79
|
+
* @throws RequestTimeoutError If the request times out.
|
|
80
|
+
* @throws RequestError If the request fails for any other reason.
|
|
81
|
+
*/
|
|
82
|
+
export async function postFormRequest(url, body, requestOptions = {}, dispatcherOrDispatcherOptions) {
|
|
83
|
+
const { request } = await import("undici");
|
|
84
|
+
try {
|
|
85
|
+
const { headers, ...baseRequestOptions } = await getBaseRequestOptions(url, requestOptions, dispatcherOrDispatcherOptions);
|
|
86
|
+
return await request(url, {
|
|
87
|
+
method: "POST",
|
|
88
|
+
...baseRequestOptions,
|
|
89
|
+
headers: {
|
|
90
|
+
...headers,
|
|
91
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
92
|
+
},
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- TODO: Add a runtime check for body's type
|
|
94
|
+
body: querystring.stringify(body),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
ensureError(e);
|
|
99
|
+
handleError(e, url);
|
|
100
|
+
throw new RequestError(url, "POST", e);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Downloads a file from a url to a destination path.
|
|
105
|
+
*
|
|
106
|
+
* @param url The url to download from.
|
|
107
|
+
* @param destination The absolute path to save the file to.
|
|
108
|
+
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
109
|
+
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
110
|
+
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
111
|
+
* @throws RequestTimeoutError If the request times out.
|
|
112
|
+
* @throws DownloadFailedError If the download fails for any other reason.
|
|
113
|
+
*/
|
|
114
|
+
export async function download(url, destination, requestOptions = {}, dispatcherOrDispatcherOptions) {
|
|
115
|
+
let statusCode;
|
|
116
|
+
try {
|
|
117
|
+
const response = await getRequest(url, requestOptions, dispatcherOrDispatcherOptions);
|
|
118
|
+
const { body } = response;
|
|
119
|
+
statusCode = response.statusCode;
|
|
120
|
+
if (statusCode < 200 || statusCode >= 300) {
|
|
121
|
+
throw new Error(await body.text());
|
|
122
|
+
}
|
|
123
|
+
const tempFilePath = await generateTempFilePath(destination);
|
|
124
|
+
const fileStream = fs.createWriteStream(tempFilePath);
|
|
125
|
+
await stream.pipeline(body, fileStream);
|
|
126
|
+
await move(tempFilePath, destination);
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
ensureError(e);
|
|
130
|
+
handleError(e, url);
|
|
131
|
+
throw new DownloadError(url, e);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Creates a dispatcher based on the provided options.
|
|
136
|
+
* If the `proxy` option is set, it creates a {@link UndiciT.ProxyAgent} dispatcher.
|
|
137
|
+
* If the `pool` option is set to `true`, it creates a {@link UndiciT.Pool} dispatcher.
|
|
138
|
+
* Otherwise, it creates a basic {@link UndiciT.Agent} dispatcher.
|
|
139
|
+
*
|
|
140
|
+
* @param url The url to make requests to.
|
|
141
|
+
* @param options The options to configure the dispatcher. See {@link DispatcherOptions}.
|
|
142
|
+
* @returns The configured dispatcher instance.
|
|
143
|
+
* @throws DispatcherError If the dispatcher can't be created.
|
|
144
|
+
*/
|
|
145
|
+
export async function getDispatcher(url, { timeout, proxy, pool, maxConnections, isTestDispatcher, } = {}) {
|
|
146
|
+
try {
|
|
147
|
+
if (pool !== undefined && proxy !== undefined) {
|
|
148
|
+
throw new Error("The pool and proxy options can't be used at the same time");
|
|
149
|
+
}
|
|
150
|
+
const baseOptions = getBaseDispatcherOptions(timeout, isTestDispatcher);
|
|
151
|
+
if (proxy !== undefined) {
|
|
152
|
+
return await getProxyDispatcher(proxy, baseOptions);
|
|
153
|
+
}
|
|
154
|
+
if (pool === true) {
|
|
155
|
+
return await getPoolDispatcher(url, {
|
|
156
|
+
...baseOptions,
|
|
157
|
+
connections: maxConnections ?? DEFAULT_POOL_MAX_CONNECTIONS,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return await getBasicDispatcher(baseOptions);
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
ensureError(e);
|
|
164
|
+
throw new DispatcherError(e.message, e);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
export async function getTestDispatcher(options = {}) {
|
|
168
|
+
const { MockAgent } = await import("undici");
|
|
169
|
+
const baseOptions = getBaseDispatcherOptions(options.timeout, true);
|
|
170
|
+
return new MockAgent(baseOptions);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Determines whether a proxy should be used for a given url.
|
|
174
|
+
*
|
|
175
|
+
* @param url The url to check.
|
|
176
|
+
* @returns `true` if a proxy should be used for the url, `false` otherwise.
|
|
177
|
+
*/
|
|
178
|
+
export function shouldUseProxy(url) {
|
|
179
|
+
const { hostname } = new URL(url);
|
|
180
|
+
const noProxy = process.env.NO_PROXY;
|
|
181
|
+
if (hostname === "localhost" || hostname === "127.0.0.1" || noProxy === "*") {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
if (noProxy !== undefined && noProxy !== "") {
|
|
185
|
+
const noProxySet = new Set(noProxy.split(","));
|
|
186
|
+
if (noProxySet.has(hostname)) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Determines whether an absolute url is valid.
|
|
194
|
+
*
|
|
195
|
+
* @param url The url to check.
|
|
196
|
+
* @returns `true` if the url is valid, `false` otherwise.
|
|
197
|
+
*/
|
|
198
|
+
export function isValidUrl(url) {
|
|
199
|
+
try {
|
|
200
|
+
new URL(url);
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
export { ConnectionRefusedError, DispatcherError, DownloadError, RequestError, RequestTimeoutError, ResponseStatusCodeError, } from "./errors/request.js";
|
|
208
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +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,MAAM,CAAC;AACtD,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACxC,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,CAAC;AAChD,MAAM,CAAC,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAoC5C;;;;;;;;;;GAUG;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;QACH,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Writable } from "node:stream";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Tansform that writes everything to actualWritable, without closing it
|
|
4
|
+
* when finished.
|
|
5
|
+
*
|
|
6
|
+
* This is useful to pipe things to stdout, without closing it, while being
|
|
7
|
+
* able to await for the result of the pipe to finish.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createNonClosingWriter(actualWritable: Writable): Writable;
|
|
10
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,cAAc,EAAE,QAAQ,GAAG,QAAQ,CAMzE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Writable } from "node:stream";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Tansform that writes everything to actualWritable, without closing it
|
|
4
|
+
* when finished.
|
|
5
|
+
*
|
|
6
|
+
* This is useful to pipe things to stdout, without closing it, while being
|
|
7
|
+
* able to await for the result of the pipe to finish.
|
|
8
|
+
*/
|
|
9
|
+
export function createNonClosingWriter(actualWritable) {
|
|
10
|
+
return new Writable({
|
|
11
|
+
write(chunk, encoding, callback) {
|
|
12
|
+
actualWritable.write(chunk, encoding, callback);
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAAC,cAAwB;IAC7D,OAAO,IAAI,QAAQ,CAAC;QAClB,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ;YAC7B,cAAc,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAClD,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a word in singular form to a pluralized string based on the number
|
|
3
|
+
* of items.
|
|
4
|
+
*
|
|
5
|
+
* @param singular The singular form of the word.
|
|
6
|
+
* @param count The number of items. This determines whether the singular or
|
|
7
|
+
* plural form is used.
|
|
8
|
+
* @param plural The optional plural form of the word. If not provided, the
|
|
9
|
+
* plural form is created by appending an "s" to the singular form.
|
|
10
|
+
* @returns The pluralized string.
|
|
11
|
+
*/
|
|
12
|
+
export declare function pluralize(singular: string, count: number, plural?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Capitalizes the first letter of a string.
|
|
15
|
+
*
|
|
16
|
+
* @param str The string to capitalize.
|
|
17
|
+
* @returns The string with the first letter capitalized.
|
|
18
|
+
*/
|
|
19
|
+
export declare function capitalize(str: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Converts a kebab-case string to camelCase.
|
|
22
|
+
*
|
|
23
|
+
* @param str The kebab-case string to convert.
|
|
24
|
+
* @returns The camelCase string.
|
|
25
|
+
*/
|
|
26
|
+
export declare function kebabToCamelCase(str: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Converts a camelCase string to snake_case.
|
|
29
|
+
*
|
|
30
|
+
* @param str The camelCase string to convert.
|
|
31
|
+
* @returns The snake_case string.
|
|
32
|
+
*/
|
|
33
|
+
export declare function camelToSnakeCase(str: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Converts a camelCase string to kebab-case.
|
|
36
|
+
*
|
|
37
|
+
* @param str The camelCase string to convert.
|
|
38
|
+
* @returns The kebab-case string.
|
|
39
|
+
*/
|
|
40
|
+
export declare function camelToKebabCase(str: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Ensures a string ends with a slash.
|
|
43
|
+
*/
|
|
44
|
+
export declare function ensureTrailingSlash(path: string): string;
|
|
45
|
+
//# sourceMappingURL=string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/string.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CACvB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAMR;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExD"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a word in singular form to a pluralized string based on the number
|
|
3
|
+
* of items.
|
|
4
|
+
*
|
|
5
|
+
* @param singular The singular form of the word.
|
|
6
|
+
* @param count The number of items. This determines whether the singular or
|
|
7
|
+
* plural form is used.
|
|
8
|
+
* @param plural The optional plural form of the word. If not provided, the
|
|
9
|
+
* plural form is created by appending an "s" to the singular form.
|
|
10
|
+
* @returns The pluralized string.
|
|
11
|
+
*/
|
|
12
|
+
export function pluralize(singular, count, plural) {
|
|
13
|
+
if (count === 1) {
|
|
14
|
+
return singular;
|
|
15
|
+
}
|
|
16
|
+
return plural !== undefined ? plural : `${singular}s`;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Capitalizes the first letter of a string.
|
|
20
|
+
*
|
|
21
|
+
* @param str The string to capitalize.
|
|
22
|
+
* @returns The string with the first letter capitalized.
|
|
23
|
+
*/
|
|
24
|
+
export function capitalize(str) {
|
|
25
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Converts a kebab-case string to camelCase.
|
|
29
|
+
*
|
|
30
|
+
* @param str The kebab-case string to convert.
|
|
31
|
+
* @returns The camelCase string.
|
|
32
|
+
*/
|
|
33
|
+
export function kebabToCamelCase(str) {
|
|
34
|
+
return str.replace(/-./g, (match) => match.charAt(1).toUpperCase());
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Converts a camelCase string to snake_case.
|
|
38
|
+
*
|
|
39
|
+
* @param str The camelCase string to convert.
|
|
40
|
+
* @returns The snake_case string.
|
|
41
|
+
*/
|
|
42
|
+
export function camelToSnakeCase(str) {
|
|
43
|
+
return str.replace(/[A-Z0-9]/g, (match) => `_${match.toLowerCase()}`);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Converts a camelCase string to kebab-case.
|
|
47
|
+
*
|
|
48
|
+
* @param str The camelCase string to convert.
|
|
49
|
+
* @returns The kebab-case string.
|
|
50
|
+
*/
|
|
51
|
+
export function camelToKebabCase(str) {
|
|
52
|
+
return str.replace(/[A-Z0-9]/g, (match) => `-${match.toLowerCase()}`);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Ensures a string ends with a slash.
|
|
56
|
+
*/
|
|
57
|
+
export function ensureTrailingSlash(path) {
|
|
58
|
+
return path.endsWith("/") ? path : path + "/";
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/string.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CACvB,QAAgB,EAChB,KAAa,EACb,MAAe;IAEf,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QAChB,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,QAAQ,GAAG,CAAC;AACxD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AACtE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,OAAO,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AACxE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,OAAO,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AACxE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spawns a detached subprocess to execute a given file with optional arguments.
|
|
3
|
+
*
|
|
4
|
+
* @param absolutePathToSubProcessFile - The absolute path to the subprocess file to be executed.
|
|
5
|
+
* @param args - Optional list of string arguments to pass to the subprocess.
|
|
6
|
+
* @param env - Optional environment key-value pairs to pass to the subprocess.
|
|
7
|
+
*
|
|
8
|
+
* The subprocess runs in a detached mode and its standard input/output is ignored.
|
|
9
|
+
* This function does not wait for the subprocess to complete and the subprocess is unreferenced
|
|
10
|
+
* to allow the parent process to exit independently.
|
|
11
|
+
*/
|
|
12
|
+
export declare function spawnDetachedSubProcess(absolutePathToSubProcessFile: string, args?: string[], env?: Record<string, string>): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=subprocess.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subprocess.d.ts","sourceRoot":"","sources":["../../src/subprocess.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;GAUG;AACH,wBAAsB,uBAAuB,CAC3C,4BAA4B,EAAE,MAAM,EACpC,IAAI,GAAE,MAAM,EAAO,EACnB,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC/B,OAAO,CAAC,IAAI,CAAC,CAsBf"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { SubprocessFileNotFoundError, SubprocessPathIsDirectoryError, } from "./errors/subprocess.js";
|
|
3
|
+
import { exists, isDirectory } from "./fs.js";
|
|
4
|
+
/**
|
|
5
|
+
* Spawns a detached subprocess to execute a given file with optional arguments.
|
|
6
|
+
*
|
|
7
|
+
* @param absolutePathToSubProcessFile - The absolute path to the subprocess file to be executed.
|
|
8
|
+
* @param args - Optional list of string arguments to pass to the subprocess.
|
|
9
|
+
* @param env - Optional environment key-value pairs to pass to the subprocess.
|
|
10
|
+
*
|
|
11
|
+
* The subprocess runs in a detached mode and its standard input/output is ignored.
|
|
12
|
+
* This function does not wait for the subprocess to complete and the subprocess is unreferenced
|
|
13
|
+
* to allow the parent process to exit independently.
|
|
14
|
+
*/
|
|
15
|
+
export async function spawnDetachedSubProcess(absolutePathToSubProcessFile, args = [], env = {}) {
|
|
16
|
+
if ((await exists(absolutePathToSubProcessFile)) === false) {
|
|
17
|
+
throw new SubprocessFileNotFoundError(absolutePathToSubProcessFile);
|
|
18
|
+
}
|
|
19
|
+
if ((await isDirectory(absolutePathToSubProcessFile)) === true) {
|
|
20
|
+
throw new SubprocessPathIsDirectoryError(absolutePathToSubProcessFile);
|
|
21
|
+
}
|
|
22
|
+
const subprocessArgs = [absolutePathToSubProcessFile, ...args];
|
|
23
|
+
if (absolutePathToSubProcessFile.endsWith(".ts")) {
|
|
24
|
+
subprocessArgs.unshift("--import", "tsx/esm");
|
|
25
|
+
}
|
|
26
|
+
const subprocess = spawn(process.execPath, subprocessArgs, {
|
|
27
|
+
detached: true,
|
|
28
|
+
env,
|
|
29
|
+
stdio: "ignore",
|
|
30
|
+
});
|
|
31
|
+
subprocess.unref();
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=subprocess.js.map
|
|
@@ -0,0 +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;AAC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