js-ipfs icon indicating copy to clipboard operation
js-ipfs copied to clipboard

`ipfs-http-client` update exports field

Open leovigna opened this issue 3 years ago • 2 comments

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/

leovigna avatar Jul 23 '22 09:07 leovigna

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:

  • The context for this PR is clear, with relevant discussion, decisions and stakeholders linked/mentioned.

  • Your contribution itself is clear (code comments, self-review for the rest) and in its best form. Follow the code contribution guidelines if they apply.

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:

  • A maintainer will triage and assign priority to this PR, commenting on any missing things and potentially assigning a reviewer for high priority items.

  • The PR gets reviews, discussed and approvals as needed.

  • The PR is merged by maintainers when it has been approved and comments addressed.

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!

welcome[bot] avatar Jul 23 '22 09:07 welcome[bot]

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?

BigLep avatar Sep 02 '22 14:09 BigLep

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?

achingbrain avatar Sep 23 '22 14:09 achingbrain