Skip to content

Commit e05b6f4

Browse files
committed
What claude did to upgrade
1 parent 87232ec commit e05b6f4

File tree

6 files changed

+1773
-3560
lines changed

6 files changed

+1773
-3560
lines changed

package.json

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,38 @@
1313
"git-pre-commit": "find . -path './**/*.ts' -not -path '*/node_modules/*' -not -path '*/dist/*' -exec sh -c 'for n; do tsfmt --verify \"$n\" || exit 1; done' sh {} +",
1414
"test": "jest --coverage",
1515
"build": "rm -rf ./dist && ncc build src/index.ts -m -s -o dist",
16-
"prepublish": "npm run build"
16+
"prepublish": "npm run build",
17+
"prepare": "husky"
1718
},
1819
"peerDependencies": {
1920
"node-fetch": "2"
2021
},
2122
"devDependencies": {
22-
"@types/debug": "4.1.5",
23-
"@types/jest": "25.1.3",
24-
"@types/lru-cache": "5.1.0",
25-
"@zeit/git-hooks": "0.1.4",
26-
"@vercel/ncc": "0.33.2",
27-
"agentkeepalive": "4.2.0",
23+
"@types/debug": "4.1.12",
24+
"@types/jest": "29.5.14",
25+
"husky": "9.1.7",
26+
"@vercel/ncc": "0.38.3",
27+
"agentkeepalive": "4.5.0",
2828
"async-retry-ng": "2.0.1",
29-
"debug": "4.1.1",
30-
"jest": "25.1.0",
31-
"lint-staged": "10.0.7",
32-
"lru-cache": "5.1.1",
33-
"node-fetch": "2.6.7",
34-
"raw-body": "2.4.2",
35-
"ts-jest": "25.2.1",
36-
"typescript": "4.5.5",
29+
"debug": "4.4.0",
30+
"jest": "29.7.0",
31+
"lint-staged": "15.2.11",
32+
"lru-cache": "11.0.2",
33+
"node-fetch": "2.7.0",
34+
"raw-body": "2.5.2",
35+
"ts-jest": "29.2.5",
36+
"typescript": "5.7.2",
3737
"typescript-formatter": "7.2.2"
3838
},
3939
"dependencies": {
4040
"@types/node-fetch": "2"
4141
},
42+
"overrides": {
43+
"js-yaml": "^4.1.1"
44+
},
4245
"jest": {
4346
"preset": "ts-jest",
44-
"verbose": true
47+
"verbose": true,
48+
"testEnvironment": "node"
4549
}
4650
}

src/dns-resolve.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import dns from 'dns';
2-
import LRU from 'lru-cache';
2+
import { LRUCache } from 'lru-cache';
33
import retry, { Options as RetryOptions } from 'async-retry-ng';
44
import resolve4 from './resolve4';
55
import resolve6 from './resolve6';
66

77
const lruOptions = { max: 500 };
8-
let cache4: LRU<string, string | Promise<string>>;
9-
let cache6: LRU<string, string | Promise<string>>;
8+
let cache4: LRUCache<string, string | Promise<string>>;
9+
let cache6: LRUCache<string, string | Promise<string>>;
1010

1111
export const localhostRegex = /(?:\.|^)localhost\.?$/
1212

@@ -49,7 +49,7 @@ export default async function dnsResolve(host: string, options: Options = {}) {
4949
}
5050

5151
if (refreshCache) {
52-
cache.del(host);
52+
cache.delete(host);
5353
} else {
5454
const ip = cache.get(host);
5555
if (ip) return await ip;
@@ -62,15 +62,15 @@ export default async function dnsResolve(host: string, options: Options = {}) {
6262
throw new DNSError('ENOTFOUND', host);
6363
}
6464
const ttl = Math.max(rec.ttl, minimumCacheTime);
65-
cache.set(host, rec.address, ttl * 1000);
65+
cache.set(host, rec.address, { ttl: ttl * 1000 });
6666
return rec.address;
6767
})();
6868

69-
cache.set(host, p, 5000);
69+
cache.set(host, p, { ttl: 5000 });
7070
return p;
7171
}
7272

7373
export function setupCache() {
74-
cache4 = new LRU(lruOptions);
75-
cache6 = new LRU(lruOptions);
74+
cache4 = new LRUCache(lruOptions);
75+
cache6 = new LRUCache(lruOptions);
7676
}

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { resolve as resolveUrl } from 'url';
1+
import { URL } from 'url';
22
import { Headers, Response } from 'node-fetch';
33
import { Readable } from 'stream';
44
import createDebug from 'debug';
@@ -140,7 +140,7 @@ function setupFetch(fetch: Fetch, agentOpts: AgentOptions = {}): any {
140140
if (fetchOpts.redirect === 'manual') {
141141
const location = res.headers.get('location');
142142
if (location) {
143-
res.headers.set('Location', resolveUrl(url, location));
143+
res.headers.set('Location', new URL(location, url).href);
144144
}
145145

146146
return res;

src/parse-host.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { isIP } from 'net';
2-
import { parse as parseUrl } from 'url';
2+
import { URL } from 'url';
33
import { Headers } from 'node-fetch';
44
import resolve from './dns-resolve';
55

66
export default async function parseHost(url: string, headers: Headers) {
7-
const parsedUrl = parseUrl(url);
7+
const parsedUrl = new URL(url);
88
const host = headers.get('host') || parsedUrl.host;
99

1010
if (!host) {
@@ -19,14 +19,8 @@ export default async function parseHost(url: string, headers: Headers) {
1919
throw new Error('Unable to determine hostname');
2020
}
2121

22-
// We need to create a new URL object here because url.parse() doesn't
23-
// return a functional WHATWG URL object but something that only looks
24-
// similar and has the same properties.
25-
// TS doesn't know about the existence global WHATWG URL.
26-
// @ts-ignore
27-
const newUrl = new URL(parsedUrl.href);
28-
newUrl.hostname = await resolve(parsedUrl.hostname);
29-
url = newUrl.href;
22+
parsedUrl.hostname = await resolve(parsedUrl.hostname);
23+
url = parsedUrl.href;
3024
}
3125

3226
return [url, host];

src/redirect.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
parse as parseUrl,
3-
resolve as resolveUrl
4-
} from 'url';
1+
import { URL } from 'url';
52
import { Headers, Response } from 'node-fetch';
63
import AgentWrapper from './agent-wrapper';
74
import { FetchOptions } from './types';
@@ -30,9 +27,11 @@ export function makeRedirectOpts(res: Response, opts: FetchOptions, agentWrapper
3027
if (!location) {
3128
throw new Error('"Location" header is missing');
3229
}
33-
const locationUrl = resolveUrl(res.url, location);
30+
// Handle both absolute and relative URLs
31+
// If location is absolute, use it directly; if relative, resolve against res.url
32+
const locationUrl = new URL(location, res.url || 'http://placeholder').href;
3433

35-
const host = parseUrl(locationUrl).host;
34+
const host = new URL(locationUrl).host;
3635
if (!host) {
3736
throw new Error('Cannot determine Host');
3837
}

0 commit comments

Comments
 (0)