|
|
|
@ -13,11 +13,9 @@ const profile = { |
|
|
|
|
|
|
|
|
|
export class CompilerImports extends Plugin { |
|
|
|
|
previouslyHandled: {} |
|
|
|
|
fileManager: any |
|
|
|
|
urlResolver: any |
|
|
|
|
constructor (fileManager) { |
|
|
|
|
constructor () { |
|
|
|
|
super(profile) |
|
|
|
|
this.fileManager = fileManager |
|
|
|
|
this.urlResolver = new RemixURLResolver() |
|
|
|
|
this.previouslyHandled = {} // cache import so we don't make the request at each compilation.
|
|
|
|
|
} |
|
|
|
@ -89,12 +87,14 @@ export class CompilerImports extends Plugin { |
|
|
|
|
this.import(url, |
|
|
|
|
// TODO: handle this event
|
|
|
|
|
(loadingMsg) => { this.emit('message', loadingMsg) }, |
|
|
|
|
(error, content, cleanUrl, type, url) => { |
|
|
|
|
async (error, content, cleanUrl, type, url) => { |
|
|
|
|
if (error) return cb(error) |
|
|
|
|
if (this.fileManager) { |
|
|
|
|
const provider = this.fileManager.currentFileProvider() |
|
|
|
|
try { |
|
|
|
|
const provider = await this.call('fileManager', 'getProviderOf', null) |
|
|
|
|
const path = targetPath || type + '/' + cleanUrl |
|
|
|
|
if (provider) provider.addExternal('.deps/' + path, content, url) |
|
|
|
|
} catch (err) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
cb(null, content) |
|
|
|
|
}, null) |
|
|
|
@ -113,14 +113,7 @@ export class CompilerImports extends Plugin { |
|
|
|
|
resolveAndSave (url, targetPath) { |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
if (url.indexOf('remix_tests.sol') !== -1) resolve(remixTests.assertLibCode) |
|
|
|
|
if (!this.fileManager) { |
|
|
|
|
// fallback to just resolving the file, it won't be saved in file manager
|
|
|
|
|
return this.importExternal(url, targetPath, (error, content) => { |
|
|
|
|
if (error) return reject(error) |
|
|
|
|
resolve(content) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
var provider = this.fileManager.fileProviderOf(url) |
|
|
|
|
this.call('fileManager', 'getProviderOf', url).then((provider) => { |
|
|
|
|
if (provider) { |
|
|
|
|
if (provider.type === 'localhost' && !provider.isConnected()) { |
|
|
|
|
return reject(new Error(`file provider ${provider.type} not available while trying to resolve ${url}`)) |
|
|
|
@ -141,7 +134,7 @@ export class CompilerImports extends Plugin { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// try to resolve localhost modules (aka truffle imports) - e.g from the node_modules folder
|
|
|
|
|
const localhostProvider = this.fileManager.getProvider('localhost') |
|
|
|
|
this.call('fileManager', 'getProviderByName', 'localhost').then((localhostProvider) => { |
|
|
|
|
if (localhostProvider.isConnected()) { |
|
|
|
|
var splitted = /([^/]+)\/(.*)$/g.exec(url) |
|
|
|
|
return async.tryEach([ |
|
|
|
@ -161,6 +154,7 @@ export class CompilerImports extends Plugin { |
|
|
|
|
resolve(result) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
this.importExternal(url, targetPath, (error, content) => { |
|
|
|
|
if (error) return reject(error) |
|
|
|
@ -170,6 +164,13 @@ export class CompilerImports extends Plugin { |
|
|
|
|
return reject(error) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}).catch(() => { |
|
|
|
|
// fallback to just resolving the file, it won't be saved in file manager
|
|
|
|
|
return this.importExternal(url, targetPath, (error, content) => { |
|
|
|
|
if (error) return reject(error) |
|
|
|
|
resolve(content) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|