Page MenuHomePhabricator

[ecash-lib] Enable NodeJS support
ClosedPublic

Authored by tobias_ruck on Apr 25 2024, 16:20.

Details

Reviewers
bytesofman
Group Reviewers
Restricted Project
Commits
rABCcaf3b259a611: [ecash-lib] Enable NodeJS support
Summary

Currently, the library is (pretty much) not usable in a NodeJS context, as it requires manually loading the WASM file, which is what we're currently doing in the tests.

However, it would be great if this library could also frictionlessly be used in a Node context.

This is done by changing initWasm to be its own funciton instead of just forwarding what is generated by wasm-bindgen, and then, on node, to use readFile to read the WASM file, which is then fed to wbg_init, or on the browser, to use the wbg_init without params, which will handle the loading internally.

The implication is that the tests now don't have to load the WASM themselves anymore, and we can remove this code from the tests.

Test Plan

npm run test && npm run build && npm run integration-tests

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

The implication is that the tests now don't have to load the WASM themselves anymore, and we can remove this code from the tests.

But we still need to make sure it is in place before we compile the typescript and publish the npm package, right?

This does seem like a cool feature and imo is worth having to support use of ecash-lib as a relative import in tests for other libraries, e.g. in Cashtab after it is implemented there (though this would still require typescript support first, in Cashtab anyway).

modules/ecash-lib/src/init.ts
12 ↗(On Diff #47423)

doesn't it still need to be built in order to exist here?

This revision now requires changes to proceed.Apr 25 2024, 17:46

But we still need to make sure it is in place before we compile the typescript and publish the npm package, right?

Yes, of course.

This does seem like a cool feature and imo is worth having to support use of ecash-lib as a relative import in tests for other libraries, e.g. in Cashtab after it is implemented there (though this would still require typescript support first, in Cashtab anyway).

You can use ecash-lib without TypeScript in CashTab!

modules/ecash-lib/src/init.ts
12 ↗(On Diff #47423)

Yes, this doesn't remove the need for the WASM file. Just that loading it in NodeJS now also works.

The implication is that the tests now don't have to load the WASM themselves anymore, and we can remove this code from the tests.

ok i understand this now. was thinking this would get rid of the wasm build but there is value without that.

You can use ecash-lib without TypeScript in CashTab!

Yes but only if it is built and compiled. To use it as a relative dependency (i.e. npm i ../modules/ecash-lib instead of from the package manager, would need to make sure it was built and compiled).

I guess this is true about all typescript stuff tho.

This revision is now accepted and ready to land.Apr 25 2024, 22:33
This revision was automatically updated to reflect the committed changes.