Switch to ESM and fix Node 18.13+ compatibility #259
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 asynchronousimport()
calls. Using asynchronousimport()
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 fromglobSource
to be named as if they existed in a single wrapping directory, I prefixedglobSource
'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 intoaegir 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: TheThis has been addressed.@filebase/client
library depends on an old fork ofipfs-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 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.