1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-26 19:47:20 +00:00

Some quick style cleanup to commonjs patches

This commit is contained in:
natecain 2013-10-01 17:56:05 -04:00
parent 5c92ec3617
commit fbc80e379d

View File

@ -337,7 +337,7 @@ $tw.utils.resolvePath = function(sourcepath,rootpath) {
var root = rootpath.split("/");
// Remove the filename part of the root
root.splice(root.length - 1, 1);
return root.join('/')+'/'+sourcepath
return root.join("/") + "/" + sourcepath;
} else {
return sourcepath;
}
@ -543,9 +543,9 @@ $tw.utils.Crypto = function() {
Execute the module named 'moduleName'. The name can optionally be relative to the module named 'moduleRoot'
*/
$tw.modules.execute = function(moduleName,moduleRoot) {
var name = moduleName[0] == '.' ? $tw.utils.resolvePath(moduleName,moduleRoot) : moduleName,
moduleInfo = $tw.modules.titles[name] || $tw.modules.titles[name+'.js'] || $tw.modules.titles[moduleName] || $tw.modules.titles[moduleName+'.js'] ,
tiddler = $tw.wiki.getTiddler(name) || $tw.wiki.getTiddler(name+'.js') || $tw.wiki.getTiddler(moduleName) || $tw.wiki.getTiddler(moduleName+'.js') ,
var name = moduleName[0] === "." ? $tw.utils.resolvePath(moduleName,moduleRoot) : moduleName,
moduleInfo = $tw.modules.titles[name] || $tw.modules.titles[name + ".js"] || $tw.modules.titles[moduleName] || $tw.modules.titles[moduleName + ".js"] ,
tiddler = $tw.wiki.getTiddler(name) || $tw.wiki.getTiddler(name + ".js") || $tw.wiki.getTiddler(moduleName) || $tw.wiki.getTiddler(moduleName + ".js") ,
_exports = {},
sandbox = {
module: moduleInfo,
@ -566,19 +566,19 @@ $tw.modules.execute = function(moduleName,moduleRoot) {
});
}
if(!moduleInfo) {
//we could not find the module on this path
//try to defer to browserify etc, or node
// We could not find the module on this path
// Try to defer to browserify etc, or node
var deferredModule;
if($tw.browser) {
if(window.require) {
try {
return window.require(moduleName)
return window.require(moduleName);
} catch(e) {}
}
throw "Cannot find module named '" + moduleName + "' required by module '" + moduleRoot + "', resolved to " + name;
} else {
// If we don't have a module with that name, let node.js try to find it
return require(moduleName)
return require(moduleName);
}
}
// Execute the module if we haven't already done so