Skip to content

Removing Undici Dependency #363

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

Draft
wants to merge 2 commits into
base: v4.x
Choose a base branch
from
Draft

Conversation

swapnil-nagar
Copy link
Contributor

No description provided.

@swapnil-nagar
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@swapnil-nagar swapnil-nagar requested a review from Copilot July 8, 2025 21:30
@swapnil-nagar swapnil-nagar marked this pull request as ready for review July 8, 2025 21:30
@swapnil-nagar swapnil-nagar requested a review from a team as a code owner July 8, 2025 21:30
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR removes the undici HTTP client in favor of the built-in Fetch API (Request/Response) and updates tests and package settings accordingly.

  • Migrate HttpRequest and HttpResponse to use global Request/Response and Headers
  • Remove undici imports and dependency, bump package version to 5.0.0 and Node engine to >=20.0
  • Adjust tests to drop undici types and use as assertions

Reviewed Changes

Copilot reviewed 7 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/http/extractHttpUserFromHeaders.test.ts Remove unused Headers import from undici
test/http/HttpRequest.test.ts Drop undici File import, switch to as File, loosen rejection check
test/converters/toRpcHttp.test.ts Remove unused Headers import from undici
src/http/extractHttpUserFromHeaders.ts Remove unused undici Headers import
src/http/HttpResponse.ts Replace undici Response/Headers with global Fetch API, adjust methods
src/http/HttpRequest.ts Replace undici Request with global Fetch API, adjust methods
package.json Bump version to 5.0.0, Node >=20.0, remove undici dependency
Comments suppressed due to low confidence (2)

test/http/HttpRequest.test.ts:137

  • [nitpick] The test no longer asserts a specific error message or type. Consider matching the exact error text or class to ensure the correct failure reason is being tested.
                await expect(req.formData()).to.eventually.be.rejectedWith();

test/http/HttpRequest.test.ts:96

  • The test uses the File type without importing it; after removing import { File } from 'undici', you need to import File from a valid source or adjust the test to work with the available global API.
            const file = parsedForm.get('myfile') as File;

Comment on lines +56 to 59
get body(): ReadableStream<Uint8Array> | null {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return this.#res.body as any; // Type compatibility between global and Node.js ReadableStream
}
Copy link
Preview

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Avoid using any and disabling lint rules. Consider defining a proper type alias or wrapper for the stream to maintain type safety.

Suggested change
get body(): ReadableStream<Uint8Array> | null {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return this.#res.body as any; // Type compatibility between global and Node.js ReadableStream
}
get body(): ReadableStream<Uint8Array> | null {
return this.#res.body as ReadableStream<Uint8Array> | null; // Type compatibility between global and Node.js ReadableStream
}

Copilot uses AI. Check for mistakes.

return this.#uReq.body;
get body(): ReadableStream<Uint8Array> | null {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return this.#req.body as any; // Type compatibility between global and Node.js ReadableStream
Copy link
Preview

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using any here bypasses type checks; consider creating a proper type guard or wrapper for the request body stream to keep type safety.

Copilot uses AI. Check for mistakes.

Comment on lines +150 to +156
const req = new Request(url, {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
body: body as any, // Node.js Readable stream compatibility
duplex: 'half',
method: nonNullProp(proxyReq, 'method'),
headers,
});
} as any); // Global Request constructor compatibility
Copy link
Preview

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Casting the init object to any can hide real type errors. You could define or extend a RequestInit type to properly handle the duplex and stream compatibility instead of using any.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant