Allow npmRequire to load dev bundle and built-in modules.

This commit is contained in:
Ben Newman
2016-03-13 14:01:09 -04:00
parent 96c802edb4
commit f595034e1a

View File

@@ -1,4 +1,5 @@
var assert = require("assert");
var topLevelIdPattern = /^[^./]/;
function getRelID(id) {
assert.strictEqual(id.charAt(0), "/");
@@ -6,7 +7,15 @@ function getRelID(id) {
}
function npmRequire(id) {
return require(getRelID(id));
try {
var absId = resolve(id);
} finally {
if (absId) return require(absId);
if (topLevelIdPattern.test(id)) {
// Fall back to dev_bundle/lib/node_modules and built-in modules.
return require(id);
}
}
}
function resolve(id) {