Skip to content

Commit

Permalink
Merge pull request #52 from takker99/master
Browse files Browse the repository at this point in the history
Support esm.sh
  • Loading branch information
hayd authored Jan 16, 2022
2 parents 4f40d1a + b1358b7 commit 23b6f4f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ udd supports the following registry domains:
- https://dev.jspm.io
- https://cdn.pika.dev
- https://cdn.skypack.dev
- https://esm.sh
- https://unpkg.com
- https://raw.githubusercontent.com
- https://gitlab.com/:user/:repo/-/raw
Expand Down
28 changes: 28 additions & 0 deletions registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,33 @@ export class Skypack implements RegistryUrl {
regexp = /https?:\/\/cdn.skypack.dev(\/\_)?\/[^\/\"\']*?\@[^\'\"]*/;
}

export class EsmSh implements RegistryUrl {
url: string;

name(): string {
return defaultName(this);
}

constructor(url: string) {
this.url = url;
}

async all(): Promise<string[]> {
return await unpkgVersions(this.name());
}

at(version: string): RegistryUrl {
const url = defaultAt(this, version);
return new EsmSh(url);
}

version(): string {
return defaultVersion(this);
}

regexp = /https?:\/\/esm.sh\/[^\/\"\']*?\@[^\'\"]*/;
}

export class GithubRaw implements RegistryUrl {
url: string;

Expand Down Expand Up @@ -496,6 +523,7 @@ export const REGISTRIES = [
Jspm,
Pika,
Skypack,
EsmSh,
GithubRaw,
GitlabRaw,
JsDelivr,
Expand Down
9 changes: 9 additions & 0 deletions registry_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ Deno.test("registrySkypack", () => {
assertEquals(vAt.url, "https://cdn.skypack.dev/foo@0.2.0/");
});

Deno.test("registryEsmSh", () => {
const url = "https://esm.sh/foo@0.1.0/";
const v = lookup(url, REGISTRIES);
assert(v !== undefined);

const vAt = v.at("0.2.0");
assertEquals(vAt.url, "https://esm.sh/foo@0.2.0/");
});

Deno.test("registryGithubRaw", () => {
const url = "https://raw.githubusercontent.com/bar/foo/0.1.0/foo.ts";
const v = lookup(url, REGISTRIES);
Expand Down

0 comments on commit 23b6f4f

Please sign in to comment.