From ee603532da874ca65044bebf6ba5c5094cdf8e5a Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 6 Oct 2022 14:22:26 +0530 Subject: [PATCH 1/2] fix compilation result sync for truffle --- libs/remixd/src/services/truffleClient.ts | 27 ++++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/libs/remixd/src/services/truffleClient.ts b/libs/remixd/src/services/truffleClient.ts index 794aac13c6..d363dd75e5 100644 --- a/libs/remixd/src/services/truffleClient.ts +++ b/libs/remixd/src/services/truffleClient.ts @@ -61,23 +61,22 @@ export class TruffleClient extends PluginClient { } private async processArtifact () { - const folderFiles = await fs.readdir(this.buildPath) + const folderFiles = await fs.readdir(this.buildPath) + const compilationResult = { + input: {}, + output: { + contracts: {}, + sources: {} + }, + solcVersion: null, + compilationTarget: null + } // name of folders are file names for (const file of folderFiles) { if (file.endsWith('.json')) { - const compilationResult = { - input: {}, - output: { - contracts: {}, - sources: {} - }, - solcVersion: null, - compilationTarget: null - } const content = await fs.readFile(join(this.buildPath, file), { encoding: 'utf-8' }) await this.feedContractArtifactFile(file, content, compilationResult) this.emit('compilationFinished', compilationResult.compilationTarget, { sources: compilationResult.input }, 'soljson', compilationResult.output, compilationResult.solcVersion) - } } if (!this.warnLog) { @@ -104,10 +103,12 @@ export class TruffleClient extends PluginClient { const contentJSON = JSON.parse(content) const contractName = basename(path).replace('.json', '') compilationResultPart.solcVersion = contentJSON.compiler.version - compilationResultPart.compilationTarget = contentJSON.ast.absolutePath + // file name in artifacts starts with `project:/` + const filepath = contentJSON.ast.absolutePath.startsWith('project:/') ? contentJSON.ast.absolutePath.replace('project:/', '') : contentJSON.ast.absolutePath + compilationResultPart.compilationTarget = filepath compilationResultPart.input[path] = { content: contentJSON.source } // extract data - const relPath = utils.relativePath(contentJSON.ast.absolutePath, this.currentSharedFolder) + const relPath = utils.relativePath(filepath, this.currentSharedFolder) if (!compilationResultPart.output['sources'][relPath]) compilationResultPart.output['sources'][relPath] = {} const location = contentJSON.ast.src.split(':') From f8d0cdf820d5ed7836136c0b8794be300f079286 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 6 Oct 2022 14:47:24 +0530 Subject: [PATCH 2/2] initialize --- libs/remixd/src/services/truffleClient.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/remixd/src/services/truffleClient.ts b/libs/remixd/src/services/truffleClient.ts index d363dd75e5..6dfd3b6f66 100644 --- a/libs/remixd/src/services/truffleClient.ts +++ b/libs/remixd/src/services/truffleClient.ts @@ -62,18 +62,18 @@ export class TruffleClient extends PluginClient { private async processArtifact () { const folderFiles = await fs.readdir(this.buildPath) - const compilationResult = { - input: {}, - output: { - contracts: {}, - sources: {} - }, - solcVersion: null, - compilationTarget: null - } // name of folders are file names for (const file of folderFiles) { if (file.endsWith('.json')) { + const compilationResult = { + input: {}, + output: { + contracts: {}, + sources: {} + }, + solcVersion: null, + compilationTarget: null + } const content = await fs.readFile(join(this.buildPath, file), { encoding: 'utf-8' }) await this.feedContractArtifactFile(file, content, compilationResult) this.emit('compilationFinished', compilationResult.compilationTarget, { sources: compilationResult.input }, 'soljson', compilationResult.output, compilationResult.solcVersion)