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: correctly set Dispatcher prototype for ProxyAgent #451

Merged
merged 3 commits into from
Apr 12, 2024
Merged

Conversation

aduh95
Copy link
Contributor

@aduh95 aduh95 commented Apr 6, 2024

In an attempt to bundle only a subset of Undici code, we forgot to take some side-effect.

Fixes: #417
Closes: #449

In an attempt to bundle only a subset of Undici code, we forgot to take
some side-effect.
import(`undici/lib/dispatcher/dispatcher.js`),
// @ts-expect-error internal module is untyped
import(`undici/lib/dispatcher/proxy-agent.js`),
]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we doing all that just to reclaim some bytes? It seems a little dangerous 🤔

Copy link
Member

Choose a reason for hiding this comment

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

304000 of them but yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added tests, hopefully those ensure we'll catch bugs if this hack breaks again in the future.

)) as { default: typeof import('undici').ProxyAgent };
if (ProxyAgent == null) {
// Doing a deep import here since undici isn't tree-shakeable
const [api, Dispatcher, _ProxyAgent] = await Promise.all([
Copy link

Choose a reason for hiding this comment

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

Do these need to be loaded in a particular order?

I would recommend putting them in a separate file and just exposing the ProxyAgent from that file and add a comment on why those files are needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, any order, that's why I'm loading them concurrently.

@aduh95 aduh95 merged commit 73d9a1e into main Apr 12, 2024
10 checks passed
@aduh95 aduh95 deleted the proxy-agent branch April 12, 2024 21:27
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.

Using corepack behind corporate proxy and injected certificate
4 participants