mirror of
https://github.com/Jermolene/TiddlyWiki5.git
synced 2025-12-06 02:30:46 -08:00
Additional improvement to CommonJS Modules support
Now implements (and mostly follows) requirements of Modules/1.1 spec
implementes only the required "secure sandbox" subset of the spec
`module` free variable changed from the `moduleInfo` to an id container
`require` free variable given a "main" property
boot module scope closed and exported
this also changes the interface between boot and bootprefix slightly
(should now be able to create multiple TW instances under node)
BREAKING CHANGES:
The tiddlywiki module itself now exports a single constructor function
Modules which depended on `module` referring to `moduleInfo` will break
Modules which don't conform to Modules/1.1 will break
(by attempting to modify require.main or module.id)
This commit is contained in:
parent
fbc80e379d
commit
b8c37a26ef
3 changed files with 60 additions and 21 deletions
|
|
@ -12,12 +12,11 @@ See Boot.js for further details of the boot process.
|
|||
|
||||
\*/
|
||||
|
||||
// Set up $tw global for the browser
|
||||
if(typeof(window) === "undefined") {
|
||||
global.$tw = global.$tw || {}; // No `browser` member for the server
|
||||
} else {
|
||||
window.$tw = window.$tw || {browser: {}};
|
||||
}
|
||||
var _bootprefix = (function($tw) {
|
||||
|
||||
"use strict";
|
||||
|
||||
$tw = $tw || {browser: typeof(window) !== "undefined" ? {} : null};
|
||||
|
||||
/*
|
||||
Information about each module is kept in an object with these members:
|
||||
|
|
@ -81,3 +80,18 @@ Convenience function for pushing a tiddler onto the preloading array
|
|||
$tw.preloadTiddler = function(fields) {
|
||||
$tw.preloadTiddlers.push(fields);
|
||||
};
|
||||
|
||||
return $tw
|
||||
|
||||
});
|
||||
|
||||
if(typeof(exports) === "undefined") {
|
||||
// Set up $tw global for the browser
|
||||
window.$tw = _bootprefix();
|
||||
} else {
|
||||
// Export functionality as a module
|
||||
exports.bootprefix = _bootprefix;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue