Skip to content

Commit ece8b39

Browse files
authored
Merge pull request #42 from jsr-core/fix-mod
fix: `mod.ts` to export new features of v1.1.0
2 parents f5a9505 + 827a56e commit ece8b39

File tree

6 files changed

+138
-4
lines changed

6 files changed

+138
-4
lines changed

deno.jsonc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@
5050
"@core/asyncutil/stack": "./stack.ts",
5151
"@core/asyncutil/wait-group": "./wait_group.ts",
5252
"@core/iterutil": "jsr:@core/iterutil@^0.6.0",
53+
"@core/unknownutil": "jsr:@core/unknownutil@^4.2.0",
5354
"@cross/test": "jsr:@cross/test@^0.0.9",
5455
"@std/assert": "jsr:@std/assert@^1.0.2",
55-
"@std/async": "jsr:@std/async@^1.0.2"
56+
"@std/async": "jsr:@std/async@^1.0.2",
57+
"@std/jsonc": "jsr:@std/jsonc@^1.0.0",
58+
"@std/path": "jsr:@std/path@^1.0.2"
5659
},
5760
"tasks": {
5861
"check": "deno check ./**/*.ts",

deno.lock

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mod.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
export * from "./async_value.ts";
22
export * from "./barrier.ts";
3+
export * from "./ensure_promise.ts";
4+
export * from "./flush_promises.ts";
35
export * from "./lock.ts";
46
export * from "./mutex.ts";
57
export * from "./notify.ts";
8+
export * from "./peek_promise_state.ts";
69
export * from "./promise_state.ts";
710
export * from "./queue.ts";
811
export * from "./rw_lock.ts";

mod_test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { test } from "@cross/test";
2+
import { assertArrayIncludes } from "@std/assert";
3+
import { basename, globToRegExp, join } from "@std/path";
4+
import { ensure, is } from "@core/unknownutil";
5+
import { parse } from "@std/jsonc";
6+
7+
const excludes = [
8+
"mod.ts",
9+
"_*.ts",
10+
"*_test.ts",
11+
"*_bench.ts",
12+
];
13+
14+
test("mod.ts must exports all exports in public modules", async () => {
15+
const modExports = await listModExports("./mod.ts");
16+
const pubExports = [];
17+
for await (const name of iterPublicModules(".")) {
18+
pubExports.push(...await listModExports(`./${name}.ts`));
19+
}
20+
assertArrayIncludes(modExports, pubExports);
21+
}, { skip: !("Deno" in globalThis) });
22+
23+
test("JSR exports must have all exports in mod.ts", async () => {
24+
const jsrExportEntries = await listJsrExportEntries();
25+
const modExportEntries: [string, string][] = [];
26+
for await (const name of iterPublicModules(".")) {
27+
modExportEntries.push([`./${name.replaceAll("_", "-")}`, `./${name}.ts`]);
28+
}
29+
assertArrayIncludes(jsrExportEntries, modExportEntries);
30+
}, { skip: !("Deno" in globalThis) });
31+
32+
async function* iterPublicModules(relpath: string): AsyncIterable<string> {
33+
const patterns = excludes.map((p) => globToRegExp(p));
34+
const root = join(import.meta.dirname!, relpath);
35+
for await (const entry of Deno.readDir(root)) {
36+
if (!entry.isFile || !entry.name.endsWith(".ts")) continue;
37+
if (patterns.some((p) => p.test(entry.name))) continue;
38+
yield basename(entry.name, ".ts");
39+
}
40+
}
41+
42+
async function listModExports(path: string): Promise<string[]> {
43+
const mod = await import(import.meta.resolve(path));
44+
return Array.from(Object.keys(mod));
45+
}
46+
47+
async function listJsrExportEntries(): Promise<[string, string][]> {
48+
const text = await Deno.readTextFile(
49+
new URL(import.meta.resolve("./deno.jsonc")),
50+
);
51+
const json = ensure(
52+
parse(text),
53+
is.ObjectOf({
54+
exports: is.RecordOf(is.String, is.String),
55+
}),
56+
);
57+
return Object.entries(json.exports);
58+
}

package-lock.json

Lines changed: 46 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
"type": "module",
33
"dependencies": {
44
"@core/iterutil": "npm:@jsr/core__iterutil@^0.6.0-pre.0",
5+
"@core/unknownutil": "npm:@jsr/core__unknownutil@^4.2.0",
56
"@cross/test": "npm:@jsr/cross__test",
67
"@std/assert": "npm:@jsr/std__assert",
7-
"@std/async": "npm:@jsr/std__async@^1.0.3"
8+
"@std/async": "npm:@jsr/std__async@^1.0.3",
9+
"@std/jsonc": "npm:@jsr/std__jsonc@^1.0.0-rc.3",
10+
"@std/path": "npm:@jsr/std__path@^1.0.2"
811
}
912
}

0 commit comments

Comments
 (0)