From 3bfee32cf4d036a73b35f059e0159f1b7a7088e9 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 20 Oct 2023 16:43:09 +0100 Subject: [PATCH] fix(cli): don't bail dev-contracts during deploy failure (#1808) --- .changeset/bright-flies-hug.md | 5 ++ packages/cli/src/commands/dev-contracts.ts | 56 +++++++++++++--------- 2 files changed, 38 insertions(+), 23 deletions(-) create mode 100644 .changeset/bright-flies-hug.md diff --git a/.changeset/bright-flies-hug.md b/.changeset/bright-flies-hug.md new file mode 100644 index 0000000000..615a6eb4c5 --- /dev/null +++ b/.changeset/bright-flies-hug.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/cli": patch +--- + +`dev-contracts` will no longer bail when there was an issue with deploying (e.g. typo in contracts) and instead wait for file changes before retrying. diff --git a/packages/cli/src/commands/dev-contracts.ts b/packages/cli/src/commands/dev-contracts.ts index bcd13ddbe3..3e0ee29ce4 100644 --- a/packages/cli/src/commands/dev-contracts.ts +++ b/packages/cli/src/commands/dev-contracts.ts @@ -9,8 +9,9 @@ import { WorldConfig } from "@latticexyz/world"; import { homedir } from "os"; import { rmSync } from "fs"; import { deployOptions, runDeploy } from "../runDeploy"; -import { BehaviorSubject, debounceTime, exhaustMap } from "rxjs"; +import { BehaviorSubject, debounceTime, exhaustMap, filter } from "rxjs"; import { Address } from "viem"; +import { isDefined } from "@latticexyz/common/utils"; const devOptions = { rpc: deployOptions.rpc, @@ -52,13 +53,15 @@ const commandModule: CommandModule(Date.now()); - chokidar.watch([configPath, srcDir, scriptDir]).on("all", async (_, updatePath) => { + chokidar.watch([configPath, srcDir, scriptDir], { ignoreInitial: true }).on("all", async (_, updatePath) => { if (updatePath.includes(configPath)) { + console.log(chalk.blue("Config changed, queuing deploy…")); lastChange$.next(Date.now()); } if (updatePath.includes(srcDir) || updatePath.includes(scriptDir)) { // Ignore changes to codegen files to avoid an infinite loop if (!updatePath.includes(initialConfig.codegenDirectory)) { + console.log(chalk.blue("Contracts changed, queuing deploy…")); lastChange$.next(Date.now()); } } @@ -71,29 +74,36 @@ const commandModule: CommandModule { if (worldAddress) { - console.log(chalk.blue("Change detected, rebuilding and running deploy...")); + console.log(chalk.blue("Rebuilding and upgrading world…")); } - // TODO: handle errors - const deploy = await runDeploy({ - ...opts, - configPath, - rpc, - skipBuild: false, - printConfig: false, - profile: undefined, - saveDeployment: true, - worldAddress, - srcDir, - }); - worldAddress = deploy.address; - // if there were changes while we were deploying, trigger it again - if (lastChange < lastChange$.value) { - lastChange$.next(lastChange$.value); - } else { - console.log(chalk.gray("Watching for file changes...")); + + try { + const deploy = await runDeploy({ + ...opts, + configPath, + rpc, + skipBuild: false, + printConfig: false, + profile: undefined, + saveDeployment: true, + worldAddress, + srcDir, + }); + worldAddress = deploy.address; + // if there were changes while we were deploying, trigger it again + if (lastChange < lastChange$.value) { + lastChange$.next(lastChange$.value); + } else { + console.log(chalk.gray("\nWaiting for file changes…\n")); + } + return deploy; + } catch (error) { + console.error(chalk.bgRed(chalk.whiteBright("\n Error while attempting deploy \n"))); + console.error(error); + console.log(chalk.gray("\nWaiting for file changes…\n")); } - return deploy; - }) + }), + filter(isDefined) ); deploys$.subscribe();