update label, add ignoreInitial to chokidar

pull/2894/head
yann300 2 years ago
parent 0945ae93e3
commit a75da420f9
  1. 6
      apps/remix-ide-e2e/src/tests/remixd.test.ts
  2. 12
      libs/remixd/src/services/foundryClient.ts
  3. 19
      libs/remixd/src/services/hardhatClient.ts
  4. 17
      libs/remixd/src/services/truffleClient.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')

@ -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: '' }
}
}

@ -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))

@ -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())

Loading…
Cancel
Save