Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lint-staged
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@

This repo is the home of BitGo's WASM libraries.


# Dependencies

- [Rust](https://www.rust-lang.org/) nightly
- [wasm-pack](https://rustwasm.github.io/wasm-pack/) (install with `cargo install wasm-pack`)
- [Node.js](https://nodejs.org/en/)

# Developer Setup

```bash
npm install
```

This will:

- Install all dependencies
- Set up pre-commit hooks via Husky

Pre-commit hooks automatically run on staged files:

- **JS/TS**: Prettier formatting + ESLint
- **Rust**: `cargo fmt` + `cargo clippy`

# Package Management

This monorepo uses [Lerna](https://lerna.js.org/) for managing package versions and publishing to npm.
Expand Down Expand Up @@ -44,7 +59,6 @@ npx lerna changed

# Packages


## wasm-utxo

This is a wrapper around the
Expand All @@ -56,5 +70,4 @@ compiled to WebAssembly.

A live playground for the wasm-utxo crate.

Go to https://bitgo.github.io/wasm-utxo to see a live demo of the wasm-utxo library in action. *WIP*

Go to https://bitgo.github.io/wasm-utxo to see a live demo of the wasm-utxo library in action. _WIP_
73 changes: 73 additions & 0 deletions lint-staged.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { existsSync } from "fs";

const IGNORED_PATTERNS = [
"node_modules",
"/dist/",
"/target/",
"/pkg/",
"/js/wasm/",
"/bundler-test/",
];

function filterIgnored(filenames) {
return filenames.filter((f) => !IGNORED_PATTERNS.some((p) => f.includes(p)));
}

/** Extract package name from a file path like packages/wasm-utxo/src/foo.rs */
function getPackageName(filepath) {
const match = filepath.match(/packages\/([^/]+)\//);
return match?.[1];
}

/** Group files by their package name */
function groupByPackage(filenames) {
const groups = new Map();
for (const f of filenames) {
const pkg = getPackageName(f);
if (!pkg) continue;
if (!groups.has(pkg)) groups.set(pkg, []);
groups.get(pkg).push(f);
}
return groups;
}

export default {
"*.{js,ts,tsx,mjs,cjs}": (filenames) => {
const filtered = filterIgnored(filenames);
if (filtered.length === 0) return [];

const commands = [`prettier --write ${filtered.join(" ")}`];

for (const [pkg, files] of groupByPackage(filtered)) {
const configPath = `packages/${pkg}/eslint.config.js`;
if (existsSync(configPath)) {
commands.push(`npx eslint -c ${configPath} --fix ${files.join(" ")}`);
}
}

return commands;
},

"*.{json,yaml,yml,md}": (filenames) => {
const filtered = filterIgnored(filenames);
if (filtered.length === 0) return [];
return [`prettier --write ${filtered.join(" ")}`];
},

"*.rs": (filenames) => {
const filtered = filterIgnored(filenames);
if (filtered.length === 0) return [];

const commands = [];
for (const pkg of new Set(filtered.map(getPackageName).filter(Boolean))) {
const manifest = `packages/${pkg}/Cargo.toml`;
if (existsSync(manifest)) {
commands.push(`cargo fmt --manifest-path ${manifest}`);
commands.push(
`cargo clippy --manifest-path ${manifest} --all-targets --all-features -- -D warnings`,
);
}
}
return commands;
},
};
Loading