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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: esm and cjs builds for node and browser #81

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

diegomura
Copy link

Hi @devongovett ! Hope you are doing good.

I'd like to start using foliojs packages again in react-pdf. I gradually moved away from them due to several reasons, among them because node deps in foliojs repos. This includes pdfkit and png-js.

Here's my fork. This is the same node entrypoint here but bundled with rollup to generate node and browser entrypoints. Node ones are just like the existing ones. For browser though, we remove fs dependency and ignore methods that use it, and replace zlib with browserify-zlib.

Not sure who's responsible of reviewing and publishing (I have merge rights here, but not publishing to npm) but this first step would be very helpful towards start unifying foliojs with react-pdf 馃槃

@diegomura diegomura self-assigned this Feb 7, 2024
"type": "module",
"main": "./lib/png-js.cjs",
"module": "./lib/png-js.js",
"browser": {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using non standard browser field, use nested conditions in exports field:
https://nodejs.org/api/packages.html#nested-conditions

IMO, for browser should have only import (es module)

This should be future proof.

Copy link
Author

@diegomura diegomura Feb 9, 2024

Choose a reason for hiding this comment

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

Sgtm! Thanks for the input @blikblum . Done in decd6ba

Copy link
Member

Choose a reason for hiding this comment

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

I think we might still need the browser field for backward compatibility though, eg for old tools that don't support exports. Otherwise we'll have to release this in a major version.

Copy link
Author

Choose a reason for hiding this comment

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

Done! I also wanted to remove Buffer usage in favor of Uint8Array (separately) if that sounds good for you guys. I think that should be breaking, but up to you 馃槃

@diegomura diegomura changed the title feat: move node file to src dir feat: esm and cjs builds for node and browser Feb 9, 2024
package.json Outdated
"import": "./lib/png-js.js",
"require": "./lib/png-js.cjs"
},
"default": "./lib/png-js.browser.js"
Copy link
Author

Choose a reason for hiding this comment

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

Will this need a "browser" path? If I understood node docs correctly node takes precedence over default, but it also mentions community conditions definitions which I guess are supported but not part of the standard

Copy link
Member

Choose a reason for hiding this comment

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

No. Browser takes the default

@diegomura
Copy link
Author

Thanks for the review @blikblum ! when can we expect to have this merged?

@blikblum
Copy link
Member

Need one more review

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.

None yet

3 participants