thi-ng / umbrella

⛱ Broadly scoped ecosystem & mono-repository of 199 TypeScript projects (and ~180 examples) for general purpose, functional, data driven development
https://thi.ng
Apache License 2.0
3.35k stars 149 forks source link

[wasm-api] Adopt consistent naming conventions & package structures #368

Closed postspectacular closed 1 year ago

postspectacular commented 1 year ago

This issue is intended as a point of reference for the upcoming breaking naming changes in various wasm-api-* packages, which are all still in ALPHA, regardless of version number...

Naming conventions for custom WASM API modules

The names of each custom WASM API module's TypeScript class should be a PascalCase'd version of the name of its parent package. The name of the interface for declared WASM exports should be the same name, suffixed with Exports, e.g.:

Package name Class name Interface name
@thi.ng/wasm-api-canvas WasmCanvas WasmCanvasExports
@thi.ng/wasm-api-dom WasmDom WasmDomExports
@thi.ng/wasm-api-schedule WasmSchedule WasmScheduleExports

C & Zig import paths

Any package exposing headers or libraries for C or Zig should place relevant files into following package structure:

Language Relative path
C /include/wasmapi_xxx.h*
Zig /zig/lib.zig

* The xxx suffix would be related to the actual package name, e.g. wasmapi_dom.h

Zig import names

For consistency, the short name for Zig imports should be the unscoped name of the parent NPM package, instead of the currently somewhat arbitrarily chosen short name. E.g.:

const wasm = @import("wasm-api");
const bindgen = @import("wasm-api-bindgen");
const dom = @import("wasm-api-dom");
const schedule = @import("wasm-api-schedule");

Conclusion

Taken together, these changes will make it much easier for users to determine the correct names and import paths, even without IDE auto-completion...

postspectacular commented 1 year ago

Done

postspectacular commented 3 weeks ago

Related addition (2024) about the new WasmModuleSpec-based API module declarations:

Each of the support packages are now also providing the following module specs:

Package name Module spec
@thi.ng/wasm-api-canvas WasmCanvasModule
@thi.ng/wasm-api-dom WasmDomModule
@thi.ng/wasm-api-schedule WasmScheduleModule
@thi.ng/wasm-api-webgl WasmWebGLModule

See Custom API modules for more info about how these module specs are used...