Skip to content

Commit ae7baf9

Browse files
jesstelfordJess Telford
authored andcommitted
Add support for watchify
By triggering `module-dep`'s `readFile` function, the `'file'` event is emitted, which is required by watchify to correctly rebuild.
1 parent f204b35 commit ae7baf9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,15 @@ function gc (folder, opts, cb) {
135135
})
136136
}
137137

138-
module.exports = function (folder, hash, log, disable) {
138+
module.exports = function (folder, hash, log, disable, atLeastOnce) {
139139
if (disable) {
140140
if (!log) {
141141
return null
142142
}
143143
return disabledLog.bind(null, log)
144144
}
145145
const cachePrefix = path.join(folder, createHash(JSON.stringify(hash)))
146+
var doneOnce = {}
146147
require('mkdirp').sync(folder)
147148
var handler = function (file, id, pkg, fallback, cb) {
148149
var start = hrtime()
@@ -188,9 +189,10 @@ module.exports = function (folder, hash, log, disable) {
188189
return readFile(cacheFile, 'utf8', function (_err, rawCacheData) {
189190
// ignore error
190191
if (doLog) cacheReadTime = msSince(cacheStart)
191-
if (!rawCacheData) {
192+
if (!rawCacheData || (atLeastOnce && !doneOnce[cacheFile])) {
192193
var generateStart = hrtime()
193-
return fallback(fileData, function (err, data) {
194+
return fallback(doneOnce[cacheFile] ? fileData : null, function (err, data) {
195+
doneOnce[cacheFile] = true
194196
if (doLog) {
195197
generateTime = msSince(generateStart)
196198
if (data) {

0 commit comments

Comments
 (0)