Merge pull request #1094 from ethereum/fixImportGithub

Fix import external (github, swarm, ipfs)
pull/3094/head
yann300 7 years ago committed by GitHub
commit f218ce9647
  1. 30
      src/app.js
  2. 12
      src/app/compiler/compiler-imports.js

@ -217,6 +217,21 @@ This instance of Remix you are visiting WILL NOT BE UPDATED.\n
Please make a backup of your contracts and start using http://remix.ethereum.org`) Please make a backup of your contracts and start using http://remix.ethereum.org`)
} }
function importExternal (url, cb) {
handleImports.import(url,
(loadingMsg) => {
toolTip(loadingMsg)
},
(error, content, cleanUrl, type, url) => {
if (!error) {
filesProviders[type].addReadOnly(cleanUrl, content, url)
cb(null, content)
} else {
cb(error)
}
})
}
// ----------------- Compiler ----------------- // ----------------- Compiler -----------------
var compiler = new Compiler((url, cb) => { var compiler = new Compiler((url, cb) => {
var provider = fileManager.fileProviderOf(url) var provider = fileManager.fileProviderOf(url)
@ -226,22 +241,11 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
if (exist) { if (exist) {
return provider.get(url, cb) return provider.get(url, cb)
} else { } else {
return cb('Unable to import "' + url + '": File not found') importExternal(url, cb)
} }
}) })
} else { } else {
handleImports.import(url, importExternal(url, cb)
(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) var offsetToLineColumnConverter = new OffsetToLineColumnConverter(compiler.event)

@ -4,6 +4,7 @@ var swarmgw = require('swarmgw')
var request = require('request') var request = require('request')
module.exports = { module.exports = {
previouslyHandled: {}, // cache import so we don't make the request at each compilation.
handleGithubCall: function (root, path, cb) { handleGithubCall: function (root, path, cb) {
return request.get( return request.get(
{ {
@ -61,6 +62,11 @@ module.exports = {
}, },
import: function (url, loadingCb, cb) { import: function (url, loadingCb, cb) {
var self = this
var imported = this.previouslyHandled[url]
if (imported) {
return cb(null, imported.content, imported.cleanUrl, imported.type, url)
}
var handlers = this.handlers() var handlers = this.handlers()
var found = false var found = false
@ -79,7 +85,11 @@ module.exports = {
cb('Unable to import "' + cleanUrl + '": ' + err) cb('Unable to import "' + cleanUrl + '": ' + err)
return return
} }
self.previouslyHandled[url] = {
content: content,
cleanUrl: cleanUrl,
type: handler.type
}
cb(null, content, cleanUrl, handler.type, url) cb(null, content, cleanUrl, handler.type, url)
}) })
} }

Loading…
Cancel
Save