Verified Commit aa5f8be1 authored by Thomas Rientjes's avatar Thomas Rientjes
Browse files

Improve shorthand notation logic

parent 7ec055fd
......@@ -41,7 +41,7 @@ var mappings = {
'swfobject/{version}/swfobject.': resources.swfobject,
'webfont/{version}/webfont.': resources.webfont,
// Common Shorthand Notations [Deprecated]
// Basic Shorthand Notations [Deprecated]
'dojo/1/dojo/dojo.': {
'path': 'resources/dojo/1.6.1/dojo/dojo.js.dec',
'type': 'application/javascript'
......@@ -50,62 +50,6 @@ var mappings = {
'path': 'resources/jquery/1.11.1/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.2/jquery.min.js': {
'path': 'resources/jquery/1.2.6/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.2/jquery.js': {
'path': 'resources/jquery/1.2.6/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.3/jquery.min.js': {
'path': 'resources/jquery/1.3.2/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.3/jquery.js': {
'path': 'resources/jquery/1.3.2/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.4/jquery.min.js': {
'path': 'resources/jquery/1.4.4/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.4/jquery.js': {
'path': 'resources/jquery/1.4.4/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.5/jquery.min.js': {
'path': 'resources/jquery/1.5.2/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.5/jquery.js': {
'path': 'resources/jquery/1.5.2/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.6/jquery.min.js': {
'path': 'resources/jquery/1.6.4/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.6/jquery.js': {
'path': 'resources/jquery/1.6.4/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.7/jquery.min.js': {
'path': 'resources/jquery/1.7.2/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.7/jquery.js': {
'path': 'resources/jquery/1.7.2/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.8/jquery.min.js': {
'path': 'resources/jquery/1.8.3/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.8/jquery.js': {
'path': 'resources/jquery/1.8.3/jquery.min.js.dec',
'type': 'application/javascript'
},
'jqueryui/1/jquery-ui.js': {
'path': 'resources/jqueryui/1.10.4/jquery-ui.min.js.dec',
'type': 'application/javascript'
......@@ -139,7 +83,6 @@ var mappings = {
// Microsoft Ajax CDN
'ajax.aspnetcdn.com': {
'/ajax/': {
'jQuery/jquery-{version}.': resources.jQuery,
'jquery/jquery-{version}.': resources.jQuery,
'modernizr/modernizr-{version}.': resources.modernizr
}
......@@ -147,7 +90,6 @@ var mappings = {
// Microsoft Ajax CDN [Deprecated]
'ajax.microsoft.com': {
'/ajax/': {
'jQuery/jquery-{version}.': resources.jQuery,
'jquery/jquery-{version}.': resources.jQuery,
'modernizr/modernizr-{version}.': resources.modernizr
}
......@@ -180,7 +122,7 @@ var mappings = {
'ui/{version}/jquery-ui.js': resources.jQueryUI,
'ui/{version}/jquery-ui.min.js': resources.jQueryUI,
// Common Shorthand Notations [Deprecated]
// Basic Shorthand Notations [Deprecated]
'jquery-latest.': {
'path': 'resources/jquery/1.11.1/jquery.min.js.dec',
'type': 'application/javascript'
......@@ -188,46 +130,6 @@ 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'
}
}
},
......
......@@ -23,6 +23,12 @@
*/
var mappings = require('./mappings');
/**
* Resource version shorthands.
* @var {object} shorthands
*/
var shorthands = require('./shorthands');
/**
* Gets and sets add-on specific preferences.
* @var {object} simplePreferences
......@@ -112,7 +118,7 @@ exports.getLocalTarget = function (channelHost, channelPath) {
}
// Return either the local target's path or false.
return _findLocalTarget(resourceMappings, basePath, channelPath);
return _findLocalTarget(resourceMappings, basePath, channelHost, channelPath);
};
/**
......@@ -131,7 +137,7 @@ function _matchBasePath (hostMappings, channelPath) {
return false;
}
function _findLocalTarget (resourceMappings, basePath, channelPath) {
function _findLocalTarget (resourceMappings, basePath, channelHost, channelPath) {
var resourcePath, versionNumber, resourcePattern;
......@@ -155,10 +161,26 @@ function _findLocalTarget (resourceMappings, basePath, channelPath) {
if (resourcePattern.startsWith(resourceMold)) {
let targetPath, targetType, hostShorthands;
targetPath = resourceMappings[resourceMold].path;
targetPath = targetPath.replace(VERSION_PLACEHOLDER, versionNumber);
targetType = resourceMappings[resourceMold].type;
hostShorthands = shorthands[channelHost];
if (hostShorthands && hostShorthands[targetPath]) {
let shorthand = hostShorthands[targetPath];
targetPath = shorthand.path;
targetType = shorthand.type;
}
// Prepare and return a local target.
return {
'path': resourceMappings[resourceMold].path.replace(VERSION_PLACEHOLDER, versionNumber),
'type': resourceMappings[resourceMold].type
'path': targetPath,
'type': targetType
};
}
}
......
/**
* Shorthands
* Belongs to Decentraleyes.
*
* @author Thomas Rientjes
* @since 2018-06-02
* @license MPL 2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
'use strict';
/**
* Shorthands
*/
var shorthands = {};
/**
* Exports
*/
module.exports = shorthands;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment