@pnpm/network.fetch 1100.0.8 → 1100.1.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/lib/dispatcher.d.ts +8 -0
- package/lib/dispatcher.js +21 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/package.json +10 -7
package/lib/dispatcher.d.ts
CHANGED
|
@@ -18,6 +18,14 @@ export interface DispatcherOptions {
|
|
|
18
18
|
* Clear the dispatcher cache. Useful for testing.
|
|
19
19
|
*/
|
|
20
20
|
export declare function clearDispatcherCache(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Destroy the global dispatcher and every cached dispatcher, closing their open
|
|
23
|
+
* sockets. Intended for process shutdown only: once called, the module can no
|
|
24
|
+
* longer perform network requests. This is used to work around a Windows crash
|
|
25
|
+
* that happens when the process exits while sockets are still open
|
|
26
|
+
* (https://github.com/nodejs/node/issues/56645).
|
|
27
|
+
*/
|
|
28
|
+
export declare function destroyDispatchers(): Promise<void>;
|
|
21
29
|
/**
|
|
22
30
|
* Get a dispatcher for the given URI and options.
|
|
23
31
|
* Returns undefined if no special configuration is needed (to use global dispatcher).
|
package/lib/dispatcher.js
CHANGED
|
@@ -5,7 +5,7 @@ import { nerfDart } from '@pnpm/config.nerf-dart';
|
|
|
5
5
|
import { PnpmError } from '@pnpm/error';
|
|
6
6
|
import { LRUCache } from 'lru-cache';
|
|
7
7
|
import { SocksClient } from 'socks';
|
|
8
|
-
import { Agent, ProxyAgent, setGlobalDispatcher } from 'undici';
|
|
8
|
+
import { Agent, getGlobalDispatcher, ProxyAgent, setGlobalDispatcher } from 'undici';
|
|
9
9
|
const DEFAULT_MAX_SOCKETS = 50;
|
|
10
10
|
const KEEP_ALIVE_TIMEOUT = 30_000; // 30 seconds
|
|
11
11
|
const KEEP_ALIVE_MAX_TIMEOUT = 600_000; // 10 minutes
|
|
@@ -16,14 +16,15 @@ const KEEP_ALIVE_MAX_TIMEOUT = 600_000; // 10 minutes
|
|
|
16
16
|
// With HTTP/2, undici multiplexes many streams over 1-2 TCP connections sharing a single
|
|
17
17
|
// congestion window. In benchmarks this was slower than opening ~50 independent HTTP/1.1
|
|
18
18
|
// connections that each get their own congestion window and can saturate bandwidth in parallel.
|
|
19
|
-
|
|
19
|
+
const GLOBAL_DISPATCHER = new Agent({
|
|
20
20
|
connections: DEFAULT_MAX_SOCKETS,
|
|
21
21
|
keepAliveTimeout: KEEP_ALIVE_TIMEOUT,
|
|
22
22
|
keepAliveMaxTimeout: KEEP_ALIVE_MAX_TIMEOUT,
|
|
23
23
|
connect: {
|
|
24
24
|
autoSelectFamily: true,
|
|
25
25
|
},
|
|
26
|
-
}).compose(stripSecFetchHeaders)
|
|
26
|
+
}).compose(stripSecFetchHeaders);
|
|
27
|
+
setGlobalDispatcher(GLOBAL_DISPATCHER);
|
|
27
28
|
// undici's fetch() automatically adds sec-fetch-* headers (e.g. sec-fetch-mode: cors)
|
|
28
29
|
// per the Fetch spec. Some registries like Azure DevOps Artifacts interpret these as
|
|
29
30
|
// browser requests and reject them with HTTP 400. Since pnpm is a CLI tool, these
|
|
@@ -75,6 +76,23 @@ const DISPATCHER_CACHE = new LRUCache({
|
|
|
75
76
|
export function clearDispatcherCache() {
|
|
76
77
|
DISPATCHER_CACHE.clear();
|
|
77
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Destroy the global dispatcher and every cached dispatcher, closing their open
|
|
81
|
+
* sockets. Intended for process shutdown only: once called, the module can no
|
|
82
|
+
* longer perform network requests. This is used to work around a Windows crash
|
|
83
|
+
* that happens when the process exits while sockets are still open
|
|
84
|
+
* (https://github.com/nodejs/node/issues/56645).
|
|
85
|
+
*/
|
|
86
|
+
export async function destroyDispatchers() {
|
|
87
|
+
// getGlobalDispatcher() is included in case something replaced GLOBAL_DISPATCHER
|
|
88
|
+
// via setGlobalDispatcher(); the Set removes the duplicate when it is still our own instance.
|
|
89
|
+
const dispatchers = new Set([
|
|
90
|
+
GLOBAL_DISPATCHER,
|
|
91
|
+
getGlobalDispatcher(),
|
|
92
|
+
...DISPATCHER_CACHE.values(),
|
|
93
|
+
]);
|
|
94
|
+
await Promise.allSettled(Array.from(dispatchers, dispatcher => dispatcher.destroy()));
|
|
95
|
+
}
|
|
78
96
|
/**
|
|
79
97
|
* Get a dispatcher for the given URI and options.
|
|
80
98
|
* Returns undefined if no special configuration is needed (to use global dispatcher).
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { clearDispatcherCache, getDispatcher } from './dispatcher.js';
|
|
1
|
+
export { clearDispatcherCache, destroyDispatchers, getDispatcher } from './dispatcher.js';
|
|
2
2
|
export { fetch, isRedirect, type RetryTimeoutOptions } from './fetch.js';
|
|
3
3
|
export { createDispatchedFetch, type CreateDispatchedFetchOptions, createFetchFromRegistry, type CreateFetchFromRegistryOptions, type DispatcherOptions, fetchWithDispatcher } from './fetchFromRegistry.js';
|
|
4
4
|
export type { FetchFromRegistry } from '@pnpm/fetching.types';
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { clearDispatcherCache, getDispatcher } from './dispatcher.js';
|
|
1
|
+
export { clearDispatcherCache, destroyDispatchers, getDispatcher } from './dispatcher.js';
|
|
2
2
|
export { fetch, isRedirect } from './fetch.js';
|
|
3
3
|
export { createDispatchedFetch, createFetchFromRegistry, fetchWithDispatcher } from './fetchFromRegistry.js';
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/network.fetch",
|
|
3
|
-
"version": "1100.0
|
|
3
|
+
"version": "1100.1.0",
|
|
4
4
|
"description": "Native fetch with retries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"funding": "https://opencollective.com/pnpm",
|
|
13
|
-
"repository":
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/pnpm/pnpm/tree/main/network/fetch"
|
|
16
|
+
},
|
|
14
17
|
"homepage": "https://github.com/pnpm/pnpm/tree/main/network/fetch#readme",
|
|
15
18
|
"bugs": {
|
|
16
19
|
"url": "https://github.com/pnpm/pnpm/issues"
|
|
@@ -31,10 +34,10 @@
|
|
|
31
34
|
"lru-cache": "^11.5.0",
|
|
32
35
|
"socks": "^2.8.9",
|
|
33
36
|
"undici": "^7.26.0",
|
|
37
|
+
"@pnpm/core-loggers": "1100.1.3",
|
|
34
38
|
"@pnpm/fetching.types": "1100.0.1",
|
|
35
|
-
"@pnpm/
|
|
36
|
-
"@pnpm/
|
|
37
|
-
"@pnpm/error": "1100.0.0"
|
|
39
|
+
"@pnpm/error": "1100.0.0",
|
|
40
|
+
"@pnpm/types": "1101.3.0"
|
|
38
41
|
},
|
|
39
42
|
"peerDependencies": {
|
|
40
43
|
"@pnpm/logger": "^1001.0.1"
|
|
@@ -42,8 +45,8 @@
|
|
|
42
45
|
"devDependencies": {
|
|
43
46
|
"@jest/globals": "30.3.0",
|
|
44
47
|
"https-proxy-server-express": "0.1.2",
|
|
45
|
-
"@pnpm/
|
|
46
|
-
"@pnpm/
|
|
48
|
+
"@pnpm/network.fetch": "1100.1.0",
|
|
49
|
+
"@pnpm/logger": "1100.0.0"
|
|
47
50
|
},
|
|
48
51
|
"engines": {
|
|
49
52
|
"node": ">=22.13"
|