Skip to content

Commit 9ce3ac2

Browse files
Migrate from node-fetch to native Node.js fetch implementation
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
1 parent 6b7572b commit 9ce3ac2

File tree

16 files changed

+349
-371
lines changed

16 files changed

+349
-371
lines changed

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default tseslint.config(
1414
globals: {
1515
Buffer: true,
1616
console: true,
17+
fetch: true,
1718
process: true,
1819
setTimeout: true,
1920
},

examples/raw-example.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as k8s from '@kubernetes/client-node';
2-
import fetch from 'node-fetch';
32
import https from 'node:https';
43

54
const kc = new k8s.KubeConfig();

package-lock.json

Lines changed: 313 additions & 337 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,12 @@
5757
"dependencies": {
5858
"@types/js-yaml": "^4.0.1",
5959
"@types/node": "^24.0.0",
60-
"@types/node-fetch": "^2.6.13",
6160
"@types/stream-buffers": "^3.0.3",
6261
"form-data": "^4.0.0",
6362
"hpagent": "^1.2.0",
6463
"isomorphic-ws": "^5.0.0",
6564
"js-yaml": "^4.1.0",
6665
"jsonpath-plus": "^10.3.0",
67-
"node-fetch": "^2.7.0",
6866
"openid-client": "^6.1.3",
6967
"rfc4648": "^1.3.0",
7068
"socks-proxy-agent": "^8.0.4",

src/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import yaml from 'js-yaml';
55
import net from 'node:net';
66
import path from 'node:path';
77

8-
import { Headers, RequestInit } from 'node-fetch';
98
import { RequestContext } from './api.js';
109
import { Authenticator } from './auth.js';
1110
import { AzureAuth } from './azure_auth.js';

src/config_test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { fileURLToPath } from 'node:url';
1818
import mockfs from 'mock-fs';
1919

2020
import { Authenticator } from './auth.js';
21-
import fetch, { Headers } from 'node-fetch';
2221
import { HttpMethod } from './index.js';
2322
import { assertRequestAgentsEqual, assertRequestOptionsEqual } from './test/match-buffer.js';
2423
import { CoreV1Api, RequestContext } from './api.js';

src/gen/http/isomorphic-fetch.ts

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/health.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fetch from 'node-fetch';
21
import { KubeConfig } from './config.js';
32
import { RequestOptions } from 'node:https';
43

src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,3 @@ export * from './health.js';
1818
export * from './middleware.js';
1919
export * from './patch.js';
2020
export { type ConfigOptions, type User, type Cluster, type Context } from './config_types.js';
21-
22-
// Export AbortError and FetchError so that instanceof checks in user code will definitely use the same instances
23-
export { AbortError, FetchError } from 'node-fetch';

src/log.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import fetch from 'node-fetch';
2-
import { Writable } from 'node:stream';
1+
import { Readable, Writable } from 'node:stream';
32
import { ApiException } from './api.js';
43
import { KubeConfig } from './config.js';
54
import { V1Status } from './gen/index.js';
@@ -140,7 +139,8 @@ export class Log {
140139
const status = response.status;
141140
if (status === 200) {
142141
// TODO: the follow search param still has the stream close prematurely based on my testing
143-
response.body!.pipe(stream);
142+
// Convert Web ReadableStream to Node.js Readable stream
143+
Readable.fromWeb(response.body as any).pipe(stream);
144144
} else if (status === 500) {
145145
const v1status = (await response.json()) as V1Status;
146146
const v1code = v1status.code;

0 commit comments

Comments
 (0)