|
|
@ -16,7 +16,6 @@ export type ResolvedImport = { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export class CompilerImports extends Plugin { |
|
|
|
export class CompilerImports extends Plugin { |
|
|
|
previouslyHandled: Record<string, ResolvedImport> |
|
|
|
|
|
|
|
urlResolver: any |
|
|
|
urlResolver: any |
|
|
|
constructor () { |
|
|
|
constructor () { |
|
|
|
super(profile) |
|
|
|
super(profile) |
|
|
@ -45,7 +44,6 @@ export class CompilerImports extends Plugin { |
|
|
|
return {} |
|
|
|
return {} |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.previouslyHandled = {} // cache import so we don't make the request at each compilation.
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async setToken () { |
|
|
|
async setToken () { |
|
|
@ -95,22 +93,12 @@ export class CompilerImports extends Plugin { |
|
|
|
if (!cb) cb = () => {} |
|
|
|
if (!cb) cb = () => {} |
|
|
|
|
|
|
|
|
|
|
|
const self = this |
|
|
|
const self = this |
|
|
|
if (force) delete this.previouslyHandled[url] |
|
|
|
|
|
|
|
const imported = this.previouslyHandled[url] |
|
|
|
|
|
|
|
if (imported) { |
|
|
|
|
|
|
|
return cb(null, imported.content, imported.cleanUrl, imported.type, url) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let resolved |
|
|
|
let resolved |
|
|
|
try { |
|
|
|
try { |
|
|
|
await this.setToken() |
|
|
|
await this.setToken() |
|
|
|
resolved = await this.urlResolver.resolve(url) |
|
|
|
resolved = await this.urlResolver.resolve(url, [], force) |
|
|
|
const { content, cleanUrl, type } = resolved |
|
|
|
const { content, cleanUrl, type } = resolved |
|
|
|
self.previouslyHandled[url] = { |
|
|
|
|
|
|
|
content, |
|
|
|
|
|
|
|
cleanUrl, |
|
|
|
|
|
|
|
type |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cb(null, content, cleanUrl, type, url) |
|
|
|
cb(null, content, cleanUrl, type, url) |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
return cb(new Error('not found ' + url)) |
|
|
|
return cb(new Error('not found ' + url)) |
|
|
|