Skip to content
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

fix: lazy load ProxyAgent to avoid bundling all the undici #1800

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aminya
Copy link

@aminya aminya commented Aug 17, 2024

This makes the loading of undici conditional by lazy loading it inside the actual function that needs the ProxyAgent.

undici is a huge library, and here it is being imported unconditionally, which results in 500KB bloat in the bundles of http-client. By requiring only what is needed and when it is needed, this issue is resolved.

Fixes #1560
Closes #1561

@aminya aminya requested a review from a team as a code owner August 17, 2024 16:47
Comment on lines +726 to +729
// Lazy load ProxyAgent to avoid bundling all the undici
const ProxyAgent =
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
require('undici/lib/proxy-agent') as typeof import('undici/types/proxy-agent').default
Copy link
Author

@aminya aminya Aug 18, 2024

Choose a reason for hiding this comment

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

This can be further improved by using dynamic imports. However, I didn't include it in this pull request, because using dynamic imports needs making getAgentDispatcher async, which changes the return type of a public method. Based on my research, this is only used in the github package, so it should be fine, but if we want to go with that, we need to have a major version bump for http-client.

aminya@0edf3eb

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.

@actions/http-client - unnecessary dependency upon undici
2 participants