ipfs / js-ipfs

IPFS implementation in JavaScript
https://js.ipfs.tech
Other
7.44k stars 1.25k forks source link

`ipfs-http-client` update exports field #4165

Closed leovigna closed 2 years ago

leovigna commented 2 years ago

Add exports to ipfs-http-client

Description

Update the ipfs-http-client package.json to support importing relative paths for the bundled index.js and index.min.js code.

Proplem

I'm currently using an ESM-focused bundler (Vite) and importing the source ipfs-http-client code causes issues with polyfills. Importing the bundled version fixes this and the minified version enables further optimization. Currently vite imports the ./src/index.js file as that is what is specified byt the exports field. I have found a temporary solution in my project by manually resolving the package with path.resolve(node_modules/ipfs-http-client/index.js) but this is counter to using the regular node resolution algorithm.

Solution

By adding subpaths to the exports field, the node resolution algorithm will be able to import the bundle and minified bundled if the developer specifies it. Critically, default import behaviour is not changed. Bundle is imported only if the developer species the subpath import IPFS from 'ipfs-http-client/index.js'.

Additional Links

https://webpack.js.org/guides/package-exports/

welcome[bot] commented 2 years ago

Thank you for submitting this PR! A maintainer will be here shortly to review it. We are super grateful, but we are also overloaded! Help us by making sure that:

Getting other community members to do a review would be great help too on complex PRs (you can ask in the chats/forums). If you are unsure about something, just leave us a comment. Next steps:

We currently aim to provide initial feedback/triaging within two business days. Please keep an eye on any labelling actions, as these will indicate priorities and status of your contribution. We are very grateful for your contribution!

BigLep commented 2 years ago

2022-09-02 triave conversation: @leovigna : if we understand right, this is resulting from issues with polyfills. What are the issues with polyfills that you're encountering?

achingbrain commented 2 years ago

Thanks for opening this PR but I'm going to close it as it does not address the underlying issue:

I'm currently using an ESM-focused bundler (Vite) and importing the source ipfs-http-client code causes issues with polyfills.

Can you please open an issue with a small reproduction case that shows the issues you are having with polyfills?