Skip to content

fix(ckb-debugger): lazy-load WASI module to suppress ExperimentalWarning#407

Merged
RetricSu merged 2 commits intodevelopfrom
fix-wasi-warning
Mar 13, 2026
Merged

fix(ckb-debugger): lazy-load WASI module to suppress ExperimentalWarning#407
RetricSu merged 2 commits intodevelopfrom
fix-wasi-warning

Conversation

@RetricSu
Copy link
Collaborator

Summary

Fixes #405 - Non-debugger commands emit WASI ExperimentalWarning

Problem

The static import `import * as wasi from 'node:wasi'` in `src/tools/ckb-debugger-wasm.ts` was causing the WASI module to load at CLI startup, even for commands that don't use the debugger (like `offckb accounts` or `offckb config list`). This resulted in the unwanted warning:

```
(node:xxxx) ExperimentalWarning: WASI is an experimental feature and might change at any time
```

Solution

Convert the static import to a dynamic import with caching:

  1. Remove static import at module load time
  2. Add a static class property to cache the WASI module
  3. Add a private `getWasiModule()` method to load/cache the module
  4. Update `run()` method to use the dynamically imported module

The WASI module is now only loaded when debugger functionality is actually executed.

Changes

  • Modified: `src/tools/ckb-debugger-wasm.ts` (+14, -2)

Verification

Tested the following commands:

  • ✅ `offckb accounts` - No WASI warning
  • ✅ `offckb config list` - No WASI warning
  • ✅ `offckb debugger --help` - Works correctly (WASI loads when needed)
  • ✅ TypeScript compilation passes
  • ✅ Build succeeds
  • ✅ Existing tests pass (27 passed, 7 skipped)

Type Safety

The implementation maintains proper TypeScript typing using `typeof import('node:wasi')` for the dynamic import cache.

Convert static import of node:wasi to dynamic import with caching.
This prevents the ExperimentalWarning from being emitted when running
non-debugger commands like 'offckb accounts' or 'offckb config list'.

The WASI module is now only loaded when debugger functionality is
actually executed.

Fixes #405
@github-actions
Copy link

github-actions bot commented Mar 13, 2026

✅ Changeset file detected.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses CLI noise by preventing node:wasi from being loaded during startup for non-debugger commands, eliminating the WASI ExperimentalWarning unless the WASM debugger is actually executed.

Changes:

  • Replaced the static node:wasi import with a cached dynamic import inside CkbDebuggerWasi.
  • Updated the WASI host instantiation to use the lazily loaded module.
  • Added a changeset documenting the patch release.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/tools/ckb-debugger-wasm.ts Lazy-loads node:wasi via a cached dynamic import and updates WASI host creation accordingly.
.changeset/lazy-wasi-warning.md Adds a patch changeset describing the warning suppression fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

try {
CkbDebuggerWasi.wasiModule = await import('node:wasi');
} catch (error) {
throw new Error('Failed to load WASI module. Node.js >= 20.0.0 is required for WASM debugger support.');
@RetricSu RetricSu merged commit e90cfe5 into develop Mar 13, 2026
7 checks passed
@RetricSu RetricSu deleted the fix-wasi-warning branch March 13, 2026 06:18
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.

Non-debugger commands emit WASI ExperimentalWarning

2 participants