update label, add ignoreInitial to chokidar

pull/5370/head
yann300 2 years ago
parent 92e20dd7d3
commit a6cb1a43d9
  1. 6
      apps/remix-ide-e2e/src/tests/remixd.test.ts
  2. 10
      libs/remixd/src/services/foundryClient.ts
  3. 11
      libs/remixd/src/services/hardhatClient.ts
  4. 11
      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)) writeFileSync('./apps/remix-ide/contracts/artifacts/build-info/c7062fdd360381a85af23eeef31c98f8.json', JSON.stringify(hardhatCompilation))
done() 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') browser.clickLaunchIcon('udapp')
.assert.textContains('*[data-id="udappCompiledBy"]', 'Compiled by hardhat') .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)) writeFileSync('./apps/remix-ide/contracts/out/Counter.sol/Counter.json', JSON.stringify(foundryCompilation))
done() 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 let contractAaddress
browser.clickLaunchIcon('udapp') browser.clickLaunchIcon('udapp')
@ -165,7 +165,7 @@ module.exports = {
writeFileSync('./apps/remix-ide/contracts/build/contracts/Migrations.json', JSON.stringify(truffle_compilation)) writeFileSync('./apps/remix-ide/contracts/build/contracts/Migrations.json', JSON.stringify(truffle_compilation))
done() 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') browser.clickLaunchIcon('udapp')
.assert.textContains('*[data-id="udappCompiledBy"]', 'Compiled by truffle') .assert.textContains('*[data-id="udappCompiledBy"]', 'Compiled by truffle')

@ -11,6 +11,7 @@ export class FoundryClient extends PluginClient {
websocket: WS websocket: WS
currentSharedFolder: string currentSharedFolder: string
watcher: chokidar.FSWatcher watcher: chokidar.FSWatcher
warnlog: boolean
constructor (private readOnly = false) { constructor (private readOnly = false) {
super() super()
@ -20,6 +21,7 @@ export class FoundryClient extends PluginClient {
setWebSocket (websocket: WS): void { setWebSocket (websocket: WS): void {
this.websocket = websocket this.websocket = websocket
this.websocket.addEventListener('close', () => { this.websocket.addEventListener('close', () => {
this.warnlog = false
if (this.watcher) this.watcher.close() if (this.watcher) this.watcher.close()
}) })
} }
@ -59,7 +61,7 @@ export class FoundryClient extends PluginClient {
listenOnFoundryCompilation () { listenOnFoundryCompilation () {
try { try {
const buildPath = utils.absolutePath('out', this.currentSharedFolder) 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 = { const compilationResult = {
input: {}, input: {},
output: { output: {
@ -74,8 +76,11 @@ export class FoundryClient extends PluginClient {
for (const file of folderFiles) { for (const file of folderFiles) {
await this.readContract(join(buildPath, file), compilationResult) await this.readContract(join(buildPath, file), compilationResult)
} }
if (!this.warnlog) {
// @ts-ignore // @ts-ignore
this.call('terminal', 'log', 'updated compilation result from foundry') this.call('terminal', 'log', 'receiving compilation result from foundry')
this.warnlog = true
}
this.emit('compilationFinished', '', compilationResult.input, 'soljson', compilationResult.output, compilationResult.solcVersion) this.emit('compilationFinished', '', compilationResult.input, 'soljson', compilationResult.output, compilationResult.solcVersion)
} }
this.watcher.on('change', async (f: string) => processArtifact()) 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' }) const content = await fs.readFile(absPath, { encoding: 'utf-8' })
compilationResultPart.input[path] = { content } compilationResultPart.input[path] = { content }
} catch (e) { } catch (e) {
console.log('unable to get the content of', path)
compilationResultPart.input[path] = { content: '' } compilationResultPart.input[path] = { content: '' }
} }
} }

@ -10,6 +10,7 @@ export class HardhatClient extends PluginClient {
websocket: WS websocket: WS
currentSharedFolder: string currentSharedFolder: string
watcher: chokidar.FSWatcher watcher: chokidar.FSWatcher
warnlog: boolean
constructor (private readOnly = false) { constructor (private readOnly = false) {
super() super()
@ -19,6 +20,7 @@ export class HardhatClient extends PluginClient {
setWebSocket (websocket: WS): void { setWebSocket (websocket: WS): void {
this.websocket = websocket this.websocket = websocket
this.websocket.addEventListener('close', () => { this.websocket.addEventListener('close', () => {
this.warnlog = false
if (this.watcher) this.watcher.close() if (this.watcher) this.watcher.close()
}) })
} }
@ -58,15 +60,20 @@ export class HardhatClient extends PluginClient {
listenOnHardhatCompilation () { listenOnHardhatCompilation () {
try { try {
const buildPath = utils.absolutePath('artifacts/build-info', this.currentSharedFolder) 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 processArtifact = async (path: string) => {
if (path.endsWith('.json')) {
const content = await fs.readFile(path, { encoding: 'utf-8' }) const content = await fs.readFile(path, { encoding: 'utf-8' })
const compilationResult = JSON.parse(content) const compilationResult = JSON.parse(content)
if (!this.warnlog) {
// @ts-ignore // @ts-ignore
this.call('terminal', 'log', 'updated compilation result from hardhat') this.call('terminal', 'log', 'receiving compilation result from hardhat')
this.warnlog = true
}
this.emit('compilationFinished', '', compilationResult.input, 'soljson', compilationResult.output, compilationResult.solcVersion) this.emit('compilationFinished', '', compilationResult.input, 'soljson', compilationResult.output, compilationResult.solcVersion)
} }
}
this.watcher.on('change', (path: string) => processArtifact(path)) this.watcher.on('change', (path: string) => processArtifact(path))
this.watcher.on('add', (path: string) => processArtifact(path)) this.watcher.on('add', (path: string) => processArtifact(path))

@ -11,6 +11,7 @@ export class TruffleClient extends PluginClient {
websocket: WS websocket: WS
currentSharedFolder: string currentSharedFolder: string
watcher: chokidar.FSWatcher watcher: chokidar.FSWatcher
warnLog: boolean
constructor (private readOnly = false) { constructor (private readOnly = false) {
super() super()
@ -20,6 +21,7 @@ export class TruffleClient extends PluginClient {
setWebSocket (websocket: WS): void { setWebSocket (websocket: WS): void {
this.websocket = websocket this.websocket = websocket
this.websocket.addEventListener('close', () => { this.websocket.addEventListener('close', () => {
this.warnLog = false
if (this.watcher) this.watcher.close() if (this.watcher) this.watcher.close()
}) })
} }
@ -59,7 +61,7 @@ export class TruffleClient extends PluginClient {
listenOnTruffleCompilation () { listenOnTruffleCompilation () {
try { try {
const buildPath = utils.absolutePath('out', this.currentSharedFolder) 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 = { const compilationResult = {
input: {}, input: {},
output: { output: {
@ -72,11 +74,16 @@ export class TruffleClient extends PluginClient {
const folderFiles = await fs.readdir(buildPath) const folderFiles = await fs.readdir(buildPath)
// name of folders are file names // name of folders are file names
for (const file of folderFiles) { for (const file of folderFiles) {
if (file.endsWith('.json')) {
const content = await fs.readFile(join(buildPath, file), { encoding: 'utf-8' }) const content = await fs.readFile(join(buildPath, file), { encoding: 'utf-8' })
await this.feedContractArtifactFile(file, content, compilationResult) await this.feedContractArtifactFile(file, content, compilationResult)
} }
}
if (!this.warnLog) {
// @ts-ignore // @ts-ignore
this.call('terminal', 'log', 'updated compilation result from truffle') this.call('terminal', 'log', 'receiving compilation result from truffle')
this.warnLog = true
}
this.emit('compilationFinished', '', compilationResult.input, 'soljson', compilationResult.output, compilationResult.solcVersion) this.emit('compilationFinished', '', compilationResult.input, 'soljson', compilationResult.output, compilationResult.solcVersion)
} }
this.watcher.on('change', async (f: string) => processArtifact()) this.watcher.on('change', async (f: string) => processArtifact())

Loading…
Cancel
Save