Skip to content

Conversation

@MicBun
Copy link
Member

@MicBun MicBun commented Sep 18, 2025

resolves: https://github.com/trufnetwork/truf-network/issues/1205

Summary by CodeRabbit

  • New Features

    • Publish native ES Module artifacts alongside CommonJS with distinct entry points and side-effects-free packaging.
    • Re-export EnvironmentType from the top-level public API.
  • Chores

    • Updated build/publish workflow and packaging scripts to produce dual outputs and type-checked ESM build.
    • Added ESM build configuration and updated package manifest to expose ESM entry.
    • Updated .gitignore to exclude ESM build artifacts.

@MicBun MicBun self-assigned this Sep 18, 2025
@coderabbitai
Copy link

coderabbitai bot commented Sep 18, 2025

Walkthrough

Adds an ES module build and packaging surface: ignore /dist-esm; package.json gains module, sideEffects, exports, updated files, and revised build/pack/type-check scripts; adds tsconfig.esm.json to emit ESM output to ./dist-esm; top-level export list now re-exports EnvironmentType.

Changes

Cohort / File(s) Summary of Changes
Git ignore updates
./.gitignore
Added ignore entry for /dist-esm; existing /dist entry unchanged.
Package metadata, files, and scripts
./package.json
Added root "module": "./dist-esm/index.js" and "sideEffects": false; added "exports" mapping: ".": { "import":"./dist-esm/index.js","require":"./dist/index.js","types":"./dist/index.d.ts" } and "./package.json":"./package.json"; updated "files" to include dist-esm/**/*.js, dist-esm/**/*.d.ts, dist-esm/package.json and exclude !dist-esm/**/*.map; changed scripts: clean removes both dist/* and dist-esm/*; build runs tsc then tsc -p tsconfig.esm.json and writes dist-esm/package.json with {"type":"module"}; added type-check:esm; removed pack_build; simplified pack_pre to only remove tarballs and pack now runs build → pack_pre → root pnpm packpack_post.
TypeScript ESM config
./tsconfig.esm.json
New TS config extending tsconfig.json targeting ESM: target = ES2021, module = ES2020, moduleResolution = node, outDir = ./dist-esm, rootDir = ./src, lib = ["DOM","DOM.Iterable","ES2020"]; disables declarations/source maps and excludes JSON resolution; includes src/**/*.ts.
Public API export update
./src/index.ts
Re-exported EnvironmentType from the top-level module: export list updated to include EnvironmentType.

Sequence Diagram(s)

sequenceDiagram
  participant App as Consumer
  participant Resolver as Platform resolver
  participant Package as @trufnetwork/sdk-js
  note over Package: package.json exposes "exports" and "module"
  App->>Resolver: import { X } from '@trufnetwork/sdk-js'
  alt ESM import resolution
    Resolver->>Package: resolve "import"
    Note right of Package #DFF7DF: returns ./dist-esm/index.js (ESM)
    Resolver-->>App: ./dist-esm/index.js
  else CommonJS require
    Resolver->>Package: resolve "require"
    Note right of Package #F0F0F0: returns ./dist/index.js (CJS)
    Resolver-->>App: ./dist/index.js
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I hop where modules split and play,
dist-esm whispers, CJS holds sway.
package.json hums a tidy tune,
builds produce two moons by noon.
Rabbit nods — the publish path is new. 🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "chore: add ES module support for browser compatibility" accurately and succinctly describes the primary change in this PR: adding ESM outputs and package metadata to support browser/ES module consumers (package.json exports/module, tsconfig.esm.json, build changes, and dist-esm artifacts). It is concise, specific, and aligned with the PR objectives and referenced issue. The chore prefix appropriately signals this is a repository/tooling change rather than a feature API change.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ESMSupport

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@holdex
Copy link

holdex bot commented Sep 18, 2025

Time Submission Status

Member Status Time Action Last Update
MicBun ✅ Submitted 4h Update time Sep 18, 2025, 1:00 PM
@outerlook ❌ Missing - ⚠️ Submit time -

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (3)
tsconfig.esm.json (1)

4-7: Prefer Node16/NodeNext resolution for ESM-aware builds

