
var Path = require("path"),
    resolve = require.resolve
;

function fromRelative (path, name) {
    try {
        return resolve(Path.join(path, name));
    }
    catch (e) {}
    
    return false;
}

function fromNodeModules (start, name) {
    var subpath = Path.join("node_modules", name),
        path
    ;
    
    do {
        if ((path = fromRelative(start, subpath))) {
            return path;
        }
        start = start.split("/").slice(0, -1).join("/") || "/";
    } while (start !== "/");
    
    return false;
}

function fromNodeLib (libPaths, name) {
    var path, libpath;
    
    function testLib (lib) {
        if ((path = fromRelative(lib, name)) ||
            (path = fromRelative(lib, libpath))
        ) {
            return true;
        }
    }
    
    if (!libPaths || libPaths.length < 1) {
        return false;
    }
    
    libpath = Path.join("lib", name);
    
    if (libPaths.some(testLib)) {
        return path;
    }
    
    return false;
}

function resolveFrom (currentPath, moduleName, libPaths) {
    var path;
    
    try {
        // see if Node will do the work for us...
        return resolve(moduleName);
    }
    catch (err) {
        // is it relative to the current path?
        if ((path = fromRelative(currentPath, moduleName)) ||
        // or, is it somewhere in a node_modules directory
            (path = fromNodeModules(currentPath, moduleName)) ||
        // or, is it somewhere in the nodejs builtins?
            (path = fromNodeLib(libPaths, moduleName))
        ) {
            return path;
        }
        else {
            throw new Error(err.message);
        }
    }
}

module.exports.resolveFrom            = resolveFrom;
module.exports.resolveFromRelative    = fromRelative;
module.exports.resolveFromNodeModules = fromNodeModules;
module.exports.rsolveFromNodeLib      = fromNodeLib;

@@ -1068,32 +1068,465 @@
 %0A    %0A    try %7B%0A
+        if (!(/%5E%5C./.test(moduleName)) && !~moduleName.indexOf(%22/%22)) %7B%0A            if (path = fromNodeLib(libPaths, moduleName)) %7B%0A                return path;%0A            %7D%0A            else if (moduleName === resolve(moduleName)) %7B%0A                throw new Error(%0A                    %22Can not resolve node builtin module path '%22 + moduleName +%0A                    %22' without -L, or --node-lib, option set.%22)%0A            %7D%0A        %7D%0A
         // see i
@@ -1559,16 +1559,16 @@
 r us...%0A
-
         
@@ -1787,16 +1787,16 @@
 rectory%0A
+
         
@@ -1852,121 +1852,8 @@
 me))
- %7C%7C%0A        // or, is it somewhere in the nodejs builtins?%0A            (path = fromNodeLib(libPaths, moduleName))
 %0A   

Fix broken builtin require.