Skip to content

Commit

Permalink
(local) run hardhat clean if registry deploy fails
Browse files Browse the repository at this point in the history
  • Loading branch information
joewagner committed Aug 29, 2023
1 parent 5473f91 commit bdfe8af
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/local/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,17 @@ class LocalTableland {
// wait until initialization is done
await waitForReady(registryReadyEvent, this.initEmitter);

await new Promise((resolve) => setTimeout(resolve, 5000));
if (process.env.HARDHAT_CLEAN) {
console.log("HARDHAT_CLEAN env set, cleaning hardhat");
await new Promise((resolve) => setTimeout(resolve, 1));
this.#_cleanHardhat();
}

this._deployRegistry();

const deployed = await this.#_ensureRegistry();

// If the deploy process failed silently we will try to clean hardhat and re-deploy
if (!deployed) {
throw new Error(
"deploying registry contract failed, cannot start network"
Expand Down Expand Up @@ -241,6 +247,20 @@ class LocalTableland {
);
}

#_cleanHardhat(): void {
// Deploy the Registry to the Hardhat node
logSync(
spawnSync(
isWindows() ? "npx.cmd" : "npx",
["hardhat", "clean", "--global"],
{
cwd: this.registryDir,
}
),
!inDebugMode()
);
}

async #_ensureRegistry(): Promise<boolean> {
const provider = getDefaultProvider(
`http://127.0.0.1:${this.registryPort}`
Expand Down

0 comments on commit bdfe8af

Please sign in to comment.