clean code from compiler-imports

yann300-patch-18
aniket-engg 4 years ago committed by Aniket
parent 91352d0e30
commit 1d6ae33be7
  1. 55
      apps/remix-ide/src/app/compiler/compiler-imports.js

@ -6,9 +6,7 @@ const remixTests = require('@remix-project/remix-tests')
const globalRegistry = require('../../global/registry')
const addTooltip = require('../ui/tooltip')
const async = require('async')
var swarmgw = require('swarmgw')()
var resolver = require('@resolver-engine/imports').ImportsEngine()
var request = require('request')
const profile = {
name: 'contentImport',
@ -27,52 +25,6 @@ module.exports = class CompilerImports extends Plugin {
this.previouslyHandled = {} // cache import so we don't make the request at each compilation.
}
handleSwarmImport (url, cleanUrl, cb) {
swarmgw.get(url, function (err, content) {
cb(err, content, cleanUrl)
})
}
handleIPFS (url, cb) {
// replace ipfs:// with /ipfs/
url = url.replace(/^ipfs:\/\/?/, 'ipfs/')
return request.get(
{
url: 'https://ipfsgw.komputing.org/' + url
},
(err, r, data) => {
if (err) {
return cb(err || 'Unknown transport error')
}
cb(null, data, url)
})
}
handleHttpCall (url, cleanUrl, cb) {
console.log('Inside ide handleHttpCall')
return request.get(
{
url
},
(err, r, data) => {
if (err) {
return cb(err || 'Unknown transport error')
}
cb(null, data, cleanUrl)
})
}
handlers () {
return [
{ type: 'github', match: /^(https?:\/\/)?(www.)?github.com\/([^/]*\/[^/]*)\/(.*)/, handler: (match, cb) => { this.handleGithubCall(match[3], match[4], cb) } },
{ type: 'http', match: /^(http?:\/\/?(.*))$/, handler: (match, cb) => { this.handleHttpCall(match[1], match[2], cb) } },
{ type: 'https', match: /^(https?:\/\/?(.*))$/, handler: (match, cb) => { this.handleHttpCall(match[1], match[2], cb) } },
{ type: 'swarm', match: /^(bzz-raw?:\/\/?(.*))$/, handler: (match, cb) => { this.handleSwarmImport(match[1], match[2], cb) } },
{ type: 'ipfs', match: /^(ipfs:\/\/?.+)/, handler: (match, cb) => { this.handleIPFS(match[1], cb) } }
]
}
isRelativeImport (url) {
return /^([^/]+)/.exec(url)
}
@ -109,17 +61,12 @@ module.exports = class CompilerImports extends Plugin {
return cb(null, imported.content, imported.cleanUrl, imported.type, url)
}
var handlers = this.urlResolver.getHandlers()
var found = false
handlers.forEach(function (handler) {
if (found) {
return
}
if (found) return
var match = handler.match(url)
if (match) {
found = true
loadingCb('Loading ' + url + ' ...')
handler.handle(match).then(function (result) {
const { content, cleanUrl } = result

Loading…
Cancel
Save