1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Refactored browser module boot loader to improve error messages

This commit is contained in:
Jeremy Ruston 2011-12-14 10:42:19 +00:00
parent 364d891ca6
commit a8099114b5

View File

@ -30,19 +30,23 @@ function resolveModuleName(srcModule,dstModule) {
}
return src.join("/");
} else {
// If there was no / or ./ then it's a built in module
// If there was no / or ./ then it's a built in module and the name doesn't need resolving
return dstModule;
}
}
function executeModule(name) {
var require = function(filepath) {
return executeModule(resolveModuleName(name,filepath));
/*
Execute the module named 'modName'. The name can optionally be relative to the module named 'modRoot'
*/
function executeModule(modName,modRoot) {
var name = modRoot ? resolveModuleName(modRoot,modName) : modName,
require = function(modRequire) {
return executeModule(modRequire,name);
},
exports = {},
module = modules[name];
if(!module) {
throw new Error("Cannot find module named '" + name + "'");
throw new Error("Cannot find module named '" + modName + "' required by module '" + modRoot + "'");
}
if(module.exports) {
return module.exports;