open-index/open-npm huggingface dataset:
npm package: @hiroyannnn/moonbit-ts-bridge
Description: Generate typed TypeScript bridges from MoonBit .mbti + JS exports
Latest version: 0.2.0

# moonbit-ts-bridge

Generate a typed TypeScript bridge from a MoonBit package interface (`pkg.generated.mbti`) + `moon.pkg.json` `link.js.exports`.

This is meant to be a small “stopgap” helper:
MoonBit already generates `.d.ts` files for JS targets, but in real projects it can still be convenient to have a single, ergonomic TS entrypoint that:

- Re-exports only the functions you explicitly export via `link.js.exports`
- Emits TS types for `pub struct` (so you can write `user.name` in TS)
- Provides TS-friendly `Result` wrappers (so you don’t have to touch `$tag/_0`)

## Install / run

After publishing, you can run via `npx`:

```sh
npx @hiroyannnn/moonbit-ts-bridge --help
```

## Usage

### Recommended (module root only)

```sh
moon info -C /path/to/moonbit-module
moon build -C /path/to/moonbit-module src/domain --target js --release

npx @hiroyannnn/moonbit-ts-bridge --module /path/to/moonbit-module --out backend/src/domain/moonbit_domain.ts
```

Defaults:
- `--package src/domain`
- `--target-dir target`
- release build (`target/js/release`)

### Advanced (explicit paths/imports)

```sh
npx @hiroyannnn/moonbit-ts-bridge \
  --mbti /path/to/moonbit-module/src/domain/pkg.generated.mbti \
  --pkg  /path/to/moonbit-module/src/domain/moon.pkg.json \
  --runtime-import "../../domain/moonbit/target/js/release/build/src/domain/domain.js" \
  --types-import   "../../domain/moonbit/target/js/release/build/src/domain/moonbit.d.ts" \
  --out backend/src/domain/moonbit_domain.ts
```

Notes:
- `--runtime-import` / `--types-import` are written verbatim into the generated TS file.
- Unknown MoonBit types are emitted as `unknown` (incrementally extendable).

## Future

If/when MoonBit’s official JS/TS output becomes “good enough” for most workflows (e.g. richer `.d.ts`, better interop conventions),
this project may become unnecessary or shrink to a much thinner layer.