};
exports.dirname = function (path) {
- return path && path.substr(0, path.lastIndexOf("/")) || ".";
+ // Can't strip trailing slashes since module.js incorrectly thinks
+ // dirname('/a/b/') should yield '/a/b' instead of '/a'.
+ // if (path.length > 1 && '/' === path[path.length-1]) {
+ // path = path.replace(/\/+$/, '');
+ // }
+ var lastSlash = path.lastIndexOf('/');
+ switch (lastSlash) {
+ case -1:
+ return '.';
+ case 0:
+ return '/';
+ default:
+ return path.substring(0, lastSlash);
+ }
};
exports.filename = function () {
assert.equal(path.basename(f, ".js"), "test-path");
assert.equal(path.extname(f), ".js");
assert.equal(path.dirname(f).substr(-11), "test/simple");
+assert.equal(path.dirname("/a/b"), "/a");
+assert.equal(path.dirname("/a"), "/");
+assert.equal(path.dirname("/"), "/");
path.exists(f, function (y) { assert.equal(y, true) });
assert.equal(path.join(".", "fixtures/b", "..", "/b/c.js"), "fixtures/b/c.js");