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 d4d4e7c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"prettier": "prettier '**/*.{ts,json,sol,md}' --check",
"prettier:fix": "npm run prettier -- --write",
"format": "npm run prettier:fix && npm run lint:fix",
"test": "npx lerna run test:ci --stream",
"build": "npx lerna run build"
"test": "HARDHAT_CLEAN=true npx lerna run test:ci --stream",
"build": "npx lerna run build",
"pub": "lerna publish from-package"
},
"devDependencies": {
"@types/chai": "^4.3.5",
Expand Down
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 d4d4e7c

Please sign in to comment.