diff --git a/bin/args.js b/bin/args.js index ccfdd3f..46d5c5e 100644 --- a/bin/args.js +++ b/bin/args.js @@ -1,7 +1,6 @@ var fromArgs = require('browserify/bin/args'); var watchify = require('../'); var defined = require('defined'); -var xtend = require('xtend'); module.exports = function (args) { var b = fromArgs(args, watchify.args); @@ -12,5 +11,5 @@ module.exports = function (args) { opts.ignoreWatch = ignoreWatch; } - return watchify(b, xtend(opts, b.argv)); + return watchify(b, Object.assign(opts, b.argv)); }; diff --git a/index.js b/index.js index 0753b9f..0f00091 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,6 @@ var through = require('through2'); var path = require('path'); var chokidar = require('chokidar'); -var xtend = require('xtend'); var anymatch = require('anymatch'); module.exports = watchify; @@ -17,7 +16,7 @@ function watchify (b, opts) { var changingDeps = {}; var pending = false; var updating = false; - + var wopts = {persistent: true}; if (opts.ignoreWatch) { var ignored = opts.ignoreWatch !== true @@ -35,39 +34,39 @@ function watchify (b, opts) { b.on('reset', collect); collect(); } - + function collect () { b.pipeline.get('deps').push(through.obj(function(row, enc, next) { var file = row.expose ? b._expose[row.id] : row.file; cache[file] = { source: row.source, - deps: xtend(row.deps) + deps: Object.assign({}, row.deps) }; this.push(row); next(); })); } - + b.on('file', function (file) { watchFile(file); }); - + b.on('package', function (pkg) { var file = path.join(pkg.__dirname, 'package.json'); watchFile(file); if (pkgcache) pkgcache[file] = pkg; }); - + b.on('reset', reset); reset(); - + function reset () { var time = null; var bytes = 0; b.pipeline.get('record').on('end', function () { time = Date.now(); }); - + b.pipeline.get('wrap').push(through(write, end)); function write (buf, enc, next) { bytes += buf.length; @@ -84,11 +83,11 @@ function watchify (b, opts) { this.push(null); } } - + var fwatchers = {}; var fwatcherFiles = {}; var ignoredFiles = {}; - + b.on('transform', function (tr, mfile) { tr.on('file', function (dep) { watchFile(mfile, dep); @@ -122,12 +121,12 @@ function watchify (b, opts) { fwatchers[file].push(w); fwatcherFiles[file].push(dep); } - + function invalidate (id) { if (cache) delete cache[id]; if (pkgcache) delete pkgcache[id]; changingDeps[id] = true; - + if (!updating && fwatchers[id]) { fwatchers[id].forEach(function (w) { w.close(); @@ -135,12 +134,12 @@ function watchify (b, opts) { delete fwatchers[id]; delete fwatcherFiles[id]; } - + // wait for the disk/editor to quiet down first: if (pending) clearTimeout(pending); pending = setTimeout(notify, delay); } - + function notify () { if (updating) { pending = setTimeout(notify, delay); @@ -150,13 +149,13 @@ function watchify (b, opts) { changingDeps = {}; } } - + b.close = function () { Object.keys(fwatchers).forEach(function (id) { fwatchers[id].forEach(function (w) { w.close() }); }); }; - + b._watcher = function (file, opts) { return chokidar.watch(file, opts); }; diff --git a/package.json b/package.json index 0fba55f..c0fb7de 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,7 @@ "chokidar": "^3.4.0", "defined": "^1.0.0", "outpipe": "^1.1.0", - "through2": "^4.0.2", - "xtend": "^4.0.2" + "through2": "^4.0.2" }, "devDependencies": { "brfs": "^2.0.1",