Skip to content

Commit

Permalink
use Function#bind when it's appropriate, use single quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Sep 8, 2012
1 parent a7c35d1 commit d9c45eb
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions lib/require-analyzer.js
Expand Up @@ -57,11 +57,7 @@ analyzer.analyze = function (options, callback) {
// for streaming results.
//
['search', 'reduce'].forEach(function (ev) {
npmEmitter.on(ev, function () {
var args = Array.prototype.slice.call(arguments);
args.unshift(ev);
emitter.emit.apply(emitter, args);
});
npmEmitter.on(ev, emitter.emit.bind(emitter, ev));
});
});

Expand Down Expand Up @@ -96,12 +92,12 @@ analyzer.path = function(options, callback){
analyzer.dir(options, callback);
}
else if (stats.isFile()) {
if("fileFilter" in options && !options.fileFilter(options.target)) return;
if('fileFilter' in options && !options.fileFilter(options.target)) return;
analyzer.file(options, callback);
}
else {
err = new Error(options.target + ' is not a file or a directory.');
err.code = "UNSUPPORTED_TYPE";
err.code = 'UNSUPPORTED_TYPE';
callback(err);
}
});
Expand Down Expand Up @@ -237,9 +233,9 @@ analyzer.dir = function (options, callback) {
//
files.forEach(function(file){
//
// skip all files from "node_modules" directories
// skip all files from 'node_modules' directories
//
if(file === "node_modules") return;
if(file === 'node_modules') return;

//
// call analyzer.path and currate all dependencies
Expand All @@ -249,7 +245,7 @@ analyzer.dir = function (options, callback) {
target: path.join(target, file),
fileFilter: filterFiles
}, function(err, deps){
if(err && err.code !== "UNSUPPORTED_TYPE"){
if(err && err.code !== 'UNSUPPORTED_TYPE'){
//
// skip symlinks & friends
// but forward real errors
Expand Down Expand Up @@ -337,7 +333,7 @@ analyzer.package = function (options, callback) {
});
}

var scripts = 'scripts' in options ? options.scripts : ["test","prestart"];
var scripts = 'scripts' in options ? options.scripts : ['test','prestart'];

scripts = scripts.map(function (item) {
return pkg.scripts && pkg.scripts[item];
Expand Down Expand Up @@ -405,8 +401,8 @@ analyzer.package = function (options, callback) {
}

// add logic to default to app.js or server.js for main if main is not present.
if ( !("main" in pkg) || pkg.main === '') {
var files = ["app.js", "server.js", "index.js"];
if ( !('main' in pkg) || pkg.main === '') {
var files = ['app.js', 'server.js', 'index.js'];
setMain(files, pkg, newoptions, setTarget);
}
else {
Expand Down Expand Up @@ -478,12 +474,12 @@ function spawnWorker (options, callback) {

deps.send(options.target);

deps.on("message", function(data){
deps.on('message', function(data){
switch(data.type){
case "load":
case 'load':
packages[data.msg] = true;
break;
case "error":
case 'error':
errs.push(data.msg);
}
});
Expand Down Expand Up @@ -600,7 +596,7 @@ analyzer.merge = function (target) {
var objs = Array.prototype.slice.call(arguments, 1);
objs.forEach(function (o) {
Object.keys(o).forEach(function (attr) {
if ( !("get" in Object.getOwnPropertyDescriptor(o, attr)) ) {
if ( !('get' in Object.getOwnPropertyDescriptor(o, attr)) ) {
target[attr] = o[attr];
}
});
Expand Down

0 comments on commit d9c45eb

Please sign in to comment.