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

Improve shorthand notation logic

parent fe60660c
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
"Resource": true, "Resource": true,
"resources": true, "resources": true,
"Setting": true, "Setting": true,
"shorthands": true,
"stateManager": true, "stateManager": true,
"WebRequest": true, "WebRequest": true,
"Whitelist": true, "Whitelist": true,
...@@ -27,7 +28,8 @@ ...@@ -27,7 +28,8 @@
"core/constants.js", "core/constants.js",
"core/files.js", "core/files.js",
"core/mappings.js", "core/mappings.js",
"core/resources.js" "core/resources.js",
"core/shorthands.js"
], ],
"rules": { "rules": {
"no-unused-vars": "off" "no-unused-vars": "off"
......
...@@ -35,7 +35,7 @@ var mappings = { ...@@ -35,7 +35,7 @@ var mappings = {
'swfobject/{version}/swfobject.': resources.swfobject, 'swfobject/{version}/swfobject.': resources.swfobject,
'webfont/{version}/webfont.': resources.webfont, 'webfont/{version}/webfont.': resources.webfont,
// Common Shorthand Notations [Deprecated] // Basic Shorthand Notations [Deprecated]
'dojo/1/dojo/dojo.': { 'dojo/1/dojo/dojo.': {
'path': 'resources/dojo/1.6.1/dojo/dojo.js.dec', 'path': 'resources/dojo/1.6.1/dojo/dojo.js.dec',
'type': 'application/javascript' 'type': 'application/javascript'
...@@ -116,7 +116,7 @@ var mappings = { ...@@ -116,7 +116,7 @@ var mappings = {
'ui/{version}/jquery-ui.js': resources.jQueryUI, 'ui/{version}/jquery-ui.js': resources.jQueryUI,
'ui/{version}/jquery-ui.min.js': resources.jQueryUI, 'ui/{version}/jquery-ui.min.js': resources.jQueryUI,
// Common Shorthand Notations [Deprecated] // Basic Shorthand Notations [Deprecated]
'jquery-latest.': { 'jquery-latest.': {
'path': 'resources/jquery/1.11.1/jquery.min.js.dec', 'path': 'resources/jquery/1.11.1/jquery.min.js.dec',
'type': 'application/javascript' 'type': 'application/javascript'
...@@ -124,46 +124,6 @@ var mappings = { ...@@ -124,46 +124,6 @@ var mappings = {
'jquery.': { 'jquery.': {
'path': 'resources/jquery/1.11.1/jquery.min.js.dec', 'path': 'resources/jquery/1.11.1/jquery.min.js.dec',
'type': 'application/javascript' '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'
} }
} }
}, },
......
...@@ -100,12 +100,23 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel ...@@ -100,12 +100,23 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
if (resourcePattern.startsWith(resourceMold)) { if (resourcePattern.startsWith(resourceMold)) {
let targetPath, version; let targetPath, hostShorthands, version;
targetPath = resourceMappings[resourceMold].path; targetPath = resourceMappings[resourceMold].path;
targetPath = targetPath.replace(Resource.VERSION_PLACEHOLDER, versionNumber); targetPath = targetPath.replace(Resource.VERSION_PLACEHOLDER, versionNumber);
version = versionNumber && versionNumber[0] || targetPath.match(Resource.VERSION_EXPRESSION); hostShorthands = shorthands[channelHost];
if (hostShorthands && hostShorthands[targetPath]) {
let shorthand = hostShorthands[targetPath];
targetPath = shorthand.path;
version = shorthand.version;
} else {
version = versionNumber && versionNumber[0] || targetPath.match(Resource.VERSION_EXPRESSION);
}
// Prepare and return a local target. // Prepare and return a local target.
return { return {
......
/**
* Shorthands
* Belongs to Decentraleyes.
*
* @author Thomas Rientjes
* @since 2018-02-24
* @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 = {
// jQuery CDN [Deprecated]
'code.jquery.com': {
'resources/jquery/1.7/jquery.min.js.dec': {
'path': 'resources/jquery/1.7.0/jquery.min.js.dec',
'version': '1.7.0'
},
'resources/jquery/1.6/jquery.min.js.dec': {
'path': 'resources/jquery/1.6.0/jquery.min.js.dec',
'version': '1.6.0'
},
'resources/jquery/1.5/jquery.min.js.dec': {
'path': 'resources/jquery/1.5.0/jquery.min.js.dec',
'version': '1.5.0'
},
'resources/jquery/1.4/jquery.min.js.dec': {
'path': 'resources/jquery/1.4.0/jquery.min.js.dec',
'version': '1.4.0'
},
'resources/jquery/1.3/jquery.min.js.dec': {
'path': 'resources/jquery/1.3.0/jquery.min.js.dec',
'version': '1.3.0'
}
}
};
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<script src="../../core/files.js"></script> <script src="../../core/files.js"></script>
<script src="../../core/resources.js"></script> <script src="../../core/resources.js"></script>
<script src="../../core/mappings.js"></script> <script src="../../core/mappings.js"></script>
<script src="../../core/shorthands.js"></script>
<script src="../../core/request-sanitizer.js"></script> <script src="../../core/request-sanitizer.js"></script>
<script src="../../core/state-manager.js"></script> <script src="../../core/state-manager.js"></script>
<script src="../../core/request-analyzer.js"></script> <script src="../../core/request-analyzer.js"></script>
......
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