From 037ceb64760d20689e86287e3136b70e02ba9a90 Mon Sep 17 00:00:00 2001 From: guybedford Date: Tue, 4 Aug 2015 14:51:27 +0200 Subject: [PATCH] AMD in bundles to use "bundle" meta over "register" format meta --- compilers/amd.js | 3 +-- lib/compile.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/compilers/amd.js b/compilers/amd.js index 4219a74..7866c29 100644 --- a/compilers/amd.js +++ b/compilers/amd.js @@ -324,9 +324,8 @@ exports.compile = function(load, opts, loader) { // because we've blindly replaced the define statement from AMD with a System.registerDynamic call // we have to ensure we still trigger any AMD guard statements in the code by creating a dummy define which isn't called - // "register" added to ensure AMD at the top of a bundle allows the bundle to be detected properly return Promise.resolve({ - source: '"format register";(function() {\nvar _removeDefine = System.get("@@amd-helpers").createDefine();\n' + output + '\n_removeDefine();\n})();', + source: '(function() {\nvar _removeDefine = System.get("@@amd-helpers").createDefine();\n' + output + '\n_removeDefine();\n})();', sourceMap: compiler.getSourceMap(), sourceMapOffset: 2 }); diff --git a/lib/compile.js b/lib/compile.js index f53c491..3e7fb38 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -155,6 +155,17 @@ function compileOutputs(loader, tree, opts, sfxEntryPoints, cache) { })); }) + // if any module in the bundle is AMD, add a "bundle" meta to the bundle + // this can be deprecated if https://github.com/systemjs/builder/issues/264 lands + .then(function() { + var hasAMD = modules.some(function(name) { + return tree[name].format == 'amd'; + }); + + if (hasAMD) + outputs.unshift('"bundle"'); + }) + .then(function() { if (sfxEntryPoints) return wrapSFXOutputs(loader, tree, outputs, sfxEntryPoints, opts);