fix foundry

pull/3285/head
filip mertens 2 years ago
parent b3fe717fdc
commit 0acc15a376
  1. 48
      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)
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()
}
}
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) {
compile(configPath: string) {
return new Promise((resolve, reject) => {
if (this.readOnly) {
const errMsg = '[Foundry Compilation]: Cannot compile in read-only mode'
@ -62,8 +83,10 @@ 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
@ -79,16 +102,19 @@ export class FoundryClient extends PluginClient {
compilationTarget: null
}
await this.readContract(path, compilationResult, cache)
this.emit('compilationFinished', compilationResult.compilationTarget, { sources: compilationResult.input } , 'soljson', compilationResult.output, compilationResult.solcVersion)
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
}
} catch (e) {
console.log(e)
}
}
listenOnFoundryCompilation () {
listenOnFoundryCompilation() {
try {
this.watcher = chokidar.watch(this.cachePath, { depth: 0, ignorePermissionErrors: true, ignoreInitial: true })
@ -101,7 +127,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) {
@ -111,7 +137,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', '')
@ -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' })
}
}

Loading…
Cancel
Save