ipfs / helia-verified-fetch

A fetch-like API for obtaining verified & trustless IPFS CIDs on the web
https://npmjs.com/package/@helia/verified-fetch
Other
11 stars 1 forks source link

feat: tree-shake ipfs-unixfs-importer #31

Open SgtPooki opened 3 months ago

SgtPooki commented 3 months ago

since we're not using any importing functionality in verified-fetch, we should make sure our resulting bundle does not include ipfs-unixfs-importer (or others.. which can be handled in separate issue)

running npm why ipfs-unixfs-importer in helia-service-worker-gateway shows the following:

ipfs-unixfs-importer@15.2.4
node_modules/ipfs-unixfs-importer
  ipfs-unixfs-importer@"^15.2.4" from @helia/unixfs@3.0.2
  node_modules/@helia/unixfs
    @helia/unixfs@"^3.0.1" from @helia/verified-fetch@1.3.0
    node_modules/@helia/verified-fetch
      @helia/verified-fetch@"^1.3.0" from the root project

Can we explicitly remove ipfs-unixfs-importer during esbuild, or do we need to modify @helia/unixfs to export a "getter only" version?

SgtPooki commented 3 months ago

with regular build:

╰─ ✔ ❯ npm run build -- -b

> @helia/verified-fetch@1.3.1 build
> aegir build -b

[10:41:55] tsc [started]
[10:41:56] tsc [completed]
[10:41:56] esbuild [started]
[10:41:56] → Use https://esbuild.github.io/analyze/ to load "./dist/stats.json".
[10:41:56] → 124.57KB (▼-7.43KB / 132KB)
[10:41:56] esbuild [completed]
image

with ipfs-unixfs-importer marked as external

╰─ ✔ ❯ npm run build -- -b

> @helia/verified-fetch@1.3.1 build
> aegir build -b

[10:44:25] tsc [started]
[10:44:26] tsc [completed]
[10:44:26] esbuild [started]
[10:44:27] → Use https://esbuild.github.io/analyze/ to load "./dist/stats.json".
[10:44:27] → 116.04KB (▼-15.96KB / 132KB)
[10:44:27] esbuild [completed]

.aegir.js changes:

diff --git a/packages/verified-fetch/.aegir.js b/packages/verified-fetch/.aegir.js
index 89b5633..cbd9809 100644
--- a/packages/verified-fetch/.aegir.js
+++ b/packages/verified-fetch/.aegir.js
@@ -1,8 +1,13 @@
 /** @type {import('aegir').PartialOptions} */
 const options = {
   build: {
-    bundlesizeMax: '132KB'
-  }
+    bundlesizeMax: '132KB',
+    config: {
+      external: [
+        'ipfs-unixfs-importer'
+      ],
+    }
+  },
 }

 export default options

Note that tests still pass with ipfs-unixfs-importer marked as external

SgtPooki commented 2 months ago

this will be resolved by #32 eventually