|
|
@ -6,7 +6,6 @@ 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') |
|
|
|
const async = require('async') |
|
|
|
const async = require('async') |
|
|
|
var resolver = require('@resolver-engine/imports').ImportsEngine() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const profile = { |
|
|
|
const profile = { |
|
|
|
name: 'contentImport', |
|
|
|
name: 'contentImport', |
|
|
@ -50,7 +49,7 @@ module.exports = class CompilerImports extends Plugin { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
import (url, force, loadingCb, cb) { |
|
|
|
async import (url, force, loadingCb, cb) { |
|
|
|
if (typeof force !== 'boolean') { |
|
|
|
if (typeof force !== 'boolean') { |
|
|
|
const temp = loadingCb |
|
|
|
const temp = loadingCb |
|
|
|
loadingCb = force |
|
|
|
loadingCb = force |
|
|
@ -66,44 +65,20 @@ 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.urlResolver.getHandlers() |
|
|
|
|
|
|
|
var found = false |
|
|
|
|
|
|
|
handlers.forEach(function (handler) { |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
self.previouslyHandled[url] = { |
|
|
|
|
|
|
|
content, |
|
|
|
|
|
|
|
cleanUrl, |
|
|
|
|
|
|
|
type: handler.type |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cb(null, content, cleanUrl, handler.type, url) |
|
|
|
|
|
|
|
}).catch(function (error) { |
|
|
|
|
|
|
|
cb('Unable to import url : ' + error) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
if (found) return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resolver |
|
|
|
let resolved |
|
|
|
.resolve(url) |
|
|
|
try { |
|
|
|
.then(result => { |
|
|
|
resolved = await this.urlResolver.resolve(url) |
|
|
|
return resolver.require(url) |
|
|
|
const { content, cleanUrl, type } = resolved |
|
|
|
}) |
|
|
|
self.previouslyHandled[url] = { |
|
|
|
.then(result => { |
|
|
|
content, |
|
|
|
if (url.indexOf(result.provider + ':') === 0) { |
|
|
|
cleanUrl, |
|
|
|
url = url.substring(result.provider.length + 1) // remove the github prefix
|
|
|
|
type |
|
|
|
} |
|
|
|
} |
|
|
|
cb(null, result.source, url, result.provider, result.url) |
|
|
|
cb(null, content, cleanUrl, type, url) |
|
|
|
}) |
|
|
|
} catch (e) { |
|
|
|
.catch(err => { |
|
|
|
return cb('Unable to import url : ' + e.message) |
|
|
|
console.error(err) |
|
|
|
} |
|
|
|
cb('Unable to import "' + url + '": File not found') |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
importExternal (url, targetPath, cb) { |
|
|
|
importExternal (url, targetPath, cb) { |
|
|
@ -182,13 +157,12 @@ module.exports = class CompilerImports extends Plugin { |
|
|
|
} |
|
|
|
} |
|
|
|
resolve(result) |
|
|
|
resolve(result) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
|
|
|
|
// try to resolve external content
|
|
|
|
|
|
|
|
this.importExternal(url, targetPath, (error, content) => { |
|
|
|
|
|
|
|
if (error) return reject(error) |
|
|
|
|
|
|
|
resolve(content) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.importExternal(url, targetPath, (error, content) => { |
|
|
|
|
|
|
|
if (error) return reject(error) |
|
|
|
|
|
|
|
resolve(content) |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|