stop the file watcher

pull/2894/head
yann300 2 years ago
parent b22352aeae
commit 8ff4e29ffe
  1. 8
      libs/remixd/src/services/hardhatClient.ts
  2. 12
      libs/remixd/src/services/remixdClient.ts

@ -9,6 +9,7 @@ export class HardhatClient extends PluginClient {
methods: Array<string>
websocket: WS
currentSharedFolder: string
watcher: chokidar.FSWatcher
constructor (private readOnly = false) {
super()
@ -17,6 +18,9 @@ export class HardhatClient extends PluginClient {
setWebSocket (websocket: WS): void {
this.websocket = websocket
this.websocket.addEventListener('close', () => {
if (this.watcher) this.watcher.close()
})
}
sharedFolder (currentSharedFolder: string): void {
@ -54,8 +58,8 @@ 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) => {
this.watcher = chokidar.watch(buildPath, { depth: 0, ignorePermissionErrors: true })
this.watcher.on('change', async (f: string) => {
const content = await fs.readFile(f, { encoding: 'utf-8' })
const compilationResult = JSON.parse(content)
// @ts-ignore

@ -11,6 +11,7 @@ export class RemixdClient extends PluginClient {
trackDownStreamUpdate: TrackDownStreamUpdate = {}
websocket: WS
currentSharedFolder: string
watcher: chokidar.FSWatcher
constructor (private readOnly = false) {
super()
@ -19,6 +20,9 @@ export class RemixdClient extends PluginClient {
setWebSocket (websocket: WS): void {
this.websocket = websocket
this.websocket.addEventListener('close', () => {
if (this.watcher) this.watcher.close()
})
}
sharedFolder (currentSharedFolder: string): void {
@ -246,7 +250,7 @@ export class RemixdClient extends PluginClient {
const absPath = utils.absolutePath('./', path)
if (!isRealPath(absPath)) return
const watcher = chokidar.watch(path, { depth: 0, ignorePermissionErrors: true })
this.watcher = chokidar.watch(path, { depth: 0, ignorePermissionErrors: true })
console.log('setup notifications for ' + path)
/* we can't listen on created file / folder
watcher.on('add', (f, stat) => {
@ -260,7 +264,7 @@ export class RemixdClient extends PluginClient {
this.emit('created', { path: utils.relativePath(f, this.currentSharedFolder), isReadOnly: false, isFolder: true })
})
*/
watcher.on('change', async (f: string) => {
this.watcher.on('change', async (f: string) => {
if (this.trackDownStreamUpdate[f]) {
delete this.trackDownStreamUpdate[f]
return
@ -269,12 +273,12 @@ export class RemixdClient extends PluginClient {
this.emit('changed', utils.relativePath(f, this.currentSharedFolder))
}
})
watcher.on('unlink', async (f: string) => {
this.watcher.on('unlink', async (f: string) => {
if (this.isLoaded) {
this.emit('removed', utils.relativePath(f, this.currentSharedFolder), false)
}
})
watcher.on('unlinkDir', async (f: string) => {
this.watcher.on('unlinkDir', async (f: string) => {
if (this.isLoaded) {
this.emit('removed', utils.relativePath(f, this.currentSharedFolder), true)
}

Loading…
Cancel
Save