Skip to content

Commit

Permalink
Replace node-fetch with fetch
Browse files Browse the repository at this point in the history
Issue #40
  • Loading branch information
OlliV committed Jul 11, 2022
1 parent 130b19e commit eacc428
Show file tree
Hide file tree
Showing 13 changed files with 445 additions and 456 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,3 @@ import createFetch from '@turist/fetch';

const fetch = createFetch();
```

If no fetch implementation is supplied, it will attempt to use peerDep
`node-fetch`.
1 change: 0 additions & 1 deletion __test__/cached-dns.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Server, createServer, IncomingMessage, ServerResponse } from 'http';
import { Response } from 'node-fetch';
import createFetch from '../src';
import { getAddr, listen } from './util';
import { FetchOptions } from '../src/types';
Expand Down
1 change: 0 additions & 1 deletion __test__/parse-host.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { isIP } from 'net';
import { Headers } from 'node-fetch';
import parseHost from '../src/parse-host';

test('Parses a domain to an IP address', async () => {
Expand Down
1 change: 0 additions & 1 deletion __test__/redirect.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import AgentWrapper from '../src/agent-wrapper';
import { Response } from 'node-fetch';
import { isRedirect, makeRedirectOpts } from '../src/redirect';

describe('isRedirect()', () => {
Expand Down
3 changes: 1 addition & 2 deletions __test__/timeout.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Server, createServer, IncomingMessage, ServerResponse } from "http";
import nodeFetch from "node-fetch";
import { getAddr, listen } from "./util";
import createFetch from "../src";

const fetch = createFetch(nodeFetch, { timeout: 2000 });
const fetch = createFetch({ timeout: 2000 });
let servers: Server[] = [];

afterEach(() => {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
"@types/debug": "4.1.5",
"@types/jest": "25.1.3",
"@types/lru-cache": "5.1.0",
"@zeit/git-hooks": "0.1.4",
"@types/node": "18.0.3",
"@vercel/ncc": "0.33.2",
"@zeit/git-hooks": "0.1.4",
"agentkeepalive": "4.2.0",
"async-retry-ng": "2.0.1",
"debug": "4.1.1",
Expand Down
2 changes: 0 additions & 2 deletions src/fetch-retry-error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Response } from 'node-fetch';

export default class FetchRetryError extends Error {
res: Response;
url: string;
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { resolve as resolveUrl } from 'url';
import { Headers, Response } from 'node-fetch';
import { Readable } from 'stream';
import createDebug from 'debug';
import retry from 'async-retry-ng';
Expand Down Expand Up @@ -103,6 +102,7 @@ function setupFetch(fetch: Fetch, agentOpts: AgentOptions = {}): any {
get: function() { return this.realUrl },
set: function(v: string) { this.realUrl = v }
});
// @ts-ignore
res.url = url;

debug('status %d', res.status);
Expand Down
1 change: 0 additions & 1 deletion src/parse-host.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { isIP } from 'net';
import { parse as parseUrl } from 'url';
import { Headers } from 'node-fetch';
import resolve from './dns-resolve';

export default async function parseHost(url: string, headers: Headers) {
Expand Down
1 change: 0 additions & 1 deletion src/redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
parse as parseUrl,
resolve as resolveUrl
} from 'url';
import { Headers, Response } from 'node-fetch';
import AgentWrapper from './agent-wrapper';
import { FetchOptions } from './types';

Expand Down
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as http from 'http';
import * as https from 'http';
import { Options as RetryOptions } from 'async-retry-ng';
import { Request, RequestInit, Response } from 'node-fetch';
import FetchRetryError from './fetch-retry-error';

export interface FetchOptions extends RequestInit {
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"declaration": true,
"esModuleInterop": true,
"lib": ["esnext"],
"lib": ["dom","esnext"],
"module": "CommonJS",
"moduleResolution": "node",
"resolveJsonModule": true,
Expand All @@ -12,7 +12,7 @@
"noUnusedParameters": false,
"removeComments": true,
"strict": true,
"target": "ES2018",
"target": "es2022",
"inlineSourceMap": true,
"types": ["jest","node"],
"typeRoots": [
Expand Down
878 changes: 439 additions & 439 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit eacc428

Please sign in to comment.