Skip to content

Commit 6230c4f

Browse files
author
Will Binns-Smith
committed
Windows compatibility and spaces -> tabs.
1 parent 5b0e9a7 commit 6230c4f

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

lib/dependencies/LocalModulesHelpers.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
var path = require('path')
65
var LocalModule = require("./LocalModule");
76

87
var LocalModulesHelpers = exports;
@@ -16,9 +15,9 @@ LocalModulesHelpers.addLocalModule = function(state, name) {
1615

1716
LocalModulesHelpers.getLocalModule = function(state, name, namedModule) {
1817
if(!state.localModules) return null;
19-
if(namedModule && isRelative(name)) {
18+
if(namedModule) {
2019
// resolve dependency name relative to the defining named module
21-
name = path.join(path.dirname(namedModule), name);
20+
name = lookup(namedModule, name);
2221
}
2322
for(var i = 0; i < state.localModules.length; i++) {
2423
if(state.localModules[i].name === name)
@@ -27,6 +26,19 @@ LocalModulesHelpers.getLocalModule = function(state, name, namedModule) {
2726
return null;
2827
};
2928

30-
function isRelative(name) {
31-
return name[0] === '.';
29+
function lookup(parent, mod) {
30+
if ('.' != mod.charAt(0)) return mod;
31+
32+
var path = parent.split('/')
33+
, segs = mod.split('/');
34+
path.pop();
35+
36+
for (var i = 0; i < segs.length; i++) {
37+
var seg = segs[i];
38+
if ('..' == seg) path.pop();
39+
else if ('.' != seg) path.push(seg);
40+
}
41+
42+
return path.join('/');
3243
}
44+

test/cases/parsing/local-modules/index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ it("should define and require a local module with deps", function() {
4343
});
4444

4545
it("should define and require a local module that is relative", function () {
46-
define("my-dir/my-module3", function(dep) {
47-
return 1234;
48-
});
49-
define("my-dir/my-other-dir/my-module4", function(dep) {
50-
return 2345;
51-
});
52-
define("my-dir/my-other-dir/my-module5", ["./my-module4", "../my-module3"], function(myModule4, myModule3) {
53-
myModule3.should.be.eql(1234);
54-
myModule4.should.be.eql(2345);
55-
return 3456;
56-
});
57-
require("my-dir/my-other-dir/my-module5").should.be.eql(3456);
46+
define("my-dir/my-module3", function() {
47+
return 1234;
48+
});
49+
define("my-dir/my-other-dir/my-module4", function() {
50+
return 2345;
51+
});
52+
define("my-dir/my-other-dir/my-module5", ["./my-module4", "../my-module3"], function(myModule4, myModule3) {
53+
myModule3.should.be.eql(1234);
54+
myModule4.should.be.eql(2345);
55+
return 3456;
56+
});
57+
require("my-dir/my-other-dir/my-module5").should.be.eql(3456);
5858
})

0 commit comments

Comments
 (0)