ipfs-shipyard / ipfs-deploy

Zero-Config CLI to Deploy Static Websites to IPFS
Other
1.15k stars 122 forks source link

Switch to ESM and fix Node 18.13+ compatibility #259

Open Macil opened 1 year ago

Macil commented 1 year ago

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 (https://github.com/ipfs/aegir/commit/e3a4b450c5eb271ae3557144d78636695751ce11), 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: https://github.com/filebase/filebase-js/issues/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.

Macil commented 1 year ago

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