From 4c9dfc53af68f911ba8a4c59ce47bca132eccab2 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 14 Jan 2023 10:49:36 +0100 Subject: [PATCH] fix all clients --- libs/remixd/src/services/foundryClient.ts | 3 +-- libs/remixd/src/services/hardhatClient.ts | 5 ++--- libs/remixd/src/services/truffleClient.ts | 21 ++++++++++++++++++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/libs/remixd/src/services/foundryClient.ts b/libs/remixd/src/services/foundryClient.ts index 58f259ceb6..8615b35e88 100644 --- a/libs/remixd/src/services/foundryClient.ts +++ b/libs/remixd/src/services/foundryClient.ts @@ -45,9 +45,8 @@ export class FoundryClient extends PluginClient { try { this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) // watch for new folders - this.watcher.on('addDir', (path) => { + this.watcher.on('addDir', () => { if (fs.existsSync(this.buildPath) && fs.existsSync(this.cachePath)) { - this.buildPath = path this.listenOnFoundryCompilation() } }) diff --git a/libs/remixd/src/services/hardhatClient.ts b/libs/remixd/src/services/hardhatClient.ts index df24a0aaf7..8b27c25b6a 100644 --- a/libs/remixd/src/services/hardhatClient.ts +++ b/libs/remixd/src/services/hardhatClient.ts @@ -125,9 +125,8 @@ export class HardhatClient extends PluginClient { try { this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) // watch for new folders - this.watcher.on('addDir', (path) => { - if (path.endsWith('artifacts/contracts')) { - this.buildPath = path + this.watcher.on('addDir', () => { + if (fs.existsSync(this.buildPath)) { this.listenOnHardhatCompilation() } }) diff --git a/libs/remixd/src/services/truffleClient.ts b/libs/remixd/src/services/truffleClient.ts index 1fa745042e..4380317670 100644 --- a/libs/remixd/src/services/truffleClient.ts +++ b/libs/remixd/src/services/truffleClient.ts @@ -30,7 +30,26 @@ export class TruffleClient extends PluginClient { sharedFolder (currentSharedFolder: string): void { this.currentSharedFolder = currentSharedFolder this.buildPath = utils.absolutePath('build/contracts', this.currentSharedFolder) - this.listenOnTruffleCompilation() + if (fs.existsSync(this.buildPath)) { + this.listenOnTruffleCompilation()} + else { + console.log('Truffle build folder doesn\'t exist... waiting for the first compilation.') + this.listenOnTruffleFolder() + } + } + + listenOnTruffleFolder () { + try { + this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) + // watch for new folders + this.watcher.on('addDir', () => { + if (fs.existsSync(this.buildPath)) { + this.listenOnTruffleCompilation() + } + }) + } catch (e) { + console.log(e) + } } compile (configPath: string) {