Skip to content

refactor(sdk,wallet-lib,test-suite)!: convert dapi-client + wallet-lib + js-dash-sdk + platform-test-suite to ESM#3689

Draft
PastaPastaPasta wants to merge 5 commits into
v3.1-devfrom
claude/esm-3-esm-conversion
Draft

refactor(sdk,wallet-lib,test-suite)!: convert dapi-client + wallet-lib + js-dash-sdk + platform-test-suite to ESM#3689
PastaPastaPasta wants to merge 5 commits into
v3.1-devfrom
claude/esm-3-esm-conversion

Conversation

@PastaPastaPasta
Copy link
Copy Markdown
Member

Summary

Final PR in the ESM migration stack. Converts @dashevo/dapi-client, @dashevo/wallet-lib, dash (@dashevo/js-dash-sdk), and @dashevo/platform-test-suite to pure ESM. Removes the webpack/karma browser-bundle infrastructure across all four packages.

This is PR 3 of 3 (after the originally-stacked PRs 3/4/5 were merged into one — see note below). Depends on #3679 (cleanup) and #3680 (Uint8Array).

Note

Originally split into three stacked PRs (#3681 dapi-client, #3682 wallet-lib, #3683 js-dash-sdk+PTS), each on a separate branch. CI fails on any of them in isolation because the monorepo build compiles every package on every PR, and dapi-client-ESM + wallet-lib-CJS is an incompatible mid-state (CJS cannot require() ESM). Since they must land together regardless, they are combined here as a single PR with three commits preserved for review focus.

What changes

@dashevo/dapi-client (commit 1: refactor(dapi-client)!: convert to ESM, drop webpack/karma)

  • package.json: "type": "module", "exports": { ".": "./lib/index.js", "./lib/*": "./lib/*" }, drops main. The wildcard preserves deep-import paths.
  • All ~115 source files and ~80 test files converted from CJS require/module.exports to ESM import/export. Relative imports include .js extension.
  • events npm package moved devDeps → deps. Used for EventEmitter in DAPIClient, ReconnectableStream, BlockHeadersProvider. Works in both Node and browser bundlers.
  • Deletes webpack.config.js, karma.conf.js, lib/test/karma/. Removes all browser-polyfill devDeps (buffer, crypto-browserify, os-browserify, path-browserify, process, stream-browserify, string_decoder, url, util, webpack, webpack-cli, karma-*, babel-*).
  • .mocharc.yml uses require: for the ESM bootstrap with a defensive loadDpp.default ?? loadDpp unwrap.

@dashevo/wallet-lib (commit 2: refactor(wallet-lib)!: convert to ESM, consume ESM dapi-client)

  • package.json: "type": "module", engines.node >= 18.18. Drops build:web, test:browsers*, prepublishOnly. Removes all browser-polyfill devDeps. Removes deps winston, node-inspect-extracted.
  • All 350+ files in src/, fixtures/, and tests/ converted from CJS to ESM with .js extensions on relative imports.
  • src/logger/index.js rewritten as a console-backed logger (matching dapi-client's pattern from PR 1).
  • Deep imports of @dashevo/dapi-client updated to include .js extensions.
  • Deletes webpack.config.js, karma/, src/test/karma/.
  • .mocharc.yml uses require: for ESM bootstrap.

dash / @dashevo/js-dash-sdk (commit 3: refactor(js-dash-sdk,platform-test-suite)!: convert to ESM, consume ESM dapi-client and wallet-lib)

  • package.json: "type": "module", exports map, engines.node >= 18.18. Drops unpkg/browser, test:browsers*. Removes karma-*, webpack, browser polyfills, ts-mock-imports (replaced with an injectable seam).
  • tsconfig.build.json and tsconfig.json: module: nodenext, moduleResolution: nodenext, target: es2020.
  • All 54 .ts files get .js extensions on relative imports (NodeNext requirement).
  • Refactored src/SDK/Client/Platform/methods/names/register.ts to accept an injectable randomBytes parameter (replaces ts-mock-imports for the existing test seam).
  • Replaced winston with console-backed logger.
  • CJS-named-import fixes (import { X } from cjs-pkgimport pkg from cjs-pkg; const { X } = pkg;) for dashcore-lib, wasm-dpp, grpc-common, contract packages.
  • Added parallel import type { X as XType }; type X = XType; aliases in 22 .ts files where destructured value names are also used in type positions (TS2440 workaround under NodeNext).
  • Defensive (loadDpp.default ?? loadDpp)() unwrap in 4 sites.
  • Deletes webpack.config.js, webpack.base.config.js, karma/.

@dashevo/platform-test-suite (also in commit 3)

  • package.json: "type": "module", drops test:browsers, browser polyfills, karma-*.
  • All ~35 .js files converted to ESM.
  • lib/test/bootstrap.js rewritten as ESM with fileURLToPath-based __dirname.
  • .mocharc.yml uses import: for ESM root hooks.

Test plan

  • yarn workspace @dashevo/dapi-client run test:unit315 passing
  • yarn workspace @dashevo/wallet-lib run test:unit377 passing, 2 pending
  • yarn workspace dash run test:unit60 passing, 3 pre-existing pending
  • yarn workspace @dashevo/platform-test-suite run lint — ESM bootstrap loads ✅
  • platform-test-suite e2e tests require live testnet credentials in .env (pre-existing constraint).

Breaking changes

  • All four packages are ESM-only. Any require() of them no longer works.
  • Deep imports require .js extensions.
  • No prebuilt browser bundles. Consumers must use a modern bundler (Vite/esbuild/webpack 5).
  • js-dash-sdk's Platform.names.register(...) gained an optional trailing randomBytes parameter. Existing callers unaffected.
  • Drops winston, bs58, node-inspect-extracted from deps where unused.

Monorepo state after this lands

Stack

@github-actions github-actions Bot added this to the v3.1.0 milestone May 19, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 19, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f22cd12e-45b7-4f93-ad9f-d68fc11be420

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/esm-3-esm-conversion

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.

@github-actions
Copy link
Copy Markdown
Contributor

✅ DashSDKFFI.xcframework built for this PR.

SwiftPM (host the zip at a stable URL, then use):

.binaryTarget(
  name: "DashSDKFFI",
  url: "https://your.cdn.example/DashSDKFFI.xcframework.zip",
  checksum: "d3a03c5dce08347513332117f46aa8601083d05f64eaeb7f09bf9f4b62651ebf"
)

Xcode manual integration:

  • Download 'DashSDKFFI.xcframework' artifact from the run link above.
  • Drag it into your app target (Frameworks, Libraries & Embedded Content) and set Embed & Sign.
  • If using the Swift wrapper package, point its binaryTarget to the xcframework location or add the package and place the xcframework at the expected path.

@PastaPastaPasta PastaPastaPasta force-pushed the claude/esm-3-esm-conversion branch 2 times, most recently from 9dcc359 to 087ecec Compare May 19, 2026 23:53
…ton/fetch/promisify shims

Non-breaking cleanup pass; package stays CJS, no public API changes, no consumer changes required.

dapi-client: replace winston with a minimal console-backed logger that preserves the same API (.error/.warn/.info/.verbose/.debug/.silly/.getForId). Drop node-fetch and the lib/test/bootstrap setimmediate shim — Node 18+ has both globally. Drop the https.Agent self-signed-TLS branch from requestJsonRpc (was Node-only; consumers wanting this must configure NODE_TLS_REJECT_UNAUTHORIZED at the app layer). Inline lodash/sample in ListDAPIAddressProvider. Add engines.node >=18.18. Remove dependencies: winston, node-fetch, lodash, bs58 (unused), node-inspect-extracted (unused). Remove devDeps: setimmediate.

dapi-grpc: inline the promisify shim in core/v0/web/CorePromiseClient.js and platform/v0/web/PlatformPromiseClient.js so the browser bundle no longer requires Node's util module. Both files document the shim so a future codegen regen does not silently reintroduce require('util').
… API

Adds lib/utils/bytes.js helper (hexToBytes/bytesToHex/base64ToBytes/bytesToBase64/concatBytes/bytesEqual) and converts all Buffer.* call sites in dapi-client lib/ to Uint8Array, with corresponding test updates. Package stays CJS.

Production exceptions where Buffer is retained: BlockHeadersReader passes Buffer to dashcore-lib's BlockHeader (its BufferReader needs .readInt32LE), and GetIdentitiesContractKeysResponse passes Buffer to wasm-dpp's Identifier.from (it explicitly requires Node Buffer).

createGrpcTransportError now handles both raw bytes (grpc-js path) and base64 strings (grpc-web path) for drive-error-data-bin, stack-bin, and dash-serialized-consensus-error-bin metadata fields, restoring the dual-format behavior that Buffer.from(x, 'base64') used to provide implicitly.

Test updates: spec files that construct expected protobuf requests now wrap .toBuffer() with new Uint8Array(...) to match production's normalization (sinon calledOnceWithExactly distinguishes Buffer from plain Uint8Array).

Breaking change for direct consumers: response object byte fields are now Uint8Array. Callers that do response.field.toString('hex') will fail — use bytesToHex(response.field) from lib/utils/bytes instead. Buffer.isBuffer(response.field) now returns false; use response.field instanceof Uint8Array.

Test results: dapi-client 315/315, wallet-lib 377/377, js-dash-sdk 60/60 — downstream consumers continue passing without modification (they exercise dapi-client mostly via mocks).
Converts @dashevo/dapi-client to pure ESM: type: module, exports map with ./lib/* wildcard, all CJS require/module.exports replaced with import/export, .js extensions on relative imports. Engine bumped to >=18.18.

Drops webpack.config.js, karma.conf.js, and lib/test/karma/. Removes the @babel/core, babel-loader, browser-polyfill, karma, and webpack devDeps. Consumers must use a modern bundler (Vite/esbuild/webpack 5) which handles ESM natively.

Moves 'events' npm package from devDependencies to dependencies — used by DAPIClient, ReconnectableStream, and BlockHeadersProvider for EventEmitter, and resolves correctly in both Node and browser bundlers.

BREAKING: CJS consumers (require) no longer work. Downstream consumers wallet-lib (PR 4) and js-dash-sdk (PR 5) are temporarily broken between this PR merging and PRs 4/5 merging — they must land as a sequence. Dashmate is already ESM and continues to work.

Test results: dapi-client 315/315. wallet-lib + js-dash-sdk fail as expected (fixed by PRs 4 + 5).
Converts @dashevo/wallet-lib to pure ESM so it can consume the ESM dapi-client from PR 3. Adds 'type: module' to package.json. All src/, fixtures/, and tests/ files converted from CJS require/module.exports to ESM import/export with .js extensions on relative imports.

Deletes webpack.config.js, karma/, src/test/karma/. Removes browser-polyfill devDeps (buffer, crypto-browserify, stream-browserify, etc.) and webpack/karma. Tests run via Mocha in Node 18+; browser builds are out of scope. Engines: >=18.18.

CJS-named-import fixes: lodash, crypto-js, @dashevo/dashcore-lib, @dashevo/wasm-dpp, @dashevo/grpc-common all use default-import + destructure pattern because Node ESM cannot statically enumerate named exports of CJS modules.

Surfaces three previously-silent CJS bugs that ESM strict mode catches: missing UnknownStrategy export from errors/index.js, missing named exports for coinSelection strategies, and a 'type=' implicit-global in DerivableKeyChain.spec.js.

Defensive (loadDpp.default ?? loadDpp)() unwrap in IdentitySyncWorker.onStart for the same wasm-dpp NodeNext interop reason as PR 3's bootstrap.

Test results: wallet-lib 377/377 passing. dapi-client unchanged (315/315). js-dash-sdk still broken (PR 5 fixes).
…SM dapi-client and wallet-lib

Final PR in the ESM migration stack. Converts the two remaining workspace packages that consumed dapi-client/wallet-lib, restoring monorepo-wide green tests after PR 3.

js-dash-sdk: TypeScript-based package with NodeNext module resolution. Adds 'type: module' + exports map. tsconfig.build.json → module: nodenext, moduleResolution: nodenext, target: es2020. All .ts files get .js extensions on relative imports (TS NodeNext compiles .ts to .js but the import string must already say .js). Drops ts-mock-imports by refactoring register.ts to accept an injectable randomBytes parameter (ts-mock-imports relies on mutable module exports which ESM forbids). Deletes webpack/karma + browser polyfills. Replaces winston with console-backed logger. CJS-named-import conversions for @dashevo/dashcore-lib, @dashevo/wasm-dpp, @dashevo/grpc-common, and the system-id imports from contract packages. Adds parallel 'import type' aliases (via 'import type { X as XType }; type X = XType;') in 22 .ts files where destructured value names are also used as types — works around TS2440 namespace collision under NodeNext.

platform-test-suite: converted ~35 files from CJS to ESM. Test bootstrap converted; .mocharc.yml uses 'import:' for ESM root hooks.

Defensive (loadDpp.default ?? loadDpp)() unwrap in 4 sites (Platform.initializeDppModule, createIdentityFixtureInAccount, contracts/get.spec.ts, contracts/history.spec.ts). createGrpcTransportError-style dual-format byte handling preserved.

Test results: 752 passing across the monorepo (dapi-client 315, wallet-lib 377, js-dash-sdk 60). platform-test-suite is end-to-end and requires live testnet credentials in .env (pre-existing constraint).
@PastaPastaPasta PastaPastaPasta force-pushed the claude/esm-3-esm-conversion branch from 087ecec to d131469 Compare May 19, 2026 23:59
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.

1 participant