From 513d63795eeae4ad7f9f49f35b0520de2480e5ce Mon Sep 17 00:00:00 2001 From: Charles Jolley Date: Mon, 25 Jul 2011 23:26:22 -0700 Subject: [PATCH] Upgrade spade to work with bpm 1.0.0.beta.7 --- package.json | 9 +++++++-- transport.js | 25 ++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index d8fde0f..fc853a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "spade", - "version": "1.0.0.2", + "version": "1.0.0.3", "description": "Dependency Management Library for JavaScript", "summary": "Dependency Management Library for JavaScript", @@ -16,5 +16,10 @@ "qunit": "~> 1.0.0" }, - "bpm:transport": "spade/transport" + "bpm:provides": { + "transport": { + "main": "spade/transport" + } + } + } diff --git a/transport.js b/transport.js index eeeb34c..806da76 100644 --- a/transport.js +++ b/transport.js @@ -1,3 +1,5 @@ +/*globals BPM_PLUGIN */ + BPM_PLUGIN.compileTransport = function(code, context, filename) { var ret = '', packageName = context['package'].name, @@ -5,11 +7,28 @@ BPM_PLUGIN.compileTransport = function(code, context, filename) { // Register package, probably a better way to do this if (id.match(/^[^\/]+\/main$/)) { - ret += 'spade.register("'+packageName+'", '+JSON.stringify(context['package'])+');\n\n'; + + var ctx = context['package'], + pkg = { name: ctx.name, + version: ctx.version, + dependencies: ctx.dependencies }; + + ret += 'spade.register("'+packageName+'", '+JSON.stringify(pkg)+');\n\n'; + } + + if (context.settings['spade:format'] === 'function') { + code = 'function(require, exports, __module, ARGV, ENV, __filename){\n'+code+'\n}'; + } else { + code = context.minify("(function(require, exports, __module, ARGV, ENV, __filename){\n"+code+"\n//@ sourceURL="+id+"\n})()"); + + var lines = code.split("\n"); + lines[0] = lines[0].replace(/^\(function\([^\)]+\)\{/, ''); + lines[lines.length-1] = lines[lines.length-1].replace(/\}\)\(\)$/, ''); + code = lines.join("\n"); + code = JSON.stringify(code); } - // TOOD: We can also pass a string here, maybe we should instead - ret += 'spade.register("'+id+'", function(require, exports, __module, ARGV, ENV, __filename){\n'+code+'\n});'; + ret += 'spade.register("'+id+'", '+code+');'; return ret; };