Skip to content

Commit

Permalink
fix: avoid infinite loop when watching
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsn committed Jul 14, 2018
1 parent 559bafa commit 2e5ccce
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/webpack-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ class VueAutoRoutingPlugin {
const generate = () => {
const code = generateRoutes(this.options)
const to = path.resolve(__dirname, '../index.js')

if (
fs.existsSync(to) &&
fs.readFileSync(to, 'utf8').trim() === code.trim()
) {
return
}

fs.writeFileSync(to, code)
}

Expand Down
22 changes: 22 additions & 0 deletions test/webpack-plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,26 @@ describe('webpack plugin', () => {
}
})
})

it('does not fire compilation when the route does not changed', done => {
const plugin = new Plugin({
pages: resolve('fixtures/pages')
})

let count = 0
const watching = compiler(plugin).watch({}, () => {
count++
switch (count) {
case 3:
fail('webpack watcher seems to go infinite loop')
done()
break
default:
}
})

setTimeout(() => {
watching.close(done)
}, 1000)
})
})

0 comments on commit 2e5ccce

Please sign in to comment.