diff --git a/packages/core/src/ide/ide-connection-utils.test.ts b/packages/core/src/ide/ide-connection-utils.test.ts index 99e62951be..a2d554b7a6 100644 --- a/packages/core/src/ide/ide-connection-utils.test.ts +++ b/packages/core/src/ide/ide-connection-utils.test.ts @@ -696,4 +696,14 @@ describe('ide-connection-utils', () => { ); // Short-circuiting }); }); + + describe('createProxyAwareFetch', () => { + it('should return a proxy-aware fetcher function', async () => { + const { createProxyAwareFetch } = await import( + './ide-connection-utils.js' + ); + const fetcher = await createProxyAwareFetch('127.0.0.1'); + expect(typeof fetcher).toBe('function'); + }); + }); }); diff --git a/packages/core/src/ide/ide-connection-utils.ts b/packages/core/src/ide/ide-connection-utils.ts index c9776e1509..4ccc2913d6 100644 --- a/packages/core/src/ide/ide-connection-utils.ts +++ b/packages/core/src/ide/ide-connection-utils.ts @@ -7,7 +7,7 @@ import * as fs from 'node:fs'; import * as path from 'node:path'; import * as os from 'node:os'; -import { EnvHttpProxyAgent } from 'undici'; +import { EnvHttpProxyAgent, fetch as undiciFetch } from 'undici'; import { debugLogger } from '../utils/debugLogger.js'; import { isSubpath, resolveToRealPath } from '../utils/paths.js'; import { isNodeError } from '../utils/errors.js'; @@ -286,12 +286,7 @@ export async function createProxyAwareFetch(ideServerHost: string) { const agent = new EnvHttpProxyAgent({ noProxy: [existingNoProxy, ideServerHost].filter(Boolean).join(','), }); - const undiciPromise = import('undici'); - // Suppress unhandled rejection if the promise is not awaited immediately. - // If the import fails, the error will be thrown when awaiting undiciPromise below. - undiciPromise.catch(() => {}); return async (url: string | URL, init?: RequestInit): Promise => { - const { fetch: fetchFn } = await undiciPromise; const fetchOptions: RequestInit & { dispatcher?: unknown } = { ...init, dispatcher: agent, @@ -299,7 +294,7 @@ export async function createProxyAwareFetch(ideServerHost: string) { // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion const options = fetchOptions as unknown as import('undici').RequestInit; try { - const response = await fetchFn(url, options); + const response = await undiciFetch(url, options); // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion return new Response(response.body as ReadableStream | null, { status: response.status,