Skip to content

Commit

Permalink
Added logic if package.json main is empty/missing to set to server.js…
Browse files Browse the repository at this point in the history
… or app.js if either exists.
  • Loading branch information
glennblock committed Feb 21, 2012
1 parent a67cd8c commit df49a49
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions lib/require-analyzer.js
Expand Up @@ -379,23 +379,55 @@ analyzer.package = function (options, callback) {
}

var newoptions = analyzer.clone(options);
try {
newoptions.target = require.resolve(path.join(newoptions.target, path.normalize(pkg.main || '/')));

function setMain(pkg,newoptions,callback) {
path.exists('app.js', function(exists) {
if (exists) {
pkg.main="app.js";
return callback(pkg, newoptions);
}
else {
path.exists('server.js', function(exists) {
if (exists) {
pkg.main="server.js";
console.log('found server.js');
}
return callback(pkg, newoptions);
});
}
});
}
catch (e) {
todo = 1;
deps = null;
dequeue(e);

function setTarget(pkg, newoptions) {
try {
newoptions.target = require.resolve(path.join(newoptions.target, path.normalize(pkg.main || '/')));
}
catch (e) {
todo = 1;
deps = null;
dequeue(e);
}
return processOptions(newoptions);
}

//add logic to default to app.js or server.js for main if main is not present.
if (typeof pkg.main === 'undefined' || pkg.main=='')
{
setMain(pkg, newoptions, setTarget);
}
else {
setTarget(callback);
}

processOptions(newoptions);
}
catch (ex) {
return callback(ex);
}
});
};




function mergeDependencies(err, deps, pkgDeps, devDeps, callback) {
var merged = {};
if (err) {
Expand Down

0 comments on commit df49a49

Please sign in to comment.