-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Description
In mocha.js they using a CommonJS require to make mocha runable in browser, it is a lite version of brequire.
Compiled single JS may looks like this:
;(function(){
// ** AMD wrapper here? **
// ** jsprelude stuff here **
// CommonJS require()
function require(p){
var path = require.resolve(p)
, mod = require.modules[path];
if (!mod) throw new Error('failed to require "' + p + '"');
if (!mod.exports) {
mod.exports = {};
mod.call(mod.exports, mod, mod.exports, require.relative(path));
}
return mod.exports;
}
require.modules = {};
require.resolve = function (path){
var orig = path
, reg = path + '.js'
, index = path + '/index.js';
return require.modules[reg] && reg
|| require.modules[index] && index
|| orig;
};
require.register = function (path, fn){
require.modules[path] = fn;
};
require.relative = function (parent) {
return function(p){
if ('.' != p.charAt(0)) return require(p);
var path = parent.split('/')
, segs = p.split('/');
path.pop();
for (var i = 0; i < segs.length; i++) {
var seg = segs[i];
if ('..' == seg) path.pop();
else if ('.' != seg) path.push(seg);
}
return require(path.join('/'));
};
};Then gorillascript compiled with options.bare on then wrapped in this form:
require.register("path/to/file.gs", function(module, exports, require){
// [gorillascript compiled]
}); // module: path/to/file.gsMetadata
Metadata
Assignees
Labels
No labels