From 3541282bd52dd0b558446780dd4d6a6a99959671 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 14 Sep 2022 11:51:43 +0200 Subject: [PATCH] watch for file added --- libs/remixd/src/services/hardhatClient.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libs/remixd/src/services/hardhatClient.ts b/libs/remixd/src/services/hardhatClient.ts index 1e3bd95607..04f158c2ff 100644 --- a/libs/remixd/src/services/hardhatClient.ts +++ b/libs/remixd/src/services/hardhatClient.ts @@ -59,13 +59,17 @@ export class HardhatClient extends PluginClient { try { const buildPath = utils.absolutePath('artifacts/build-info', this.currentSharedFolder) this.watcher = chokidar.watch(buildPath, { depth: 0, ignorePermissionErrors: true }) - this.watcher.on('change', async (f: string) => { - const content = await fs.readFile(f, { encoding: 'utf-8' }) + + const processArtifact = async (path: string) => { + const content = await fs.readFile(path, { encoding: 'utf-8' }) const compilationResult = JSON.parse(content) // @ts-ignore this.call('terminal', 'log', 'received compilation result from hardhat') this.emit('compilationFinished', '', compilationResult.input, 'soljson', compilationResult.output, compilationResult.solcVersion) - }) + } + + this.watcher.on('change', (path: string) => processArtifact(path)) + this.watcher.on('add', (path: string) => processArtifact(path)) } catch (e) { console.log(e) }