Skip to content

Commit

Permalink
Merge pull request #42 from jsr-core/fix-mod
Browse files Browse the repository at this point in the history
fix: `mod.ts` to export new features of v1.1.0
  • Loading branch information
lambdalisue authored Aug 21, 2024
2 parents f5a9505 + 827a56e commit ece8b39
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 4 deletions.
5 changes: 4 additions & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@
"@core/asyncutil/stack": "./stack.ts",
"@core/asyncutil/wait-group": "./wait_group.ts",
"@core/iterutil": "jsr:@core/iterutil@^0.6.0",
"@core/unknownutil": "jsr:@core/unknownutil@^4.2.0",
"@cross/test": "jsr:@cross/test@^0.0.9",
"@std/assert": "jsr:@std/assert@^1.0.2",
"@std/async": "jsr:@std/async@^1.0.2"
"@std/async": "jsr:@std/async@^1.0.2",
"@std/jsonc": "jsr:@std/jsonc@^1.0.0",
"@std/path": "jsr:@std/path@^1.0.2"
},
"tasks": {
"check": "deno check ./**/*.ts",
Expand Down
24 changes: 23 additions & 1 deletion deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
export * from "./async_value.ts";
export * from "./barrier.ts";
export * from "./ensure_promise.ts";
export * from "./flush_promises.ts";
export * from "./lock.ts";
export * from "./mutex.ts";
export * from "./notify.ts";
export * from "./peek_promise_state.ts";
export * from "./promise_state.ts";
export * from "./queue.ts";
export * from "./rw_lock.ts";
Expand Down
58 changes: 58 additions & 0 deletions mod_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { test } from "@cross/test";
import { assertArrayIncludes } from "@std/assert";
import { basename, globToRegExp, join } from "@std/path";
import { ensure, is } from "@core/unknownutil";
import { parse } from "@std/jsonc";

const excludes = [
"mod.ts",
"_*.ts",
"*_test.ts",
"*_bench.ts",
];

test("mod.ts must exports all exports in public modules", async () => {
const modExports = await listModExports("./mod.ts");
const pubExports = [];
for await (const name of iterPublicModules(".")) {
pubExports.push(...await listModExports(`./${name}.ts`));
}
assertArrayIncludes(modExports, pubExports);
}, { skip: !("Deno" in globalThis) });

test("JSR exports must have all exports in mod.ts", async () => {
const jsrExportEntries = await listJsrExportEntries();
const modExportEntries: [string, string][] = [];
for await (const name of iterPublicModules(".")) {
modExportEntries.push([`./${name.replaceAll("_", "-")}`, `./${name}.ts`]);
}
assertArrayIncludes(jsrExportEntries, modExportEntries);
}, { skip: !("Deno" in globalThis) });

async function* iterPublicModules(relpath: string): AsyncIterable<string> {
const patterns = excludes.map((p) => globToRegExp(p));
const root = join(import.meta.dirname!, relpath);
for await (const entry of Deno.readDir(root)) {
if (!entry.isFile || !entry.name.endsWith(".ts")) continue;
if (patterns.some((p) => p.test(entry.name))) continue;
yield basename(entry.name, ".ts");
}
}

async function listModExports(path: string): Promise<string[]> {
const mod = await import(import.meta.resolve(path));
return Array.from(Object.keys(mod));
}

async function listJsrExportEntries(): Promise<[string, string][]> {
const text = await Deno.readTextFile(
new URL(import.meta.resolve("./deno.jsonc")),
);
const json = ensure(
parse(text),
is.ObjectOf({
exports: is.RecordOf(is.String, is.String),
}),
);
return Object.entries(json.exports);
}
47 changes: 46 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
"type": "module",
"dependencies": {
"@core/iterutil": "npm:@jsr/core__iterutil@^0.6.0-pre.0",
"@core/unknownutil": "npm:@jsr/core__unknownutil@^4.2.0",
"@cross/test": "npm:@jsr/cross__test",
"@std/assert": "npm:@jsr/std__assert",
"@std/async": "npm:@jsr/std__async@^1.0.3"
"@std/async": "npm:@jsr/std__async@^1.0.3",
"@std/jsonc": "npm:@jsr/std__jsonc@^1.0.0-rc.3",
"@std/path": "npm:@jsr/std__path@^1.0.2"
}
}

0 comments on commit ece8b39

Please sign in to comment.