From 634ba33f69c364b13dac7262decbe05c3187d1a8 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 6 Sep 2016 00:58:41 +0100 Subject: [PATCH 1/6] Remove obsolete code --- src/app.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/app.js b/src/app.js index 1bd505602e..4fbb73552c 100644 --- a/src/app.js +++ b/src/app.js @@ -477,9 +477,6 @@ var run = function () { function loadVersion (version) { queryParams.update({version: version}); - if (window.soljsonReleases !== undefined && window.soljsonReleases[version] !== undefined) { - version = window.soljsonReleases[version]; - } var url; if (version === 'builtin') { url = 'soljson.js'; @@ -524,7 +521,7 @@ var run = function () { }); $('#versionSelector').attr('disabled', false); - // load initial verison + // load initial version var latestRelease = null; if (window.soljsonReleases !== undefined) { for (var release in window.soljsonReleases) { From 091478ec1e9052122a6bf66390f1a90359b29b51 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 6 Sep 2016 19:42:13 +0100 Subject: [PATCH 2/6] Load version list from list.json --- index.html | 1 - src/app.js | 54 +++++++++++++++++++++++++++++++----------------------- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/index.html b/index.html index ed660a6058..d874250be6 100644 --- a/index.html +++ b/index.html @@ -36,7 +36,6 @@ - diff --git a/src/app.js b/src/app.js index 4fbb73552c..5fa87d46ef 100644 --- a/src/app.js +++ b/src/app.js @@ -1,4 +1,4 @@ -/* global alert, confirm, prompt, Option, Worker, soljsonSources */ +/* global alert, confirm, prompt, Option, Worker */ var $ = require('jquery'); var semver = require('semver'); @@ -510,36 +510,44 @@ var run = function () { loadVersion($('#versionSelector').val()); }); - // var soljsonSources is provided by bin/list.js - if (window.soljsonSources !== undefined) { - // populate selector list with available versions - $.each(soljsonSources, function (i, file) { - if (file) { - var version = file.replace(/soljson-(.*).js/, '$1'); - $('#versionSelector').append(new Option(version, file)); - } + $.getJSON('https://ethereum.github.io/solc-bin/bin/list.json', function (data, status) { + // loading failed for some reason, fall back to local compiler + if (status !== 'success') { + $('#versionSelector').append(new Option('latest local version', 'builtin')); + + loadVersion('builtin'); + return; + } + + // populate version dropdown with all available compiler versions + // NOTE: the list currently is oldest first + $.each(data.builds.reverse(), function (i, build) { + $('#versionSelector').append(new Option(build.version + '-' + build.prerelease, build.path)); }); + $('#versionSelector').attr('disabled', false); - // load initial version + // always include the local version + $('#versionSelector').append(new Option('latest local version', 'builtin')); + + // find latest release var latestRelease = null; - if (window.soljsonReleases !== undefined) { - for (var release in window.soljsonReleases) { - if (latestRelease === null || semver.gt(release, latestRelease)) { - latestRelease = release; - } + for (var release in data.releases) { + if (latestRelease === null || semver.gt(release, latestRelease)) { + latestRelease = release; } } - if (latestRelease === null) { - latestRelease = 'soljson-latest.js'; + if (latestRelease !== null) { + latestRelease = data.releases[latestRelease]; } - loadVersion(queryParams.get().version || latestRelease); - } else { - loadVersion('builtin'); - } - // always include the local version - $('#versionSelector').append(new Option('latest local version', 'builtin')); + // override with the requested version + if (queryParams.get().version) { + latestRelease = queryParams.get().version; + } + + loadVersion(latestRelease); + }); storage.sync(); }; From 8d9f1c6d0981d009fedeb3e9bd155d22780cc9aa Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 6 Sep 2016 19:44:49 +0100 Subject: [PATCH 3/6] Rename latestRelease to selectedVersion --- src/app.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app.js b/src/app.js index 5fa87d46ef..ce4d814f27 100644 --- a/src/app.js +++ b/src/app.js @@ -531,22 +531,22 @@ var run = function () { $('#versionSelector').append(new Option('latest local version', 'builtin')); // find latest release - var latestRelease = null; + var selectedVersion = null; for (var release in data.releases) { - if (latestRelease === null || semver.gt(release, latestRelease)) { - latestRelease = release; + if (selectedVersion === null || semver.gt(release, selectedVersion)) { + selectedVersion = release; } } - if (latestRelease !== null) { - latestRelease = data.releases[latestRelease]; + if (selectedVersion !== null) { + selectedVersion = data.releases[selectedVersion]; } // override with the requested version if (queryParams.get().version) { - latestRelease = queryParams.get().version; + selectedVersion = queryParams.get().version; } - loadVersion(latestRelease); + loadVersion(selectedVersion); }); storage.sync(); From de5b894d8da9815fc73a8815a105a6db72934232 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 7 Sep 2016 12:42:05 +0100 Subject: [PATCH 4/6] Sort version dropdown according to semver --- src/app.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/app.js b/src/app.js index ce4d814f27..a0fa0599b9 100644 --- a/src/app.js +++ b/src/app.js @@ -520,8 +520,15 @@ var run = function () { } // populate version dropdown with all available compiler versions - // NOTE: the list currently is oldest first - $.each(data.builds.reverse(), function (i, build) { + + // Sort builds according to semver + var builds = data.builds.sort(function (a, b) { + a = a.version + '-' + a.prerelease; + b = b.version + '-' + b.prerelease; + return semver.compare(a, b); + }).reverse(); + + $.each(builds, function (i, build) { $('#versionSelector').append(new Option(build.version + '-' + build.prerelease, build.path)); }); From 1b8972a9725fc3a5b46ef7ecba2246def6fe4a27 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 7 Sep 2016 18:54:03 +0100 Subject: [PATCH 5/6] Use helper buildVersion --- src/app.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/app.js b/src/app.js index a0fa0599b9..2c8c40d933 100644 --- a/src/app.js +++ b/src/app.js @@ -519,17 +519,24 @@ var run = function () { return; } - // populate version dropdown with all available compiler versions + function buildVersion (build) { + if (build.prerelease && build.prerelease.length > 0) { + return build.version + '-' + build.prerelease; + } else { + return build.version; + } + } // Sort builds according to semver var builds = data.builds.sort(function (a, b) { - a = a.version + '-' + a.prerelease; - b = b.version + '-' + b.prerelease; + a = buildVersion(a); + b = buildVersion(b); return semver.compare(a, b); }).reverse(); + // populate version dropdown with all available compiler versions $.each(builds, function (i, build) { - $('#versionSelector').append(new Option(build.version + '-' + build.prerelease, build.path)); + $('#versionSelector').append(new Option(buildVersion(build), build.path)); }); $('#versionSelector').attr('disabled', false); From 077075be03eab601e207306d885bc76f648f48a9 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 7 Sep 2016 19:07:59 +0100 Subject: [PATCH 6/6] More optimised way to sort in reverse --- src/app.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/app.js b/src/app.js index 2c8c40d933..2e09d2b067 100644 --- a/src/app.js +++ b/src/app.js @@ -529,10 +529,9 @@ var run = function () { // Sort builds according to semver var builds = data.builds.sort(function (a, b) { - a = buildVersion(a); - b = buildVersion(b); - return semver.compare(a, b); - }).reverse(); + // NOTE: b vs. a (the order is important), because we want latest first in the list + return semver.compare(buildVersion(b), buildVersion(a)); + }); // populate version dropdown with all available compiler versions $.each(builds, function (i, build) {