From 0acc15a376558eb478dba94c4fdb1320e6e1b3e7 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 14 Jan 2023 10:44:55 +0100 Subject: [PATCH 01/36] fix foundry --- libs/remixd/src/services/foundryClient.ts | 102 ++++++++++++++-------- 1 file changed, 64 insertions(+), 38 deletions(-) diff --git a/libs/remixd/src/services/foundryClient.ts b/libs/remixd/src/services/foundryClient.ts index aa4e42f4c1..58f259ceb6 100644 --- a/libs/remixd/src/services/foundryClient.ts +++ b/libs/remixd/src/services/foundryClient.ts @@ -15,12 +15,12 @@ export class FoundryClient extends PluginClient { buildPath: string cachePath: string - constructor (private readOnly = false) { + constructor(private readOnly = false) { super() this.methods = ['compile', 'sync'] } - setWebSocket (websocket: WS): void { + setWebSocket(websocket: WS): void { this.websocket = websocket this.websocket.addEventListener('close', () => { this.warnlog = false @@ -28,14 +28,35 @@ export class FoundryClient extends PluginClient { }) } - sharedFolder (currentSharedFolder: string): void { + sharedFolder(currentSharedFolder: string): void { this.currentSharedFolder = currentSharedFolder this.buildPath = utils.absolutePath('out', this.currentSharedFolder) this.cachePath = utils.absolutePath('cache', this.currentSharedFolder) - this.listenOnFoundryCompilation() + if (fs.existsSync(this.buildPath) && fs.existsSync(this.cachePath)) { + this.listenOnFoundryCompilation() + } else { + console.log('Foundry out folder doesn\'t exist... waiting for the first compilation.') + this.listenOFoundryFolder() + } + } - compile (configPath: string) { + listenOFoundryFolder() { + try { + this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) + // watch for new folders + this.watcher.on('addDir', (path) => { + if (fs.existsSync(this.buildPath) && fs.existsSync(this.cachePath)) { + this.buildPath = path + this.listenOnFoundryCompilation() + } + }) + } catch (e) { + console.log(e) + } + } + + compile(configPath: string) { return new Promise((resolve, reject) => { if (this.readOnly) { const errMsg = '[Foundry Compilation]: Cannot compile in read-only mode' @@ -62,48 +83,53 @@ export class FoundryClient extends PluginClient { }) } - private async processArtifact () { + private async processArtifact() { const folderFiles = await fs.readdir(this.buildPath) // "out" folder - const cache = JSON.parse(await fs.readFile(join(this.cachePath, 'solidity-files-cache.json'), { encoding: 'utf-8' })) - - // name of folders are file names - for (const file of folderFiles) { - const path = join(this.buildPath, file) // out/Counter.sol/ - const compilationResult = { - input: {}, - output: { - contracts: {}, - sources: {} - }, - solcVersion: null, - compilationTarget: null + if (!fs.existsSync(join(this.cachePath, 'solidity-files-cache.json'))) return + try { + const cache = JSON.parse(await fs.readFile(join(this.cachePath, 'solidity-files-cache.json'), { encoding: 'utf-8' })) + + // name of folders are file names + for (const file of folderFiles) { + const path = join(this.buildPath, file) // out/Counter.sol/ + const compilationResult = { + input: {}, + output: { + contracts: {}, + sources: {} + }, + solcVersion: null, + compilationTarget: null + } + await this.readContract(path, compilationResult, cache) + this.emit('compilationFinished', compilationResult.compilationTarget, { sources: compilationResult.input }, 'soljson', compilationResult.output, compilationResult.solcVersion) } - await this.readContract(path, compilationResult, cache) - this.emit('compilationFinished', compilationResult.compilationTarget, { sources: compilationResult.input } , 'soljson', compilationResult.output, compilationResult.solcVersion) - } - if (!this.warnlog) { - // @ts-ignore - this.call('terminal', 'log', { type: 'log', value: 'receiving compilation result from Foundry' }) - this.warnlog = true + if (!this.warnlog) { + // @ts-ignore + this.call('terminal', 'log', { type: 'log', value: 'receiving compilation result from Foundry' }) + this.warnlog = true + } + } catch (e) { + console.log(e) } } - listenOnFoundryCompilation () { - try { + listenOnFoundryCompilation() { + try { this.watcher = chokidar.watch(this.cachePath, { depth: 0, ignorePermissionErrors: true, ignoreInitial: true }) - + this.watcher.on('change', async (f: string) => this.processArtifact()) this.watcher.on('add', async (f: string) => this.processArtifact()) // process the artifact on activation setTimeout(() => this.processArtifact(), 1000) } catch (e) { console.log(e) - } + } } - async readContract (contractFolder, compilationResultPart, cache) { + async readContract(contractFolder, compilationResultPart, cache) { const files = await fs.readdir(contractFolder) - + for (const file of files) { const path = join(contractFolder, file) const content = await fs.readFile(path, { encoding: 'utf-8' }) @@ -111,13 +137,13 @@ export class FoundryClient extends PluginClient { } } - async feedContractArtifactFile (path, content, compilationResultPart, cache) { + async feedContractArtifactFile(path, content, compilationResultPart, cache) { const contentJSON = JSON.parse(content) const contractName = basename(path).replace('.json', '') - + const currentCache = cache.files[contentJSON.ast.absolutePath] if (!currentCache.artifacts[contractName]) return - + // extract source and version const metadata = contentJSON.metadata if (metadata.compiler && metadata.compiler.version) { @@ -141,7 +167,7 @@ export class FoundryClient extends PluginClient { console.log('\x1b[32m%s\x1b[0m', 'sources input not found, please update Foundry to the latest version.') } - + compilationResultPart.compilationTarget = contentJSON.ast.absolutePath // extract data if (!compilationResultPart.output['sources'][contentJSON.ast.absolutePath]) compilationResultPart.output['sources'][contentJSON.ast.absolutePath] = {} @@ -163,10 +189,10 @@ export class FoundryClient extends PluginClient { } } - async sync () { + async sync() { console.log('syncing from Foundry') this.processArtifact() // @ts-ignore - this.call('terminal', 'log', { type: 'log', value: 'synced with Foundry'}) + this.call('terminal', 'log', { type: 'log', value: 'synced with Foundry' }) } } From 53c89c68bd0e29e3abfe03b66e6a7cfca946cccb Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 14 Jan 2023 10:49:36 +0100 Subject: [PATCH 02/36] 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) { From 3711d568e05da258be0a3722f15073082e6b19f0 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 14 Jan 2023 10:51:24 +0100 Subject: [PATCH 03/36] synatx --- libs/remixd/src/services/foundryClient.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libs/remixd/src/services/foundryClient.ts b/libs/remixd/src/services/foundryClient.ts index 8615b35e88..788db5371d 100644 --- a/libs/remixd/src/services/foundryClient.ts +++ b/libs/remixd/src/services/foundryClient.ts @@ -20,7 +20,7 @@ export class FoundryClient extends PluginClient { this.methods = ['compile', 'sync'] } - setWebSocket(websocket: WS): void { + setWebSocket (websocket: WS): void { this.websocket = websocket this.websocket.addEventListener('close', () => { this.warnlog = false @@ -28,7 +28,7 @@ export class FoundryClient extends PluginClient { }) } - sharedFolder(currentSharedFolder: string): void { + sharedFolder (currentSharedFolder: string): void { this.currentSharedFolder = currentSharedFolder this.buildPath = utils.absolutePath('out', this.currentSharedFolder) this.cachePath = utils.absolutePath('cache', this.currentSharedFolder) @@ -55,7 +55,7 @@ export class FoundryClient extends PluginClient { } } - compile(configPath: string) { + compile (configPath: string) { return new Promise((resolve, reject) => { if (this.readOnly) { const errMsg = '[Foundry Compilation]: Cannot compile in read-only mode' @@ -82,7 +82,7 @@ export class FoundryClient extends PluginClient { }) } - private async processArtifact() { + private async processArtifact () { const folderFiles = await fs.readdir(this.buildPath) // "out" folder if (!fs.existsSync(join(this.cachePath, 'solidity-files-cache.json'))) return try { @@ -113,7 +113,7 @@ export class FoundryClient extends PluginClient { } } - listenOnFoundryCompilation() { + listenOnFoundryCompilation () { try { this.watcher = chokidar.watch(this.cachePath, { depth: 0, ignorePermissionErrors: true, ignoreInitial: true }) @@ -126,7 +126,7 @@ export class FoundryClient extends PluginClient { } } - async readContract(contractFolder, compilationResultPart, cache) { + async readContract (contractFolder, compilationResultPart, cache) { const files = await fs.readdir(contractFolder) for (const file of files) { @@ -136,7 +136,7 @@ export class FoundryClient extends PluginClient { } } - async feedContractArtifactFile(path, content, compilationResultPart, cache) { + async feedContractArtifactFile (path, content, compilationResultPart, cache) { const contentJSON = JSON.parse(content) const contractName = basename(path).replace('.json', '') @@ -188,7 +188,7 @@ export class FoundryClient extends PluginClient { } } - async sync() { + async sync () { console.log('syncing from Foundry') this.processArtifact() // @ts-ignore From 3c13087cb3ddef88f131543497319b46e2580766 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 14 Jan 2023 10:52:54 +0100 Subject: [PATCH 04/36] syntax --- libs/remixd/src/services/foundryClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remixd/src/services/foundryClient.ts b/libs/remixd/src/services/foundryClient.ts index 788db5371d..51b6c08963 100644 --- a/libs/remixd/src/services/foundryClient.ts +++ b/libs/remixd/src/services/foundryClient.ts @@ -15,7 +15,7 @@ export class FoundryClient extends PluginClient { buildPath: string cachePath: string - constructor(private readOnly = false) { + constructor (private readOnly = false) { super() this.methods = ['compile', 'sync'] } From 1fb994f9f46fcad567e29855b20f9fc7bb803e6d Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 14 Jan 2023 10:44:55 +0100 Subject: [PATCH 05/36] fix foundry --- libs/remixd/src/services/foundryClient.ts | 102 ++++++++++++++-------- 1 file changed, 64 insertions(+), 38 deletions(-) diff --git a/libs/remixd/src/services/foundryClient.ts b/libs/remixd/src/services/foundryClient.ts index aa4e42f4c1..58f259ceb6 100644 --- a/libs/remixd/src/services/foundryClient.ts +++ b/libs/remixd/src/services/foundryClient.ts @@ -15,12 +15,12 @@ export class FoundryClient extends PluginClient { buildPath: string cachePath: string - constructor (private readOnly = false) { + constructor(private readOnly = false) { super() this.methods = ['compile', 'sync'] } - setWebSocket (websocket: WS): void { + setWebSocket(websocket: WS): void { this.websocket = websocket this.websocket.addEventListener('close', () => { this.warnlog = false @@ -28,14 +28,35 @@ export class FoundryClient extends PluginClient { }) } - sharedFolder (currentSharedFolder: string): void { + sharedFolder(currentSharedFolder: string): void { this.currentSharedFolder = currentSharedFolder this.buildPath = utils.absolutePath('out', this.currentSharedFolder) this.cachePath = utils.absolutePath('cache', this.currentSharedFolder) - this.listenOnFoundryCompilation() + if (fs.existsSync(this.buildPath) && fs.existsSync(this.cachePath)) { + this.listenOnFoundryCompilation() + } else { + console.log('Foundry out folder doesn\'t exist... waiting for the first compilation.') + this.listenOFoundryFolder() + } + } - compile (configPath: string) { + listenOFoundryFolder() { + try { + this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) + // watch for new folders + this.watcher.on('addDir', (path) => { + if (fs.existsSync(this.buildPath) && fs.existsSync(this.cachePath)) { + this.buildPath = path + this.listenOnFoundryCompilation() + } + }) + } catch (e) { + console.log(e) + } + } + + compile(configPath: string) { return new Promise((resolve, reject) => { if (this.readOnly) { const errMsg = '[Foundry Compilation]: Cannot compile in read-only mode' @@ -62,48 +83,53 @@ export class FoundryClient extends PluginClient { }) } - private async processArtifact () { + private async processArtifact() { const folderFiles = await fs.readdir(this.buildPath) // "out" folder - const cache = JSON.parse(await fs.readFile(join(this.cachePath, 'solidity-files-cache.json'), { encoding: 'utf-8' })) - - // name of folders are file names - for (const file of folderFiles) { - const path = join(this.buildPath, file) // out/Counter.sol/ - const compilationResult = { - input: {}, - output: { - contracts: {}, - sources: {} - }, - solcVersion: null, - compilationTarget: null + if (!fs.existsSync(join(this.cachePath, 'solidity-files-cache.json'))) return + try { + const cache = JSON.parse(await fs.readFile(join(this.cachePath, 'solidity-files-cache.json'), { encoding: 'utf-8' })) + + // name of folders are file names + for (const file of folderFiles) { + const path = join(this.buildPath, file) // out/Counter.sol/ + const compilationResult = { + input: {}, + output: { + contracts: {}, + sources: {} + }, + solcVersion: null, + compilationTarget: null + } + await this.readContract(path, compilationResult, cache) + this.emit('compilationFinished', compilationResult.compilationTarget, { sources: compilationResult.input }, 'soljson', compilationResult.output, compilationResult.solcVersion) } - await this.readContract(path, compilationResult, cache) - this.emit('compilationFinished', compilationResult.compilationTarget, { sources: compilationResult.input } , 'soljson', compilationResult.output, compilationResult.solcVersion) - } - if (!this.warnlog) { - // @ts-ignore - this.call('terminal', 'log', { type: 'log', value: 'receiving compilation result from Foundry' }) - this.warnlog = true + if (!this.warnlog) { + // @ts-ignore + this.call('terminal', 'log', { type: 'log', value: 'receiving compilation result from Foundry' }) + this.warnlog = true + } + } catch (e) { + console.log(e) } } - listenOnFoundryCompilation () { - try { + listenOnFoundryCompilation() { + try { this.watcher = chokidar.watch(this.cachePath, { depth: 0, ignorePermissionErrors: true, ignoreInitial: true }) - + this.watcher.on('change', async (f: string) => this.processArtifact()) this.watcher.on('add', async (f: string) => this.processArtifact()) // process the artifact on activation setTimeout(() => this.processArtifact(), 1000) } catch (e) { console.log(e) - } + } } - async readContract (contractFolder, compilationResultPart, cache) { + async readContract(contractFolder, compilationResultPart, cache) { const files = await fs.readdir(contractFolder) - + for (const file of files) { const path = join(contractFolder, file) const content = await fs.readFile(path, { encoding: 'utf-8' }) @@ -111,13 +137,13 @@ export class FoundryClient extends PluginClient { } } - async feedContractArtifactFile (path, content, compilationResultPart, cache) { + async feedContractArtifactFile(path, content, compilationResultPart, cache) { const contentJSON = JSON.parse(content) const contractName = basename(path).replace('.json', '') - + const currentCache = cache.files[contentJSON.ast.absolutePath] if (!currentCache.artifacts[contractName]) return - + // extract source and version const metadata = contentJSON.metadata if (metadata.compiler && metadata.compiler.version) { @@ -141,7 +167,7 @@ export class FoundryClient extends PluginClient { console.log('\x1b[32m%s\x1b[0m', 'sources input not found, please update Foundry to the latest version.') } - + compilationResultPart.compilationTarget = contentJSON.ast.absolutePath // extract data if (!compilationResultPart.output['sources'][contentJSON.ast.absolutePath]) compilationResultPart.output['sources'][contentJSON.ast.absolutePath] = {} @@ -163,10 +189,10 @@ export class FoundryClient extends PluginClient { } } - async sync () { + async sync() { console.log('syncing from Foundry') this.processArtifact() // @ts-ignore - this.call('terminal', 'log', { type: 'log', value: 'synced with Foundry'}) + this.call('terminal', 'log', { type: 'log', value: 'synced with Foundry' }) } } From b37476cd05b554f119d1569a4f05dba602b2b802 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 14 Jan 2023 10:49:36 +0100 Subject: [PATCH 06/36] 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) { From a5193b6f461cba3bd9bddb1f6b7ff0fcdf2b67ce Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 14 Jan 2023 10:51:24 +0100 Subject: [PATCH 07/36] synatx --- libs/remixd/src/services/foundryClient.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libs/remixd/src/services/foundryClient.ts b/libs/remixd/src/services/foundryClient.ts index 8615b35e88..788db5371d 100644 --- a/libs/remixd/src/services/foundryClient.ts +++ b/libs/remixd/src/services/foundryClient.ts @@ -20,7 +20,7 @@ export class FoundryClient extends PluginClient { this.methods = ['compile', 'sync'] } - setWebSocket(websocket: WS): void { + setWebSocket (websocket: WS): void { this.websocket = websocket this.websocket.addEventListener('close', () => { this.warnlog = false @@ -28,7 +28,7 @@ export class FoundryClient extends PluginClient { }) } - sharedFolder(currentSharedFolder: string): void { + sharedFolder (currentSharedFolder: string): void { this.currentSharedFolder = currentSharedFolder this.buildPath = utils.absolutePath('out', this.currentSharedFolder) this.cachePath = utils.absolutePath('cache', this.currentSharedFolder) @@ -55,7 +55,7 @@ export class FoundryClient extends PluginClient { } } - compile(configPath: string) { + compile (configPath: string) { return new Promise((resolve, reject) => { if (this.readOnly) { const errMsg = '[Foundry Compilation]: Cannot compile in read-only mode' @@ -82,7 +82,7 @@ export class FoundryClient extends PluginClient { }) } - private async processArtifact() { + private async processArtifact () { const folderFiles = await fs.readdir(this.buildPath) // "out" folder if (!fs.existsSync(join(this.cachePath, 'solidity-files-cache.json'))) return try { @@ -113,7 +113,7 @@ export class FoundryClient extends PluginClient { } } - listenOnFoundryCompilation() { + listenOnFoundryCompilation () { try { this.watcher = chokidar.watch(this.cachePath, { depth: 0, ignorePermissionErrors: true, ignoreInitial: true }) @@ -126,7 +126,7 @@ export class FoundryClient extends PluginClient { } } - async readContract(contractFolder, compilationResultPart, cache) { + async readContract (contractFolder, compilationResultPart, cache) { const files = await fs.readdir(contractFolder) for (const file of files) { @@ -136,7 +136,7 @@ export class FoundryClient extends PluginClient { } } - async feedContractArtifactFile(path, content, compilationResultPart, cache) { + async feedContractArtifactFile (path, content, compilationResultPart, cache) { const contentJSON = JSON.parse(content) const contractName = basename(path).replace('.json', '') @@ -188,7 +188,7 @@ export class FoundryClient extends PluginClient { } } - async sync() { + async sync () { console.log('syncing from Foundry') this.processArtifact() // @ts-ignore From 388aecea68ba27d000111841b3a76b9fae7f1082 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 14 Jan 2023 10:52:54 +0100 Subject: [PATCH 08/36] syntax --- libs/remixd/src/services/foundryClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remixd/src/services/foundryClient.ts b/libs/remixd/src/services/foundryClient.ts index 788db5371d..51b6c08963 100644 --- a/libs/remixd/src/services/foundryClient.ts +++ b/libs/remixd/src/services/foundryClient.ts @@ -15,7 +15,7 @@ export class FoundryClient extends PluginClient { buildPath: string cachePath: string - constructor(private readOnly = false) { + constructor (private readOnly = false) { super() this.methods = ['compile', 'sync'] } From 21c1bcc752aef28a582c3446029cb9cb670fa6d6 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 19 Jan 2023 20:20:47 +0100 Subject: [PATCH 09/36] extra checks --- libs/remixd/src/services/foundryClient.ts | 36 +++++++++++++++-------- libs/remixd/src/services/hardhatClient.ts | 9 +++++- libs/remixd/src/services/truffleClient.ts | 15 +++++++--- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/libs/remixd/src/services/foundryClient.ts b/libs/remixd/src/services/foundryClient.ts index 51b6c08963..6def00becc 100644 --- a/libs/remixd/src/services/foundryClient.ts +++ b/libs/remixd/src/services/foundryClient.ts @@ -15,12 +15,12 @@ export class FoundryClient extends PluginClient { buildPath: string cachePath: string - constructor (private readOnly = false) { + constructor(private readOnly = false) { super() this.methods = ['compile', 'sync'] } - setWebSocket (websocket: WS): void { + setWebSocket(websocket: WS): void { this.websocket = websocket this.websocket.addEventListener('close', () => { this.warnlog = false @@ -28,7 +28,7 @@ export class FoundryClient extends PluginClient { }) } - sharedFolder (currentSharedFolder: string): void { + sharedFolder(currentSharedFolder: string): void { this.currentSharedFolder = currentSharedFolder this.buildPath = utils.absolutePath('out', this.currentSharedFolder) this.cachePath = utils.absolutePath('cache', this.currentSharedFolder) @@ -55,7 +55,7 @@ export class FoundryClient extends PluginClient { } } - compile (configPath: string) { + compile(configPath: string) { return new Promise((resolve, reject) => { if (this.readOnly) { const errMsg = '[Foundry Compilation]: Cannot compile in read-only mode' @@ -82,12 +82,12 @@ export class FoundryClient extends PluginClient { }) } - private async processArtifact () { + private async processArtifact() { const folderFiles = await fs.readdir(this.buildPath) // "out" folder if (!fs.existsSync(join(this.cachePath, 'solidity-files-cache.json'))) return try { const cache = JSON.parse(await fs.readFile(join(this.cachePath, 'solidity-files-cache.json'), { encoding: 'utf-8' })) - + // name of folders are file names for (const file of folderFiles) { const path = join(this.buildPath, file) // out/Counter.sol/ @@ -113,7 +113,7 @@ export class FoundryClient extends PluginClient { } } - listenOnFoundryCompilation () { + listenOnFoundryCompilation() { try { this.watcher = chokidar.watch(this.cachePath, { depth: 0, ignorePermissionErrors: true, ignoreInitial: true }) @@ -126,7 +126,7 @@ export class FoundryClient extends PluginClient { } } - async readContract (contractFolder, compilationResultPart, cache) { + async readContract(contractFolder, compilationResultPart, cache) { const files = await fs.readdir(contractFolder) for (const file of files) { @@ -136,7 +136,7 @@ export class FoundryClient extends PluginClient { } } - async feedContractArtifactFile (path, content, compilationResultPart, cache) { + async feedContractArtifactFile(path, content, compilationResultPart, cache) { const contentJSON = JSON.parse(content) const contractName = basename(path).replace('.json', '') @@ -188,10 +188,20 @@ export class FoundryClient extends PluginClient { } } - async sync () { + async sync() { console.log('syncing from Foundry') - this.processArtifact() - // @ts-ignore - this.call('terminal', 'log', { type: 'log', value: 'synced with Foundry' }) + if (fs.existsSync(this.buildPath) && fs.existsSync(this.cachePath)) { + if (!fs.existsSync(join(this.cachePath, 'solidity-files-cache.json'))) { + console.log('No compilation data found') + // @ts-ignore + this.call('terminal', 'log', { type: 'log', value: 'No compilation data found' }) + } else{ + this.processArtifact() + // @ts-ignore + this.call('terminal', 'log', { type: 'log', value: 'synced with Foundry' }) + } + } else { + this.listenOFoundryFolder() + } } } diff --git a/libs/remixd/src/services/hardhatClient.ts b/libs/remixd/src/services/hardhatClient.ts index 8b27c25b6a..6207cdb091 100644 --- a/libs/remixd/src/services/hardhatClient.ts +++ b/libs/remixd/src/services/hardhatClient.ts @@ -151,7 +151,14 @@ export class HardhatClient extends PluginClient { async sync() { console.log('syncing from Hardhat') - this.processArtifact() + if(fs.existsSync(this.buildPath)) { + this.processArtifact() + }else{ + console.log('No compilation result found') + this.listenOnHardHatFolder() + // ts-ignore + this.call('terminal', 'log', { type: 'log', value: 'No compilation result found' }) + } } async feedContractArtifactFile(artifactContent, compilationResultPart) { diff --git a/libs/remixd/src/services/truffleClient.ts b/libs/remixd/src/services/truffleClient.ts index 4380317670..e1a998c8aa 100644 --- a/libs/remixd/src/services/truffleClient.ts +++ b/libs/remixd/src/services/truffleClient.ts @@ -157,9 +157,16 @@ export class TruffleClient extends PluginClient { } async sync () { - console.log('syncing from Truffle') - this.processArtifact() - // @ts-ignore - this.call('terminal', 'log', { type: 'log', value: 'synced with Truffle' }) + if (fs.existsSync(this.buildPath)) { + console.log('syncing from Truffle') + this.processArtifact() + // @ts-ignore + this.call('terminal', 'log', { type: 'log', value: 'synced with Truffle' }) + }else{ + console.log('Truffle build folder doesn\'t exist... waiting for the first compilation.') + this.listenOnTruffleFolder() + // @ts-ignore + this.call('terminal', 'log', { type: 'log', value: 'Truffle build folder doesn\'t exist... waiting for the first compilation.' }) + } } } From c1f4d1ef63126fb41f5135c06063672758980d7c Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 09:53:50 +0100 Subject: [PATCH 10/36] remixd script --- .circleci/config.yml | 42 +++++++++++++++- apps/remix-ide/ci/remixd_test.sh | 23 +++++++++ libs/remixd/src/services/foundryClient.ts | 61 +++++++++++++---------- 3 files changed, 99 insertions(+), 27 deletions(-) create mode 100644 apps/remix-ide/ci/remixd_test.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index bce1337067..c782528c08 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -76,6 +76,43 @@ jobs: - run: node dist/libs/remix-tests/bin/remix-tests ./libs/remix-tests/tests/examples_0/assert_ok_test.sol - run: yarn run test:libs + remixd: + docker: + - image: cimg/node:14.17.6-browsers + resource_class: + xlarge + working_directory: ~/remix-project + steps: + - browser-tools/install-browser-tools + - run: + command: | + google-chrome --version + firefox --version + geckodriver --version + chromedriver --version + rm LICENSE.chromedriver 2> /dev/null + - checkout + - attach_workspace: + at: . + - run: unzip ./persist/dist.zip + + - restore_cache: + keys: + - v1-deps-{{ checksum "yarn.lock" }} + - run: yarn + - run: yarn run downloadsolc_assets_e2e && yarn run downloadsolc_assets_dist + - run: ls -la ./dist/apps/remix-ide/assets/js + - run: yarn run selenium-install || yarn run selenium-install + - run: + name: Start Selenium + command: yarn run selenium + background: true + - run: ./apps/remix-ide/ci/remixd_test.sh + - store_test_results: + path: ./reports/tests + - store_artifacts: + path: ./reports/screenshots + remix-ide-browser: docker: - image: cimg/node:14.17.6-browsers @@ -273,6 +310,9 @@ workflows: matrix: parameters: script: ["browser_tests_plugin_api.sh", "browser_tests_etherscan_plugin.sh", "browser_tests_vyper_plugin.sh"] + - remixd: + requires: + - build - remix-ide-browser: requires: - build @@ -316,4 +356,4 @@ workflows: branches: only: remix_beta -# VS Code Extension Version: 1.5.0 \ No newline at end of file +# VS Code Extension Version: 1.5.1 \ No newline at end of file diff --git a/apps/remix-ide/ci/remixd_test.sh b/apps/remix-ide/ci/remixd_test.sh new file mode 100644 index 0000000000..573db6d238 --- /dev/null +++ b/apps/remix-ide/ci/remixd_test.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -e + +BUILD_ID=${CIRCLE_BUILD_NUM:-${TRAVIS_JOB_NUMBER}} +echo "$BUILD_ID" +TEST_EXITCODE=0 + +# install foundry +curl -L https://foundry.paradigm.xyz | bash +foundryup +forge init foundry +ls -la foundry + +sleep 5 + +yarn run build:e2e + +echo "$TEST_EXITCODE" +if [ "$TEST_EXITCODE" -eq 1 ] +then + exit 1 +fi diff --git a/libs/remixd/src/services/foundryClient.ts b/libs/remixd/src/services/foundryClient.ts index 5f9fbc02e3..85b5a9319b 100644 --- a/libs/remixd/src/services/foundryClient.ts +++ b/libs/remixd/src/services/foundryClient.ts @@ -14,6 +14,8 @@ export class FoundryClient extends PluginClient { warnlog: boolean buildPath: string cachePath: string + logTimeout: NodeJS.Timeout + processingTimeout: NodeJS.Timeout constructor(private readOnly = false) { super() @@ -36,12 +38,13 @@ export class FoundryClient extends PluginClient { this.listenOnFoundryCompilation() } else { console.log('Foundry out folder doesn\'t exist... waiting for the first compilation.') - this.listenOFoundryFolder() + this.listenOnFoundryFolder() } - } - listenOFoundryFolder() { + + + listenOnFoundryFolder() { try { this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) // watch for new folders @@ -55,7 +58,7 @@ export class FoundryClient extends PluginClient { } } - compile(configPath: string) { + compile() { return new Promise((resolve, reject) => { if (this.readOnly) { const errMsg = '[Foundry Compilation]: Cannot compile in read-only mode' @@ -82,9 +85,19 @@ export class FoundryClient extends PluginClient { }) } + checkPath() { + console.log('checkPath', fs.existsSync(this.buildPath), fs.existsSync(this.cachePath), fs.existsSync(join(this.cachePath, 'solidity-files-cache.json'))) + if (!fs.existsSync(this.buildPath) || !fs.existsSync(this.cachePath)) { + this.listenOnFoundryFolder() + return false + } + if (!fs.existsSync(join(this.cachePath, 'solidity-files-cache.json'))) return false + return true + } + private async processArtifact() { + if (!this.checkPath()) return const folderFiles = await fs.readdir(this.buildPath) // "out" folder - if (!fs.existsSync(join(this.cachePath, 'solidity-files-cache.json'))) return try { const cache = JSON.parse(await fs.readFile(join(this.cachePath, 'solidity-files-cache.json'), { encoding: 'utf-8' })) // name of folders are file names @@ -102,24 +115,32 @@ export class FoundryClient extends PluginClient { await this.readContract(path, compilationResult, cache) this.emit('compilationFinished', compilationResult.compilationTarget, { sources: compilationResult.input }, 'soljson', compilationResult.output, compilationResult.solcVersion) } - if (!this.warnlog) { + + clearTimeout(this.logTimeout) + this.logTimeout = setTimeout(() => { // @ts-ignore - this.call('terminal', 'log', { type: 'log', value: 'receiving compilation result from Foundry' }) - this.warnlog = true - } + this.call('terminal', 'log', { type: 'log', value: 'receiving compilation result from Foundry' }), 1000 + }) + } catch (e) { console.log(e) } } + async triggerProcessArtifact() { + // prevent multiple calls + clearTimeout(this.processingTimeout) + this.processingTimeout = setTimeout(async () => await this.processArtifact(), 1000) + } + listenOnFoundryCompilation() { try { this.watcher = chokidar.watch(this.cachePath, { depth: 0, ignorePermissionErrors: true, ignoreInitial: true }) - this.watcher.on('change', async (f: string) => this.processArtifact()) - this.watcher.on('add', async (f: string) => this.processArtifact()) + this.watcher.on('change', async () => await this.triggerProcessArtifact()) + this.watcher.on('add', async () => await this.triggerProcessArtifact()) // process the artifact on activation - setTimeout(() => this.processArtifact(), 1000) + this.triggerProcessArtifact() } catch (e) { console.log(e) } @@ -188,19 +209,7 @@ export class FoundryClient extends PluginClient { } async sync() { - console.log('syncing from Foundry') - if (fs.existsSync(this.buildPath) && fs.existsSync(this.cachePath)) { - if (!fs.existsSync(join(this.cachePath, 'solidity-files-cache.json'))) { - console.log('No compilation data found') - // @ts-ignore - this.call('terminal', 'log', { type: 'log', value: 'No compilation data found' }) - } else{ - this.processArtifact() - // @ts-ignore - this.call('terminal', 'log', { type: 'log', value: 'synced with Foundry' }) - } - } else { - this.listenOFoundryFolder() - } + console.log('syncing Foundry with Remix...') + this.processArtifact() } } From e4a484cc6d75820d294d137c722f1adaf096134d Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 10:01:32 +0100 Subject: [PATCH 11/36] permissions --- apps/remix-ide/ci/remixd_test.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 apps/remix-ide/ci/remixd_test.sh diff --git a/apps/remix-ide/ci/remixd_test.sh b/apps/remix-ide/ci/remixd_test.sh old mode 100644 new mode 100755 From 8f3fc4ae4abe823f80288c0a4fd1d70d94a3a58c Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 10:04:47 +0100 Subject: [PATCH 12/36] truffle install --- apps/remix-ide/ci/remixd_test.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/remix-ide/ci/remixd_test.sh b/apps/remix-ide/ci/remixd_test.sh index 573db6d238..4d6c27c2da 100755 --- a/apps/remix-ide/ci/remixd_test.sh +++ b/apps/remix-ide/ci/remixd_test.sh @@ -12,6 +12,15 @@ foundryup forge init foundry ls -la foundry +# install truffle with yarn +yarn global add truffle +# install truffle metacoin box +mkdir MetaCoin +cd MetaCoin +truffle unbox metacoin + + + sleep 5 yarn run build:e2e From 9b6f8a81b67612150a3221cb18c870428c341e1b Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 10:05:38 +0100 Subject: [PATCH 13/36] add hardhat --- apps/remix-ide/ci/remixd_test.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/remix-ide/ci/remixd_test.sh b/apps/remix-ide/ci/remixd_test.sh index 4d6c27c2da..5ef72959f5 100755 --- a/apps/remix-ide/ci/remixd_test.sh +++ b/apps/remix-ide/ci/remixd_test.sh @@ -19,6 +19,8 @@ mkdir MetaCoin cd MetaCoin truffle unbox metacoin +# install hardhat +yarn global add hardhat sleep 5 From 811dedc88314a1f7c1c2329f6d5b8a98596e4429 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 10:06:21 +0100 Subject: [PATCH 14/36] directory change --- apps/remix-ide/ci/remixd_test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/remix-ide/ci/remixd_test.sh b/apps/remix-ide/ci/remixd_test.sh index 5ef72959f5..6003e86d45 100755 --- a/apps/remix-ide/ci/remixd_test.sh +++ b/apps/remix-ide/ci/remixd_test.sh @@ -18,6 +18,7 @@ yarn global add truffle mkdir MetaCoin cd MetaCoin truffle unbox metacoin +cd .. # install hardhat yarn global add hardhat From 26a59c9cb4451846432a424f865aa3408957478d Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 10:15:33 +0100 Subject: [PATCH 15/36] path --- apps/remix-ide/ci/remixd_test.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/remix-ide/ci/remixd_test.sh b/apps/remix-ide/ci/remixd_test.sh index 6003e86d45..9e5af1969b 100755 --- a/apps/remix-ide/ci/remixd_test.sh +++ b/apps/remix-ide/ci/remixd_test.sh @@ -8,6 +8,8 @@ TEST_EXITCODE=0 # install foundry curl -L https://foundry.paradigm.xyz | bash +# export /home/circleci/.foundry/bin to PATH +export PATH=$PATH:/home/circleci/.foundry/bin foundryup forge init foundry ls -la foundry From 25c04a4653de5b8fe84cbda9c2577d703bb58772 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 10:21:36 +0100 Subject: [PATCH 16/36] rm set --- apps/remix-ide/ci/remixd_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/ci/remixd_test.sh b/apps/remix-ide/ci/remixd_test.sh index 9e5af1969b..afe00942e3 100755 --- a/apps/remix-ide/ci/remixd_test.sh +++ b/apps/remix-ide/ci/remixd_test.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -e +# set -e BUILD_ID=${CIRCLE_BUILD_NUM:-${TRAVIS_JOB_NUMBER}} echo "$BUILD_ID" From e71db2df43094c77bab3115de2796368b589abfc Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 10:24:30 +0100 Subject: [PATCH 17/36] shell --- apps/remix-ide/ci/remixd_test.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/remix-ide/ci/remixd_test.sh b/apps/remix-ide/ci/remixd_test.sh index afe00942e3..cc7ae53463 100755 --- a/apps/remix-ide/ci/remixd_test.sh +++ b/apps/remix-ide/ci/remixd_test.sh @@ -6,6 +6,8 @@ BUILD_ID=${CIRCLE_BUILD_NUM:-${TRAVIS_JOB_NUMBER}} echo "$BUILD_ID" TEST_EXITCODE=0 +echo $SHELL + # install foundry curl -L https://foundry.paradigm.xyz | bash # export /home/circleci/.foundry/bin to PATH From ef78d3ae50092496a990ba6cbd7bad49048e3f98 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 10:31:09 +0100 Subject: [PATCH 18/36] zsh --- .circleci/config.yml | 2 +- apps/remix-ide/ci/remixd_test.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c782528c08..387ef33053 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -107,7 +107,7 @@ jobs: name: Start Selenium command: yarn run selenium background: true - - run: ./apps/remix-ide/ci/remixd_test.sh + - run: zsh ./apps/remix-ide/ci/remixd_test.sh - store_test_results: path: ./reports/tests - store_artifacts: diff --git a/apps/remix-ide/ci/remixd_test.sh b/apps/remix-ide/ci/remixd_test.sh index cc7ae53463..109267a8e3 100755 --- a/apps/remix-ide/ci/remixd_test.sh +++ b/apps/remix-ide/ci/remixd_test.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# set -e +set -e BUILD_ID=${CIRCLE_BUILD_NUM:-${TRAVIS_JOB_NUMBER}} echo "$BUILD_ID" From 56970e5f3f82191a65dae0fa598d4bc0de979444 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 10:38:13 +0100 Subject: [PATCH 19/36] zsh --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 387ef33053..5ccdfc8360 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -103,6 +103,7 @@ jobs: - run: yarn run downloadsolc_assets_e2e && yarn run downloadsolc_assets_dist - run: ls -la ./dist/apps/remix-ide/assets/js - run: yarn run selenium-install || yarn run selenium-install + - run: sudo apt install zsh - run: name: Start Selenium command: yarn run selenium From 052fea82d3cdc150346c1a4ad2734cfcd887d9c9 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 10:44:54 +0100 Subject: [PATCH 20/36] zsh --- apps/remix-ide/ci/remixd_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/ci/remixd_test.sh b/apps/remix-ide/ci/remixd_test.sh index 109267a8e3..3953431993 100755 --- a/apps/remix-ide/ci/remixd_test.sh +++ b/apps/remix-ide/ci/remixd_test.sh @@ -9,7 +9,7 @@ TEST_EXITCODE=0 echo $SHELL # install foundry -curl -L https://foundry.paradigm.xyz | bash +curl -L https://foundry.paradigm.xyz | zsh # export /home/circleci/.foundry/bin to PATH export PATH=$PATH:/home/circleci/.foundry/bin foundryup From d9953ad96ef6af9b1bb70cac41a22ccaaaff2154 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 10:46:07 +0100 Subject: [PATCH 21/36] zsh --- apps/remix-ide/ci/remixd_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/ci/remixd_test.sh b/apps/remix-ide/ci/remixd_test.sh index 3953431993..211d8f7716 100755 --- a/apps/remix-ide/ci/remixd_test.sh +++ b/apps/remix-ide/ci/remixd_test.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env zsh set -e From 4073004257b8408fd3905eed4e17a261c19d3ad5 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 10:56:11 +0100 Subject: [PATCH 22/36] bash --- .circleci/config.yml | 2 +- apps/remix-ide/ci/remixd_test.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5ccdfc8360..bee02b8ed5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -108,7 +108,7 @@ jobs: name: Start Selenium command: yarn run selenium background: true - - run: zsh ./apps/remix-ide/ci/remixd_test.sh + - run: bash ./apps/remix-ide/ci/remixd_test.sh - store_test_results: path: ./reports/tests - store_artifacts: diff --git a/apps/remix-ide/ci/remixd_test.sh b/apps/remix-ide/ci/remixd_test.sh index 211d8f7716..109267a8e3 100755 --- a/apps/remix-ide/ci/remixd_test.sh +++ b/apps/remix-ide/ci/remixd_test.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env zsh +#!/usr/bin/env bash set -e @@ -9,7 +9,7 @@ TEST_EXITCODE=0 echo $SHELL # install foundry -curl -L https://foundry.paradigm.xyz | zsh +curl -L https://foundry.paradigm.xyz | bash # export /home/circleci/.foundry/bin to PATH export PATH=$PATH:/home/circleci/.foundry/bin foundryup From 8b55bdce2662cafaa562689b78a48d696ddcaa5e Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 11:02:58 +0100 Subject: [PATCH 23/36] catching --- apps/remix-ide/ci/remixd_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/ci/remixd_test.sh b/apps/remix-ide/ci/remixd_test.sh index 109267a8e3..ac44e207ed 100755 --- a/apps/remix-ide/ci/remixd_test.sh +++ b/apps/remix-ide/ci/remixd_test.sh @@ -9,7 +9,7 @@ TEST_EXITCODE=0 echo $SHELL # install foundry -curl -L https://foundry.paradigm.xyz | bash +curl -L https://foundry.paradigm.xyz | bash || true # export /home/circleci/.foundry/bin to PATH export PATH=$PATH:/home/circleci/.foundry/bin foundryup From 6a592512a0b613a05ced461e2f3f8a6fff052786 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 11:04:13 +0100 Subject: [PATCH 24/36] wrap --- apps/remix-ide/ci/remixd_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/ci/remixd_test.sh b/apps/remix-ide/ci/remixd_test.sh index ac44e207ed..966c12e472 100755 --- a/apps/remix-ide/ci/remixd_test.sh +++ b/apps/remix-ide/ci/remixd_test.sh @@ -9,7 +9,7 @@ TEST_EXITCODE=0 echo $SHELL # install foundry -curl -L https://foundry.paradigm.xyz | bash || true +{ curl -L https://foundry.paradigm.xyz | bash } || true # export /home/circleci/.foundry/bin to PATH export PATH=$PATH:/home/circleci/.foundry/bin foundryup From c989ec18900959212e8d284044ceba6e0168bbbc Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 11:10:35 +0100 Subject: [PATCH 25/36] fix error --- apps/remix-ide/ci/remixd_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/ci/remixd_test.sh b/apps/remix-ide/ci/remixd_test.sh index 966c12e472..ac44e207ed 100755 --- a/apps/remix-ide/ci/remixd_test.sh +++ b/apps/remix-ide/ci/remixd_test.sh @@ -9,7 +9,7 @@ TEST_EXITCODE=0 echo $SHELL # install foundry -{ curl -L https://foundry.paradigm.xyz | bash } || true +curl -L https://foundry.paradigm.xyz | bash || true # export /home/circleci/.foundry/bin to PATH export PATH=$PATH:/home/circleci/.foundry/bin foundryup From 6a1342d0d55c9d1427f6c8e35334d49cde18cb22 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 11:16:14 +0100 Subject: [PATCH 26/36] zsh --- .circleci/config.yml | 2 +- apps/remix-ide/ci/{remixd_test.sh => remixd_test.zsh} | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) rename apps/remix-ide/ci/{remixd_test.sh => remixd_test.zsh} (77%) diff --git a/.circleci/config.yml b/.circleci/config.yml index bee02b8ed5..d37e57a0ae 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -108,7 +108,7 @@ jobs: name: Start Selenium command: yarn run selenium background: true - - run: bash ./apps/remix-ide/ci/remixd_test.sh + - run: zsh ./apps/remix-ide/ci/remixd_test.zsh - store_test_results: path: ./reports/tests - store_artifacts: diff --git a/apps/remix-ide/ci/remixd_test.sh b/apps/remix-ide/ci/remixd_test.zsh similarity index 77% rename from apps/remix-ide/ci/remixd_test.sh rename to apps/remix-ide/ci/remixd_test.zsh index ac44e207ed..9db7498380 100755 --- a/apps/remix-ide/ci/remixd_test.sh +++ b/apps/remix-ide/ci/remixd_test.zsh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env zsh set -e @@ -9,7 +9,11 @@ TEST_EXITCODE=0 echo $SHELL # install foundry -curl -L https://foundry.paradigm.xyz | bash || true +# undo set -e because this script won't find the correct shell +# set +e +curl -L https://foundry.paradigm.xyz | zsh +# redo set -e +# set -e # export /home/circleci/.foundry/bin to PATH export PATH=$PATH:/home/circleci/.foundry/bin foundryup From bac38777168152f275479c5bf06ceb308176b6ed Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 11:22:13 +0100 Subject: [PATCH 27/36] back to bash --- .circleci/config.yml | 3 +-- apps/remix-ide/ci/remixd_test.zsh | 8 ++------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d37e57a0ae..b77ea13f05 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -103,12 +103,11 @@ jobs: - run: yarn run downloadsolc_assets_e2e && yarn run downloadsolc_assets_dist - run: ls -la ./dist/apps/remix-ide/assets/js - run: yarn run selenium-install || yarn run selenium-install - - run: sudo apt install zsh - run: name: Start Selenium command: yarn run selenium background: true - - run: zsh ./apps/remix-ide/ci/remixd_test.zsh + - run: ./apps/remix-ide/ci/remixd_test.zsh - store_test_results: path: ./reports/tests - store_artifacts: diff --git a/apps/remix-ide/ci/remixd_test.zsh b/apps/remix-ide/ci/remixd_test.zsh index 9db7498380..ac44e207ed 100755 --- a/apps/remix-ide/ci/remixd_test.zsh +++ b/apps/remix-ide/ci/remixd_test.zsh @@ -1,4 +1,4 @@ -#!/usr/bin/env zsh +#!/usr/bin/env bash set -e @@ -9,11 +9,7 @@ TEST_EXITCODE=0 echo $SHELL # install foundry -# undo set -e because this script won't find the correct shell -# set +e -curl -L https://foundry.paradigm.xyz | zsh -# redo set -e -# set -e +curl -L https://foundry.paradigm.xyz | bash || true # export /home/circleci/.foundry/bin to PATH export PATH=$PATH:/home/circleci/.foundry/bin foundryup From f085b4ae882a260db2390bbc60e7dd36e3c79a9d Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 11:27:05 +0100 Subject: [PATCH 28/36] hello_foundry --- apps/remix-ide/ci/remixd_test.zsh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide/ci/remixd_test.zsh b/apps/remix-ide/ci/remixd_test.zsh index ac44e207ed..a92e4cce86 100755 --- a/apps/remix-ide/ci/remixd_test.zsh +++ b/apps/remix-ide/ci/remixd_test.zsh @@ -13,8 +13,11 @@ curl -L https://foundry.paradigm.xyz | bash || true # export /home/circleci/.foundry/bin to PATH export PATH=$PATH:/home/circleci/.foundry/bin foundryup -forge init foundry -ls -la foundry +mkdir foundry +cd foundry +forge init hello_foundry +ls -la hello_foundry +cd .. # install truffle with yarn yarn global add truffle From 00c8e3344b402014c6c840fb3ee75d97113ff693 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 11:33:52 +0100 Subject: [PATCH 29/36] pwd --- apps/remix-ide/ci/remixd_test.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/remix-ide/ci/remixd_test.zsh b/apps/remix-ide/ci/remixd_test.zsh index a92e4cce86..fac4da1e43 100755 --- a/apps/remix-ide/ci/remixd_test.zsh +++ b/apps/remix-ide/ci/remixd_test.zsh @@ -7,7 +7,8 @@ echo "$BUILD_ID" TEST_EXITCODE=0 echo $SHELL - +ls -la . +pwd # install foundry curl -L https://foundry.paradigm.xyz | bash || true # export /home/circleci/.foundry/bin to PATH @@ -15,6 +16,7 @@ export PATH=$PATH:/home/circleci/.foundry/bin foundryup mkdir foundry cd foundry +ls -la . forge init hello_foundry ls -la hello_foundry cd .. From 3c8e8ab9cb974cb978e35c844f4f4d5476caa92f Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 11:44:53 +0100 Subject: [PATCH 30/36] dirs --- apps/remix-ide/ci/remixd_test.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/remix-ide/ci/remixd_test.zsh b/apps/remix-ide/ci/remixd_test.zsh index fac4da1e43..a7999f78fb 100755 --- a/apps/remix-ide/ci/remixd_test.zsh +++ b/apps/remix-ide/ci/remixd_test.zsh @@ -6,6 +6,7 @@ BUILD_ID=${CIRCLE_BUILD_NUM:-${TRAVIS_JOB_NUMBER}} echo "$BUILD_ID" TEST_EXITCODE=0 +cd .. echo $SHELL ls -la . pwd @@ -35,6 +36,7 @@ yarn global add hardhat sleep 5 +cd remix-project yarn run build:e2e echo "$TEST_EXITCODE" From 6a03e8fba4d786a02a3c5f067541226b2423a8ae Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 11:49:48 +0100 Subject: [PATCH 31/36] git config --- apps/remix-ide/ci/remixd_test.zsh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/remix-ide/ci/remixd_test.zsh b/apps/remix-ide/ci/remixd_test.zsh index a7999f78fb..c50c7e7865 100755 --- a/apps/remix-ide/ci/remixd_test.zsh +++ b/apps/remix-ide/ci/remixd_test.zsh @@ -6,6 +6,9 @@ BUILD_ID=${CIRCLE_BUILD_NUM:-${TRAVIS_JOB_NUMBER}} echo "$BUILD_ID" TEST_EXITCODE=0 +git config --global user.email "you@example.com" +git config --global user.name "Your Name" + cd .. echo $SHELL ls -la . From ee909fcc761532947883bffd992cf0a43fb09fc2 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 11:50:38 +0100 Subject: [PATCH 32/36] rm test --- .circleci/config.yml | 40 ------------------------- apps/remix-ide/ci/remixd_test.zsh | 49 ------------------------------- 2 files changed, 89 deletions(-) delete mode 100755 apps/remix-ide/ci/remixd_test.zsh diff --git a/.circleci/config.yml b/.circleci/config.yml index b77ea13f05..e5f2985f6e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -76,43 +76,6 @@ jobs: - run: node dist/libs/remix-tests/bin/remix-tests ./libs/remix-tests/tests/examples_0/assert_ok_test.sol - run: yarn run test:libs - remixd: - docker: - - image: cimg/node:14.17.6-browsers - resource_class: - xlarge - working_directory: ~/remix-project - steps: - - browser-tools/install-browser-tools - - run: - command: | - google-chrome --version - firefox --version - geckodriver --version - chromedriver --version - rm LICENSE.chromedriver 2> /dev/null - - checkout - - attach_workspace: - at: . - - run: unzip ./persist/dist.zip - - - restore_cache: - keys: - - v1-deps-{{ checksum "yarn.lock" }} - - run: yarn - - run: yarn run downloadsolc_assets_e2e && yarn run downloadsolc_assets_dist - - run: ls -la ./dist/apps/remix-ide/assets/js - - run: yarn run selenium-install || yarn run selenium-install - - run: - name: Start Selenium - command: yarn run selenium - background: true - - run: ./apps/remix-ide/ci/remixd_test.zsh - - store_test_results: - path: ./reports/tests - - store_artifacts: - path: ./reports/screenshots - remix-ide-browser: docker: - image: cimg/node:14.17.6-browsers @@ -310,9 +273,6 @@ workflows: matrix: parameters: script: ["browser_tests_plugin_api.sh", "browser_tests_etherscan_plugin.sh", "browser_tests_vyper_plugin.sh"] - - remixd: - requires: - - build - remix-ide-browser: requires: - build diff --git a/apps/remix-ide/ci/remixd_test.zsh b/apps/remix-ide/ci/remixd_test.zsh deleted file mode 100755 index c50c7e7865..0000000000 --- a/apps/remix-ide/ci/remixd_test.zsh +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env bash - -set -e - -BUILD_ID=${CIRCLE_BUILD_NUM:-${TRAVIS_JOB_NUMBER}} -echo "$BUILD_ID" -TEST_EXITCODE=0 - -git config --global user.email "you@example.com" -git config --global user.name "Your Name" - -cd .. -echo $SHELL -ls -la . -pwd -# install foundry -curl -L https://foundry.paradigm.xyz | bash || true -# export /home/circleci/.foundry/bin to PATH -export PATH=$PATH:/home/circleci/.foundry/bin -foundryup -mkdir foundry -cd foundry -ls -la . -forge init hello_foundry -ls -la hello_foundry -cd .. - -# install truffle with yarn -yarn global add truffle -# install truffle metacoin box -mkdir MetaCoin -cd MetaCoin -truffle unbox metacoin -cd .. - -# install hardhat -yarn global add hardhat - - -sleep 5 - -cd remix-project -yarn run build:e2e - -echo "$TEST_EXITCODE" -if [ "$TEST_EXITCODE" -eq 1 ] -then - exit 1 -fi From 7e8d60a8d1a8775072fa93fc45d84f929a8c2112 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sun, 22 Jan 2023 11:22:03 +0100 Subject: [PATCH 33/36] fix clients --- libs/remixd/src/services/foundryClient.ts | 7 +- libs/remixd/src/services/hardhatClient.ts | 63 +++++++++++------ libs/remixd/src/services/truffleClient.ts | 85 +++++++++++++---------- 3 files changed, 95 insertions(+), 60 deletions(-) diff --git a/libs/remixd/src/services/foundryClient.ts b/libs/remixd/src/services/foundryClient.ts index 85b5a9319b..b7b49fbea0 100644 --- a/libs/remixd/src/services/foundryClient.ts +++ b/libs/remixd/src/services/foundryClient.ts @@ -46,6 +46,7 @@ export class FoundryClient extends PluginClient { listenOnFoundryFolder() { try { + if(this.watcher) this.watcher.close() this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) // watch for new folders this.watcher.on('addDir', () => { @@ -86,7 +87,6 @@ export class FoundryClient extends PluginClient { } checkPath() { - console.log('checkPath', fs.existsSync(this.buildPath), fs.existsSync(this.cachePath), fs.existsSync(join(this.cachePath, 'solidity-files-cache.json'))) if (!fs.existsSync(this.buildPath) || !fs.existsSync(this.cachePath)) { this.listenOnFoundryFolder() return false @@ -119,8 +119,9 @@ export class FoundryClient extends PluginClient { clearTimeout(this.logTimeout) this.logTimeout = setTimeout(() => { // @ts-ignore - this.call('terminal', 'log', { type: 'log', value: 'receiving compilation result from Foundry' }), 1000 - }) + this.call('terminal', 'log', { type: 'log', value: 'receiving compilation result from Foundry' }) + console.log('Syncing compilation result from Foundry') + }, 1000) } catch (e) { console.log(e) diff --git a/libs/remixd/src/services/hardhatClient.ts b/libs/remixd/src/services/hardhatClient.ts index 6207cdb091..e3d198156a 100644 --- a/libs/remixd/src/services/hardhatClient.ts +++ b/libs/remixd/src/services/hardhatClient.ts @@ -13,6 +13,8 @@ export class HardhatClient extends PluginClient { watcher: chokidar.FSWatcher warnLog: boolean buildPath: string + logTimeout: NodeJS.Timeout + processingTimeout: NodeJS.Timeout constructor(private readOnly = false) { super() @@ -30,14 +32,14 @@ export class HardhatClient extends PluginClient { sharedFolder(currentSharedFolder: string): void { this.currentSharedFolder = currentSharedFolder this.buildPath = utils.absolutePath('artifacts/contracts', this.currentSharedFolder) - if(fs.existsSync(this.buildPath)) { + if (fs.existsSync(this.buildPath)) { this.listenOnHardhatCompilation() - }else{ + } else { console.log('Hardhat artifacts folder doesn\'t exist... waiting for the first compilation.') console.log('If you are using Hardhat, run `npx hardhat compile` or run the compilation with `Enable Hardhat Compilation` checked from the Remix IDE.') this.listenOnHardHatFolder() } - + } compile(configPath: string) { @@ -67,7 +69,16 @@ export class HardhatClient extends PluginClient { }) } + checkPath() { + if (!fs.existsSync(this.buildPath)) { + this.listenOnHardHatFolder() + return false + } + return true + } + private async processArtifact() { + if (!this.checkPath()) return // resolving the files const folderFiles = await fs.readdir(this.buildPath) const targetsSynced = [] @@ -111,18 +122,27 @@ export class HardhatClient extends PluginClient { } } } - if (!this.warnLog) { - this.call('terminal', 'log', { value: 'receiving compilation result from Hardhat', type: 'log'} ) - this.warnLog = true - } - if (targetsSynced.length) { - console.log(`Processing artifacts for files: ${[...new Set(targetsSynced)].join(', ')}`) - this.call('terminal', 'log', { type: 'log', value: `synced with Hardhat: ${[...new Set(targetsSynced)].join(', ')}` }) - } + + clearTimeout(this.logTimeout) + this.logTimeout = setTimeout(() => { + this.call('terminal', 'log', { value: 'receiving compilation result from Hardhat', type: 'log' }) + if (targetsSynced.length) { + console.log(`Processing artifacts for files: ${[...new Set(targetsSynced)].join(', ')}`) + // @ts-ignore + this.call('terminal', 'log', { type: 'log', value: `synced with Hardhat: ${[...new Set(targetsSynced)].join(', ')}` }) + } else { + console.log('No artifacts to process') + // @ts-ignore + this.call('terminal', 'log', { type: 'log', value: 'No artifacts from Hardhat to process' }) + } + }, 1000) + + } listenOnHardHatFolder() { try { + this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) // watch for new folders this.watcher.on('addDir', () => { @@ -135,15 +155,21 @@ export class HardhatClient extends PluginClient { } } + async triggerProcessArtifact() { + // prevent multiple calls + clearTimeout(this.processingTimeout) + this.processingTimeout = setTimeout(async () => await this.processArtifact(), 1000) + } + listenOnHardhatCompilation() { try { console.log('listening on Hardhat compilation...') this.watcher = chokidar.watch(this.buildPath, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) - this.watcher.on('change', () => this.processArtifact()) - this.watcher.on('add', () => this.processArtifact()) + this.watcher.on('change', async () => await this.triggerProcessArtifact()) + this.watcher.on('add', async () => await this.triggerProcessArtifact()) // process the artifact on activation - setTimeout(() => this.processArtifact(), 1000) + this.processArtifact() } catch (e) { console.log(e) } @@ -151,14 +177,7 @@ export class HardhatClient extends PluginClient { async sync() { console.log('syncing from Hardhat') - if(fs.existsSync(this.buildPath)) { - this.processArtifact() - }else{ - console.log('No compilation result found') - this.listenOnHardHatFolder() - // ts-ignore - this.call('terminal', 'log', { type: 'log', value: 'No compilation result found' }) - } + this.processArtifact() } async feedContractArtifactFile(artifactContent, compilationResultPart) { diff --git a/libs/remixd/src/services/truffleClient.ts b/libs/remixd/src/services/truffleClient.ts index e1a998c8aa..b11d4f8bf1 100644 --- a/libs/remixd/src/services/truffleClient.ts +++ b/libs/remixd/src/services/truffleClient.ts @@ -13,13 +13,15 @@ export class TruffleClient extends PluginClient { watcher: chokidar.FSWatcher warnLog: boolean buildPath: string + logTimeout: NodeJS.Timeout + processingTimeout: NodeJS.Timeout - constructor (private readOnly = false) { + constructor(private readOnly = false) { super() this.methods = ['compile', 'sync'] } - setWebSocket (websocket: WS): void { + setWebSocket(websocket: WS): void { this.websocket = websocket this.websocket.addEventListener('close', () => { this.warnLog = false @@ -27,18 +29,19 @@ export class TruffleClient extends PluginClient { }) } - sharedFolder (currentSharedFolder: string): void { + sharedFolder(currentSharedFolder: string): void { this.currentSharedFolder = currentSharedFolder this.buildPath = utils.absolutePath('build/contracts', this.currentSharedFolder) if (fs.existsSync(this.buildPath)) { - this.listenOnTruffleCompilation()} + this.listenOnTruffleCompilation() + } else { console.log('Truffle build folder doesn\'t exist... waiting for the first compilation.') this.listenOnTruffleFolder() } } - listenOnTruffleFolder () { + listenOnTruffleFolder() { try { this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) // watch for new folders @@ -52,7 +55,7 @@ export class TruffleClient extends PluginClient { } } - compile (configPath: string) { + compile(configPath: string) { return new Promise((resolve, reject) => { if (this.readOnly) { const errMsg = '[Truffle Compilation]: Cannot compile in read-only mode' @@ -79,8 +82,19 @@ export class TruffleClient extends PluginClient { }) } - private async processArtifact () { - const folderFiles = await fs.readdir(this.buildPath) + checkPath() { + if (!fs.existsSync(this.buildPath)) { + this.listenOnTruffleFolder() + return false + } + return true + } + + + private async processArtifact() { + if (!this.checkPath()) return + const folderFiles = await fs.readdir(this.buildPath) + const filesFound = folderFiles.filter(file => file.endsWith('.json')) // name of folders are file names for (const file of folderFiles) { if (file.endsWith('.json')) { @@ -98,27 +112,38 @@ export class TruffleClient extends PluginClient { this.emit('compilationFinished', compilationResult.compilationTarget, { sources: compilationResult.input }, 'soljson', compilationResult.output, compilationResult.solcVersion) } } - if (!this.warnLog) { - // @ts-ignore - this.call('terminal', 'log', { type: 'log', value: 'receiving compilation result from Truffle' }) - this.warnLog = true - } + clearTimeout(this.logTimeout) + this.logTimeout = setTimeout(() => { + if (filesFound.length === 0) { + // @ts-ignore + this.call('terminal', 'log', { value: 'No contract found in the Truffle build folder', type: 'log' }) + } else { + // @ts-ignore + this.call('terminal', 'log', { value: 'receiving compilation result from Truffle', type: 'log' }) + } + }, 1000) + } + + async triggerProcessArtifact() { + // prevent multiple calls + clearTimeout(this.processingTimeout) + this.processingTimeout = setTimeout(async () => await this.processArtifact(), 1000) } - listenOnTruffleCompilation () { - try { + listenOnTruffleCompilation() { + try { this.watcher = chokidar.watch(this.buildPath, { depth: 3, ignorePermissionErrors: true, ignoreInitial: true }) - - this.watcher.on('change', async (f: string) => this.processArtifact()) - this.watcher.on('add', async (f: string) => this.processArtifact()) + + this.watcher.on('change', async () => await this.triggerProcessArtifact()) + this.watcher.on('add', async () => await this.triggerProcessArtifact()) // process the artifact on activation - setTimeout(() => this.processArtifact(), 1000) + this.triggerProcessArtifact() } catch (e) { console.log(e) - } + } } - async feedContractArtifactFile (path, content, compilationResultPart) { + async feedContractArtifactFile(path, content, compilationResultPart) { const contentJSON = JSON.parse(content) const contractName = basename(path).replace('.json', '') compilationResultPart.solcVersion = contentJSON.compiler.version @@ -129,10 +154,10 @@ export class TruffleClient extends PluginClient { // extract data const relPath = utils.relativePath(filepath, this.currentSharedFolder) if (!compilationResultPart.output['sources'][relPath]) compilationResultPart.output['sources'][relPath] = {} - + const location = contentJSON.ast.src.split(':') const id = parseInt(location[location.length - 1]) - + compilationResultPart.output['sources'][relPath] = { ast: contentJSON.ast, id @@ -156,17 +181,7 @@ export class TruffleClient extends PluginClient { } } - async sync () { - if (fs.existsSync(this.buildPath)) { - console.log('syncing from Truffle') - this.processArtifact() - // @ts-ignore - this.call('terminal', 'log', { type: 'log', value: 'synced with Truffle' }) - }else{ - console.log('Truffle build folder doesn\'t exist... waiting for the first compilation.') - this.listenOnTruffleFolder() - // @ts-ignore - this.call('terminal', 'log', { type: 'log', value: 'Truffle build folder doesn\'t exist... waiting for the first compilation.' }) - } + async sync() { + this.processArtifact() } } From 92c2962592bad461f00a1f0aea9fc4a21c5f4a21 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sun, 22 Jan 2023 11:57:46 +0100 Subject: [PATCH 34/36] fix activation --- libs/remixd/src/services/foundryClient.ts | 13 +++++++++---- libs/remixd/src/services/hardhatClient.ts | 11 ++++++++--- libs/remixd/src/services/truffleClient.ts | 11 ++++++++++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/libs/remixd/src/services/foundryClient.ts b/libs/remixd/src/services/foundryClient.ts index b7b49fbea0..e74988fb8c 100644 --- a/libs/remixd/src/services/foundryClient.ts +++ b/libs/remixd/src/services/foundryClient.ts @@ -20,6 +20,10 @@ export class FoundryClient extends PluginClient { constructor(private readOnly = false) { super() this.methods = ['compile', 'sync'] + this.onActivation = () => { + console.log('Foundry plugin activated') + this.startListening() + } } setWebSocket(websocket: WS): void { @@ -34,17 +38,18 @@ export class FoundryClient extends PluginClient { this.currentSharedFolder = currentSharedFolder this.buildPath = utils.absolutePath('out', this.currentSharedFolder) this.cachePath = utils.absolutePath('cache', this.currentSharedFolder) + } + + startListening() { if (fs.existsSync(this.buildPath) && fs.existsSync(this.cachePath)) { this.listenOnFoundryCompilation() } else { - console.log('Foundry out folder doesn\'t exist... waiting for the first compilation.') this.listenOnFoundryFolder() } } - - listenOnFoundryFolder() { + console.log('Foundry out folder doesn\'t exist... waiting for the compilation.') try { if(this.watcher) this.watcher.close() this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) @@ -119,7 +124,7 @@ export class FoundryClient extends PluginClient { clearTimeout(this.logTimeout) this.logTimeout = setTimeout(() => { // @ts-ignore - this.call('terminal', 'log', { type: 'log', value: 'receiving compilation result from Foundry' }) + this.call('terminal', 'log', { type: 'log', value: `receiving compilation result from Foundry` }) console.log('Syncing compilation result from Foundry') }, 1000) diff --git a/libs/remixd/src/services/hardhatClient.ts b/libs/remixd/src/services/hardhatClient.ts index e3d198156a..5c8095ed51 100644 --- a/libs/remixd/src/services/hardhatClient.ts +++ b/libs/remixd/src/services/hardhatClient.ts @@ -19,6 +19,10 @@ export class HardhatClient extends PluginClient { constructor(private readOnly = false) { super() this.methods = ['compile', 'sync'] + this.onActivation = () => { + console.log('Hardhat plugin activated') + this.startListening() + } } setWebSocket(websocket: WS): void { @@ -32,14 +36,15 @@ export class HardhatClient extends PluginClient { sharedFolder(currentSharedFolder: string): void { this.currentSharedFolder = currentSharedFolder this.buildPath = utils.absolutePath('artifacts/contracts', this.currentSharedFolder) + } + + startListening() { if (fs.existsSync(this.buildPath)) { this.listenOnHardhatCompilation() } else { - console.log('Hardhat artifacts folder doesn\'t exist... waiting for the first compilation.') console.log('If you are using Hardhat, run `npx hardhat compile` or run the compilation with `Enable Hardhat Compilation` checked from the Remix IDE.') this.listenOnHardHatFolder() } - } compile(configPath: string) { @@ -141,8 +146,8 @@ export class HardhatClient extends PluginClient { } listenOnHardHatFolder() { + console.log('Hardhat artifacts folder doesn\'t exist... waiting for the compilation.') try { - this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) // watch for new folders this.watcher.on('addDir', () => { diff --git a/libs/remixd/src/services/truffleClient.ts b/libs/remixd/src/services/truffleClient.ts index b11d4f8bf1..d4d388944e 100644 --- a/libs/remixd/src/services/truffleClient.ts +++ b/libs/remixd/src/services/truffleClient.ts @@ -19,6 +19,10 @@ export class TruffleClient extends PluginClient { constructor(private readOnly = false) { super() this.methods = ['compile', 'sync'] + this.onActivation = () => { + console.log('Truffle plugin activated') + this.startListening() + } } setWebSocket(websocket: WS): void { @@ -32,16 +36,20 @@ export class TruffleClient extends PluginClient { sharedFolder(currentSharedFolder: string): void { this.currentSharedFolder = currentSharedFolder this.buildPath = utils.absolutePath('build/contracts', this.currentSharedFolder) + + } + + startListening() { if (fs.existsSync(this.buildPath)) { this.listenOnTruffleCompilation() } else { - console.log('Truffle build folder doesn\'t exist... waiting for the first compilation.') this.listenOnTruffleFolder() } } listenOnTruffleFolder() { + console.log('Truffle build folder doesn\'t exist... waiting for the compilation.') try { this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) // watch for new folders @@ -120,6 +128,7 @@ export class TruffleClient extends PluginClient { } else { // @ts-ignore this.call('terminal', 'log', { value: 'receiving compilation result from Truffle', type: 'log' }) + console.log('Syncing compilation result from Truffle') } }, 1000) } From 93dfbd8e1cf95e84e96e81acd96872cf43960906 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sun, 22 Jan 2023 12:29:17 +0100 Subject: [PATCH 35/36] close watchers --- libs/remixd/src/services/foundryClient.ts | 3 ++- libs/remixd/src/services/hardhatClient.ts | 4 +++- libs/remixd/src/services/truffleClient.ts | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/remixd/src/services/foundryClient.ts b/libs/remixd/src/services/foundryClient.ts index e74988fb8c..add3378407 100644 --- a/libs/remixd/src/services/foundryClient.ts +++ b/libs/remixd/src/services/foundryClient.ts @@ -22,6 +22,7 @@ export class FoundryClient extends PluginClient { this.methods = ['compile', 'sync'] this.onActivation = () => { console.log('Foundry plugin activated') + this.call('terminal', 'log', { type: 'log', value: 'Foundry plugin activated' }) this.startListening() } } @@ -141,8 +142,8 @@ export class FoundryClient extends PluginClient { listenOnFoundryCompilation() { try { + if(this.watcher) this.watcher.close() this.watcher = chokidar.watch(this.cachePath, { depth: 0, ignorePermissionErrors: true, ignoreInitial: true }) - this.watcher.on('change', async () => await this.triggerProcessArtifact()) this.watcher.on('add', async () => await this.triggerProcessArtifact()) // process the artifact on activation diff --git a/libs/remixd/src/services/hardhatClient.ts b/libs/remixd/src/services/hardhatClient.ts index 5c8095ed51..5a79af9e6b 100644 --- a/libs/remixd/src/services/hardhatClient.ts +++ b/libs/remixd/src/services/hardhatClient.ts @@ -21,6 +21,7 @@ export class HardhatClient extends PluginClient { this.methods = ['compile', 'sync'] this.onActivation = () => { console.log('Hardhat plugin activated') + this.call('terminal', 'log', { type: 'log', value: 'Hardhat plugin activated' }) this.startListening() } } @@ -148,6 +149,7 @@ export class HardhatClient extends PluginClient { listenOnHardHatFolder() { console.log('Hardhat artifacts folder doesn\'t exist... waiting for the compilation.') try { + if(this.watcher) this.watcher.close() this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) // watch for new folders this.watcher.on('addDir', () => { @@ -169,8 +171,8 @@ export class HardhatClient extends PluginClient { listenOnHardhatCompilation() { try { console.log('listening on Hardhat compilation...') + if(this.watcher) this.watcher.close() this.watcher = chokidar.watch(this.buildPath, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) - this.watcher.on('change', async () => await this.triggerProcessArtifact()) this.watcher.on('add', async () => await this.triggerProcessArtifact()) // process the artifact on activation diff --git a/libs/remixd/src/services/truffleClient.ts b/libs/remixd/src/services/truffleClient.ts index d4d388944e..9659ddefbd 100644 --- a/libs/remixd/src/services/truffleClient.ts +++ b/libs/remixd/src/services/truffleClient.ts @@ -21,6 +21,7 @@ export class TruffleClient extends PluginClient { this.methods = ['compile', 'sync'] this.onActivation = () => { console.log('Truffle plugin activated') + this.call('terminal', 'log', { type: 'log', value: 'Truffle plugin activated' }) this.startListening() } } @@ -51,6 +52,7 @@ export class TruffleClient extends PluginClient { listenOnTruffleFolder() { console.log('Truffle build folder doesn\'t exist... waiting for the compilation.') try { + if (this.watcher) this.watcher.close() this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) // watch for new folders this.watcher.on('addDir', () => { @@ -141,8 +143,8 @@ export class TruffleClient extends PluginClient { listenOnTruffleCompilation() { try { + if (this.watcher) this.watcher.close() this.watcher = chokidar.watch(this.buildPath, { depth: 3, ignorePermissionErrors: true, ignoreInitial: true }) - this.watcher.on('change', async () => await this.triggerProcessArtifact()) this.watcher.on('add', async () => await this.triggerProcessArtifact()) // process the artifact on activation From 012ebd274947c5437111d8835d247d597c9fc9d9 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sun, 22 Jan 2023 12:46:19 +0100 Subject: [PATCH 36/36] watcher depth --- libs/remixd/src/services/hardhatClient.ts | 2 +- libs/remixd/src/services/truffleClient.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/remixd/src/services/hardhatClient.ts b/libs/remixd/src/services/hardhatClient.ts index 5a79af9e6b..bf7ca0cc9d 100644 --- a/libs/remixd/src/services/hardhatClient.ts +++ b/libs/remixd/src/services/hardhatClient.ts @@ -150,7 +150,7 @@ export class HardhatClient extends PluginClient { console.log('Hardhat artifacts folder doesn\'t exist... waiting for the compilation.') try { if(this.watcher) this.watcher.close() - this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) + this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 2, ignorePermissionErrors: true, ignoreInitial: true }) // watch for new folders this.watcher.on('addDir', () => { if (fs.existsSync(this.buildPath)) { diff --git a/libs/remixd/src/services/truffleClient.ts b/libs/remixd/src/services/truffleClient.ts index 9659ddefbd..e62fe54ba2 100644 --- a/libs/remixd/src/services/truffleClient.ts +++ b/libs/remixd/src/services/truffleClient.ts @@ -53,7 +53,7 @@ export class TruffleClient extends PluginClient { console.log('Truffle build folder doesn\'t exist... waiting for the compilation.') try { if (this.watcher) this.watcher.close() - this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) + this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 2, ignorePermissionErrors: true, ignoreInitial: true }) // watch for new folders this.watcher.on('addDir', () => { if (fs.existsSync(this.buildPath)) {