Skip to content

Commit d4d4e7c

Browse files
committed
(local) run hardhat clean if registry deploy fails
1 parent 5473f91 commit d4d4e7c

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
"prettier": "prettier '**/*.{ts,json,sol,md}' --check",
1111
"prettier:fix": "npm run prettier -- --write",
1212
"format": "npm run prettier:fix && npm run lint:fix",
13-
"test": "npx lerna run test:ci --stream",
14-
"build": "npx lerna run build"
13+
"test": "HARDHAT_CLEAN=true npx lerna run test:ci --stream",
14+
"build": "npx lerna run build",
15+
"pub": "lerna publish from-package"
1516
},
1617
"devDependencies": {
1718
"@types/chai": "^4.3.5",

packages/local/src/main.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,17 @@ class LocalTableland {
154154
// wait until initialization is done
155155
await waitForReady(registryReadyEvent, this.initEmitter);
156156

157-
await new Promise((resolve) => setTimeout(resolve, 5000));
157+
if (process.env.HARDHAT_CLEAN) {
158+
console.log("HARDHAT_CLEAN env set, cleaning hardhat");
159+
await new Promise((resolve) => setTimeout(resolve, 1));
160+
this.#_cleanHardhat();
161+
}
158162

159163
this._deployRegistry();
160164

161165
const deployed = await this.#_ensureRegistry();
166+
167+
// If the deploy process failed silently we will try to clean hardhat and re-deploy
162168
if (!deployed) {
163169
throw new Error(
164170
"deploying registry contract failed, cannot start network"
@@ -241,6 +247,20 @@ class LocalTableland {
241247
);
242248
}
243249

250+
#_cleanHardhat(): void {
251+
// Deploy the Registry to the Hardhat node
252+
logSync(
253+
spawnSync(
254+
isWindows() ? "npx.cmd" : "npx",
255+
["hardhat", "clean", "--global"],
256+
{
257+
cwd: this.registryDir,
258+
}
259+
),
260+
!inDebugMode()
261+
);
262+
}
263+
244264
async #_ensureRegistry(): Promise<boolean> {
245265
const provider = getDefaultProvider(
246266
`http://127.0.0.1:${this.registryPort}`

0 commit comments

Comments
 (0)