MoonBit DTS Normalization
Use this skill when changing how MoonBit-generated .d.ts files are
rewritten into clearer TypeScript declarations.
Scope
This is intentionally narrow.
- It targets MoonBit-generated
.d.ts. - It mainly rewrites the
import type * as MoonBit from "./moonbit.d.ts"alias layer. - It is a readability pass, not a general-purpose
.d.tspretty-printer. - Public CLI surface:
mbt2ts normalize <ts> [out]. The library entry ispub async fn emit_typescript_declinsrc/main.mbt.
Start here
Read these files first:
src/bridge/typescript_decl.mbt— the normalization rewritersrc/bridge/typescript_decl_wbtest.mbt— fixture-based testssrc/main.mbt— theemit_typescript_decllibrary entrysrc/main_wbtest.mbt— end-to-end "MoonBit-generated d.ts in, normalized d.ts out" testssrc/cmd/mbt2ts/main.mbt— dispatcher arm fornormalize
If the companion plugin repo exists, also read:
/tmp/vite-plugin-moonbit-worktree/src/index.ts/tmp/vite-plugin-moonbit-worktree/test/normalized-dts.test.mjs/tmp/vite-plugin-moonbit-worktree/README.md
UX rules
normalizedDtsis experimental. Keep that explicit in docs and logs.- If the plugin skips normalization, it should say why.
- If the plugin reuses
tsBridge.generatorRoot, that should stay visible to the user. - Document the manual fallback command for workflows that call
moon builddirectly. - The CLI invocation is
moon run src/cmd/mbt2ts -- normalize <ts>— not the oldnormalize-moonbit-dtsverb.
Validation
In this repo:
moon check --deny-warn
moon test --target native
moon test --target native -p mizchi/ts/bridge --filter typescript_decl
moon fmt
In the companion plugin repo when present:
pnpm exec tsc --noEmit
pnpm test