Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize directory structure #44

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { parse as parseJsonc } from "./lib/std/jsonc.ts";
import { dirname, extname, join } from "./lib/std/path.ts";
import { colors, Command, List, Select } from "./lib/x/cliffy.ts";
import { URI } from "./lib/uri.ts";
import { DependencyUpdate, FileUpdate } from "./mod.ts";
import { commitAll } from "./git.ts";
import { DependencyUpdate } from "./lib/update.ts";
import { FileUpdate } from "./lib/file.ts";
import { commitAll } from "./lib/git.ts";

const { gray, yellow, bold } = colors;

Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"exclude": ["CHANGELOG.md"]
},
"lint": {
"exclude": ["tests/"],
"exclude": ["test/"],
"rules": {
"include": [
"no-sync-fn-in-async-fn"
Expand Down
2 changes: 1 addition & 1 deletion git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
* @module
*/

export * from "./src/git.ts";
export * from "./lib/git.ts";
7 changes: 3 additions & 4 deletions src/dependency.ts → lib/dependency.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { Maybe } from "../lib/types.ts";
import { Mutex } from "../lib/x/async.ts";
import type { Path, SemVerString } from "./types.ts";
import { assertExists } from "./std/assert.ts";
import { Mutex } from "./x/async.ts";
import type { Maybe, Path, SemVerString } from "./types.ts";
import { parseSemVer } from "./semver.ts";
import { assertExists } from "../lib/std/assert.ts";

export interface Dependency {
name: string;
Expand Down
4 changes: 2 additions & 2 deletions src/dependency_test.ts → lib/dependency_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it } from "../lib/std/testing.ts";
import { assertEquals } from "../lib/std/assert.ts";
import { describe, it } from "./std/testing.ts";
import { assertEquals } from "./std/assert.ts";
import { Dependency } from "./dependency.ts";

describe("parseProps()", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/file.ts → lib/file.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DependencyUpdate } from "./update.ts";
import { URI } from "../lib/uri.ts";
import { URI } from "./uri.ts";

export interface FileUpdate {
/** The specifier of the updated dependency (a remote module.) */
Expand Down
36 changes: 19 additions & 17 deletions src/file_test.ts → lib/file_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ import {
it,
type Stub,
stub,
} from "../lib/std/testing.ts";
} from "./std/testing.ts";
import {
assertArrayIncludes,
assertEquals,
assertExists,
} from "../lib/std/assert.ts";
} from "./std/assert.ts";
import { DependencyUpdate } from "./update.ts";
import { FileUpdate } from "./file.ts";
import { URI } from "../lib/uri.ts";
import { URI } from "./uri.ts";

describe("collect", () => {
it("direct import", async () => {
const results = FileUpdate.collect(
await DependencyUpdate.collect("./tests/direct-import/mod.ts"),
await DependencyUpdate.collect("./test/fixtures/direct-import/mod.ts"),
);
assertEquals(results.length, 2);
});

it("import map", async () => {
const results = FileUpdate.collect(
await DependencyUpdate.collect(
"./tests/import-map/mod.ts",
{ importMap: "./tests/import-map/deno.json" },
"./test/fixtures/import-map/mod.ts",
{ importMap: "./test/fixtures/import-map/deno.json" },
),
);
assertEquals(results.length, 2);
Expand All @@ -44,8 +44,8 @@ describe("collect", () => {
it("import map with no resolve", async () => {
const results = FileUpdate.collect(
await DependencyUpdate.collect(
"./tests/import-map-no-resolve/mod.ts",
{ importMap: "./tests/import-map-no-resolve/deno.json" },
"./test/fixtures/import-map-no-resolve/mod.ts",
{ importMap: "./test/fixtures/import-map-no-resolve/deno.json" },
),
);
assertEquals(results.length, 1);
Expand Down Expand Up @@ -75,32 +75,34 @@ describe("writeAll", () => {

it("direct import", async () => {
const results = FileUpdate.collect(
await DependencyUpdate.collect("./tests/direct-import/mod.ts"),
await DependencyUpdate.collect("./test/fixtures/direct-import/mod.ts"),
);
FileUpdate.writeAll(results);
assertExists(output.get(URI.from("tests/direct-import/mod.ts")));
assertExists(output.get(URI.from("tests/direct-import/lib.ts")));
assertExists(output.get(URI.from("test/fixtures/direct-import/mod.ts")));
assertExists(output.get(URI.from("test/fixtures/direct-import/lib.ts")));
});

it("import map", async () => {
const results = FileUpdate.collect(
await DependencyUpdate.collect(
"./tests/import-map/mod.ts",
{ importMap: "./tests/import-map/deno.json" },
"./test/fixtures/import-map/mod.ts",
{ importMap: "./test/fixtures/import-map/deno.json" },
),
);
FileUpdate.writeAll(results);
assertExists(output.get(URI.from("tests/import-map/deno.json")));
assertExists(output.get(URI.from("test/fixtures/import-map/deno.json")));
});

it("import map with no resolve", async () => {
const results = FileUpdate.collect(
await DependencyUpdate.collect(
"./tests/import-map-no-resolve/mod.ts",
{ importMap: "./tests/import-map-no-resolve/deno.json" },
"./test/fixtures/import-map-no-resolve/mod.ts",
{ importMap: "./test/fixtures/import-map-no-resolve/deno.json" },
),
);
FileUpdate.writeAll(results);
assertExists(output.get(URI.from("tests/import-map-no-resolve/mod.ts")));
assertExists(
output.get(URI.from("test/fixtures/import-map-no-resolve/mod.ts")),
);
});
});
2 changes: 1 addition & 1 deletion src/git.ts → lib/git.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DependencyUpdate } from "./update.ts";
import { FileUpdate } from "./file.ts";
import { createVersionProp, type VersionProp } from "./versions.ts";
import { URI } from "../lib/uri.ts";
import { URI } from "./uri.ts";

export interface CommitProps {
/** The name of the module group */
Expand Down
29 changes: 15 additions & 14 deletions src/git_test.ts → lib/git_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// deno-lint-ignore-file no-explicit-any

import {
afterAll,
afterEach,
Expand All @@ -9,9 +8,9 @@ import {
it,
type Stub,
stub,
} from "../lib/std/testing.ts";
import { assertArrayIncludes, assertEquals } from "../lib/std/assert.ts";
import { URI } from "../lib/uri.ts";
} from "./std/testing.ts";
import { assertArrayIncludes, assertEquals } from "./std/assert.ts";
import { URI } from "./uri.ts";
import { DependencyUpdate } from "./update.ts";
import { commitAll } from "./git.ts";

Expand Down Expand Up @@ -42,7 +41,9 @@ describe("commitAll()", () => {
let readTextFileSyncStub: Stub;

beforeAll(async () => {
updates = await DependencyUpdate.collect("./tests/direct-import/mod.ts");
updates = await DependencyUpdate.collect(
"./test/fixtures/direct-import/mod.ts",
);
writeTextFileSyncStub = stub(
Deno,
"writeTextFileSync",
Expand Down Expand Up @@ -73,8 +74,8 @@ describe("commitAll()", () => {
beforeEach(() => {
for (
const file of [
"./tests/direct-import/mod.ts",
"./tests/direct-import/lib.ts",
"./test/fixtures/direct-import/mod.ts",
"./test/fixtures/direct-import/lib.ts",
]
) {
const content = readTextFileSyncOriginal(file);
Expand Down Expand Up @@ -108,11 +109,11 @@ describe("commitAll()", () => {
assertArrayIncludes(
DenoCommandStub.commands,
[
"git add tests/direct-import/mod.ts",
"git add test/fixtures/direct-import/mod.ts",
'git commit -m "build(deps): update node-emoji"',
"git add tests/direct-import/mod.ts",
"git add test/fixtures/direct-import/mod.ts",
'git commit -m "build(deps): update deno.land/x/deno_graph"',
// "git add tests/direct-import/mod.ts tests/direct-import/lib.ts",
// "git add test/fixtures/direct-import/mod.ts test/fixtures/direct-import/lib.ts",
'git commit -m "build(deps): update deno.land/std"',
],
);
Expand All @@ -127,10 +128,10 @@ describe("commitAll()", () => {
assertArrayIncludes(
DenoCommandStub.commands,
[
"git add tests/direct-import/mod.ts",
'git commit -m "build(deps): update tests/direct-import/mod.ts"',
"git add tests/direct-import/lib.ts",
'git commit -m "build(deps): update tests/direct-import/lib.ts"',
"git add test/fixtures/direct-import/mod.ts",
'git commit -m "build(deps): update test/fixtures/direct-import/mod.ts"',
"git add test/fixtures/direct-import/lib.ts",
'git commit -m "build(deps): update test/fixtures/direct-import/lib.ts"',
],
);
});
Expand Down
12 changes: 6 additions & 6 deletions src/import_map.ts → lib/import_map.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { maxBy } from "../lib/std/collections.ts";
import { parse as parseJsonc } from "../lib/std/jsonc.ts";
import { type ImportMapJson, parseFromJson } from "../lib/x/import_map.ts";
import { is } from "../lib/x/unknownutil.ts";
import type { Maybe } from "../lib/types.ts";
import { URI } from "../lib/uri.ts";
import { maxBy } from "./std/collections.ts";
import { parse as parseJsonc } from "./std/jsonc.ts";
import { type ImportMapJson, parseFromJson } from "./x/import_map.ts";
import { is } from "./x/unknownutil.ts";
import type { Maybe } from "./types.ts";
import { URI } from "./uri.ts";
import { URIScheme } from "./types.ts";

export type { ImportMapJson };
Expand Down
45 changes: 27 additions & 18 deletions src/import_map_test.ts → lib/import_map_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { beforeAll, describe, it } from "../lib/std/testing.ts";
import { assertEquals, assertExists } from "../lib/std/assert.ts";
import { URI } from "../lib/uri.ts";
import { beforeAll, describe, it } from "./std/testing.ts";
import { assertEquals, assertExists } from "./std/assert.ts";
import { URI } from "./uri.ts";
import { ImportMap } from "./import_map.ts";

describe("readFromJson()", () => {
Expand All @@ -15,31 +15,34 @@ describe("readFromJson()", () => {
assertEquals(importMap, undefined);
await Deno.remove(f);
});
it("tests/import-map/deno.json", async () => {
it("test/fixtures/import-map/deno.json", async () => {
const importMap = await ImportMap.readFromJson(
new URL("../tests/import-map/deno.json", import.meta.url),
new URL("../test/fixtures/import-map/deno.json", import.meta.url),
);
assertExists(importMap);
});
it("tests/import-map-referred/import_map.json", async () => {
it("test/fixtures/import-map-referred/import_map.json", async () => {
const importMap = await ImportMap.readFromJson(
new URL("../tests/import-map-referred/deno.json", import.meta.url),
new URL(
"../test/fixtures/import-map-referred/deno.json",
import.meta.url,
),
);
assertExists(importMap);
assertEquals(
importMap.specifier,
URI.from("./tests/import-map-referred/import_map.json"),
URI.from("./test/fixtures/import-map-referred/import_map.json"),
);
});
});

describe("resolve()", () => {
it("resolve specifiers in import maps", async () => {
const importMap = await ImportMap.readFromJson(
new URL("../tests/import-map/deno.json", import.meta.url),
new URL("../test/fixtures/import-map/deno.json", import.meta.url),
);
assertExists(importMap);
const referrer = URI.from("tests/import-map/mod.ts");
const referrer = URI.from("test/fixtures/import-map/mod.ts");
assertEquals(
importMap.resolve("std/version.ts", referrer),
{
Expand Down Expand Up @@ -67,19 +70,19 @@ describe("resolve()", () => {
assertEquals(
importMap.resolve("/lib.ts", referrer),
{
specifier: URI.from("tests/import-map/lib.ts"),
specifier: URI.from("test/fixtures/import-map/lib.ts"),
},
);
});
it("do not resolve an url", async () => {
const importMap = await ImportMap.readFromJson(
new URL(
"../tests/import-map-no-resolve/deno.json",
"../test/fixtures/import-map-no-resolve/deno.json",
import.meta.url,
),
);
assertExists(importMap);
const referrer = URI.from("tests/import-map-no-resolve/deps.ts");
const referrer = URI.from("test/fixtures/import-map-no-resolve/deps.ts");
assertEquals(
importMap.resolve(
"https://deno.land/std@0.171.0/testing/asserts.ts",
Expand All @@ -90,10 +93,13 @@ describe("resolve()", () => {
});
it("resolve specifiers in a referred import map", async () => {
const importMap = await ImportMap.readFromJson(
new URL("../tests/import-map-referred/deno.json", import.meta.url),
new URL(
"../test/fixtures/import-map-referred/deno.json",
import.meta.url,
),
);
assertExists(importMap);
const referrer = URI.from("tests/import-map-referred/mod.ts");
const referrer = URI.from("test/fixtures/import-map-referred/mod.ts");
assertEquals(
importMap.resolve("dax", referrer),
{
Expand All @@ -109,15 +115,18 @@ describe("resolveSimple()", () => {
let importMap: ImportMap;
beforeAll(async () => {
const maybe = await ImportMap.readFromJson(
new URL("../tests/import-map/deno.json", import.meta.url),
new URL("../test/fixtures/import-map/deno.json", import.meta.url),
);
assertExists(maybe);
importMap = maybe;
});
it("resolve an absolute path", () => {
assertEquals(
importMap.resolveSimple("/lib.ts", URI.from("tests/import-map/mod.ts")),
URI.from("tests/import-map/lib.ts"),
importMap.resolveSimple(
"/lib.ts",
URI.from("test/fixtures/import-map/mod.ts"),
),
URI.from("test/fixtures/import-map/lib.ts"),
);
});
});
2 changes: 1 addition & 1 deletion src/loader.ts → lib/loader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
type CreateGraphOptions,
load as defaultLoad,
} from "../lib/x/deno_graph.ts";
} from "./x/deno_graph.ts";

export const load: NonNullable<CreateGraphOptions["load"]> = async (
specifier,
Expand Down
3 changes: 1 addition & 2 deletions src/semver.ts → lib/semver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Maybe } from "../lib/types.ts";
import type { SemVerString } from "./types.ts";
import type { Maybe, SemVerString } from "./types.ts";

// Ref: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
const SEMVER_REGEXP =
Expand Down
4 changes: 2 additions & 2 deletions src/semver_test.ts → lib/semver_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it } from "../lib/std/testing.ts";
import { assertEquals } from "../lib/std/assert.ts";
import { describe, it } from "./std/testing.ts";
import { assertEquals } from "./std/assert.ts";
import { parseSemVer } from "./semver.ts";

describe("parseSemVer", () => {
Expand Down
12 changes: 12 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
export type Maybe<T> = T | undefined;
export type Brand<T, B> = T & { __brand: B };

/** A string that represents a path segment (e.g. `src/lib.ts`.) */
export type Path = Brand<string, "Path">;

/** A string that represents a semver (e.g. `v1.0.0`.) */
export type SemVerString = Brand<string, "SemVerString">;

const URI_SCHEMES = ["http", "https", "file", "npm", "node"] as const;
export type URIScheme = typeof URI_SCHEMES[number];
export const URIScheme = {
values: URI_SCHEMES,
};
Loading