diff --git a/apps/remix-ide-e2e/src/tests/remixd.test.ts b/apps/remix-ide-e2e/src/tests/remixd.test.ts index 7fc4a4e06f..2ab9a60b72 100644 --- a/apps/remix-ide-e2e/src/tests/remixd.test.ts +++ b/apps/remix-ide-e2e/src/tests/remixd.test.ts @@ -124,7 +124,7 @@ module.exports = { writeFileSync('./apps/remix-ide/contracts/artifacts/build-info/c7062fdd360381a85af23eeef31c98f8.json', JSON.stringify(hardhatCompilation)) done() }) - .expect.element('*[data-id="terminalJournal"]').text.to.contain('updated compilation result from hardhat').before(60000) + .expect.element('*[data-id="terminalJournal"]').text.to.contain('receiving compilation result from hardhat').before(60000) browser.clickLaunchIcon('udapp') .assert.textContains('*[data-id="udappCompiledBy"]', 'Compiled by hardhat') @@ -139,7 +139,7 @@ module.exports = { writeFileSync('./apps/remix-ide/contracts/out/Counter.sol/Counter.json', JSON.stringify(foundryCompilation)) done() }) - .expect.element('*[data-id="terminalJournal"]').text.to.contain('updated compilation result from foundry').before(60000) + .expect.element('*[data-id="terminalJournal"]').text.to.contain('receiving compilation result from foundry').before(60000) let contractAaddress browser.clickLaunchIcon('udapp') @@ -165,7 +165,7 @@ module.exports = { writeFileSync('./apps/remix-ide/contracts/build/contracts/Migrations.json', JSON.stringify(truffle_compilation)) done() }) - .expect.element('*[data-id="terminalJournal"]').text.to.contain('updated compilation result from truffle').before(60000) + .expect.element('*[data-id="terminalJournal"]').text.to.contain('receiving compilation result from truffle').before(60000) browser.clickLaunchIcon('udapp') .assert.textContains('*[data-id="udappCompiledBy"]', 'Compiled by truffle') diff --git a/libs/remixd/src/services/foundryClient.ts b/libs/remixd/src/services/foundryClient.ts index 18f77c49d1..9dd89a8049 100644 --- a/libs/remixd/src/services/foundryClient.ts +++ b/libs/remixd/src/services/foundryClient.ts @@ -11,6 +11,7 @@ export class FoundryClient extends PluginClient { websocket: WS currentSharedFolder: string watcher: chokidar.FSWatcher + warnlog: boolean constructor (private readOnly = false) { super() @@ -20,6 +21,7 @@ export class FoundryClient extends PluginClient { setWebSocket (websocket: WS): void { this.websocket = websocket this.websocket.addEventListener('close', () => { + this.warnlog = false if (this.watcher) this.watcher.close() }) } @@ -59,7 +61,7 @@ export class FoundryClient extends PluginClient { listenOnFoundryCompilation () { try { const buildPath = utils.absolutePath('out', this.currentSharedFolder) - this.watcher = chokidar.watch(buildPath, { depth: 3, ignorePermissionErrors: true }) + this.watcher = chokidar.watch(buildPath, { depth: 3, ignorePermissionErrors: true, ignoreInitial: true }) const compilationResult = { input: {}, output: { @@ -74,8 +76,11 @@ export class FoundryClient extends PluginClient { for (const file of folderFiles) { await this.readContract(join(buildPath, file), compilationResult) } - // @ts-ignore - this.call('terminal', 'log', 'updated compilation result from foundry') + if (!this.warnlog) { + // @ts-ignore + this.call('terminal', 'log', 'receiving compilation result from foundry') + this.warnlog = true + } this.emit('compilationFinished', '', compilationResult.input, 'soljson', compilationResult.output, compilationResult.solcVersion) } this.watcher.on('change', async (f: string) => processArtifact()) @@ -105,7 +110,6 @@ export class FoundryClient extends PluginClient { const content = await fs.readFile(absPath, { encoding: 'utf-8' }) compilationResultPart.input[path] = { content } } catch (e) { - console.log('unable to get the content of', path) compilationResultPart.input[path] = { content: '' } } } diff --git a/libs/remixd/src/services/hardhatClient.ts b/libs/remixd/src/services/hardhatClient.ts index 1134795871..6e804aae19 100644 --- a/libs/remixd/src/services/hardhatClient.ts +++ b/libs/remixd/src/services/hardhatClient.ts @@ -10,6 +10,7 @@ export class HardhatClient extends PluginClient { websocket: WS currentSharedFolder: string watcher: chokidar.FSWatcher + warnlog: boolean constructor (private readOnly = false) { super() @@ -19,6 +20,7 @@ export class HardhatClient extends PluginClient { setWebSocket (websocket: WS): void { this.websocket = websocket this.websocket.addEventListener('close', () => { + this.warnlog = false if (this.watcher) this.watcher.close() }) } @@ -58,14 +60,19 @@ export class HardhatClient extends PluginClient { listenOnHardhatCompilation () { try { const buildPath = utils.absolutePath('artifacts/build-info', this.currentSharedFolder) - this.watcher = chokidar.watch(buildPath, { depth: 0, ignorePermissionErrors: true }) + this.watcher = chokidar.watch(buildPath, { depth: 0, ignorePermissionErrors: true, ignoreInitial: true }) 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', 'updated compilation result from hardhat') - this.emit('compilationFinished', '', compilationResult.input, 'soljson', compilationResult.output, compilationResult.solcVersion) + if (path.endsWith('.json')) { + const content = await fs.readFile(path, { encoding: 'utf-8' }) + const compilationResult = JSON.parse(content) + if (!this.warnlog) { + // @ts-ignore + this.call('terminal', 'log', 'receiving compilation result from hardhat') + this.warnlog = true + } + this.emit('compilationFinished', '', compilationResult.input, 'soljson', compilationResult.output, compilationResult.solcVersion) + } } this.watcher.on('change', (path: string) => processArtifact(path)) diff --git a/libs/remixd/src/services/truffleClient.ts b/libs/remixd/src/services/truffleClient.ts index 8193b34108..3d9d957648 100644 --- a/libs/remixd/src/services/truffleClient.ts +++ b/libs/remixd/src/services/truffleClient.ts @@ -11,6 +11,7 @@ export class TruffleClient extends PluginClient { websocket: WS currentSharedFolder: string watcher: chokidar.FSWatcher + warnLog: boolean constructor (private readOnly = false) { super() @@ -20,6 +21,7 @@ export class TruffleClient extends PluginClient { setWebSocket (websocket: WS): void { this.websocket = websocket this.websocket.addEventListener('close', () => { + this.warnLog = false if (this.watcher) this.watcher.close() }) } @@ -59,7 +61,7 @@ export class TruffleClient extends PluginClient { listenOnTruffleCompilation () { try { const buildPath = utils.absolutePath('out', this.currentSharedFolder) - this.watcher = chokidar.watch(buildPath, { depth: 3, ignorePermissionErrors: true }) + this.watcher = chokidar.watch(buildPath, { depth: 3, ignorePermissionErrors: true, ignoreInitial: true }) const compilationResult = { input: {}, output: { @@ -72,11 +74,16 @@ export class TruffleClient extends PluginClient { const folderFiles = await fs.readdir(buildPath) // name of folders are file names for (const file of folderFiles) { - const content = await fs.readFile(join(buildPath, file), { encoding: 'utf-8' }) - await this.feedContractArtifactFile(file, content, compilationResult) + if (file.endsWith('.json')) { + const content = await fs.readFile(join(buildPath, file), { encoding: 'utf-8' }) + await this.feedContractArtifactFile(file, content, compilationResult) + } + } + if (!this.warnLog) { + // @ts-ignore + this.call('terminal', 'log', 'receiving compilation result from truffle') + this.warnLog = true } - // @ts-ignore - this.call('terminal', 'log', 'updated compilation result from truffle') this.emit('compilationFinished', '', compilationResult.input, 'soljson', compilationResult.output, compilationResult.solcVersion) } this.watcher.on('change', async (f: string) => processArtifact())