Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Only bundle when the modification time changed #222

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+22 −7
Split
View
@@ -12,17 +12,32 @@ function reg (w, opts, body, file) {
if (w.watches[file]) return body;
var type = w.files[file] ? 'files' : 'entries';
+ var mtime = null;
var watch = function () {
if (w.files[file] && w.files[file].synthetic) return;
- if (typeof opts === 'object') {
- w.watches[file] = fs.watch(file, opts, watcher);
- }
- else {
- w.watches[file] = fs.watch(file, watcher);
- }
+ fs.stat(file, function (err, stats) {
+ if (!err )
+ mtime = stats.mtime.getTime();
+ if (typeof opts === 'object') {
+ w.watches[file] = fs.watch(file, opts, watcher);
+ }
+ else {
+ w.watches[file] = fs.watch(file, watcher);
+ }
+ });
};
+
+ var ifchanged = function (cb) {
+ fs.stat(file, function(err, stats) {
+ if (!err && stats.mtime.getTime() != mtime) {
+ mtime = stats.mtime.getTime();
+ cb();
+ }
+ });
+ };
+
var pending = null;
var bundle = function () {
if (pending) return;
@@ -58,7 +73,7 @@ function reg (w, opts, body, file) {
w._cache = null;
}
else if (event === 'change') {
- bundle();
+ ifchanged(bundle);
}
else if (event === 'rename') {
w.watches[file].close();