Skip to content
Draft
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
5 changes: 5 additions & 0 deletions .github/workflows/lint-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ jobs:
matrix:
node-version: [18.x, 20.x, 22.x]
package-name: ${{ fromJson(needs.prepare.outputs.child-workspace-package-names) }}
exclude:
# @metamask/wallet-cli depends on better-sqlite3, which only ships
# prebuilt binaries for Node 20+.
- node-version: 18.x
package-name: '@metamask/wallet-cli'
steps:
- name: Checkout and setup environment
uses: MetaMask/action-checkout-and-setup@v2
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,8 @@ linkStyle default opacity:0.5
wallet --> messenger;
wallet --> remote_feature_flag_controller;
wallet --> storage_service;
wallet_cli --> base_controller;
wallet_cli --> wallet;
```

<!-- end dependency graph -->
Expand Down
4 changes: 4 additions & 0 deletions packages/wallet-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add the daemon transport layer: a newline-delimited JSON-RPC client and server over a Unix socket, plus daemon spawn/stop lifecycle helpers ([#9108](https://github.com/MetaMask/core/pull/9108))
- Add SQLite-backed persistence for wallet controller state ([#9067](https://github.com/MetaMask/core/pull/9067))
- A `KeyValueStore` backed by `better-sqlite3` for synchronous reads and writes.
- `loadState` to rehydrate persist-flagged controller state from the store and `subscribeToChanges` to write persist-flagged controller state through to disk on every `stateChanged` event.
- Initial package scaffold for `@metamask/wallet-cli`, an [oclif](https://oclif.io)-based `mm` CLI for `@metamask/wallet` ([#9065](https://github.com/MetaMask/core/pull/9065)).

[Unreleased]: https://github.com/MetaMask/core/
18 changes: 18 additions & 0 deletions packages/wallet-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ or

`npm install @metamask/wallet-cli`

## Troubleshooting

### Rebuilding `better-sqlite3`

This package depends on `better-sqlite3`, which ships a native C addon. The monorepo runs Yarn with `enableScripts: false`, so the addon is **not** fetched automatically during `yarn install`. Instead, the package's `test:prepare` script (`scripts/install-binaries.sh`) downloads the matching prebuild on demand the first time you run tests, falling back to compiling the addon from source (via `node-gyp`) when no prebuild is published for your Node ABI/platform.

If you switch Node versions or branches and the binding is missing, re-run:

```sh
yarn workspace @metamask/wallet-cli run test:prepare
```

Or invoke `prebuild-install` directly from the monorepo root (where `better-sqlite3` is hoisted):

```sh
cd node_modules/better-sqlite3 && node ../.bin/prebuild-install
```

## Contributing

This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
15 changes: 12 additions & 3 deletions packages/wallet-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,26 @@
"changelog:update": "../../scripts/update-changelog.sh @metamask/wallet-cli",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/wallet-cli",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
"test:prepare": "./scripts/install-binaries.sh",
"test": "yarn test:prepare && NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"dependencies": {
"@oclif/core": "^4.10.5"
"@inquirer/confirm": "^6.0.11",
"@metamask/base-controller": "^9.1.0",
"@metamask/rpc-errors": "^7.0.2",
"@metamask/utils": "^11.11.0",
"@metamask/wallet": "^3.0.0",
"@oclif/core": "^4.10.5",
"better-sqlite3": "^12.9.0",
"immer": "^9.0.6"
},
"devDependencies": {
"@metamask/auto-changelog": "^6.1.0",
"@ts-bridge/cli": "^0.6.4",
"@types/better-sqlite3": "^7.6.13",
"@types/jest": "^29.5.14",
"deepmerge": "^4.2.2",
"jest": "^29.7.0",
Expand All @@ -60,6 +69,6 @@
"topicSeparator": " "
},
"engines": {
"node": "^18.18 || >=20"
"node": ">=20"
}
}
28 changes: 28 additions & 0 deletions packages/wallet-cli/scripts/install-binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

set -e
set -o pipefail

# Pin cwd to the package root so all paths are predictable regardless of how
# this script is invoked. Also derive the monorepo root (two levels up).
PACKAGE_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
MONOREPO_ROOT="$(cd "${PACKAGE_ROOT}/../.." && pwd)"
cd "${PACKAGE_ROOT}"

# Install the better-sqlite3 native addon if missing. Yarn has
# `enableScripts: false` globally, so install scripts never run during
# `yarn install` and the addon may be absent from the filesystem. Reproduce
# better-sqlite3's own install step (`prebuild-install || node-gyp rebuild
# --release`): fetch a matching prebuild for the active Node version and
# platform, and fall back to compiling from source when no prebuild is
# published for that ABI/libc combination (e.g. some Linux CI runners).
BETTER_SQLITE3_DIR="${MONOREPO_ROOT}/node_modules/better-sqlite3"
if [ ! -f "${BETTER_SQLITE3_DIR}/build/Release/better_sqlite3.node" ]; then
(
cd "${BETTER_SQLITE3_DIR}"
if ! "${MONOREPO_ROOT}/node_modules/.bin/prebuild-install"; then
echo "wallet-cli: prebuild-install failed (see its output above); compiling better-sqlite3 from source. This needs a C/C++ toolchain and Python." >&2
"${MONOREPO_ROOT}/node_modules/.bin/node-gyp" rebuild --release
fi
)
fi
Loading
Loading