Merge pull request #1035 from ethereum/refactor/remove_jquery_from_compiler_code

remove jquery & UI dependency from compiler code
pull/3094/head
yann300 7 years ago committed by GitHub
commit 0dabef30d2
  1. 1
      package.json
  2. 6
      src/app.js
  3. 45
      src/app/compiler/compiler-imports.js

@ -46,6 +46,7 @@
"remix-lib": "latest", "remix-lib": "latest",
"remix-solidity": "latest", "remix-solidity": "latest",
"remixd": "git+https://github.com/ethereum/remixd.git", "remixd": "git+https://github.com/ethereum/remixd.git",
"request": "^2.83.0",
"rimraf": "^2.6.1", "rimraf": "^2.6.1",
"selenium-standalone": "^6.0.1", "selenium-standalone": "^6.0.1",
"standard": "^8.5.0", "standard": "^8.5.0",

@ -201,7 +201,11 @@ function run () {
if (provider && provider.exists(url)) { if (provider && provider.exists(url)) {
return provider.get(url, cb) return provider.get(url, cb)
} }
handleImports.import(url, (error, content, cleanUrl, type, url) => { handleImports.import(url,
(loadingMsg) => {
$('#output').append($('<div/>').append($('<pre/>').text(loadingMsg)))
},
(error, content, cleanUrl, type, url) => {
if (!error) { if (!error) {
filesProviders[type].addReadOnly(cleanUrl, content, url) filesProviders[type].addReadOnly(cleanUrl, content, url)
cb(null, content) cb(null, content)

@ -1,23 +1,30 @@
'use strict' 'use strict'
// TODO: can just use request or fetch instead
var $ = require('jquery')
var base64 = require('js-base64').Base64 var base64 = require('js-base64').Base64
var swarmgw = require('swarmgw') var swarmgw = require('swarmgw')
var request = require('request')
module.exports = { module.exports = {
handleGithubCall: function (root, path, cb) { handleGithubCall: function (root, path, cb) {
return $.getJSON('https://api.github.com/repos/' + root + '/contents/' + path) return request.get(
.done(function (data) { {
url: 'https://api.github.com/repos/' + root + '/contents/' + path,
json: true,
headers: {
'User-Agent': 'Remix'
}
},
(err, r, data) => {
if (err) {
return cb(err || 'Unknown transport error')
}
if ('content' in data) { if ('content' in data) {
cb(null, base64.decode(data.content), root + '/' + path) cb(null, base64.decode(data.content), root + '/' + path)
} else if ('message' in data) {
cb(data.message)
} else { } else {
cb('Content not received') cb('Content not received')
} }
}) })
.fail(function (xhr, text, err) {
// NOTE: on some browsers, err equals to '' for certain errors (such as offline browser)
cb(err || 'Unknown transport error')
})
}, },
handleSwarmImport: function (url, cb) { handleSwarmImport: function (url, cb) {
@ -30,14 +37,19 @@ module.exports = {
// replace ipfs:// with /ipfs/ // replace ipfs:// with /ipfs/
url = url.replace(/^ipfs:\/\/?/, 'ipfs/') url = url.replace(/^ipfs:\/\/?/, 'ipfs/')
return $.ajax({ type: 'GET', url: 'https://gateway.ipfs.io/' + url }) return request.get(
.done(function (data) { {
url: 'https://gateway.ipfs.io/' + url,
headers: {
'User-Agent': 'Remix'
}
},
(err, r, data) => {
if (err) {
return cb(err || 'Unknown transport error')
}
cb(null, data, url) cb(null, data, url)
}) })
.fail(function (xhr, text, err) {
// NOTE: on some browsers, err equals to '' for certain errors (such as offline browser)
cb(err || 'Unknown transport error')
})
}, },
handlers: function () { handlers: function () {
@ -48,7 +60,7 @@ module.exports = {
] ]
}, },
import: function (url, cb) { import: function (url, loadingCb, cb) {
var handlers = this.handlers() var handlers = this.handlers()
var found = false var found = false
@ -61,8 +73,7 @@ module.exports = {
if (match) { if (match) {
found = true found = true
// TODO: this needs to be moved to the caller loadingCb('Loading ' + url + ' ...')
$('#output').append($('<div/>').append($('<pre/>').text('Loading ' + url + ' ...')))
handler.handler(match, function (err, content, cleanUrl) { handler.handler(match, function (err, content, cleanUrl) {
if (err) { if (err) {
cb('Unable to import "' + cleanUrl + '": ' + err) cb('Unable to import "' + cleanUrl + '": ' + err)

Loading…
Cancel
Save