Skip to content

Commit 00efdf0

Browse files
committed
Merge branch 'main' into dependabot/npm_and_yarn/wretch-3.0.7
Resolve package.json and package-lock.json conflicts: keep wretch ^3.0.7, main's make-fetch-happen ^15.0.5 and undici ^8.0.2, and widen wretch peer range to ^2.0.0 || ^3.0.0. wretch v3 removes wretch.polyfills(); use a factory wrapper that applies .fetchPolyfill() per chain so proxy-header fetch is used. Made-with: Cursor
2 parents 377a415 + 568f26f commit 00efdf0

4 files changed

Lines changed: 143 additions & 633 deletions

File tree

lib/wretch-proxy.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
22
* wretch extension for proxy header support.
33
*
4-
* Registers a custom `fetch` (node-fetch + ProxyHeadersAgent) as wretch's fetch polyfill.
5-
* wretch stores polyfills on a module singleton; avoid mixing different proxy configs
6-
* in the same process without coordinating polyfills.
4+
* Wraps the wretch factory so each request chain uses a custom `fetch`
5+
* (node-fetch + ProxyHeadersAgent). wretch v3 uses per-chain `.fetchPolyfill()`
6+
* instead of the old module-level `.polyfills()`.
77
*
88
* @example
99
* const wretch = await createProxyWretch({ proxy: 'http://proxy:8080' });
@@ -20,7 +20,7 @@ import { createProxyFetch } from './node-fetch-proxy.js';
2020
* @param {string} options.proxy - Proxy URL
2121
* @param {Object} [options.proxyHeaders] - Headers to send on CONNECT
2222
* @param {Function} [options.onProxyConnect] - CONNECT callback
23-
* @returns {Promise<import('wretch').Wretch>} Default wretch export after polyfills are set
23+
* @returns {Promise<typeof import('wretch').default>} Wretch factory wired to proxy-header fetch
2424
*/
2525
export async function createProxyWretch(options) {
2626
const { proxy, proxyHeaders = {}, onProxyConnect } = options;
@@ -29,15 +29,20 @@ export async function createProxyWretch(options) {
2929
throw new Error('proxy option is required');
3030
}
3131

32-
let wretch;
32+
let rawWretch;
3333
try {
34-
wretch = (await import('wretch')).default;
34+
rawWretch = (await import('wretch')).default;
3535
} catch {
3636
throw new Error('wretch is required. Install it with: npm install wretch');
3737
}
3838

39-
const fetch = createProxyFetch({ proxy, proxyHeaders, onProxyConnect });
40-
wretch.polyfills({ fetch });
39+
const fetchImpl = createProxyFetch({ proxy, proxyHeaders, onProxyConnect });
4140

42-
return wretch;
41+
function proxyWretch(url, opts) {
42+
return rawWretch(url, opts).fetchPolyfill(fetchImpl);
43+
}
44+
proxyWretch.default = proxyWretch;
45+
proxyWretch.WretchError = rawWretch.WretchError;
46+
47+
return proxyWretch;
4348
}

0 commit comments

Comments
 (0)