Comparing version
96
index.js
@@ -32,3 +32,4 @@ var fs = require("fs"); | ||
scope.currentCaller = null; | ||
// option for allowing testing Errors | ||
scope.throwErrors = true; | ||
@@ -43,14 +44,13 @@ /** | ||
scope.include = function(path, tempPath, callback) { | ||
if(scope.validateIncludePaths == true) { | ||
if(os.platform() === 'darwin') { | ||
// Check file path that is calling include | ||
scope.currentCaller = scope.getCaller(); | ||
} else { | ||
// prevent this check on linux or win32 or other platforms than macosx unix | ||
console.warn('puremvc.validateIncludePaths feature only works when os is "darwin".\n'); | ||
scope.validateIncludePaths = false; | ||
if (scope.validateIncludePaths == true) { | ||
if (scope.validateIncludePaths == true) { | ||
if (os.platform().toLowerCase() !== "darwin") { | ||
// prevent this check on linux or win32 or other platforms than macosx unix | ||
console.warn('puremvc.validateIncludePaths feature only works when os is "darwin".\n'); | ||
scope.validateIncludePaths = false; | ||
} | ||
} | ||
} | ||
var _path = (tempPath || scope.basePath) + "/" + path + ".js"; | ||
@@ -67,4 +67,12 @@ | ||
// console.log("basePath:", scope.basePath); | ||
if (scope.validateIncludePaths == true) scope.exists(_path); | ||
if (scope.validateIncludePaths == true) { | ||
var e = scope.exists(_path); | ||
if (e === true) { | ||
} else { | ||
if(scope.throwErrors) | ||
throw e | ||
return e; | ||
} | ||
} | ||
return require(_path)(scope.include, scope, callback); | ||
@@ -95,4 +103,13 @@ | ||
if (exists) { | ||
// It points to an existing file in a path to a module. | ||
if (scope.validateIncludePaths == true) scope.exists(class_basedir_file); | ||
if (scope.validateIncludePaths == true) { | ||
var e = scope.exists(class_basedir_file); | ||
if (e === true) { | ||
// It points to an existing file in a path to a module. | ||
} else { | ||
if(scope.throwErrors) | ||
throw e; | ||
return e; | ||
} | ||
} | ||
return require(class_basedir_file)(scope.include, scope, callback); | ||
@@ -105,4 +122,13 @@ } else { | ||
if (exists) { | ||
if (scope.validateIncludePaths == true) scope.exists(resolvedPlugin); | ||
if (scope.validateIncludePaths == true) { | ||
var e = scope.exists(resolvedPlugin); | ||
if (e === true) { | ||
// It points to an existing file in a path to a module. | ||
return require(resolvedPlugin)(scope.include, scope, callback); | ||
} else { | ||
if(scope.throwErrors) | ||
throw e; | ||
return e; | ||
} | ||
} | ||
return require(resolvedPlugin)(scope.include, scope, callback); | ||
@@ -136,4 +162,4 @@ } else { | ||
if (exactPath !== dir) { | ||
header = format('[ PureMVC Include Path warning: Case sensitive warning in path:\n'); | ||
warning.push(format('%sIn %s\n "%s" \nDoesn\'t exactly match the actual directory path: \n"%s"]', header, scope.currentCaller, dir, exactPath)); | ||
header = format('[ PureMVC Include Path warning: Case sensitive warning in path:'); | ||
warning.push(format('%s\n "%s" \nDoesn\'t exactly match the actual directory path: \n"%s"]', header, dir, exactPath)); | ||
} | ||
@@ -160,6 +186,6 @@ | ||
} | ||
header = format('[ PureMVC Include warning: Case sensitive warning for class or file:\n'); | ||
header = format('[ PureMVC Include warning: Case sensitive warning for class or file:'); | ||
// Only check file reference from stack on unix... | ||
warning.push(format('%sIn %s\n"%s" \ndoesn\'t exactly match the actual file path: \n"%s"]', header, scope.currentCaller, fullRequiredPath, ___path.join(dir, matchingEntry))); | ||
warning.push(format('%s\n"%s" \ndoesn\'t exactly match the actual file path: \n"%s"]', header, fullRequiredPath, ___path.join(dir, matchingEntry))); | ||
} | ||
@@ -169,30 +195,16 @@ | ||
if (warning.length > 0) { | ||
var warnings = ""; | ||
for (var warn in warning) { | ||
console.warn(warning[warn] + '\n'); | ||
console.warn(warning[warn] ); | ||
} | ||
var puremvcError = new Error('[PureMVC Case sensitive Error]'); | ||
return puremvcError; | ||
} else { | ||
return true; | ||
} | ||
} | ||
scope.getCaller = function() { | ||
try { | ||
var err = new Error(); | ||
var callerfile; | ||
var currentfile; | ||
Error.prepareStackTrace = function(err, stack) { | ||
return stack; | ||
}; | ||
currentfile = err.stack.shift().getFileName(); | ||
while (err.stack.length) { | ||
callerfile = err.stack.shift().getFileName(); | ||
if (currentfile !== callerfile) return callerfile; | ||
} | ||
} catch (err) {} | ||
return undefined; | ||
} | ||
return scope; | ||
})(module.exports); |
{ | ||
"name": "npmvc", | ||
"version": "1.0.6-rc1", | ||
"version": "1.0.6-rc2", | ||
"description": "PureMVC for node.js", | ||
@@ -9,3 +9,3 @@ "engines": { | ||
"scripts": { | ||
"test": "DEBUG=test node test/test.js" | ||
"test": "DEBUG=test node test/testAllFeatures.js" | ||
}, | ||
@@ -12,0 +12,0 @@ "author": { |
@@ -1,2 +0,2 @@ | ||
[](https://travis-ci.org/rstr74/npmvc) | ||
[](https://travis-ci.org/rstr74/npmvc) | ||
[](https://www.npmjs.org/package/npmvc) | ||
@@ -159,2 +159,7 @@ [](https://www.npmjs.org/package/npmvc) | ||
puremvc.validateIncludePaths = true; | ||
``` | ||
``` | ||
### puremvc.throwErrors | ||
**boolean (default:true)** | ||
This option only works on macosx darwin. It suppresses throwing case insensitive errors. It is mainly for testing, so you can ignore it basicly. |
86959
0.51%2565
0.67%165
3.77%11
-15.38%8
14.29%