-
Notifications
You must be signed in to change notification settings - Fork 30
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
Ready to boost your popularity to like 22 mil download / week? #82
Comments
Sooooo yeah, my initial intention for this polyfill was to target web browsers. I noticed that it also runs fine on Node, so I slapped a I haven't put much thought into optimizing for download size. I provide (too) many variants in a single npm package, so that you can install one and then import whichever variant you're interested in (e.g. I could overhaul the project and remove all of the transpilation, bundling and minification, and instead compile every TypeScript source file to an individual JavaScript file (basically Alternatively, I could publish it as a separate package aimed for Node users. So you'd have Looking further ahead, maybe it would make sense to have a dedicated, separate polyfill for Node? Instead of tracking the reference implementation, it could track the Node implementation instead. It could also polyfill the adapters between WHATWG streams an Node streams that were added in nodejs/node#39134. 🤔 |
This had me concerned... what if two packages use different version of the stream polyfill or one includes the cjs and another includes the esm? node-fetch uses one version and the developer who use node-fetch uses something else...? and one other use usually when you do something on your own internally then it's fine to use the same version but when you expose public api's that uses whatwg streams between different packages then it becomes a problem with interchangeable streams
yea, that seems to be the issue here
I would want to see the implementation of |
For simplicity, we currently require all streams to be from the exact same version of the polyfill. If we want to allow streams from "foreign" polyfill versions, it has to be a conscious decision and we have to be very clear what is allowed and what isn't. I'm not opposed to the idea, but it's gonna be more work to get right. For example: with cases like #75, For CJS/ESM, we could use the ES module wrapper approach for dual packages. But yeah, that doesn't really help for different versions installed in different parts of the dependency tree.
That would be the nicer solution. However, the behavior of Also, I don't know if the Streams standard will ever have |
I think wrapper approach could solve the same instanceof part if you just use a ES module wrapper, but it would require you to switch all import to require everywhere else... (and only use import in the wrappers files) seems like a unappealing approach but something that could work, really the only thing that changes about a wrapper approach is how you load the files. it would seem like the best option is to provide one variant that is compiled to old syntax (combined with ES wrapper) even if it means that a file becomes larger. but at least you will get rid of more foreign streams. the bad part about wrappers is that they don't really work in browser cuz browser don't support commonjs Cool, now i learned that there is a easy way to convert node streams with |
Could you provide a semi public/private method/backdoor into the streams internals that allows you to cancel the internal read between two different versions or something like that? 🤔 |
I would configure TypeScript with
I agree, there's just too many of them... I can probably remove and/or merge a few without too much worries, but I don't know if it'll be enough. 😕
Yup! Very cool stuff. 😁
That just means that the stream internals also become part of the public API... 😛 It would make backward and forward compatibility more difficult. |
That would probably be best. hope you didn't miss my update about browser not being able to unwrap esm wrappers... FYI. https://jspm.dev/ is a awesome CDN tools that allows you to load any npm/cjs module in Deno/browser without much hassle. clearly more superior than jsdeliver or cdnjs or any other. it converts the file for you to ESM
it would be a undocumented public api starting with I just learned a cool hack from NodeJS that goes something like this: class Headers {
#headers = []
static getRawHeaders(headers) {
const result = {};
for (const { 0: key, 1: values } of headers.#headers.entries()) {
...
}
return result;
}
}
// backdoor
const private_method_shared_internally_in_core = getRawHeaders
delete Headers.getRawHeaders |
Speaking of tracking NodeJS implementation Maybe that would be a good place to put it...? |
What is your thought process on ditching cjs entirely? Many developers have already ditched cjs and switched to ...we decided to ditch cjs in node-fetch@3, fetch-blob@3, formdata-polyfill, native-file-system-adapter and put the lowest targeted node support to 12.20 in package.json. and smashed in type=module sindresorhus is converting all of his 1k packages to esm sindresorhus/meta#15 webtorrent and all sub packages is about to as soon as the test framework they use gets unblocked and starts to support esm |
That's also a possibility. I'm thinking:
This will be quite the breaking change. I should probably start a |
Feel free to close this if you want. Would love to see some new (meta) issue, milestone or just a draft PR about what is coming next in v4 so i can stay in the loop and what's being worked on :) |
Not sure yet. I would like to (finally) tackle #20, but I'm afraid it might take too long and people might get annoyed about being stuck on v4.0.0-beta.1 for ages. 😛 So I might just release v4.0.0 as-is (save for a few fixes) and leave #20 for a v5.0.0. 🤷 For now, there's just the v4.0.0 milestone. If I have a more concrete plan, I'll make sure to put a new issue under that milestone. 😉 |
woho! Have long been waiting for #20 🙂 |
@jimmywarting You probably already moved on from |
Do you think you can reduce the bundle by a magnitude?
node-fetch/node-fetch#1217
We have always been hesitated to include this package cuz of its size... We also would never thought NodeJS would ship whatwg streams that it would become useful. but it looks like we are in a area where ppl demand more spec'ed cross compatible code across Deno, NodeJS and Browsers instead
There is a ambition to get whatwg streams into node-fetch body as well. (b/c NodeJS started to support whatwg streams) (planed for v4)
The text was updated successfully, but these errors were encountered: