Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove xtend #382

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions bin/args.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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));
};
33 changes: 16 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -122,25 +121,25 @@ 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();
});
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);
Expand All @@ -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);
};
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down