Last active
January 9, 2020 16:59
-
-
Save jkrems/3b1938b3331ecd20701310167b7bdd2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ResolvedRef { | |
#href; | |
#signature; | |
static get protocol() { | |
return 'resolved-ref:'; | |
} | |
constructor(href, signature) { | |
this.#href = href; | |
this.#signature = signature; | |
} | |
get href() { | |
return this.#href; | |
} | |
toString() { | |
return `${ResolvedRef.protocol}:${this.#signature}/${this.#href}`; | |
} | |
} | |
import.meta.resolve = async (specifier) => { | |
const href = await loader.resolveImportURL(specifier, import.meta.url); | |
return new ResolvedRef(href, signHref(href)); | |
}; | |
loader.resolveImportURL = (specifier) => { | |
if (specifier.startsWith(ResolvedRef.protocol) { | |
return validateSignature(specifier); | |
} | |
// [actual resolution] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment