From 7c74e6c9e894430f578e6075d1c196833197243a Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Fri, 7 Feb 2025 17:34:40 -0800 Subject: [PATCH] revert node-fetch --- gax/package.json | 2 +- gax/src/fallbackServiceStub.ts | 20 +++++--------------- gax/tsconfig.json | 8 +------- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/gax/package.json b/gax/package.json index a3bf3cf06..6f17b4f8d 100644 --- a/gax/package.json +++ b/gax/package.json @@ -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", diff --git a/gax/src/fallbackServiceStub.ts b/gax/src/fallbackServiceStub.ts index 328c1c2ab..cf28522b8 100644 --- a/gax/src/fallbackServiceStub.ts +++ b/gax/src/fallbackServiceStub.ts @@ -1,4 +1,3 @@ -/* eslint-disable prettier/prettier */ /** * Copyright 2021 Google LLC * @@ -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'; @@ -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; } @@ -164,7 +153,7 @@ export function generateServiceStub( authClient .getRequestHeaders() .then(authHeader => { - const fetchRequest: any = { + const fetchRequest: RequestInit = { headers: { ...authHeader, ...headers, @@ -172,6 +161,7 @@ export function generateServiceStub( body: fetchParameters.body as | string | Buffer + | Uint8Array | undefined, method: fetchParameters.method, signal: cancelSignal, @@ -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, diff --git a/gax/tsconfig.json b/gax/tsconfig.json index 3b87b26f9..0921b23c8 100644 --- a/gax/tsconfig.json +++ b/gax/tsconfig.json @@ -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", @@ -18,8 +15,5 @@ "src/*/*.ts", "test/system-test/*.ts", "test/unit/*.ts", - "*/*.json", - "test/fixtures/*.json", - "test/showcase-echo-client/*/*.json" ] }