listen on hardhat compile

pull/2894/head
yann300 2 years ago
parent e5a65662c9
commit 8b5698f8f8
  1. 5
      libs/remix-core-plugin/src/lib/compiler-artefacts.ts
  2. 2
      libs/remix-ui/run-tab/src/lib/actions/events.ts
  3. 12
      libs/remix-ui/run-tab/src/lib/components/contractDropdownUI.tsx
  4. 19
      libs/remixd/src/services/hardhatClient.ts

@ -58,6 +58,11 @@ export class CompilerArtefacts extends Plugin {
this.compilersArtefacts.__last = new CompilerAbstract(languageVersion, data, source)
saveCompilationPerFileResult(file, source, languageVersion, data)
})
this.on('hardhat', 'compilationFinished', (file, source, languageVersion, data) => {
this.compilersArtefacts.__last = new CompilerAbstract(languageVersion, data, source)
saveCompilationPerFileResult(file, source, languageVersion, data)
})
}
/**

@ -51,6 +51,8 @@ export const setupEvents = (plugin: RunTab, dispatch: React.Dispatch<any>) => {
plugin.on('nahmii-compiler', 'compilationFinished', (file, source, languageVersion, data) => broadcastCompilationResult(plugin, dispatch, file, source, languageVersion, data))
plugin.on('hardhat', 'compilationFinished', (file, source, languageVersion, data) => broadcastCompilationResult(plugin, dispatch, file, source, languageVersion, data))
plugin.on('udapp', 'setEnvironmentModeReducer', (env: { context: string, fork: string }, from: string) => {
plugin.call('notification', 'toast', envChangeNotification(env, from))
setExecutionContext(plugin, dispatch, env)

@ -31,6 +31,10 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
const atAddressValue = useRef<HTMLInputElement>(null)
const { contractList, loadType, currentFile, currentContract, compilationCount, deployOptions, proxyKey } = props.contracts
useEffect(() => {
enableContractNames(true)
}, [Object.keys(props.contracts.contractList).length])
useEffect(() => {
enableAtAddress(false)
setAbiLabel({
@ -72,13 +76,7 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
})
if (!currentContract) enableAtAddress(false)
}
if (currentFile) {
enableContractNames(true)
setCompFails('none')
} else {
enableContractNames(false)
setCompFails('block')
}
enableContractNames(true)
initSelectedContract()
}, [loadType, currentFile, compilationCount])

@ -1,5 +1,8 @@
import * as WS from 'ws' // eslint-disable-line
import { PluginClient } from '@remixproject/plugin'
import * as chokidar from 'chokidar'
import * as utils from '../utils'
import * as fs from 'fs-extra'
const { spawn } = require('child_process') // eslint-disable-line
export class HardhatClient extends PluginClient {
@ -18,6 +21,7 @@ export class HardhatClient extends PluginClient {
sharedFolder (currentSharedFolder: string): void {
this.currentSharedFolder = currentSharedFolder
this.listenOnHardhatCompilation()
}
compile (configPath: string) {
@ -46,4 +50,19 @@ export class HardhatClient extends PluginClient {
})
})
}
listenOnHardhatCompilation () {
try {
const buildPath = utils.absolutePath('artifacts/build-info', this.currentSharedFolder)
const watcher = chokidar.watch(buildPath, { depth: 0, ignorePermissionErrors: true })
watcher.on('change', async (f: string) => {
const content = await fs.readFile(f, { encoding: 'utf-8' })
const compilationResult = JSON.parse(content)
this.call('terminal', 'log', {type: 'info', value: 'received compilation result from hardhat'})
this.emit('compilationFinished', '', compilationResult.input, 'soljson', compilationResult.output, compilationResult.solcVersion)
})
} catch (e) {
console.log(e)
}
}
}

Loading…
Cancel
Save