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

Commit

Permalink
feat: virtual database entries for npm and github (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored May 28, 2020
1 parent 56f12de commit 930a182
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
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
13 changes: 11 additions & 2 deletions pages/x/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const ThirdPartyRegistryList = () => {
<div className="">
<div className="max-w-screen-lg mx-auto px-4 sm:px-6 md:px-8 pt-4">
<div className="text-gray-900 mt-4 sm:mt-8 break-words">
<p>
<p className="text-gray-900 mt-4">
<span className="font-semibold">deno.land/x</span> is a URL
rewriting service for Deno scripts. The basic format of code
URLs is{" "}
Expand All @@ -54,6 +54,13 @@ const ThirdPartyRegistryList = () => {
. If you leave out the branch, it will default to the module’s
default branch, usually <InlineCode>master</InlineCode>.
</p>

<p className="text-gray-900 mt-4">
Experimental: 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
runtime is documented on{" "}
Expand All @@ -78,7 +85,9 @@ const ThirdPartyRegistryList = () => {
>
database.json
</a>
.
{". "}
Run the tests and formatting before submitting a patch - the PR
must be green to be considered.
</p>
</div>
<div className="mt-12">
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

0 comments on commit 930a182

Please sign in to comment.