Permalink
Browse files

Handle deep parent references, move to using fs.read() for returning …

…strings
  • Loading branch information...
1 parent 0a3a0d7 commit 43a173cb03ed29821067c52514329f961da367d3 @kriszyp committed Jun 2, 2010
Showing with 12 additions and 8 deletions.
  1. +12 −8 lib/nodules.js
View
@@ -36,7 +36,7 @@ function EnginePackage(engine){
var enginePackage = this;
this.useLocal= function(){
try{
- var packageJson = fs.readFileSync("package.json");
+ var packageJson = fs.read("package.json");
}catch(e){
packageJson = "{}";
}
@@ -61,11 +61,11 @@ function EnginePackage(engine){
this.getModuleSource = function(id){
try{
- return fs.readFileSync(enginePackage.getCachePath(id));
+ return fs.read(enginePackage.getCachePath(id));
}catch(e){
if(id.indexOf(":") === -1 && moduleExports[id.substring(0, id.length - 3)]){
try{
- return fs.readFileSync(__dirname+ "/nodules-utils/" + id);
+ return fs.read(__dirname+ "/nodules-utils/" + id);
}
catch(e){}
}
@@ -116,12 +116,12 @@ Module.prototype.supportsUri = true;
exports.baseFilePath = system.env.NODULES_PATH || "downloaded-modules";
try{
- var filePathMappingsJson = fs.readFileSync(exports.baseFilePath + "/paths.json");
+ var filePathMappingsJson = fs.read(exports.baseFilePath + "/paths.json");
}catch(e){
}
if(filePathMappingsJson){
- filePathMappingsObject = JSON.parse(filePathMappingsJson);
+ var filePathMappingsObject = JSON.parse(filePathMappingsJson);
useSetInterval = filePathMappingsObject.useSetInterval;
for(var i in filePathMappingsObject){
filePathMappings.push({
@@ -142,8 +142,12 @@ function resolveUri(currentId, uri, mappings){
if(uri.charAt(0) === '.'){
var extension = currentId.match(/\.[\w]+$/);
extension = extension ? extension[0] : "";
- currentId = currentId.substring(0, currentId.lastIndexOf('/') + 1);
- return [(currentId + uri).replace(/\/[^\/]*\/\.\.\//g,'/').replace(/\/\.\//g,'/')] + extension;
+ uri = currentId.substring(0, currentId.lastIndexOf('/') + 1) + uri;
+ while(lastUri !== uri){
+ var lastUri = uri;
+ uri = uri.replace(/\/[^\/]*\/\.\.\//,'/');
+ }
+ return [uri.replace(/\/\.\//g,'/')] + extension;
}
else if(uri.indexOf(":") > -1){
return uri;
@@ -572,7 +576,7 @@ function promiseReadFileSync(path){
var deferred = promiseModule.defer();
process.nextTick(function(){
try{
- deferred.resolve(fs.readFileSync(path));
+ deferred.resolve(fs.read(path));
}catch(e){
e.message += " " + path;
deferred.reject(e);

0 comments on commit 43a173c

Please sign in to comment.