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

Switch to ESM and fix Node 18.13+ compatibility #259

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

Conversation

Macil
Copy link

@Macil Macil commented Jan 29, 2023

Fixes #258.

In order to fix the Node compatibility issue, the ipfs-http-client dependency needed to be upgraded from v50.1.0 to v60.0.0. However, ipfs-http-client v57.0.0 went ESM only, so upgrading to it either requires upgrading this project to ESM, or for the require() calls to load the library to be replaced with asynchronous import() calls. Using asynchronous import() calls would require some of the public API to be awkwardly reworked, so instead I upgraded the project to ESM.

In ipfs-http-client v53.0.0, the globSource function had some subtle incompatible changes. One important difference is that the file paths returned by it no longer start with the upload directory's name but instead now start with "/" and are relative to the inside of the upload directory. In the places where we needed all of the results from globSource to be named as if they existed in a single wrapping directory, I prefixed globSource's results with an arbitrary directory name ("upload").

Proxyquire, which was used in the tests to replace some dependencies with mocks, isn't compatible with Node ESM, so I replaced it with esmock, which was practically a drop-in replacement.

Axios was upgraded from ^0.26.0 to ^1.2.6 because the older version had an issue preventing it from working with Typescript and ESM together.

Aegir was upgraded from ^33 to ^38 for ESM compatibility. Aegir has combined the aegir ts command into aegir lint (ipfs/aegir@e3a4b45), so package.json's scripts.lint value was simplified to just "aegir lint".

Remaining work

This PR makes the library ESM-only, which is a breaking change for anyone using it as a library through require() calls, so this change should cause a major version bump.

There is one incomplete part of this PR: The @filebase/client library depends on an old fork of ipfs-car which is not ESM compatible, so this PR currently disables support for the Filebase pinning service. (Reported: filebase/filebase-js#3.) Either the docs should be updated to remove Filebase from the list of supported pinning services, or the support should be fixed. This has been addressed.

This PR needs a bit more testing: I have tested this PR by uploading files to Infura and using the CloudFlare dns updater. The Pinata and IPFS Cluster pinning support were both impacted by the globSource changes so they ought to be tested by someone. Everything else in the PR is very straight-forward with less risk.

Fixes Node 19 compatibility issue.
@Macil Macil changed the title Switch to ESM and fix Node 19 compatibility Switch to ESM and fix Node 18.13+ compatibility Jan 29, 2023
Issue that lead to it being disabled has been fixed:
filebase/filebase-js#3
@Macil
Copy link
Author

Macil commented Feb 4, 2023

The Filebase client library issue was fixed (filebase/filebase-js#3) so it's been re-enabled in this PR.

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.

Broken in Node 18.13: "TypeError: RequestInit: duplex option is required when sending a body"
1 participant