Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

feat: virtual database entries for npm and github #659

Merged
merged 8 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions database.json
Original file line number Diff line number Diff line change
Expand Up @@ -836,13 +836,13 @@
"type": "github",
"owner": "viandwi24",
"repo": "denova",
"desc": "A Typescript Framework For Deno - Framework Looks Like Laravel."
"desc": "A Typescript Framework For Deno - Framework Looks Like Laravel."
},
"denovel": {
"type": "github",
"owner": "fauzan121002",
"repo": "denovel",
"desc": "A Deno Framework for Web Artisan - Inspired by Laravel."
"desc": "A Deno Framework for Web Artisan - Inspired by Laravel."
},
"denoversion": {
"type": "github",
Expand Down Expand Up @@ -2232,7 +2232,7 @@
"repo": "router",
"desc": "A high-performance basic router works everywhere."
},
"rsocket": {
"rsocket": {
"type": "github",
"owner": "linux-china",
"repo": "rsocket-deno",
Expand Down
5 changes: 4 additions & 1 deletion pages/x/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ const ThirdPartyRegistryList = () => {
https://deno.land/x/MODULE_NAME@BRANCH/SCRIPT.ts
</InlineCode>
. If you leave out the branch, it will default to the module’s
default branch, usually <InlineCode>master</InlineCode>.
default branch, usually <InlineCode>master</InlineCode>. You can
use <InlineCode>npm:[package]</InlineCode> or
<InlineCode>gh:[owner]:[repo]</InlineCode> as module name to
resolve any artibrary repository or npm package.
</p>
<p className="text-gray-900 mt-4">
Functionality built-in to Deno is not listed here. The built-in
Expand Down
23 changes: 23 additions & 0 deletions util/registry_utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { findEntry } from "./registry_utils";
import { DenoStdEntry } from "./registries/deno_std";
import { NPMEntry } from "./registries/npm";
import { GithubEntry } from "./registries/github";

/* eslint-env jest */

Expand All @@ -11,3 +13,24 @@ test("find 'std' in database", () => {
})
);
});

test("Resolve virtual 'gh:owner:repo'", () => {
expect(findEntry("gh:owner:repo")).toEqual(
new GithubEntry({
type: "github",
desc: "owner/repo",
owner: "owner",
repo: "repo",
})
);
});

test("Resolve virtual 'npm:package'", () => {
expect(findEntry("npm:package")).toEqual(
new NPMEntry({
type: "npm",
desc: "package",
package: "package",
})
);
});
21 changes: 21 additions & 0 deletions util/registry_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ function findDatabaseEntry(
| URLDatabaseEntry
| NPMDatabaseEntry
| undefined {
if (name.startsWith("npm:")) {
const [_, packageName] = name.split(":");
const entry: NPMDatabaseEntry = {
desc: packageName,
package: packageName,
type: "npm",
};
return entry;
}

if (name.startsWith("gh:")) {
const [_, owner, repo] = name.split(":");
const entry: GithubDatabaseEntry = {
desc: `${owner}/${repo}`,
owner,
repo,
type: "github",
};
return entry;
}

// @ts-ignore
return DATABASE[name];
}
Expand Down