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

Commit

Permalink
Replace Gaze with Chokidar
Browse files Browse the repository at this point in the history
  • Loading branch information
xzyfer committed Apr 4, 2018
1 parent d1b36b4 commit 80fc103
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 318 deletions.
12 changes: 12 additions & 0 deletions bin/emcc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

skip=0

for arg; do
shift
[ "$skip" = "1" ] && skip=0 && continue
[ "$arg" = "-arch" ] && skip=1 && continue
set -- "$@" "$arg"
done

emcc $@
34 changes: 14 additions & 20 deletions bin/node-sass
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var Emitter = require('events').EventEmitter,
forEach = require('async-foreach').forEach,
Gaze = require('gaze'),
chokidar = require('chokidar'),
meow = require('meow'),
util = require('util'),
path = require('path'),
Expand Down Expand Up @@ -230,39 +230,33 @@ function getOptions(args, options) {

function watch(options, emitter) {
var handler = function(files) {
files.added.forEach(function(file) {
var watch = gaze.watched();
Object.keys(watch).forEach(function (dir) {
if (watch[dir].indexOf(file) !== -1) {
gaze.add(file);
}
});
});

files.changed.forEach(function(file) {
if (path.basename(file)[0] !== '_') {
renderFile(file, options, emitter);
}
});

files.removed.forEach(function(file) {
gaze.remove(file);
});
};

var gaze = new Gaze();
gaze.add(watcher.reset(options));
gaze.on('error', emitter.emit.bind(emitter, 'error'));
watcher.reset(options);

var service = chokidar.watch(options.includePath, {
ignore: /(?!\.s[ac]ss$)/,
followSymlinks: options.follow,
});

service.on('error', function(error) {
emitter.emit.error(error);
});

gaze.on('changed', function(file) {
service.on('change', function(file) {
handler(watcher.changed(file));
});

gaze.on('added', function(file) {
service.on('add', function(file) {
handler(watcher.added(file));
});

gaze.on('deleted', function(file) {
service.on('unlink', function(file) {
handler(watcher.removed(file));
});
}
Expand Down
60 changes: 28 additions & 32 deletions lib/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,68 +23,64 @@ watcher.reset = function(opts) {
};

watcher.changed = function(absolutePath) {
var files = {
added: [],
changed: [],
removed: [],
};
var files = [];

this.reset();

if (absolutePath && path.basename(absolutePath)[0] !== '_') {
files.changed.push(absolutePath);
if (!absolutePath) {
return files;
}

if (path.basename(absolutePath)[0] !== '_') {
if (Object.keys(graph.index).indexOf(absolutePath) !== -1) {
files.push(absolutePath);
}
}

graph.visitAncestors(absolutePath, function(parent) {
if (path.basename(parent)[0] !== '_') {
files.changed.push(parent);
files.push(parent);
}
});

graph.visitDescendents(absolutePath, function(child) {
files.added.push(child);
});

return files;
};

watcher.added = function(absolutePath) {
var files = {
added: [],
changed: [],
removed: [],
};
var files = [];
var oldIndex = Object.keys(graph.index);

this.reset();

if (Object.keys(graph.index).indexOf(absolutePath) === -1) {
files.added.push(absolutePath);
if (!absolutePath) {
return files;
}

graph.visitDescendents(absolutePath, function(child) {
files.added.push(child);
});
var newIndex = Object.keys(graph.index);
files.concat(newIndex.filter(function (file) {
return oldIndex.indexOf(file) === -1;
}));

if (path.basename(absolutePath)[0] === '_') {
graph.visitAncestors(absolutePath, function(parent) {
if (path.basename(parent)[0] !== '_') {
files.push(parent);
}
});
}

return files;
};

watcher.removed = function(absolutePath) {
var files = {
added: [],
changed: [],
removed: [],
};
var files = [];

graph.visitAncestors(absolutePath, function(parent) {
if (path.basename(parent)[0] !== '_') {
files.changed.push(parent);
files.push(parent);
}
});

if (Object.keys(graph.index).indexOf(absolutePath) !== -1) {
files.removed.push(absolutePath);
}

this.reset();

return files;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"dependencies": {
"async-foreach": "^0.1.3",
"chalk": "^1.1.1",
"chokidar": "^2.0.3",
"cross-spawn": "^3.0.0",
"gaze": "^1.0.0",
"get-stdin": "^4.0.1",
"glob": "^7.0.3",
"in-publish": "^2.0.0",
Expand Down
Loading

0 comments on commit 80fc103

Please sign in to comment.