Skip to content

Commit

Permalink
revert node-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
sofisl committed Feb 8, 2025
1 parent f53600c commit 7c74e6c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 23 deletions.
2 changes: 1 addition & 1 deletion gax/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"abort-controller": "^3.0.0",
"duplexify": "^4.1.3",
"google-auth-library": "^9.15.1",
"node-fetch": "^3.3.2",
"node-fetch": "^2.7.0",
"object-hash": "^3.0.0",
"proto3-json-serializer": "^2.0.2",
"protobufjs": "^7.4.0",
Expand Down
20 changes: 5 additions & 15 deletions gax/src/fallbackServiceStub.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable prettier/prettier */
/**
* Copyright 2021 Google LLC
*
Expand All @@ -18,11 +17,8 @@
/* global window */
/* global AbortController */

// import type {
// Response as NodeFetchResponse,
// RequestInfo,
// RequestInit,
// } from 'node-fetch';
import nodeFetch from 'node-fetch';
import {Response as NodeFetchResponse, RequestInit} from 'node-fetch';
import {AbortController as NodeAbortController} from 'abort-controller';

import {hasWindowFetch, hasAbortController, isNodeJS} from './featureDetection';
Expand All @@ -31,14 +27,7 @@ import {StreamArrayParser} from './streamArrayParser';
import {pipeline, PipelineSource} from 'stream';
import type {Agent as HttpAgent} from 'http';
import type {Agent as HttpsAgent} from 'https';
// const nodeFetch = (url: any, request: any) =>
// import('node-fetch').then(({default: fetch}) => fetch(url, request));

async function loadNodeFetch() {
return await import('node-fetch'); // Path to the module
}

const nodeFetch = loadNodeFetch();
interface NodeFetchType {
(url: RequestInfo, init?: RequestInit): Promise<Response>;
}
Expand Down Expand Up @@ -164,14 +153,15 @@ export function generateServiceStub(
authClient
.getRequestHeaders()
.then(authHeader => {
const fetchRequest: any = {
const fetchRequest: RequestInit = {
headers: {
...authHeader,
...headers,
},
body: fetchParameters.body as
| string
| Buffer
| Uint8Array
| undefined,
method: fetchParameters.method,
signal: cancelSignal,
Expand All @@ -187,7 +177,7 @@ export function generateServiceStub(
}
return fetch(url, fetchRequest as {});
})
.then((response: any) => {
.then((response: Response | NodeFetchResponse) => {
if (response.ok && rpc.responseStream) {
pipeline(
response.body as PipelineSource<unknown>,
Expand Down
8 changes: 1 addition & 7 deletions gax/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
"extends": "./node_modules/gts/tsconfig-google.json",
"compilerOptions": {
"lib": ["es2018", "dom"],
"module": "commonjs",
"target": "es2018",
"rootDir": ".",
"outDir": "build",
"noImplicitAny": true,
"resolveJsonModule": true,
"moduleResolution": "node"
"resolveJsonModule": true
},
"include": [
"src/*.ts",
Expand All @@ -18,8 +15,5 @@
"src/*/*.ts",
"test/system-test/*.ts",
"test/unit/*.ts",
"*/*.json",
"test/fixtures/*.json",
"test/showcase-echo-client/*/*.json"
]
}

0 comments on commit 7c74e6c

Please sign in to comment.