Currently, integrating ecash-lib into CashTab is very difficult, due to the different environments between jest and webpack:
- Jest can't handle ES modules, and either fails to import ecash-lib altogether (as it is a module), or, if we change it to be a CommonJS compatible, the generated JS from wasm-bindgen breaks it as import.meta.url can't be used, even if it's never executed.
- Webpack can't find node:fs/promises, even though it's lazily loaded and never actually imported.
wasm-bindgen can build ffi modules that work for either NodeJS or web, but it can't build them for both. Since for CashTab, we need both in different occasions, one solution would be to split out the WASM part of ecash-lib, and allow users to specify which version should be used, by adding either ecash-lib-init-node for NodeJS or ecash-lib-init-web for web.
We use wasm-bindgen to build each version and then expose functions to mount either of them.