Fix dirname so that dirname('/a/b/') -> '/a', like sh's does.
Before there was this comment: Can't strip trailing slashes since module.js incorrectly thinks dirname('/a/b/') should yield '/a/b' instead of '/a'. But now, such thinking is corrected.
This commit is contained in:
parent
e0d6f14b22
commit
f0f247d7e5
@ -197,7 +197,7 @@ function resolveModulePath(request, parent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var parentIdPath = path.dirname(parent.id +
|
var parentIdPath = path.dirname(parent.id +
|
||||||
(path.basename(parent.filename).match(new RegExp('^index\\.(' + exts.join('|') + ')$')) ? "/" : ""));
|
(path.basename(parent.filename).match(new RegExp('^index\\.(' + exts.join('|') + ')$')) ? "/." : ""));
|
||||||
id = path.join(parentIdPath, request);
|
id = path.join(parentIdPath, request);
|
||||||
// make sure require('./path') and require('path') get distinct ids, even
|
// make sure require('./path') and require('path') get distinct ids, even
|
||||||
// when called from the toplevel js file
|
// when called from the toplevel js file
|
||||||
|
@ -38,11 +38,9 @@ exports.normalize = function (path, keepBlanks) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.dirname = function (path) {
|
exports.dirname = function (path) {
|
||||||
// Can't strip trailing slashes since module.js incorrectly thinks
|
if (path.length > 1 && '/' === path[path.length-1]) {
|
||||||
// dirname('/a/b/') should yield '/a/b' instead of '/a'.
|
path = path.replace(/\/+$/, '');
|
||||||
// if (path.length > 1 && '/' === path[path.length-1]) {
|
}
|
||||||
// path = path.replace(/\/+$/, '');
|
|
||||||
// }
|
|
||||||
var lastSlash = path.lastIndexOf('/');
|
var lastSlash = path.lastIndexOf('/');
|
||||||
switch (lastSlash) {
|
switch (lastSlash) {
|
||||||
case -1:
|
case -1:
|
||||||
|
@ -8,6 +8,7 @@ assert.equal(path.basename(f), "test-path.js");
|
|||||||
assert.equal(path.basename(f, ".js"), "test-path");
|
assert.equal(path.basename(f, ".js"), "test-path");
|
||||||
assert.equal(path.extname(f), ".js");
|
assert.equal(path.extname(f), ".js");
|
||||||
assert.equal(path.dirname(f).substr(-11), "test/simple");
|
assert.equal(path.dirname(f).substr(-11), "test/simple");
|
||||||
|
assert.equal(path.dirname("/a/b/"), "/a");
|
||||||
assert.equal(path.dirname("/a/b"), "/a");
|
assert.equal(path.dirname("/a/b"), "/a");
|
||||||
assert.equal(path.dirname("/a"), "/");
|
assert.equal(path.dirname("/a"), "/");
|
||||||
assert.equal(path.dirname("/"), "/");
|
assert.equal(path.dirname("/"), "/");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user