Skip to content
Browse files

Search parent directories for a package.json

  • Loading branch information...
1 parent 288df4c commit fedf3e23600d0ab653e11344bd8b0810d24674a4 @kriszyp committed Jul 3, 2010
Showing with 15 additions and 6 deletions.
  1. +15 −6 lib/nodules.js
View
21 lib/nodules.js
@@ -29,24 +29,33 @@ var request = require("./nodules-utils/node-http-client").request,
WorkerConstructor = typeof Worker !== "undefined" ? Worker : null;
SharedWorkerConstructor = typeof SharedWorker !== "undefined" ? SharedWorker : null;
defaultMap = {
- "http://github.com/([^/]+)/([^/]+)/raw/([^/]+)/(.*)": "zip:http://github.com/$1/$2/zipball/$3!/$4"
+ "http://github.com/([^/]+)/}([^/]+)/raw/([^/]+)/(.*)": "zip:http://github.com/$1/$2/zipball/$3!/$4"
};
function EnginePackage(engine){
var enginePackage = this;
this.useLocal= function(){
- try{
- var packageJson = fs.read("package.json");
- }catch(e){
- packageJson = "{}";
+ var packageJson = "{}",
+ path = ".";
+ function findPackage(directory){
+ path = fs.realpathSync(directory);
+ try{
+ packageJson = fs.read(path + "/package.json");
+ }catch(e){
+ return findPackage(directory + "/..");
+ }
+ return path;
}
try{
+ path = findPackage(".");
+ }catch(e){}
+ try{
var parsed = JSON.parse(packageJson);
}catch(e){
e.message += " trying to parse local package.json";
throw e;
}
- return enginePackage.usePackage(parsed, "file://" + fs.realpathSync("."));
+ return enginePackage.usePackage(parsed, "file://" + path);
};
this.usePackage= function(packageData, path){
processPackage(path, packageData, engine);

0 comments on commit fedf3e2

Please sign in to comment.
Something went wrong with that request. Please try again.