Skip to content

chore: remove node-fetch #55112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
6777060
chore: remove `node-fetch`
balazsorban44 Sep 7, 2023
77b6d3e
use polyfill import
balazsorban44 Sep 7, 2023
9c637f6
use polyfill import
balazsorban44 Sep 7, 2023
7e20c0e
use polyfill fetch in scripts
balazsorban44 Sep 7, 2023
02f18fe
use polyfill fetch in bench
balazsorban44 Sep 7, 2023
3b5708f
use polyfill fetch in tests
balazsorban44 Sep 7, 2023
87c9d4c
import whole fetch module
balazsorban44 Sep 7, 2023
3031c1a
fix run-tests
balazsorban44 Sep 7, 2023
8882b54
use `src`
balazsorban44 Sep 7, 2023
722bdef
fix run-tests
balazsorban44 Sep 7, 2023
ca8471f
drop `node-fetch` methods
balazsorban44 Sep 7, 2023
7cbb337
fix font tests
balazsorban44 Sep 7, 2023
fee5806
use ArrayBuffer
balazsorban44 Sep 7, 2023
88ae501
remove compiled `node-fetch`
balazsorban44 Sep 7, 2023
ab1f82f
fix more buffer
balazsorban44 Sep 7, 2023
f41e8c2
fix types
balazsorban44 Sep 7, 2023
c0a4669
Merge branch 'canary' into chore/remove-node-fetch
balazsorban44 Sep 7, 2023
dc92041
use ReadableStream
balazsorban44 Sep 7, 2023
8a09bc2
fix types
balazsorban44 Sep 7, 2023
9c6ad9e
remove `node-fetch` from taskfile
balazsorban44 Sep 7, 2023
0ffbd41
use undici agent
balazsorban44 Sep 7, 2023
6c1b698
fix image optimizer tests
balazsorban44 Sep 8, 2023
c74803c
use jest-setup-after-env for fetch/ReadableStream setup
balazsorban44 Sep 8, 2023
ce88444
Merge branch 'canary' into chore/remove-node-fetch
balazsorban44 Sep 8, 2023
4b69e59
fix integration test
balazsorban44 Sep 8, 2023
ee3562a
fix streaming tests
balazsorban44 Sep 8, 2023
aeca006
fix integration tests
balazsorban44 Sep 8, 2023
88acd4c
fix tests
balazsorban44 Sep 8, 2023
87acbfd
fix more streaming tests
balazsorban44 Sep 8, 2023
fa4dfaa
correctly parse URLs
balazsorban44 Sep 8, 2023
5c21955
query -> search
balazsorban44 Sep 8, 2023
eefcf2c
add `?`
balazsorban44 Sep 8, 2023
8fb5767
use `src` in tests
balazsorban44 Sep 8, 2023
05e6b28
exclude tests from build
balazsorban44 Sep 8, 2023
1ce0a7f
Merge branch 'canary' into chore/remove-node-fetch
balazsorban44 Sep 13, 2023
2ac2838
move more tests to `URL` from `url.parse`
balazsorban44 Sep 13, 2023
1beb92c
drop `node-fetch` proxy agents in favor of undici's
balazsorban44 Sep 13, 2023
330944e
use undici's proxy Agent
balazsorban44 Sep 13, 2023
83267f5
use undici proxy agent
balazsorban44 Sep 14, 2023
9309a00
use dist, fix types
balazsorban44 Sep 14, 2023
475f11b
fix types
balazsorban44 Sep 14, 2023
4295c94
remove imports
balazsorban44 Sep 14, 2023
fa1cd16
Merge branch 'canary' into chore/remove-node-fetch
balazsorban44 Oct 20, 2023
a8fff3a
fix TS build error
balazsorban44 Oct 20, 2023
f929a4d
fix errors
balazsorban44 Oct 20, 2023
7e38555
Merge branch 'canary' into chore/remove-node-fetch
balazsorban44 Oct 20, 2023
b401fd5
tweak ts comment
balazsorban44 Oct 20, 2023
b31bc7b
drop `url.parse` from tests
balazsorban44 Oct 20, 2023
7f23f4b
remove unused import
balazsorban44 Oct 20, 2023
4c889da
remove more polyfills
balazsorban44 Oct 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bench/nested-deps-app-router/bench.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { execSync, spawn } from 'child_process'
import { join } from 'path'
import { fileURLToPath } from 'url'
import fetch from 'node-fetch'
import {
existsSync,
readFileSync,
Expand Down
1 change: 0 additions & 1 deletion bench/nested-deps/bench.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { execSync, spawn } from 'child_process'
import { join } from 'path'
import { fileURLToPath } from 'url'
import fetch from 'node-fetch'
import {
existsSync,
readFileSync,
Expand Down
1 change: 0 additions & 1 deletion bench/vercel/project-utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { config } from 'dotenv'

import fetch from 'node-fetch'
import execa from 'execa'
import path from 'path'
import url from 'url'
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
"@types/http-proxy": "1.17.3",
"@types/jest": "29.5.5",
"@types/node": "20.2.5",
"@types/node-fetch": "2.6.1",
"@types/react": "18.2.28",
"@types/react-dom": "18.2.13",
"@types/relay-runtime": "14.1.13",
Expand Down Expand Up @@ -172,7 +171,6 @@
"moment": "^2.24.0",
"nanoid": "3.1.30",
"next": "workspace:*",
"node-fetch": "2.6.7",
"npm-run-all": "4.1.5",
"nprogress": "0.2.0",
"octokit": "3.1.0",
Expand Down
5 changes: 2 additions & 3 deletions packages/font/src/google/fetch-css-from-google-fonts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-ignore
import fetch from 'next/dist/compiled/node-fetch'
import { nextFontError } from '../next-font-error'
import { getProxyAgent } from './get-proxy-agent'

Expand Down Expand Up @@ -60,7 +58,8 @@ export async function fetchCSSFromGoogleFonts(
: undefined

const res = await fetch(url, {
agent: getProxyAgent(),
// @ts-expect-error `undici`/Node.js type mismatch with the Web API
dispatcher: getProxyAgent(),
// Add a timeout in dev
signal,
headers: {
Expand Down
5 changes: 2 additions & 3 deletions packages/font/src/google/fetch-font-file.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-ignore
import fetch from 'next/dist/compiled/node-fetch'
import { getProxyAgent } from './get-proxy-agent'

/**
Expand All @@ -19,7 +17,8 @@ export async function fetchFontFile(url: string, isDev: boolean) {
const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), 3000)
const arrayBuffer = await fetch(url, {
agent: getProxyAgent(),
// @ts-expect-error `undici`/Node.js type mismatch with the Web API
dispatcher: getProxyAgent(),
// Add a timeout in dev
signal: isDev ? controller.signal : undefined,
})
Expand Down
25 changes: 8 additions & 17 deletions packages/font/src/google/get-proxy-agent.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
// @ts-ignore
import HttpsProxyAgent from 'next/dist/compiled/https-proxy-agent'
// @ts-ignore
import HttpProxyAgent from 'next/dist/compiled/http-proxy-agent'
import type { Agent } from 'https'
import { Agent as HttpAgent } from 'node:http'
import { Agent as HttpsAgent } from 'node:https'

/**
* If the http(s)_proxy environment variables is set, return a proxy agent.
*/
export function getProxyAgent(): Agent | undefined {
const httpsProxy = process.env['https_proxy'] || process.env['HTTPS_PROXY']
if (httpsProxy) {
return new HttpsProxyAgent(httpsProxy)
}
/* If the http(s)_proxy environment variables are set, return a proxy agent. */
export function getProxyAgent() {
const httpProxy = process.env['http_proxy'] ?? process.env['HTTP_PROXY']
const httpsProxy = process.env['https_proxy'] ?? process.env['HTTPS_PROXY']

const httpProxy = process.env['http_proxy'] || process.env['HTTP_PROXY']
if (httpProxy) {
return new HttpProxyAgent(httpProxy)
}
if (httpsProxy) return new HttpsAgent({ host: httpsProxy })
return new HttpAgent({ host: httpProxy })
}
1 change: 1 addition & 0 deletions packages/font/src/google/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
NextFontWithVariable,
Display,
} from '../types'

export declare function ABeeZee<
T extends CssVariable | undefined = undefined
>(options: {
Expand Down
6 changes: 1 addition & 5 deletions packages/font/src/google/loader.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import nextFontGoogleFontLoader from './loader'
// @ts-ignore
import fetch from 'next/dist/compiled/node-fetch'

jest.mock('next/dist/compiled/node-fetch')

describe('next/font/google loader', () => {
afterEach(() => {
Expand Down Expand Up @@ -120,7 +116,7 @@ describe('next/font/google loader', () => {
fontFunctionArguments: any,
expectedUrl: any
) => {
fetch.mockResolvedValue({
globalThis.fetch = jest.fn().mockResolvedValue({
ok: true,
text: async () => 'OK',
})
Expand Down
2 changes: 1 addition & 1 deletion packages/font/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"rootDir": "src"
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
"exclude": ["node_modules", "src/**/*.test.ts"]
}
2 changes: 0 additions & 2 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,7 @@
"glob": "7.1.7",
"gzip-size": "5.1.1",
"http-proxy": "1.18.1",
"http-proxy-agent": "5.0.0",
"https-browserify": "1.0.0",
"https-proxy-agent": "5.0.1",
"icss-utils": "5.1.0",
"ignore-loader": "0.1.2",
"image-size": "1.0.0",
Expand Down
1 change: 0 additions & 1 deletion packages/next/src/compiled/http-proxy-agent/index.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/next/src/compiled/http-proxy-agent/package.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/next/src/compiled/https-proxy-agent/index.js

This file was deleted.

Loading