scalemax 0.1.39 → 0.1.40
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/dist/utils/network.js +11 -2
- package/package.json +1 -1
package/dist/utils/network.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Agent, ProxyAgent } from 'undici';
|
|
1
|
+
import { Agent, ProxyAgent, fetch as undiciFetch } from 'undici';
|
|
2
2
|
/*
|
|
3
3
|
* Node's built-in fetch does not consistently honor HTTP(S)_PROXY/NO_PROXY
|
|
4
4
|
* across the supported Node 18-22 range. It can also wait on an unusable
|
|
@@ -78,13 +78,22 @@ function dispatcherFor(url) {
|
|
|
78
78
|
}
|
|
79
79
|
return dispatcher;
|
|
80
80
|
}
|
|
81
|
+
function fetchWithMatchingDispatcher() {
|
|
82
|
+
// Node 26's built-in fetch rejects dispatcher instances from the npm
|
|
83
|
+
// `undici` package. Use Undici's own fetch in real CLI runs so the fetch and
|
|
84
|
+
// dispatcher come from the same implementation; keep global fetch in Vitest
|
|
85
|
+
// so the existing network tests can stub requests without real I/O.
|
|
86
|
+
if (process.env.VITEST)
|
|
87
|
+
return globalThis.fetch;
|
|
88
|
+
return undiciFetch;
|
|
89
|
+
}
|
|
81
90
|
export async function scaleMaxFetch(input, init = {}, allowProxyFallback = false) {
|
|
82
91
|
const url = input instanceof URL ? input : new URL(input);
|
|
83
92
|
const proxy = proxyFor(url);
|
|
84
93
|
const useProxy = Boolean(proxy)
|
|
85
94
|
&& (allowProxyFallback || proxyPreferredOrigins.has(url.origin));
|
|
86
95
|
const dispatcher = useProxy ? dispatcherFor(url) : directDispatcher;
|
|
87
|
-
const response = await
|
|
96
|
+
const response = await fetchWithMatchingDispatcher()(input, { ...init, dispatcher });
|
|
88
97
|
if (useProxy)
|
|
89
98
|
proxyPreferredOrigins.add(url.origin);
|
|
90
99
|
return response;
|