hirosystems / clarinet

Write, test and deploy high-quality smart contracts to the Stacks blockchain and Bitcoin.
https://hiro.so/clarinet
GNU General Public License v3.0
290 stars 129 forks source link

Feat/clarinet sdk browser #1448

Open hugocaillard opened 1 month ago

hugocaillard commented 1 month ago

Description

Closes: #1432

This is a pretty important PR that brings the Clarinet SDK for the browser.

Two new packages

They are the equivalent of these existing packages (but for the browser)

Enhancement

This PR also brings some enhancement to the SDK and some new methods useful for the browser use case (such as initEmptySession() and clearCache()).

Improved typing

Some Rust structs are encoded in JS objects, and the TS types for those were in clarinet-sdk. They have been moved to components/clarinet-sdk-wasm/src/ts_types.rs

Review

A good first step to review this PR is to look at these 4 READMEs:

Caveats

It brings complexity to an already complicated architecture.

The clarinet-sdk-wasm component remain almost the same, except that it now requires a build script that runs wasm-pack twice targeting nodejs and web. It will also rename the web package to @hirosystems/clarinet-sdk-wasm-browser.

node build.mjs

The src directory of the clarinet-sdk component has been split into 3 directories common/src, node/src, browser/src. With a bit of code duplication between node/src/sdkProxy.ts and browser/src/sdkProxy.ts. But thanks to NPM workspace, it still easy to build and publish the two components.

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 37.50000% with 180 lines in your changes missing coverage. Please review. Files Patch % Lines
components/clarity-repl/src/repl/session.rs 38.97% 166 Missing :warning:
components/clarity-repl/src/frontend/terminal.rs 0.00% 10 Missing :warning:
components/clarinet-deployments/src/lib.rs 40.00% 3 Missing :warning:
components/clarity-repl/src/bin.rs 0.00% 1 Missing :warning:

:loudspeaker: Thoughts on this report? Let us know!