This repository contains a sample code and a starter template to illustrate interoperability between C++/WebAssembly and TypeScript. It is structured as a monorepo.
- Implement heavy computations and business logic in an appropriate C++ library or create new
- For interfacing with TS code declare emscripten bindings in a corresponding .embind.cpp file
- Minimize data exchange between C++ WebAssembly and TS
- Do not hard code colors
npm run tsc:sample --noEmit path/to/file.tsx
npm run format:sample --write path/to/file.tsx
npm run lint:sample --fix path/to/file.tsx
npm run build:native
npm run dev- tests
npm run test- full build when explicitly requested
npm run build- TypeScript strict mode
- Use functional patterns where possible
Allowed without prompt:
- read files, list files
- single file prettier and eslint
- tsc, build, test
Ask first:
- package installs
- git push
- deleting files, chmod
- running full build or end to end suites
native: C++/CMake sources and wasm build scripts (Emscripten)
native/libs/NlpLib: A C++ library with NLP and text processing classes.
packages: TypeScript client and server node applications and tests
packages/sample: Example TypeScript application which consumes WebAssembly
packages/tests: Tests of functionality of the WebAssembly from typescript
- Primary Responsibility: Root of C++/CMake libraries and wasm build scripts (Emscripten)
- Interaction Pattern: The native code is compiled into WebAssembly using Emscripten. The resulting
.wasmfile is then used by the TypeScript consumer via a generated WebassemblyTemplate.js. New libraries can be added to libs folder and add_subdirectory to the root CMakeLists.txt. - Dependencies: Catch2 for native unit tests
- Output: A
.wasmfile that can be consumed by the TypeScript consumer.
- Primary Responsibility: Example TypeScript consumer
- Interaction Pattern: The TypeScript consumer loads the
.wasmfile generated by the native code and uses it to perform operations. - Dependencies: The native code must be compiled into WebAssembly using Emscripten.
- Output: A TypeScript application that uses the WebAssembly module.
- Primary Responsibility: Tests of WebAssembly classes from a TS client
- Interaction Pattern: The tests are used to test the native code from the TypeScript consumer.
- Dependencies: The native code must be compiled into WebAssembly using Emscripten.
- Output: Test results and CI reports.