Permalink
Browse files

#94 clean up based on comment

clean up based on comment from Jakob
  • Loading branch information...
chaozhang committed Apr 3, 2012
1 parent f8ea1ae commit 5b79913dfb98e37cdc151baf6b86b743f90b3aa7
View
@@ -78,6 +78,7 @@ requireRegex = /(?:^|[^\w\$_.\(])require\s*\(\s*("[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\
defineStaticRequireRegex = /^[\r\n\s]*define\(\s*("\S+",|'\S+',|\s*)\s*\[([^\]]*)\],\s*(function\s*\(|{).+/
requireGreedyCapture = /require.*/
commentRegex = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg
+relativePathRegex = /^(.\/|..\/).*/
###
CommonJS wrappers for a header and footer
@@ -749,7 +750,7 @@ downloadTree = (tree, callback) ->
# apply the ruleset for this module if we haven't yet
if db.module.getRulesApplied() is false
- if /^(.\/|..\/).*/.test(moduleId)
+ if relativePathRegex.test(moduleId)
# handle relative path
relativePath = userConfig.moduleRoot
if tree.getParent() and tree.getParent().getValue()
@@ -901,9 +902,7 @@ applyRules = (moduleId, save, relativePath) ->
else if typeof(userConfig.moduleRoot) is "function" then workingPath = userConfig.moduleRoot(workingPath)
if typeof(relativePath) is "string"
- workingPath = relativePath + moduleId
- if relativePath.lastIndexOf("/") isnt -1
- workingPath = relativePath.substring(0, relativePath.lastIndexOf("/") + 1) + moduleId
+ workingPath = basedir(relativePath) + moduleId
if !fileSuffix.test(workingPath) then workingPath = "#{workingPath}.js"
@@ -1044,6 +1043,11 @@ createModule = (id, uri, exports) ->
return module["exports"]
return module
+basedir = (path) ->
+ if path.lastIndexOf("/") isnt -1
+ path = path.substring(0, path.lastIndexOf("/") + 1)
+ return path
+
###
Main Payloads: require, require.ensure, etc
###
@@ -0,0 +1 @@
+exports.divide = function(val) { return val/2 - 1; };
@@ -1,2 +1,3 @@
exports.divide = require("../divide").divide;
exports.divide_plus_one = require("./divide-plus_one").divide;
+exports.divide_minus_one = require("../../divide-minus_one").divide;
@@ -12,6 +12,7 @@ equal(boo.divide(4), 2, "relative path '.' test pass");
var boo = require("relative-three/relative-three");
equal(boo.divide(4), 2, "relative path '.' test pass");
equal(boo.divide_plus_one(10), 6, "relative path '.' test pass");
+equal(boo.divide_minus_one(10), 4, "relative path '.' test pass");
try {
var qux = require("invalid$module");
@@ -34,7 +34,7 @@ asyncTest("Compliance", 13, function() {
require.run("compliance");
});
-asyncTest("Compliance - Module Identifiers", 7, function() {
+asyncTest("Compliance - Module Identifiers", 8, function() {
require.setModuleRoot("http://localhost:4000/tests/modules-1.1.1/includes/spec/identifiers");
require.run("terms");
});

0 comments on commit 5b79913

Please sign in to comment.