With TypeScript 4.9, moduleResolution: "node16" (or "nodenext") improves resolution for packages with exports. This can reduce edge-case resolution issues when targeting ESM.

Apply this diff:

-    "module": "ES2020",
-    "target": "ES2020",
-    "moduleResolution": "node",
+    "module": "ES2020",
+    "target": "ES2020",
+    "moduleResolution": "node16",
package.json (2)

31-46: Pack flow doesn’t build/publish ESM outputs

pack uses pack_build which only builds dist. If you rely on pnpm run pack for release validation, it should also build dist-esm (or reuse build).

Apply this diff:

-    "pack_build": "pnpm run clean && tsc --outDir ./dist --sourceMap false --declarationDir ./dist",
+    "pack_build": "pnpm run build",

1-98: Optional: help bundlers and tree‑shaking

Consider adding:

  • "sideEffects": false if the package has no top-level side effects.
  • A default condition in exports for older tooling fallbacks.

Example:

   "exports": {
     ".": {
       "import": "./dist-esm/index.js",
       "require": "./dist/index.js",
       "types": "./dist/index.d.ts"
     }
   },
+  "sideEffects": false,
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ffabc8 and d8135ce.

📒 Files selected for processing (3)
  • .gitignore (1 hunks)
  • package.json (1 hunks)
  • tsconfig.esm.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (3)
.gitignore (1)

11-11: LGTM: ignore dist-esm artifacts

Adding /dist-esm mirrors the existing /dist rule and keeps build outputs out of VCS. No issues.

package.json (2)

8-14: Export map looks good — confirm no historical deep imports

Only "." is exported in package.json (exports section); that will break consumers that deep-import internals (e.g., @trufnetwork/kwil-js/dist/...). I ran the suggested ripgrep scan in this repo and it returned no matches. Absence of matches is not conclusive — verify downstream consumers, examples/docs/CI and any published packages for deep imports. Command to run locally: rg -n "@trufnetwork/kwil-js/" -S || true


76-83: Sanity-check CJS build for ESM-only dep (ethers v6)

package.json publishes a CJS entry (main: ./dist/index.js, exports.require -> ./dist/index.js) but there is no dist/ build in this branch so I couldn't inspect the compiled CJS. Build the package and search the CJS output for require('ethers'); if any require('ethers') exist, switch those to dynamic import() or ship ESM-only to avoid runtime errors with ethers v6.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (2)
tsconfig.esm.json (1)

8-11: ESM config looks good; browser libs and no maps.

You added DOM libs and disabled maps; aligns with browser ESM output. This addresses the prior comment about adding browser libs and removing invalid declarationDir.

package.json (1)

6-14: Exports map for dual CJS/ESM LGTM.

Top-level “module” and conditional “exports” for import/require/types are set correctly for bundlers and Node.

🧹 Nitpick comments (8)
tsconfig.esm.json (2)

3-11: Prefer bundler-friendly resolution and stable ESM semantics.

For browser toolchains, use moduleResolution "bundler" and enable verbatimModuleSyntax to avoid TS inserting CJS interop and to align with ESM packages.

Apply:

   "compilerOptions": {
-    "module": "ES2020",
-    "target": "ES2020",
-    "moduleResolution": "node",
+    "module": "ES2020",
+    "target": "ES2020",
+    "moduleResolution": "bundler",
     "outDir": "./dist-esm",
     "lib": ["DOM", "ES2020"],
     "declaration": true,
+    "verbatimModuleSyntax": true,
     "declarationMap": false,
     "sourceMap": false
   }

8-11: Avoid duplicate .d.ts outputs or repoint “types”.

You emit declarations for both CJS (dist) and ESM (dist-esm) but the package “types” points to dist/index.d.ts. Either disable ESM declarations or repoint “types” to dist-esm. Pick one to reduce confusion/size.

Option A (disable ESM .d.ts):

-    "declaration": true,
+    "declaration": false,

Option B (keep ESM .d.ts): update package.json “types” and exports.types to dist-esm (see package.json comment).

package.json (6)

19-29: Avoid publishing unnecessary sources and duplicated .d.ts.

