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

Explicit Node dependencies imports #7

Open
alexandercerutti opened this issue May 31, 2024 · 4 comments
Open

Explicit Node dependencies imports #7

alexandercerutti opened this issue May 31, 2024 · 4 comments

Comments

@alexandercerutti
Copy link

Hi @Conduitry, thanks for your work. I'm using for library on my project https://github.com/alexandercerutti/passkit-generator.

Someone in the issues was reporting me that do-not-zip seems to not be working on Cloudflare pages / workers, as that platform seems to have only a compatibility with Node.JS API. Also, they run ESM.

The "not working" seems to be only about the absence of explicit imports of Buffer.

I know that the last package update is dated over 5 year ago. So here I'm asking: would you be open to include a PR that adds this little change?

Let me know, and thank you again!

@Conduitry
Copy link
Owner

Hey! There are a number of things here that, were I writing this package today, I would probably do differently. The 'detect whether Blob exists as a global and either return a Blob or Buffer' thing seems, in hindsight, like a bad idea. I haven't checked all the implications of doing this, but what right now is sounding like a better idea is to just have a single exported function that returns a Uint8Array and then leave it to the consumer to convert that to a Buffer or to a Blob depending on their use case. How does that sound to you?

@Conduitry
Copy link
Owner

Also, in the meantime, if the issue for your users is Buffer as an implicit global, then I think you ought to be able to use this library's toArray and then call Buffer.from() on your end with Buffer appropriately imported. This would move you in the direction you would have to go anyway with my above proposal.

@alexandercerutti
Copy link
Author

Hey @Conduitry, first of all thanks for your reply!

I see what you mean, of course after 5 years you see things with a completely different eye!

I think you ought to be able to use this library's toArray and then call Buffer.from() on your end with Buffer appropriately imported

That is an interesting solution that could help to bypass everything. Thank you!

There are a number of things here that, were I writing this package today, I would probably do differently.

About this, I've also added Typescript definitions to DefinitelyTyped some years ago. Another thing to improve, could be to import them in here, in order to have just one source for typings.

The 'detect whether Blob exists as a global and either return a Blob or Buffer' thing seems, in hindsight, like a bad idea [...] a better idea is to just have a single exported function that returns a Uint8Array and then leave it to the consumer to convert that to a Buffer or to a Blob depending on their use case

I like this. Checking Blob to perform a choice is a poor choice to me either.
I think using a Uint8Array would be the best choice because, as you might already know, a Buffer is already an extension of Uint8Array in Node.

So, using a Uint8Array would give you an implicit support to all the JS runtimes and platforms out there that follow the standard (both Cloudflare workers / pages and Node included but not limited to).

Then, correct me if I'm wrong, if you would remove the check "Blob || Buffer", that would mean to deprecate and remove everything but toArray and either include it in the index.js, as it doesn't even make sense anymore to have a dedicated file.

@alexandercerutti
Copy link
Author

Is there anything I can do to help here? If you think I can help, I perhaps could setup a PR with the changes you said. Let me know :)

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

No branches or pull requests

2 participants