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

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