Add react-native support (#63)
Some checks failed
Publish / build (push) Waiting to run
Publish / publish-crate (push) Blocked by required conditions
Publish / publish-npm (push) Blocked by required conditions
Publish / publish-pypi (push) Blocked by required conditions
Check / build (push) Has been cancelled

Reviewed-on: https://home.schmelczer.dev/git/git/andras/reconcile/pulls/63
This commit is contained in:
Andras Schmelczer 2026-05-31 20:28:20 +01:00
commit a8fbac6934

View file

@ -0,0 +1,47 @@
// React Native entrypoint (resolved via the `react-native` package field).
//
// Hermes — the default React Native engine since RN 0.84 / Expo SDK 56 — does
// not expose a runtime `WebAssembly` global, so the normal `new
// WebAssembly.Module(...)` path used by `index.ts` throws
// `ReferenceError: Property 'WebAssembly' doesn't exist`.
//
// Instead we link a wasm2js translation of the module: pure JavaScript that
// needs no `WebAssembly` global and is instantiated synchronously at import
// time. The public API and its synchronous signatures are unchanged, so
// callers need no modification. The `pkg-rn` directory is generated by
// `scripts/build-rn.mjs`.
import {
CursorPosition as wasmCursorPosition,
TextWithCursors as wasmTextWithCursors,
reconcile as wasmReconcile,
reconcileWithHistory as wasmReconcileWithHistory,
diff as wasmDiff,
undiff as wasmUndiff,
} from '../pkg-rn/reconcile_text.js';
import { makeReconcileApi, type WasmBackend } from './core';
const backend: WasmBackend = {
CursorPosition: wasmCursorPosition,
TextWithCursors: wasmTextWithCursors,
reconcile: wasmReconcile,
reconcileWithHistory: wasmReconcileWithHistory,
diff: wasmDiff,
undiff: wasmUndiff,
// The wasm2js module initialises itself at import time, so this is a no-op.
ensureReady() {},
};
export const { reconcile, diff, undiff, reconcileWithHistory } =
makeReconcileApi(backend);
export type {
BuiltinTokenizer,
History,
CursorPosition,
TextWithCursors,
TextWithOptionalCursors,
TextWithCursorsAndHistory,
SpanWithHistory,
} from './core';