Skip to content

Commit

Permalink
[CLI] Add hardhat to peer deps and handle errors (#414)
Browse files Browse the repository at this point in the history
* Add hardhat to peer deps

* Change command name

* Remove hardhat from artifacts

* Handle run errors

* Handle missing hardhat

* Add changesets
  • Loading branch information
ryangoree authored Feb 24, 2024
1 parent adb4291 commit a5ed20e
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-students-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@delvtech/council-cli": patch
---

Make Hardhat a peer dependency and add more error handling
5 changes: 5 additions & 0 deletions .changeset/soft-steaks-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@delvtech/council-artifacts": patch
---

Remove hardhat dependency
1 change: 0 additions & 1 deletion packages/council-artifacts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"devDependencies": {
"@council/eslint-config": "*",
"@council/tsconfig": "*",
"hardhat": "^2.20.1",
"typescript": "^5.3.3"
},
"publishConfig": {
Expand Down
16 changes: 12 additions & 4 deletions packages/council-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"license": "MIT",
"type": "module",
"main": "dist/council.js",
"bin": "dist/council.js",
"bin": {
"council": "dist/council.js"
},
"files": [
"dist"
],
Expand All @@ -15,6 +17,15 @@
"build": "rimraf dist && tsc",
"watch": "tsc --watch"
},
"peerDependencies": {
"viem": ">=2",
"hardhat": ">=2"
},
"peerDependenciesMeta": {
"hardhat": {
"optional": true
}
},
"dependencies": {
"@delvtech/council-artifacts": "^0.0.2",
"@delvtech/council-viem": "^0.0.2",
Expand Down Expand Up @@ -44,9 +55,6 @@
"typescript": "^5.3.3",
"viem": "^2.7.12"
},
"peerDependencies": {
"viem": ">=2"
},
"publishConfig": {
"access": "public"
}
Expand Down
40 changes: 39 additions & 1 deletion packages/council-cli/src/commands/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { command } from "clide-js";
import hre from "hardhat";
import { execSync } from "node:child_process";
import signale from "signale";
import { parseUnits } from "viem";

// This command is only available if the optional hardhat peer dependency is
// installed so we import it dynamically to avoid crashing if it's not
// installed.
let error: Error | undefined;
const hardhat = await import("hardhat").catch((e) => {
error = e;
return undefined;
});

export default command({
description: "Start a local ethereum node",
isMiddleware: false,
Expand Down Expand Up @@ -34,6 +44,34 @@ export default command({
},

handler: async ({ options, end }) => {
if (!hardhat) {
// https://hardhat.org/hardhat-runner/docs/errors#HH1
if (error?.message.startsWith("HH1")) {
signale.error(
"Must be inside a Hardhat project with a hardhat config file.",
);
} else if (error?.message.startsWith("HH")) {
signale.error(error.message);
} else {
const globalNodeModules = execSync("npm root -g").toString().trim();
const localNodeModules = execSync("npm root").toString().trim();
const isGlobal = globalNodeModules === localNodeModules;

signale.error(error?.message ?? error);
signale.error(
`This command requires hardhat to be installed. Run ${
isGlobal
? "`npm install -g hardhat`"
: "`npm install --save-dev hardhat`"
} to install hardhat.`,
);
}

return end();
}

const hre = hardhat.default;

const host = await options.host();
const port = await options.port();
const balance = await options.balance();
Expand Down
3 changes: 3 additions & 0 deletions packages/council-cli/src/council.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node
import { help, run } from "clide-js";
import { commandMenu } from "clide-plugin-command-menu";
import signale from "signale";

run({
plugins: [
Expand Down Expand Up @@ -34,4 +35,6 @@ run({
}
}
},
}).catch((error) => {
signale.error(error);
});
55 changes: 41 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4117,7 +4117,7 @@ check-error@^1.0.3:
dependencies:
get-func-name "^2.0.2"

[email protected], chokidar@^3.4.0, chokidar@^3.5.1, chokidar@^3.5.2, chokidar@^3.5.3:
[email protected], chokidar@^3.5.1, chokidar@^3.5.2, chokidar@^3.5.3:
version "3.5.3"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd"
integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==
Expand All @@ -4132,6 +4132,21 @@ [email protected], chokidar@^3.4.0, chokidar@^3.5.1, chokidar@^3.5.2, chokidar@^3.5
optionalDependencies:
fsevents "~2.3.2"

chokidar@^3.4.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.6.0.tgz#197c6cc669ef2a8dc5e7b4d97ee4e092c3eb0d5b"
integrity sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==
dependencies:
anymatch "~3.1.2"
braces "~3.0.2"
glob-parent "~5.1.2"
is-binary-path "~2.1.0"
is-glob "~4.0.1"
normalize-path "~3.0.0"
readdirp "~3.6.0"
optionalDependencies:
fsevents "~2.3.2"

ci-info@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46"
Expand Down Expand Up @@ -6003,6 +6018,17 @@ [email protected]:
once "^1.3.0"
path-is-absolute "^1.0.0"

[email protected]:
version "8.1.0"
resolved "https://registry.yarnpkg.com/glob/-/glob-8.1.0.tgz#d388f656593ef708ee3e34640fdfb99a9fd1c33e"
integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^5.0.1"
once "^1.3.0"

glob@^7.1.3, glob@^7.2.3:
version "7.2.3"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b"
Expand Down Expand Up @@ -7613,6 +7639,13 @@ minimatch@^3.0.4, minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2:
dependencies:
brace-expansion "^1.1.7"

minimatch@^5.0.1:
version "5.1.6"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96"
integrity sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==
dependencies:
brace-expansion "^2.0.1"

minimist-options@^4.0.2:
version "4.1.0"
resolved "https://registry.yarnpkg.com/minimist-options/-/minimist-options-4.1.0.tgz#c0655713c53a8a2ebd77ffa247d342c40f010619"
Expand Down Expand Up @@ -7662,9 +7695,9 @@ mnemonist@^0.38.0:
obliterator "^2.0.0"

mocha@^10.0.0:
version "10.2.0"
resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.2.0.tgz#1fd4a7c32ba5ac372e03a17eef435bd00e5c68b8"
integrity sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg==
version "10.3.0"
resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.3.0.tgz#0e185c49e6dccf582035c05fa91084a4ff6e3fe9"
integrity sha512-uF2XJs+7xSLsrmIvn37i/wnc91nw7XjOQB8ccyx5aEgdnohr7n+rEiZP23WkCYHjilR6+EboEnbq/ZQDz4LSbg==
dependencies:
ansi-colors "4.1.1"
browser-stdout "1.3.1"
Expand All @@ -7673,13 +7706,12 @@ mocha@^10.0.0:
diff "5.0.0"
escape-string-regexp "4.0.0"
find-up "5.0.0"
glob "7.2.0"
glob "8.1.0"
he "1.2.0"
js-yaml "4.1.0"
log-symbols "4.1.0"
minimatch "5.0.1"
ms "2.1.3"
nanoid "3.3.3"
serialize-javascript "6.0.0"
strip-json-comments "3.1.1"
supports-color "8.1.1"
Expand Down Expand Up @@ -7751,11 +7783,6 @@ mz@^2.7.0:
object-assign "^4.0.1"
thenify-all "^1.0.0"

[email protected]:
version "3.3.3"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.3.tgz#fd8e8b7aa761fe807dba2d1b98fb7241bb724a25"
integrity sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==

nanoid@^3.3.4, nanoid@^3.3.7:
version "3.3.7"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.7.tgz#d0c301a691bc8d54efa0a2226ccf3fe2fd656bd8"
Expand Down Expand Up @@ -10377,9 +10404,9 @@ undici-types@~5.26.4:
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==

undici@^5.14.0:
version "5.28.2"
resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.2.tgz#fea200eac65fc7ecaff80a023d1a0543423b4c91"
integrity sha512-wh1pHJHnUeQV5Xa8/kyQhO7WFa8M34l026L5P/+2TYiakvGy5Rdc8jWZVyG7ieht/0WgJLEd3kcU5gKx+6GC8w==
version "5.28.3"
resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.3.tgz#a731e0eff2c3fcfd41c1169a869062be222d1e5b"
integrity sha512-3ItfzbrhDlINjaP0duwnNsKpDQk3acHI3gVJ1z4fmwMK31k5G9OVIAMLSIaP6w4FaGkaAkN6zaQO9LUvZ1t7VA==
dependencies:
"@fastify/busboy" "^2.0.0"

Expand Down

0 comments on commit a5ed20e

Please sign in to comment.