Skip to content

Commit 673ecfa

Browse files
committed
docs: document --target web (WebAssembly) build alongside native targets
- README.md: add web/WASM to the cross-platform list and a "Run in the browser" section with the build/serve commands and a brief description of what degrades on web (SQLite → in-memory transient store, Hone code editor's native FFI → no-op, MongoDB driver → needs Mango Server proxy). - CLAUDE.md: * Project Overview now mentions the self-contained HTML+WASM build. * Commands section adds the perry compile --target web invocation and python3 -m http.server (file:// hits CORS). * New "Web Target Notes" section explaining what __platform__ === 5 triggers in the source: connection-store falls back to webTransient, Keychain → localStorage, Hone editor degrades, MongoDB needs a proxy, and CORS swallows telemetry from non-whitelisted origins. Mango compiles cleanly with Perry 0.4.65's WASM target and renders its welcome screen ("Welcome to Mango" + "+ New Connection") matching the native app.
1 parent 68cb4e4 commit 673ecfa

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

CLAUDE.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## Project Overview
66

7-
Mango is a native desktop MongoDB GUI built with Perry (TypeScript-to-native compiler). It produces ~7 MB cross-platform binaries targeting macOS (AppKit), iOS (UIKit), Android (Views), Linux (GTK4), and Windows (Win32) from a single TypeScript codebase.
7+
Mango is a native MongoDB GUI built with Perry (TypeScript-to-native compiler). It produces ~7 MB cross-platform binaries targeting macOS (AppKit), iOS (UIKit), Android (Views), Linux (GTK4), and Windows (Win32) from a single TypeScript codebase. It also compiles to a single self-contained HTML+WebAssembly file via `--target web` for in-browser use.
88

99
## Commands
1010

@@ -21,6 +21,12 @@ npm run build:macos # Platform-specific builds
2121
npm run build:linux
2222
npm run build:windows
2323

24+
# Web (WebAssembly + DOM bridge in a single self-contained HTML file)
25+
perry compile src/app.ts --target web -o dist/mango.html
26+
# Serve over HTTP so fetch() works (file:// hits CORS)
27+
python3 -m http.server 8765 -d dist
28+
open http://localhost:8765/mango.html
29+
2430
# Testing (uses Bun, not Node)
2531
npm test # All tests
2632
npm run test:unit # Unit tests only
@@ -44,8 +50,21 @@ bun test tests/connection-store.test.ts # Run a single test file
4450

4551
## Key Conventions
4652

47-
- **Perry, not Electron:** UI uses Perry's native bindings, not DOM/HTML. No `document`, `window`, or CSS — use Perry widget types and RGBA colors.
53+
- **Perry, not Electron:** UI uses Perry's native bindings, not DOM/HTML. No `document`, `window`, or CSS — use Perry widget types and RGBA colors. (On the `--target web` build, Perry's WASM runtime maps every widget to a DOM element under the hood, but the source code stays the same — you never write HTML.)
4854
- **Path alias:** `@/*` maps to `src/*` in imports.
4955
- **External editor widget:** `@honeide/editor` is a local dependency (`file:../hone/hone-editor`) used for document editing.
5056
- **Test mocks:** Perry APIs and MongoDB are mocked in `tests/mocks/`. Tests preload `tests/preload.ts` via bunfig.toml. Use `reset-database.ts` to clear state between tests.
5157
- **Connection URI building:** `ConnectionStore.buildConnectionUri()` handles auth mechanisms (SCRAM-SHA-256, etc.) and TLS options. Always use this rather than constructing URIs manually.
58+
59+
## Web Target Notes
60+
61+
`perry compile src/app.ts --target web` produces a single ~4 MB self-contained HTML file with the WebAssembly binary, the JS bridge for DOM widgets, and all string/data sections embedded. It's the same backend as `--target wasm`; both flags produce identical output.
62+
63+
Platform branches with `__platform__ === 5` cover the web case:
64+
65+
- **Connection storage**: `connection-store.ts` falls back to an in-memory `webTransient` store on web instead of SQLite (which doesn't compile to WASM). Connection profiles are not persisted across reloads in the browser.
66+
- **Keychain**: maps to `localStorage` (Perry's web bridge). Fine for connection metadata but **not** for production secrets — anything in localStorage is readable by other scripts in the same origin.
67+
- **Hone code editor**: requires native FFI (`hone_editor_*`) that has no browser implementation. Perry's WASM bridge auto-stubs these to no-ops via a `Proxy`, so the editor area shows up but key/mouse handling is inactive. Document editing works with the plain `<textarea>` fallback.
68+
- **MongoDB driver**: native MongoDB doesn't run in the browser. The web build needs to talk to a Mango Server proxy (`web-mongo-client.ts` over `fetch`). For local testing, run mongod + mango-server alongside the served HTML and update the connection string.
69+
- **fetch / CORS**: any third-party URL (telemetry, public APIs) must allow your origin. Mango's `trackEvent` will silently fail with a CORS error from `file://` and from origins not whitelisted by `api.chirp247.com` — this is expected and the catch in `trackEvent` swallows it.
70+
- **Serving**: must be served over HTTP, not opened directly via `file://` (browsers reject `fetch()` from file URLs). Any static server works (`python3 -m http.server`, `npx serve`, etc.).

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Mango is a native desktop MongoDB client written in TypeScript and compiled to n
3131
- **Document CRUD** — Insert, update, delete, and duplicate documents.
3232
- **Index listing** — View indexes with key, uniqueness, and size info.
3333
- **Dark & light mode** — Follows system preference automatically.
34-
- **Cross-platform** — Targets macOS (AppKit), iOS (UIKit), Android (Views), Linux (GTK4), and Windows (Win32).
34+
- **Cross-platform** — Targets macOS (AppKit), iOS (UIKit), Android (Views), Linux (GTK4), Windows (Win32), and the **browser** (WebAssembly + DOM via Perry's `--target web`).
3535

3636
## Getting Started
3737

@@ -54,6 +54,19 @@ perry compile src/app.ts --output mango
5454
./mango
5555
```
5656

57+
### Run in the browser (WebAssembly)
58+
59+
```bash
60+
# Compile to a single self-contained HTML+WASM file (~4 MB)
61+
perry compile src/app.ts --target web -o dist/mango.html
62+
63+
# Serve over HTTP (file:// won't work — fetch() hits CORS errors)
64+
python3 -m http.server 8765 -d dist
65+
open http://localhost:8765/mango.html
66+
```
67+
68+
The web build is the same source code, compiled by Perry to WebAssembly with a JavaScript bridge that maps every Perry widget to a DOM element. SQLite-backed connection storage degrades to an in-memory transient store on web; the Hone code editor's native bindings degrade to no-ops; and you'll need to point at a Mango Server proxy if you want to talk to MongoDB from the browser. Everything else (UI, navigation, query builder, document viewer, dark/light mode, i18n) works the same as the native builds.
69+
5770
### Development
5871

5972
```bash

0 commit comments

Comments
 (0)