Skip to content

Commit d3e0b3b

Browse files
committed
Expand skipped paths.
Keys corresponding to skipped paths (i.e. where the value is `false`) did not get expanded, so only module IDs were supported. This lets us skip relative paths as well.
1 parent a242aef commit d3e0b3b

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

index.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,23 @@ function find_shims_in_package(pkgJson, cur_path, shims, browser) {
5151

5252
// http://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders
5353
Object.keys(replacements).forEach(function(key) {
54+
var val;
5455
if (replacements[key] === false) {
55-
return shims[key] = __dirname + '/empty.js';
56+
val = __dirname + '/empty.js';
5657
}
57-
58-
var val = replacements[key];
59-
60-
// if target is a relative path, then resolve
61-
// otherwise we assume target is a module
62-
if (val[0] === '.') {
63-
val = path.resolve(cur_path, val);
58+
else {
59+
val = replacements[key];
60+
// if target is a relative path, then resolve
61+
// otherwise we assume target is a module
62+
if (val[0] === '.') {
63+
val = path.resolve(cur_path, val);
64+
}
6465
}
6566

66-
// if does not begin with / ../ or ./ then it is a module
67-
if (key[0] !== '/' && key[0] !== '.') {
68-
return shims[key] = val;
67+
if (key[0] === '/' || key[0] === '.') {
68+
// if begins with / ../ or ./ then we must resolve to a full path
69+
key = path.resolve(cur_path, key);
6970
}
70-
71-
key = path.resolve(cur_path, key);
7271
shims[key] = val;
7372
});
7473
}

test/false.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,14 @@ test('false module', function(done) {
2222
});
2323
});
2424

25+
test('false expand path', function(done) {
26+
var parent = {
27+
filename: fixtures_dir + '/node_modules/module-m/lib/index.js'
28+
};
29+
30+
resolve('./hide', parent, function(err, p, pkg) {
31+
assert.ifError(err);
32+
assert.equal(p, path.normalize(__dirname + '/../empty.js'));
33+
done();
34+
});
35+
});

test/fixtures/node_modules/module-m/lib/hide.js

Whitespace-only changes.

test/fixtures/node_modules/module-m/lib/index.js

Whitespace-only changes.

test/fixtures/node_modules/module-m/package.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)