Merge pull request #3413 from ethereum/fix-sync

Fix Remixd Sync
pull/3396/head
Aniket 2 years ago committed by GitHub
commit eb7c40f6c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      libs/remixd/src/services/remixdClient.ts

@ -5,12 +5,14 @@ import * as utils from '../utils'
import * as chokidar from 'chokidar'
import * as fs from 'fs-extra'
import * as isbinaryfile from 'isbinaryfile'
import * as pathModule from 'path'
export class RemixdClient extends PluginClient {
methods: Array<string>
websocket: WS
currentSharedFolder: string
watcher: chokidar.FSWatcher
trackDownStreamUpdate: Record<string, string> = {}
constructor (private readOnly = false) {
super()
@ -105,6 +107,7 @@ export class RemixdClient extends PluginClient {
this.createDir({ path: args.path.substr(0, args.path.lastIndexOf('/')) })
}
try {
this.trackDownStreamUpdate[path] = args.content
fs.writeFile(path, args.content, 'utf8', (error: Error) => {
if (error) {
console.log(error)
@ -263,8 +266,9 @@ export class RemixdClient extends PluginClient {
})
*/
this.watcher.on('change', async (f: string) => {
const currentContent = await this.call('editor', 'getText' as any, f)
const newContent = fs.readFileSync(f)
const path = pathModule.resolve(f)
const currentContent = this.trackDownStreamUpdate[path]
const newContent = fs.readFileSync(f, 'utf-8')
if (currentContent !== newContent && this.isLoaded) {
this.emit('changed', utils.relativePath(f, this.currentSharedFolder))
}

Loading…
Cancel
Save