Permalink
Browse files

remove findit dependency

  • Loading branch information...
1 parent 44d7bc4 commit cc653649af35fcd7097cf2ff963cacae052c1368 @jairajs89 committed Apr 5, 2013
Showing with 60 additions and 7 deletions.
  1. +3 −4 package.json
  2. +57 −3 watcher.js
View
@@ -2,7 +2,7 @@
"author": "Jairaj Sethi <j@jairaj.org> (http://jairaj.org/)",
"name": "zerver",
"description": "client-integrated webapp server",
- "version": "0.9.4",
+ "version": "0.9.6",
"repository": {
"type": "git",
"url": "git://github.com/jairajs89/zerver.git"
@@ -17,9 +17,8 @@
"less" : "1.3.3"
},
"devDependencies": {
- "stalker" : "0.0.20" ,
- "findit" : "0.1.2" ,
- "socket.io" : "0.9.11"
+ "stalker" : "0.0.20" ,
+ "socket.io" : "0.9.11"
},
"bin": {
"zerver": "run.js"
View
@@ -1,12 +1,11 @@
var fs = require('fs'),
- findit = require('findit'),
+ path = require('path'),
stalker = require('stalker');
-
exports.watch = function (dir, callback) {
- var filesNames = findit.sync(dir),
+ var filesNames = findSync(dir),
files = {};
filesNames.forEach(function (fileName) {
@@ -68,3 +67,58 @@ exports.watch = function (dir, callback) {
callback(fileName);
}
};
+
+
+
+// taken from node-findit@0.1.2
+// wasnt included as a dependency because its
+// devDependencies tend to take *really* long
+// to install with all that C compilation.
+
+function createInodeChecker () {
+ var inodes = {};
+ return function inodeSeen(inode) {
+ if (inodes[inode]) {
+ return true;
+ } else {
+ inodes[inode] = true;
+ return false;
+ }
+ }
+}
+
+function findSync (dir, options, callback) {
+ cb = arguments[arguments.length - 1];
+ if (typeof(cb) !== 'function') {
+ cb = undefined;
+ }
+ var inodeSeen = createInodeChecker();
+ var files = [];
+ var fileQueue = [];
+ var processFile = function processFile(file) {
+ var stat = fs.lstatSync(file);
+ if (inodeSeen(stat.ino)) {
+ return;
+ }
+ files.push(file);
+ cb && cb(file, stat)
+ if (stat.isDirectory()) {
+ fs.readdirSync(file).forEach(function(f) { fileQueue.push(path.join(file, f)); });
+ } else if (stat.isSymbolicLink()) {
+ if (options && options.follow_symlinks && path.existsSync(file)) {
+ fileQueue.push(fs.realpathSync(file));
+ }
+ }
+ };
+ /* we don't include the starting directory unless it is a file */
+ var stat = fs.lstatSync(dir);
+ if (stat.isDirectory()) {
+ fs.readdirSync(dir).forEach(function(f) { fileQueue.push(path.join(dir, f)); });
+ } else {
+ fileQueue.push(dir);
+ }
+ while (fileQueue.length > 0) {
+ processFile(fileQueue.shift());
+ }
+ return files;
+};

0 comments on commit cc65364

Please sign in to comment.