From ff6244a311170bd8f77181cd21153ae33a86620d Mon Sep 17 00:00:00 2001
From: Thomas Rientjes <synzvato@protonmail.com>
Date: Sun, 3 Apr 2016 19:10:32 +0200
Subject: [PATCH] Resolve #63 by adding shorthands

---
 lib/mappings.js               | 44 +++++++++++++++++++++++++++++++++--
 lib/request-analyzer.js       | 11 +++++++++
 test/test-request-analyzer.js |  5 ++++
 3 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/lib/mappings.js b/lib/mappings.js
index 86178c1..7ff31ad 100644
--- a/lib/mappings.js
+++ b/lib/mappings.js
@@ -41,7 +41,7 @@ var mappings = {
             'swfobject/{version}/swfobject.': resources.swfobject,
             'webfont/{version}/webfont.': resources.webfont,
 
-            // Common Shorthand Notations
+            // Common Shorthand Notations [Deprecated]
             'dojo/1/dojo/dojo.': {
                 path: 'resources/dojo/1.6.1/dojo/dojo.js.dec',
                 type: 'application/javascript'
@@ -122,7 +122,7 @@ var mappings = {
             'ui/{version}/jquery-ui.js': resources.jQueryUI,
             'ui/{version}/jquery-ui.min.js': resources.jQueryUI,
 
-            // Common Shorthand Notations
+            // Common Shorthand Notations [Deprecated]
             'jquery-latest.': {
                 path: 'resources/jquery/1.11.1/jquery.min.js.dec',
                 type: 'application/javascript'
@@ -130,6 +130,46 @@ var mappings = {
             'jquery.': {
                 path: 'resources/jquery/1.11.1/jquery.min.js.dec',
                 type: 'application/javascript'
+            },
+            'jquery-1.3.min.js': {
+                path: 'resources/jquery/1.3.0/jquery.min.js.dec',
+                type: 'application/javascript'
+            },
+            'jquery-1.3.js': {
+                path: 'resources/jquery/1.3.0/jquery.min.js.dec',
+                type: 'application/javascript'
+            },
+            'jquery-1.4.min.js': {
+                path: 'resources/jquery/1.4.0/jquery.min.js.dec',
+                type: 'application/javascript'
+            },
+            'jquery-1.4.js': {
+                path: 'resources/jquery/1.4.0/jquery.min.js.dec',
+                type: 'application/javascript'
+            },
+            'jquery-1.5.min.js': {
+                path: 'resources/jquery/1.5.0/jquery.min.js.dec',
+                type: 'application/javascript'
+            },
+            'jquery-1.5.js': {
+                path: 'resources/jquery/1.5.0/jquery.min.js.dec',
+                type: 'application/javascript'
+            },
+            'jquery-1.6.min.js': {
+                path: 'resources/jquery/1.6.0/jquery.min.js.dec',
+                type: 'application/javascript'
+            },
+            'jquery-1.6.js': {
+                path: 'resources/jquery/1.6.0/jquery.min.js.dec',
+                type: 'application/javascript'
+            },
+            'jquery-1.7.min.js': {
+                path: 'resources/jquery/1.7.0/jquery.min.js.dec',
+                type: 'application/javascript'
+            },
+            'jquery-1.7.js': {
+                path: 'resources/jquery/1.7.0/jquery.min.js.dec',
+                type: 'application/javascript'
             }
         }
     },
diff --git a/lib/request-analyzer.js b/lib/request-analyzer.js
index c0c11b7..30ce6aa 100644
--- a/lib/request-analyzer.js
+++ b/lib/request-analyzer.js
@@ -135,6 +135,17 @@ function _findLocalTarget(resourceMappings, basePath, channelPath) {
     versionNumber = resourcePath.match(VERSION_EXPRESSION);
     resourcePattern = resourcePath.replace(versionNumber, VERSION_PLACEHOLDER);
 
+    // Determine if the resource path has a static mapping.
+    if (resourceMappings[resourcePath]) {
+
+        // Prepare and return a local target.
+        return {
+            path: resourceMappings[resourcePath].path,
+            type: resourceMappings[resourcePath].type
+        };
+    }
+
+    // Determine if the resource path fits into a resource mold.
     for (let resourceMold of Object.keys(resourceMappings)) {
 
         if (resourcePattern.startsWith(resourceMold)) {
diff --git a/test/test-request-analyzer.js b/test/test-request-analyzer.js
index c796334..aaf9e46 100644
--- a/test/test-request-analyzer.js
+++ b/test/test-request-analyzer.js
@@ -281,6 +281,11 @@ exports['test jquery-ui on jquery cdn'] = function (assert) {
     assert.equal(target.path, localPaths.jQueryUI, 'Target was determined.');
 };
 
+exports['test jquery shorthand on jquery cdn'] = function (assert) {
+    var target = requestAnalyzer.getLocalTarget('code.jquery.com', '/jquery-1.5.min.js');
+    assert.equal(target.path, 'resources/jquery/1.5.0/jquery.min.js.dec', 'Target found for jquery shorthand on jquery cdn.');
+};
+
 // jsDelivr (MaxCDN)
 
 exports['test angular on jsdelivr'] = function (assert) {
-- 
GitLab