Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
fix(server): close chokidar watcher when stats file found
Browse files Browse the repository at this point in the history
  • Loading branch information
Metnew committed Feb 19, 2018
1 parent 9a4afc6 commit 5fbb823
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/server/ssr/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ async function getFile (path) {
}

return new Promise((resolve, reject) => {
const watcher = chokidar.watch(path)

// This `readFile` func is looking like it escaped from procedure programming
const readFile = () => {
fs.readFile(path, 'utf8', (err, data) => {
Expand All @@ -23,14 +25,15 @@ async function getFile (path) {
}
const json = JSON.parse(data)
cache[path] = json
watcher.close()
resolve(json)
})
}
// does file exist?
fs.access(path, fs.constants.R_OK, err => {
if (err) {
// No. Watch for changes, resolve on `add`.
chokidar.watch(path).on('add', readFile)
watcher.on('add', readFile)
} else {
// Yes. resolve!
readFile()
Expand All @@ -44,16 +47,17 @@ export default async function () {
const assets = await getFile(process.env.CLIENT_ASSETS_MANIFEST)
// AutoDLL assets aren't included in CLIENT_ASSET_MANIFEST (webpack stats)
// So they are hardcoded here
const AutoDLLDevOnly = process.env.NODE_ENV === 'development'
? {
vendor: {
js: 'http://localhost:3000/vendor.js'
},
polyfills: {
js: 'http://localhost:3000/polyfills.js'
const AutoDLLDevOnly =
process.env.NODE_ENV === 'development'
? {
vendor: {
js: 'http://localhost:3000/vendor.js'
},
polyfills: {
js: 'http://localhost:3000/polyfills.js'
}
}
}
: {}
: {}

return {
...assets,
Expand Down

0 comments on commit 5fbb823

Please sign in to comment.