handlers loaded from remix-url-resolver

pull/713/head
aniket-engg 4 years ago committed by Aniket
parent 672a662ab8
commit c8a00057b9
  1. 20
      apps/remix-ide/src/app/compiler/compiler-imports.js
  2. 2
      libs/remix-url-resolver/src/index.ts
  3. 1
      libs/remix-url-resolver/src/resolve.ts

@ -1,6 +1,7 @@
'use strict' 'use strict'
import { Plugin } from '@remixproject/engine' import { Plugin } from '@remixproject/engine'
import * as packageJson from '../../../../../package.json' import * as packageJson from '../../../../../package.json'
import {RemixURLResolver} from '@remix-project/remix-url-resolver'
const remixTests = require('@remix-project/remix-tests') const remixTests = require('@remix-project/remix-tests')
const globalRegistry = require('../../global/registry') const globalRegistry = require('../../global/registry')
const addTooltip = require('../ui/tooltip') const addTooltip = require('../ui/tooltip')
@ -79,6 +80,7 @@ module.exports = class CompilerImports extends Plugin {
} }
handleHttpCall (url, cleanUrl, cb) { handleHttpCall (url, cleanUrl, cb) {
console.log('Inside ide handleHttpCall')
return request.get( return request.get(
{ {
url url
@ -136,7 +138,7 @@ module.exports = class CompilerImports extends Plugin {
if (imported) { if (imported) {
return cb(null, imported.content, imported.cleanUrl, imported.type, url) return cb(null, imported.content, imported.cleanUrl, imported.type, url)
} }
var handlers = this.handlers() var handlers = new RemixURLResolver().getHandlers()
var found = false var found = false
handlers.forEach(function (handler) { handlers.forEach(function (handler) {
@ -149,18 +151,24 @@ module.exports = class CompilerImports extends Plugin {
found = true found = true
loadingCb('Loading ' + url + ' ...') loadingCb('Loading ' + url + ' ...')
handler.handler(match, function (err, content, cleanUrl) { handler.handle(match).then(function(content) {
if (err) {
cb('Unable to import "' + cleanUrl + '": ' + err)
return
}
self.previouslyHandled[url] = { self.previouslyHandled[url] = {
content: content, content: content,
cleanUrl: cleanUrl, cleanUrl: cleanUrl,
type: handler.type type: handler.type
} }
cb(null, content, cleanUrl, handler.type, url) cb(null, content, cleanUrl, handler.type, url)
}).catch(function (error) {
cb('Unable to import "' + cleanUrl + '": ' + error)
return
}) })
// function (err, content, cleanUrl) {
// if (err) {
// }
// })
} }
}) })
if (found) return if (found) return

@ -1 +1 @@
export * from './resolve' export { RemixURLResolver } from './resolve'

@ -42,6 +42,7 @@ export class RemixURLResolver {
* @params cleanURL * @params cleanURL
*/ */
async handleHttp(url: string, _: string) { async handleHttp(url: string, _: string) {
console.log('Inside libs handleHttpCall')
//eslint-disable-next-line no-useless-catch //eslint-disable-next-line no-useless-catch
try { try {
const response: AxiosResponse = await axios.get(url) const response: AxiosResponse = await axios.get(url)

Loading…
Cancel
Save