Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Upgraded to follow latest AMD proposal

  • Loading branch information...
commit 87fc3d60cee11d87ab109a7cc4da1f3b39bdb4c4 1 parent 9680b70
@kriszyp authored
Showing with 17 additions and 19 deletions.
  1. +1 −1  README.md
  2. +7 −10 lib/jsgi/transporter.js
  3. +9 −8 lib/receiver.js
View
2  README.md
@@ -9,7 +9,7 @@ with any client side module loader that supports the CommonJS module transport
format. This has been primarily tested with RequireJS and Yabble:
[http://github.com/jrburke/requirejs](http://github.com/jrburke/requirejs)
-[http://github.com/kriszyp/yabble](http://github.com/kriszyp/yabble) (currently the kriszyp fork is needed because of some implementation bugs in require.def handling in Yabble)
+[http://github.com/kriszyp/yabble](http://github.com/kriszyp/yabble) (currently the kriszyp fork is needed because of some implementation bugs in define handling in Yabble)
To use transporter, include the appliance in your JSGI stack:
View
17 lib/jsgi/transporter.js
@@ -1,7 +1,5 @@
//TODO: optionally write to target file
-require.def||(require.def=function(factory){module.exports=factory(require, exports, module);});
-require.def(function(require, exports, module){
exports = module.exports ? Transporter : exports;
exports.Transporter = Transporter;
function Transporter(options, app) {
@@ -85,7 +83,7 @@ function Transporter(options, app) {
}
errors.forEach(write);
if(requestedModules.length > 1){
- write('require.def("' + requestedModules.join(",") + '", [], function(){});');
+ write('define("' + requestedModules.join(",") + '", [], function(){});');
}
if(autoRun && requestedModules.length){
write('require.ensure&&require.ensure(["' + requestedModules.join(",") + '"], function(require){' +
@@ -217,10 +215,10 @@ exports.CommonJS = function(moduleName, fileContents, loadModule, modules, write
var depNames = {};
var baseModule = moduleName.substring(0, moduleName.lastIndexOf("/") + 1);
var needsStaticAnalysis = true;
- var firstRequireDef = fileContents.indexOf("require.def(");
+ var firstRequireDef = fileContents.indexOf("define(");
if(firstRequireDef > -1){
// in AMD form
- fileContents = fileContents.replace(/require\.def\(\s*(?:['"]([^'"]*)['"]\s*,)?\s*(?:(\[[^\]]*\]\s*),)?/,function(t, id, depsJson){
+ fileContents = fileContents.replace(/define\(\s*(?:['"]([^'"]*)['"]\s*,)?\s*(?:(\[[^\]]*\]\s*),)?/,function(t, id, depsJson){
if(depsJson){
JSON.parse(depsJson).forEach(onDependency);
}else if(!id){
@@ -234,7 +232,7 @@ exports.CommonJS = function(moduleName, fileContents, loadModule, modules, write
if(!depsJson && !id){// && deps.length){
deps = ["require", "exports", "module"].concat(deps);
}
- return 'require.def("' + moduleName + '",' + (deps.length ? '["' + deps.join('", "') + '"],' : '');
+ return 'define("' + moduleName + '",' + (deps.length ? '["' + deps.join('", "') + '"],' : '');
});
}else{
staticAnalysis();
@@ -279,7 +277,7 @@ exports.CommonJS = function(moduleName, fileContents, loadModule, modules, write
}
if(write){
if(firstRequireDef == -1){
- write('require.def("');
+ write('define("');
write(moduleName);
write('", ["require", "exports", "module"');
write((deps.length ? ', "' + deps.join('", "') + '"' : '') + '], ');
@@ -333,7 +331,7 @@ exports.DojoRequireJS = function(moduleName, fileContents, loadModule, modules,
}
});
if(write){
- write('require.def("');
+ write('define("');
write(moduleName);
write('", [');
write((deps.length ? '"' + deps.join('", "') + '"' : '') + '], ');
@@ -342,5 +340,4 @@ exports.DojoRequireJS = function(moduleName, fileContents, loadModule, modules,
write('\n});\n');
}
};
-return exports;
-});
+module.exports = exports;
View
17 lib/receiver.js
@@ -48,17 +48,18 @@
}
return modules[id];
}
+ define = function(id, deps, factory){
+ if(typeof deps == "function"){
+ factories[id] = deps;
+ }else{
+ (factories[id] = factory).deps = deps;
+ }
+ };
+
require = {
- def: function(id, deps, factory){
- if(typeof deps == "function"){
- factories[id] = deps;
- }else{
- (factories[id] = factory).deps = deps;
- }
- },
ensure: function(modules, callback){
for(var i = 0; i < modules.length; i++){
- req(modules[i]);
+ modules = req(modules[i]);
}
callback(req);
}
Please sign in to comment.
Something went wrong with that request. Please try again.