ladjs / superagent

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
https://ladjs.github.io/superagent/
MIT License
16.57k stars 1.33k forks source link

[feat] Switch to `undici` (PR welcome) #1763

Open titanism opened 1 year ago

titanism commented 1 year ago

We'd like to switch to use undici instead of http and https packages. The performance difference is staggering and it would make superagent one of the only userland wrappers that use it under the hood.

titanism commented 1 year ago

This would be a major semver bump and large rewrite.

jimmywarting commented 10 months ago

👍 for this!

Looking at the dependency graph: https://npmgraph.js.org/?q=superagent@8.1.2 i see things like formidable and form-data

it would be nice to replace them with undici or NodeJS FormData stuff. parsing formdata could be as simple as using Response/Request.formData() all doe you get a FormData back along with File instances that are real web stuff

titanism commented 10 months ago

yeah it would be amazing to have all functionality of superagent (e.g. retrys) on top of undici

jimmywarting commented 10 months ago

Could you maybe create a new brach?

i would expect there to be kind of many breaking changes...

I could expect blob/files could be used on the backend as well along with FormData NodeJS just recently introduced const blob = await fs.openAsBlob(path, { type }) but there is no sync method, and it only works in NodeJS v20+

to solve this problem then fetch-blob could be used instead. but it's ESM-only so loading it would be hard unless this pkg dose not also becomes ESM enabled.

another approch would be to import fetch-blob async using import() then attach() would kind of have to queue up all those path -> Blob conversions.

or we would have to read the files content sync and create a Blob in memory...

titanism commented 10 months ago

@jimmywarting this all sounds amazing. we just gave you collab access to the entire @ladjs org.