summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Carver2019-02-14 20:26:52 (GMT)
committerMark Carver2019-02-14 20:26:52 (GMT)
commitab9ef697a7262bd63d640fb497247b454b60f728 (patch)
tree4e872e205efefc511b8e5f7d7236e018610f8754
parent21004416203126239576ac02264a796b0ebfb6d7 (diff)
Issue #3033135 by markcarver: Bootswatch needs static mapping for broken/missing versions
-rw-r--r--grunt/sync.js33
-rw-r--r--src/Plugin/Provider/JsDelivr.php29
-rw-r--r--src/Plugin/Provider/ProviderBase.php13
3 files changed, 70 insertions, 5 deletions
diff --git a/grunt/sync.js b/grunt/sync.js
index 9308e58..3117f04 100644
--- a/grunt/sync.js
+++ b/grunt/sync.js
@@ -11,7 +11,12 @@ module.exports = function (grunt) {
var simpleJsonRequest = require('simple-json-request');
var semver = require('semver');
var getJson = function (uri) {
- return simpleJsonRequest.get({url: uri});
+ grunt.log.debug('Requesting JSON from: ' + uri);
+ return simpleJsonRequest.get({url: uri}).catch(function (e) {
+ grunt.log.fail('Unable to request JSON from:' + uri);
+ grunt.log.fail('(' + e.statusCode + ') ' + e);
+ return [];
+ });
};
// Internal variables.
@@ -33,10 +38,32 @@ module.exports = function (grunt) {
grunt.verbose.writeln((expired ? 'EXPIRED' : 'VALID')[expired ? 'red' : 'green']);
}
+ // While the Bootswatch project attempts to maintain version parity with
+ // Bootstrap, it doesn't always happen. This causes issues when the system
+ // expects a 1:1 version match between Bootstrap and Bootswatch.
+ // @see https://github.com/thomaspark/bootswatch/issues/892#ref-issue-410070082
+ var mapVersion = function ($version, $package) {
+ if ($package === 'bootswatch') {
+ switch ($version) {
+ // This version is "broken" because of jsDelivr's API limit.
+ case '3.4.1':
+ $version = '3.4.0';
+ break;
+
+ // This version doesn't exist.
+ case '3.1.1':
+ $version = '3.2.0';
+ break;
+ }
+ }
+ return $version;
+ };
+
var getApiV1Json = function ($package) {
var $json = {name: $package, assets: []};
var $latest = '0.0.0';
var $versions = [];
+ grunt.log.writeln('Retrieving data for: ' + $package);
return getJson('https://data.jsdelivr.com/v1/package/npm/' + $package)
.catch(function (error) {
if (!(error instanceof Error)) {
@@ -56,7 +83,7 @@ module.exports = function (grunt) {
if (!$version.match(/^3\.\d+\.\d+$/)) {
return Promise.resolve();
}
- return getJson('https://data.jsdelivr.com/v1/package/npm/' + $package + '@' + $version + '/flat')
+ return getJson('https://data.jsdelivr.com/v1/package/npm/' + $package + '@' + mapVersion($version, $package) + '/flat')
.then(function ($versionJson) {
// Skip empty files.
if (!$versionJson.files || !$versionJson.files.length) {
@@ -176,7 +203,7 @@ module.exports = function (grunt) {
for (var version in libraries[library]) {
if (!libraries[library].hasOwnProperty(version)) continue;
- var endpoint = library + '#' + version;
+ var endpoint = library + '#' + mapVersion(version, library);
// Check if library is already installed. If so, skip.
var versionPath = path.join(librariesPath, version);
diff --git a/src/Plugin/Provider/JsDelivr.php b/src/Plugin/Provider/JsDelivr.php
index c538c6f..d85003b 100644
--- a/src/Plugin/Provider/JsDelivr.php
+++ b/src/Plugin/Provider/JsDelivr.php
@@ -82,8 +82,9 @@ class JsDelivr extends ProviderBase {
if (!isset($this->themes[$version])) {
$this->themes[$version] = $this->cacheGet('themes.' . Unicode::escapeDelimiter($version), [], function ($themes) use ($version) {
foreach (['bootstrap', 'bootswatch'] as $package) {
- $files = $this->requestApiV1($package, $version);
- $themes = $this->parseThemes($files, $package, $version, $themes);
+ $mappedVersion = $this->mapVersion($version, $package);
+ $files = $this->requestApiV1($package, $mappedVersion);
+ $themes = $this->parseThemes($files, $package, $mappedVersion, $themes);
}
return $themes;
});
@@ -112,6 +113,30 @@ class JsDelivr extends ProviderBase {
}
/**
+ * {@inheritdoc}
+ */
+ protected function mapVersion($version, $package = NULL) {
+ // While the Bootswatch project attempts to maintain version parity with
+ // Bootstrap, it doesn't always happen. This causes issues when the system
+ // expects a 1:1 version match between Bootstrap and Bootswatch.
+ // @see https://github.com/thomaspark/bootswatch/issues/892#ref-issue-410070082
+ if ($package === 'bootswatch') {
+ switch ($version) {
+ // This version is "broken" because of jsDelivr's API limit.
+ case '3.4.1':
+ $version = '3.4.0';
+ break;
+
+ // This version doesn't exist.
+ case '3.1.1':
+ $version = '3.2.0';
+ break;
+ }
+ }
+ return $version;
+ }
+
+ /**
* Parses JSON from the API and retrieves valid files.
*
* @param array $json
diff --git a/src/Plugin/Provider/ProviderBase.php b/src/Plugin/Provider/ProviderBase.php
index a1ca93a..b02614a 100644
--- a/src/Plugin/Provider/ProviderBase.php
+++ b/src/Plugin/Provider/ProviderBase.php
@@ -318,6 +318,19 @@ class ProviderBase extends PluginBase implements ProviderInterface {
}
/**
+ * Allows providers a way to map a version to a different version.
+ *
+ * @param string $version
+ * The version to map.
+ *
+ * @return string
+ * The mapped version.
+ */
+ protected function mapVersion($version) {
+ return $version;
+ }
+
+ /**
* {@inheritdoc}
*/
public function hasError() {