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. 20
      src/app.js
  3. 45
      src/app/compiler/compiler-imports.js

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

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

@ -1,23 +1,30 @@
'use strict'
// TODO: can just use request or fetch instead
var $ = require('jquery')
var base64 = require('js-base64').Base64
var swarmgw = require('swarmgw')
var request = require('request')
module.exports = {
handleGithubCall: function (root, path, cb) {
return $.getJSON('https://api.github.com/repos/' + root + '/contents/' + path)
.done(function (data) {
return request.get(
{
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) {
cb(null, base64.decode(data.content), root + '/' + path)
} else if ('message' in data) {
cb(data.message)
} else {
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) {
@ -30,14 +37,19 @@ module.exports = {
// replace ipfs:// with /ipfs/
url = url.replace(/^ipfs:\/\/?/, 'ipfs/')
return $.ajax({ type: 'GET', url: 'https://gateway.ipfs.io/' + url })
.done(function (data) {
return request.get(
{
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)
})
.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 () {
@ -48,7 +60,7 @@ module.exports = {
]
},
import: function (url, cb) {
import: function (url, loadingCb, cb) {
var handlers = this.handlers()
var found = false
@ -61,8 +73,7 @@ module.exports = {
if (match) {
found = true
// TODO: this needs to be moved to the caller
$('#output').append($('<div/>').append($('<pre/>').text('Loading ' + url + ' ...')))
loadingCb('Loading ' + url + ' ...')
handler.handler(match, function (err, content, cleanUrl) {
if (err) {
cb('Unable to import "' + cleanUrl + '": ' + err)

Loading…
Cancel
Save