|
@ -164,10 +164,8 @@ var module = (function () { |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function findModulePath (id, dirs) { |
|
|
function findModulePath (request, paths) { |
|
|
process.assert(Array.isArray(dirs)); |
|
|
var nextLoc = traverser(request, request.charAt(0) === '/' ? [''] : paths); |
|
|
|
|
|
|
|
|
var nextLoc = traverser(id, id.charAt(0) === '/' ? [''] : dirs); |
|
|
|
|
|
|
|
|
|
|
|
var fs = requireNative('fs'); |
|
|
var fs = requireNative('fs'); |
|
|
|
|
|
|
|
@ -181,7 +179,10 @@ var module = (function () { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// sync - no i/o performed
|
|
|
// sync - no i/o performed
|
|
|
function resolveModulePath(request, parent) { |
|
|
function resolveModuleLookupPaths (request, parent) { |
|
|
|
|
|
|
|
|
|
|
|
if (natives[request]) return [request, []]; |
|
|
|
|
|
|
|
|
var start = request.substring(0, 2); |
|
|
var start = request.substring(0, 2); |
|
|
if (start !== "./" && start !== "..") { |
|
|
if (start !== "./" && start !== "..") { |
|
|
return [request, modulePaths]; |
|
|
return [request, modulePaths]; |
|
@ -207,18 +208,33 @@ var module = (function () { |
|
|
function loadModule (request, parent) { |
|
|
function loadModule (request, parent) { |
|
|
debug("loadModule REQUEST " + (request) + " parent: " + parent.id); |
|
|
debug("loadModule REQUEST " + (request) + " parent: " + parent.id); |
|
|
|
|
|
|
|
|
|
|
|
var resolved = resolveModuleFilename(request, parent); |
|
|
|
|
|
var id = resolved[0]; |
|
|
|
|
|
var filename = resolved[1]; |
|
|
|
|
|
|
|
|
// With natives id === request
|
|
|
// With natives id === request
|
|
|
// We deal with these first
|
|
|
// We deal with these first
|
|
|
var cachedNative = internalModuleCache[request]; |
|
|
var cachedNative = internalModuleCache[id]; |
|
|
if (cachedNative) { |
|
|
if (cachedNative) { |
|
|
return cachedNative.exports; |
|
|
return cachedNative.exports; |
|
|
} |
|
|
} |
|
|
if (natives[request]) { |
|
|
if (natives[id]) { |
|
|
debug('load native module ' + request); |
|
|
debug('load native module ' + request); |
|
|
return loadNative(request).exports; |
|
|
return loadNative(id).exports; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var resolvedModule = resolveModulePath(request, parent), |
|
|
var cachedModule = moduleCache[filename]; |
|
|
|
|
|
if (cachedModule) return cachedModule.exports; |
|
|
|
|
|
|
|
|
|
|
|
var module = new Module(id, parent); |
|
|
|
|
|
moduleCache[filename] = module; |
|
|
|
|
|
module.load(filename); |
|
|
|
|
|
return module.exports; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function resolveModuleFilename (request, parent) { |
|
|
|
|
|
if (natives[request]) return [request, request]; |
|
|
|
|
|
var resolvedModule = resolveModuleLookupPaths(request, parent), |
|
|
id = resolvedModule[0], |
|
|
id = resolvedModule[0], |
|
|
paths = resolvedModule[1]; |
|
|
paths = resolvedModule[1]; |
|
|
|
|
|
|
|
@ -228,15 +244,8 @@ var module = (function () { |
|
|
if (!filename) { |
|
|
if (!filename) { |
|
|
throw new Error("Cannot find module '" + request + "'"); |
|
|
throw new Error("Cannot find module '" + request + "'"); |
|
|
} |
|
|
} |
|
|
|
|
|
return [id, filename]; |
|
|
var cachedModule = moduleCache[filename]; |
|
|
} |
|
|
if (cachedModule) return cachedModule.exports; |
|
|
|
|
|
|
|
|
|
|
|
var module = new Module(id, parent); |
|
|
|
|
|
moduleCache[filename] = module; |
|
|
|
|
|
module.load(filename); |
|
|
|
|
|
return module.exports; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Module.prototype.load = function (filename) { |
|
|
Module.prototype.load = function (filename) { |
|
@ -262,6 +271,9 @@ var module = (function () { |
|
|
return loadModule(path, self); |
|
|
return loadModule(path, self); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
require.resolve = function (request) { |
|
|
|
|
|
return resolveModuleFilename(request, self)[1]; |
|
|
|
|
|
} |
|
|
require.paths = modulePaths; |
|
|
require.paths = modulePaths; |
|
|
require.main = process.mainModule; |
|
|
require.main = process.mainModule; |
|
|
// Enable support to add extra extension types
|
|
|
// Enable support to add extra extension types
|
|
|