Skip to content

Instantly share code, notes, and snippets.

@jkrems
Last active January 9, 2020 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkrems/3b1938b3331ecd20701310167b7bdd2d to your computer and use it in GitHub Desktop.
Save jkrems/3b1938b3331ecd20701310167b7bdd2d to your computer and use it in GitHub Desktop.
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