Skip to content

Commit

Permalink
refactor(lib/dependency): export functions directly
Browse files Browse the repository at this point in the history
  • Loading branch information
hasundue committed Nov 3, 2023
1 parent aaf3239 commit 6ef3541
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
7 changes: 1 addition & 6 deletions lib/dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ export interface DependencyProps {
path?: Path;
}

export const Dependency = {
parseProps,
resolveLatestURL,
};

function parseProps(url: URL): DependencyProps {
export function parseProps(url: URL): DependencyProps {
const body = url.hostname + url.pathname;
const semver = parseSemVer(url.href);
if (!semver) {
Expand Down
10 changes: 5 additions & 5 deletions lib/dependency_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it } from "./std/testing.ts";
import { assertEquals } from "./std/assert.ts";
import { Dependency, parseSemVer } from "./dependency.ts";
import { parseProps, parseSemVer } from "./dependency.ts";
import { Path, SemVerString } from "./types.ts";

describe("parseSemVer", () => {
Expand All @@ -19,7 +19,7 @@ describe("parseSemVer", () => {
describe("parseProps()", () => {
it("https://deno.land/std", () =>
assertEquals(
Dependency.parseProps(
parseProps(
new URL("https://deno.land/std@0.1.0/version.ts"),
),
{
Expand All @@ -30,7 +30,7 @@ describe("parseProps()", () => {
));
it("https://deno.land/std (no semver)", () =>
assertEquals(
Dependency.parseProps(
parseProps(
new URL("https://deno.land/std/version.ts"),
),
{
Expand All @@ -39,7 +39,7 @@ describe("parseProps()", () => {
));
it("https://deno.land/x/hono (with a leading 'v')", () =>
assertEquals(
Dependency.parseProps(
parseProps(
new URL("https://deno.land/x/hono@v0.1.0"),
),
{
Expand All @@ -50,7 +50,7 @@ describe("parseProps()", () => {
));
it("npm:node-emoji", () =>
assertEquals(
Dependency.parseProps(
parseProps(
new URL("npm:node-emoji@1.0.0"),
),
{
Expand Down
11 changes: 8 additions & 3 deletions lib/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import {
import { URI } from "./uri.ts";
import type { Maybe } from "./types.ts";
import { ImportMap } from "./import_map.ts";
import { Dependency, type DependencyProps, parseSemVer } from "./dependency.ts";
import {
type DependencyProps,
parseProps,
parseSemVer,
resolveLatestURL,
} from "./dependency.ts";

type DependencyJson = NonNullable<ModuleJson["dependencies"]>[number];

Expand Down Expand Up @@ -136,11 +141,11 @@ export async function _create(
} has no resolved specifier.`,
);
}
const latest = await Dependency.resolveLatestURL(new URL(specifier));
const latest = await resolveLatestURL(new URL(specifier));
if (!latest) {
return;
}
const props = Dependency.parseProps(latest);
const props = parseProps(latest);
const mapped = options?.importMap?.resolve(
dependency.specifier,
referrer,
Expand Down

0 comments on commit 6ef3541

Please sign in to comment.