Consider dropping dist//*.ts and dist-esm//.d.ts (if “types” points to dist/) to keep the tarball lean.

   "files": [
     "dist/**/*.js",
-    "dist/**/*.ts",
     "dist-esm/**/*.js",
-    "dist-esm/**/*.d.ts",
     "dist-esm/package.json",

If you keep ESM declarations (tsconfig.esm.json), also repoint “types”/exports.types to dist-esm instead (see below).


33-36: Make postbuild cross‑platform and idempotent.

echo with quotes can break on Windows shells. Use Node to write dist-esm/package.json.

-    "build": "pnpm run clean && tsc && tsc -p tsconfig.esm.json && echo '{\"type\":\"module\"}' > dist-esm/package.json",
+    "build": "pnpm run clean && tsc && tsc -p tsconfig.esm.json && node -e \"const fs=require('fs');fs.mkdirSync('dist-esm',{recursive:true});fs.writeFileSync('dist-esm/package.json','{\\\"type\\\":\\\"module\\\"}\\n');\"",

6-13: If keeping ESM .d.ts, align the “types” entry.

If tsconfig.esm.json continues to emit declarations, point “types” and exports.types at dist-esm to match the ESM import path and reduce mismatches.

-  "types": "./dist/index.d.ts",
+  "types": "./dist-esm/index.d.ts",
   "exports": {
     ".": {
       "import": "./dist-esm/index.js",
       "require": "./dist/index.js",
-      "types": "./dist/index.d.ts"
+      "types": "./dist-esm/index.d.ts"
     }
   },

8-14: Expose package.json via exports for tooling.

Small DX win for bundlers and analyzers.

   "exports": {
     ".": {
       "import": "./dist-esm/index.js",
       "require": "./dist/index.js",
       "types": "./dist/index.d.ts"
     }
+    ,"./package.json": "./package.json"
   },

33-48: Add an ESM type‑check script and CI guard.

Ensure the ESM build type‑checks with DOM libs (tsconfig.esm.json).

   "scripts": {
     "clean": "rimraf dist/* dist-esm/*",
     "build": "pnpm run clean && tsc && tsc -p tsconfig.esm.json && echo '{\"type\":\"module\"}' > dist-esm/package.json",
+    "type-check:esm": "tsc -p tsconfig.esm.json --noEmit",

Consider running both type-check and type-check:esm in CI.


1-14: Optional: add “sideEffects”: false for better tree‑shaking.

If modules are pure on import, mark as side-effect free.

 {
   "name": "@trufnetwork/kwil-js",
   "version": "0.9.5",
   "description": "",
   "main": "./dist/index.js",
   "module": "./dist-esm/index.js",
+  "sideEffects": false,
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d8135ce and 8e983ad.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • tsconfig.esm.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (3)
package.json (3)

6-14: Optional: add “browser” hint.

If any Node shims are used, a browser field can aid bundlers.

   "main": "./dist/index.js",
   "module": "./dist-esm/index.js",
+  "browser": "./dist-esm/index.js",

Verify this doesn’t break Node resolution in your consumers.


6-14: Confirm: TypeScript resolves the "types" condition in package.json "exports" (since v4.7).
TypeScript added support in v4.7 and matches the "types" (and "default") conditions; your top-level "types" fallback covers pre-4.7 consumers — no change required.


78-85: Risk: CJS entry (./dist/index.js) vs ESM-only dependency (ethers v6) — verify build

package.json exposes exports.require -> ./dist/index.js and dependencies include "ethers": "^6.9.1" (ethers v6 is ESM‑only). The repo has no dist/ so I could not run the require() runtime check.

Action — reproduce and confirm:

  • Build the CJS bundle: pnpm run pack_build
  • Run the runtime check:
node -e "try{require('./dist/index.js');console.log('CJS ok')}catch(e){console.error('CJS failed:',e.message);process.exit(1)}"

If the check fails because ethers is ESM‑only, choose one: remove/publish only ESM (drop the require export), or make the CJS entry lazy-load ethers with dynamic import('ethers') behind a function boundary, or provide an ESM wrapper instead of a CJS require.

@MicBun MicBun marked this pull request as draft September 18, 2025 06:07
@MicBun MicBun marked this pull request as ready for review September 18, 2025 06:15
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
tsconfig.esm.json (3)

3-11: Use NodeNext resolution for ESM correctness.

With TS 4.9, pairing "module": "NodeNext" and "moduleResolution": "NodeNext" aligns type resolution with package "exports"/conditional types and prevents subtle ESM/CJS resolver mismatches.

-    "target": "ES2021",
-    "module": "ES2020",
+    "target": "ES2021",
+    "module": "NodeNext",
     ...
-    "moduleResolution": "node",
+    "moduleResolution": "NodeNext",

12-12: Add DOM.Iterable for browser iterables.

Enables proper typing for Headers/FormData/URLSearchParams iteration in browsers.

-    "lib": ["DOM", "ES2020"],
+    "lib": ["DOM", "DOM.Iterable", "ES2020"],

6-7: Minor: redundant flag.

allowSyntheticDefaultImports is implied when esModuleInterop is true; you can drop it.

-    "esModuleInterop": true,
+    "esModuleInterop": true,
     ...
-    "allowSyntheticDefaultImports": true

Also applies to: 17-17

package.json (1)

9-16: Exports map looks good; consider broader compatibility.

The dual export for import/require + types is correct. Optionally add a "default" condition as a safe fallback.

     ".": {
+      "default": "./dist-esm/index.js",
       "import": "./dist-esm/index.js",
       "require": "./dist/index.js",
       "types": "./dist/index.d.ts"
     },
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e983ad and 3333f2b.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • tsconfig.esm.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (5)
tsconfig.esm.json (2)

13-14: Confirm intentional: no .d.ts from ESM build.

declaration: false means consumers get types only from CJS (dist/index.d.ts). Fine if surfaces are identical; otherwise types may drift.

Please confirm your base build emits up-to-date dist/index.d.ts and matches the ESM entry points.


19-27: Broaden/DRY the ESM include (avoid missing ESM artifacts)

Extend the base tsconfig and replace the hard-coded include list with a recursive glob so all source files (e.g., BrowserTNClient) are included; repo search returned no matches for BrowserTNClient — cannot verify automatically.

+{
+  "extends": "./tsconfig.json",
   "compilerOptions": {
     "rootDir": "./src",
     "outDir": "./dist-esm",
     ...
   },
-  "include": [
-    "src/index.ts",
-    "src/core/*.ts",
-    "src/funder/abi/*.ts",
-    "src/funder/*.ts",
-    "src/client/kwil.ts",
-    "src/api_client/config.ts",
-    "src/utils/*.ts"
-  ]
+  "include": ["src/**/*.ts"]
 }

Confirm BrowserTNClient exists in the repo and that tsconfig.esm.json change will include it.

package.json (3)

35-37: LGTM on emitting dist-esm/package.json.

Creating { "type": "module" } in dist-esm avoids Node treating ESM .js as CJS.


8-8: Verify sideEffects: false won't drop required top-level initialization

Quick grep for 'register|init|polyfill' in src/ returned no matches; scan is not exhaustive.

  • Confirm package.json entry points (main/module/exports) and entry files (index.js, src/index.ts) do not rely on top-level side-effectful imports (polyfills, shims, registrations).
  • If unsure, run a broader repo search: rg -nP '\b(polyfill|register|init|shim|patch|setup)\b' -S -C2.

1-16: Optional: add a smoke-test to catch the original browser import error.

Add a CI job that builds the ESM bundle, packs the package, and runs a minimal Vite/Webpack import of BrowserTNClient to prevent regressions like “Class extends value undefined”.

Findings: package.json exports point to ./dist-esm/index.js (import) and ./dist/index.js (require); dist and dist-esm are not present in the repo and no BrowserTNClient symbol was found — unable to run smoke locally; CI should run this against the packaged build.

@MicBun MicBun marked this pull request as draft September 18, 2025 11:49
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
package.json (1)

42-46: Pack script omits ESM artifacts — pnpm --prefix ./dist pack packs from ./dist and excludes ./dist-esm.

This will publish a tarball without the ESM build, undermining the PR goal.

Proposed fix: pack from repo root (uses root "files" list) and reuse the existing build:

-    "pack_build": "pnpm run clean && tsc --outDir ./dist --sourceMap false --declarationDir ./dist",
-    "pack_pre": "copyfiles package.json README.md dist && rimraf ./kwil*.tgz",
+    "pack_build": "pnpm run build",
+    "pack_pre": "rimraf ./kwil*.tgz",
-    "pack": "pnpm run pack_build && pnpm run pack_pre && pnpm --prefix ./dist pack && pnpm run pack_post",
+    "pack": "pnpm run pack_build && pnpm run pack_pre && pnpm pack && pnpm run pack_post",
♻️ Duplicate comments (1)
tsconfig.esm.json (1)

11-11: Remove invalid declarationDir: null (TS config error).

declarationDir must be a string path. With declarations disabled it should be omitted.

   "declaration": false,
-  "declarationDir": null,
   "declarationMap": false,
🧹 Nitpick comments (3)
tsconfig.esm.json (2)

10-14: Clarify ESM declaration strategy.

ESM build disables declarations while package.json publishes dist-esm/**/*.d.ts. Either:

  • keep a single type source (CJS) and drop ESM .d.ts from files, or
  • emit ESM .d.ts too (set declaration: true and declarationDir: "./dist-esm").

Which do you intend?


5-6: Optional: consider moduleResolution: "Bundler" when upgrading to TS ≥5.

Helps browser/bundler ESM resolution (optional future tweak). Current NodeNext is fine with TS 4.9.

package.json (1)

21-31: Files list vs emitted artifacts.

You include dist-esm/**/*.d.ts but ESM declarations are not emitted. Either remove that line or enable ESM declarations (see tsconfig comment).

-    "dist-esm/**/*.d.ts",
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3333f2b and 434f927.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • tsconfig.esm.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (4)
package.json (4)

9-16: Exports map looks good for dual CJS/ESM.

Please confirm no consumers rely on deep imports, since only “.” and “./package.json” are exported.


36-39: LGTM on ESM marker generation.

Creating dist-esm/package.json with { "type": "module" } is the right call.


8-8: Double-check side-effect safety.

"sideEffects": false enables tree‑shaking. Verify no modules rely on side effects (polyfills, global patches, CSS-in-JS auto‑injection, etc.).


81-88: Verify CommonJS entry won't require() ESM-only deps (uuid, lru-cache)

  • Evidence: code imports 'uuid' (src/utils/uuid.ts) and 'lru-cache' (src/client/kwil.ts); npm metadata shows lru-cache and uuid publish with "type":"module" while ethers v6 still exposes a CJS fallback.
  • If you must support CommonJS: ensure exports.require (./dist/index.js) does not require() ESM-only entrypoints — options: dynamic import(), createRequire(), consume a package-provided CJS 'require' export, or publish ESM‑only and drop CJS.
  • Verify now by inspecting each dependency's package.json 'exports' for a 'require' target or by running Node to require your built ./dist/index.js in a pure CommonJS environment.

@MicBun MicBun marked this pull request as ready for review September 18, 2025 11:55
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
tsconfig.esm.json (1)

11-11: Remove invalid compiler option: declarationDir: null.

TypeScript expects a string path; null can break tsc even when declarations are disabled.

Apply:

     "declaration": false,
-    "declarationDir": null,
     "declarationMap": false,
🧹 Nitpick comments (4)
tsconfig.esm.json (2)

5-6: Use NodeNext/Node16 resolution for ESM-aware dependency typing.

moduleResolution: "node" can mis-resolve packages with "exports" (e.g., ethers v6). Prefer "nodenext" (TS 4.9 supports it).

-    "moduleResolution": "node",
+    "moduleResolution": "nodenext",

4-4: Align libs with target.

Target is ES2021 but libs pin ES2020; bump to keep type surface consistent.

-    "target": "ES2021",
-    ...
-    "lib": ["DOM", "DOM.Iterable", "ES2020"],
+    "target": "ES2021",
+    ...
+    "lib": ["DOM", "DOM.Iterable", "ES2021"],

Also applies to: 9-9

package.json (2)

9-16: Add "browser" export condition.

Helps bundlers prefer the ESM build in web targets.

   "exports": {
     ".": {
+      "browser": "./dist-esm/index.js",
       "import": "./dist-esm/index.js",
       "require": "./dist/index.js",
       "types": "./dist/index.d.ts"
     },
     "./package.json": "./package.json"
   },

21-27: Prune unused ESM .d.ts glob.

ESM build doesn’t emit declarations; keep the publish list lean.

   "files": [
     "dist/**/*.js",
     "dist/**/*.d.ts",
     "dist-esm/**/*.js",
-    "dist-esm/**/*.d.ts",
     "dist-esm/package.json",
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 434f927 and 478bcea.

📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/index.ts (1 hunks)
  • tsconfig.esm.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (1)
src/index.ts (1)

98-98: Good addition: re‑export EnvironmentType at top level.

This improves DX for browser users. Confirm it’s included in the public API docs/changelog for 0.9.x.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
package.json (1)

23-26: Types and ESM files correctly included in publish

Including dist/**/*.d.ts and dist-esm/** (with dist-esm/package.json) addresses missing typings and ESM markers noted earlier. Looks good.

Also applies to: 30-30

🧹 Nitpick comments (2)
package.json (2)

9-16: Enabling exports can break deep imports

Consumers using deep paths (e.g., @trufnetwork/kwil-js/some/internal) will now resolve only "." and "./package.json". Consider documenting this as a breaking change, or add explicit subpath exports if you support them.


42-46: Pack from repo root fixed; remove unused pack_build script

Packing via pnpm pack at repo root solves the prior bad tarball issue. pack_build now appears unused; drop it to avoid confusion.

Apply this minimal clean-up:

   "scripts": {
-    "pack_build": "pnpm run clean && tsc --outDir ./dist --sourceMap false --declarationDir ./dist",
     "pack_pre": "rimraf ./kwil*.tgz",
     "pack_post": "copyfiles ./kwil*.tgz ./pkg && rimraf ./kwil*.tgz",
     "pack": "pnpm run build && pnpm run pack_pre && pnpm pack && pnpm run pack_post",
   }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 478bcea and 621ea0a.

📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/index.ts (1 hunks)
  • tsconfig.esm.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/index.ts
  • tsconfig.esm.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (4)
package.json (4)

6-6: Keep module for bundlers; exports now drives resolution

Adding "module": "./dist-esm/index.js" is fine for legacy bundlers, but Node will use "exports". No change requested.


36-39: Build flow LGTM; ESM marker generation is correct

Dual tsc builds plus writing dist-esm/package.json ensures Node treats ESM as such. No change requested.


9-16: CJS export may break — verify ./dist/index.js doesn't require ESM-only 'ethers'

package.json depends on ethers (^6.9.1) and many source files import 'ethers'; ./dist/ is missing so the compiled CJS output couldn't be inspected. If ./dist/index.js ends up calling require('ethers') consumers using require() will throw ERR_REQUIRE_ESM.

  • Fix options: ship ESM-only (remove exports["."].require), convert CJS build to use dynamic await import() for ESM-only deps, or dual-publish a CJS-compatible alternative/fallback.
  • Action: run the build and inspect ./dist/index.js for require('ethers') (or share the compiled CJS output) and update package.json exports accordingly.

8-8: Verify sideEffects: false is safe

Ensure no module relies on import-time side effects (polyfills, global/window/globalThis mutations, prototype patches, or process.env access/assignments); otherwise bundlers may tree‑shake necessary code. My scan couldn’t search files — run the following in the repo root and paste results:

#!/bin/bash
set -euo pipefail

echo "1) polyfills / runtime imports"
rg -n -S -C2 --hidden --glob '!node_modules/**' '(@babel\/polyfill|core-js|zone\.js|regenerator-runtime|polyfill)' . || true

echo "2) Object.defineProperty/assign on global/window/globalThis"
rg -n -S -C2 --hidden --glob '!node_modules/**' 'Object\.(defineProperty|assign)\s*\(\s*(globalThis|window|global)\b' . || true

echo "3) direct global assignments"
rg -n -S -C2 --hidden --glob '!node_modules/**' '(globalThis|window|global)\.[A-Za-z_$][A-Za-z0-9_$]*\s*=' . || true

echo "4) process.env usage"
rg -n -S -C2 --hidden --glob '!node_modules/**' 'process\.env' . || true

echo "5) prototype modifications"
rg -n -S -C2 --hidden --glob '!node_modules/**' '(Object|Array|String|Date|HTMLElement|Node)\.prototype' . || true

echo "6) package.json sideEffects:false"
rg -n --hidden --glob '!node_modules/**' '"sideEffects"\s*:\s*false' . || true

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
package.json (2)

21-31: files includes dist‑esm//*.d.ts but ESM build disables declarations**

Since tsconfig.esm.json sets "declaration": false, no .d.ts will be emitted under dist-esm. Keeping the glob is harmless but redundant. Either enable ESM declarations or remove the pattern to avoid confusion.

   "files": [
     "dist/**/*.js",
     "dist/**/*.d.ts",
     "dist-esm/**/*.js",
-    "dist-esm/**/*.d.ts",
     "dist-esm/package.json",

1-34: Consider publishConfig for scoped package visibility

Scoped packages default to restricted on npm. Add publishConfig to avoid accidental private publishes.

 {
   "name": "@trufnetwork/kwil-js",
   "version": "0.9.5",
+  "publishConfig": { "access": "public" },
   "description": "",
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 621ea0a and 1076c6e.

📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/index.ts (1 hunks)
  • tsconfig.esm.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • tsconfig.esm.json
  • src/index.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (4)
package.json (4)

42-45: Packing from repo root — good fix for dual export maps

This avoids the previous tarball path skew. LGTM.


5-16: Exports map looks correct for dual CJS/ESM; keep "module" for older bundlers

The import/require split with a root types pointer is solid. No changes needed here.

If you support TypeScript <4.7 consumers, consider adding typesVersions for safety. Want a snippet?


81-83: CJS export present; Ethers v6 is ESM‑only — CJS consumers will likely hit ERR_REQUIRE_ESM

package.json exports map "require" → ./dist/index.js while source has runtime imports of "ethers" (e.g., src/core/signature.ts, src/core/kwilSigner.ts, src/transaction/payloadTx.ts). dist/ is not present in the repo so the compiled CJS output couldn't be inspected; if dist/index.js contains a top‑level require('ethers') it will throw at runtime.

Options (choose one):

  • Publish ESM‑only: remove the CJS "main"/"require" export so consumers import the ESM build (dist‑esm).
  • Keep CJS but make the CJS entry a shim that does NOT top‑level require('ethers'') — lazy‑load via dynamic import(...) or proxy the API so CJS consumers don't require an ESM package synchronously.
  • Provide a CJS‑friendly shim that avoids requiring the ESM‑only dependency.

8-8: Don't keep "sideEffects": false while any packaged module has import-time side-effects — remove or whitelist them.

Scan found import-time side effects; action needed:

  • Paths with import-time side effects (representative):

    • testing-functions/test.js — top-level require('dotenv').config().
    • tests/** (e.g., tests/unitTests/.../validation.test.js, tests/unitTests/api_client/client.test.ts) — top-level dotenv imports and imports of ../dist/index.
    • test-eth-app/src/App.tsx, test-eth-app/src/main.tsx — side-effect CSS imports (import './App.css', import './index.css') and browser-only window.ethereum usage.
  • Fix options (pick one):

    • Ensure test/example files are excluded from the published package (npm "files" or .npmignore) and then keep "sideEffects": false.
    • Otherwise remove/move import-time effects (move dotenv.config() to test setup scripts, avoid top-level CSS or global mutations in library entrypoints).
    • Or explicitly list intentional side-effectful files in package.json "sideEffects".

Copy link
Contributor

@outerlook outerlook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@MicBun MicBun merged commit c669bb8 into main Sep 18, 2025
3 of 4 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Oct 6, 2025
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.

3 participants