From 95a9c6b96014a4fbfe242f85693c5d8dc5d7f18c Mon Sep 17 00:00:00 2001 From: guybedford Date: Thu, 18 Dec 2014 12:29:13 +0200 Subject: [PATCH] fix to allow versioned plugins --- lib/extension-versions.js | 5 +++-- test/test.js | 11 ++++++++++- test/tests/plugin@1.2.3/plugin.js | 3 +++ test/tests/versioned-plugin-test@1.2.3/main.js | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 test/tests/plugin@1.2.3/plugin.js create mode 100644 test/tests/versioned-plugin-test@1.2.3/main.js diff --git a/lib/extension-versions.js b/lib/extension-versions.js index dff0c3671..244e6a324 100644 --- a/lib/extension-versions.js +++ b/lib/extension-versions.js @@ -245,8 +245,9 @@ function versions(loader) { // strip the version before applying map config var stripVersion, stripSubPathLength; - if (name.indexOf('@') > 0) { - var versionIndex = name.lastIndexOf('@'); + var pluginIndex = name.lastIndexOf('!'); + var versionIndex = (pluginIndex == -1 ? name : name.substr(0, pluginIndex)).lastIndexOf('@'); + if (versionIndex > 0) { var parts = name.substr(versionIndex + 1, name.length - versionIndex - 1).split('/'); stripVersion = parts[0]; stripSubPathLength = parts.length; diff --git a/test/test.js b/test/test.js index fb04a6d2c..9871c8e68 100644 --- a/test/test.js +++ b/test/test.js @@ -22,7 +22,7 @@ function err(e) { var ie8 = typeof navigator != 'undefined' && navigator.appVersion && navigator.appVersion.indexOf('MSIE 8') != -1; -System.traceurOptions = { asyncFunctions: true }; +System.traceurOptions.asyncFunctions = true; asyncTest('Error handling', function() { System['import']('tests/error-loader').then(err, function(e) { @@ -373,6 +373,15 @@ asyncTest('Simple compiler Plugin', function() { }, err); }); +asyncTest('Versioned plugin', function() { + System.versions['tests/versioned-plugin-test'] = '1.2.3'; + System['import']('tests/versioned-plugin-test/main').then(function(m) { + ok(m.output == 'plugin output'); + ok(m.versionedPlugin == true); + start(); + }, err); +}) + asyncTest('Mapping to a plugin', function() { System.map['pluginrequest'] = 'tests/compiled.coffee!'; System.map['coffee'] = 'tests/compiler-plugin'; diff --git a/test/tests/plugin@1.2.3/plugin.js b/test/tests/plugin@1.2.3/plugin.js new file mode 100644 index 000000000..741d6e0f6 --- /dev/null +++ b/test/tests/plugin@1.2.3/plugin.js @@ -0,0 +1,3 @@ +exports.translate = function(load) { + load.source += '\nexports.versionedPlugin = true;'; +} \ No newline at end of file diff --git a/test/tests/versioned-plugin-test@1.2.3/main.js b/test/tests/versioned-plugin-test@1.2.3/main.js new file mode 100644 index 000000000..d33f3e20a --- /dev/null +++ b/test/tests/versioned-plugin-test@1.2.3/main.js @@ -0,0 +1 @@ +module.exports = require('../compiler-test.coffee!tests/plugin@1.2.3/plugin'); \ No newline at end of file