From 463b188bf3651406be20708b09be09165dc3ce5b Mon Sep 17 00:00:00 2001 From: Alisue Date: Wed, 21 Aug 2024 12:53:06 +0900 Subject: [PATCH 1/2] test: add test for `mod.ts` --- deno.jsonc | 5 +++- deno.lock | 24 +++++++++++++++++++- mod_test.ts | 58 +++++++++++++++++++++++++++++++++++++++++++++++ package-lock.json | 47 +++++++++++++++++++++++++++++++++++++- package.json | 5 +++- 5 files changed, 135 insertions(+), 4 deletions(-) create mode 100644 mod_test.ts diff --git a/deno.jsonc b/deno.jsonc index 976c35e..e085fae 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -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", diff --git a/deno.lock b/deno.lock index d1f004c..dfb8f03 100644 --- a/deno.lock +++ b/deno.lock @@ -4,11 +4,15 @@ "specifiers": { "jsr:@core/asyncutil@~1.0.0": "jsr:@core/asyncutil@1.0.2", "jsr:@core/iterutil@^0.6.0": "jsr:@core/iterutil@0.6.0", + "jsr:@core/unknownutil@^4.2.0": "jsr:@core/unknownutil@4.2.0", "jsr:@cross/runtime@^1.0.0": "jsr:@cross/runtime@1.0.0", "jsr:@cross/test@^0.0.9": "jsr:@cross/test@0.0.9", "jsr:@std/assert@^1.0.2": "jsr:@std/assert@1.0.2", "jsr:@std/async@^1.0.2": "jsr:@std/async@1.0.3", "jsr:@std/internal@^1.0.1": "jsr:@std/internal@1.0.1", + "jsr:@std/json@^1.0.0": "jsr:@std/json@1.0.0", + "jsr:@std/jsonc@^1.0.0": "jsr:@std/jsonc@1.0.0", + "jsr:@std/path@^1.0.2": "jsr:@std/path@1.0.2", "npm:@types/node": "npm:@types/node@18.16.19" }, "jsr": { @@ -21,6 +25,9 @@ "@core/iterutil@0.6.0": { "integrity": "8de0d0062a515496ae744983941d7e379668c2ee2edf43f63423e8da753828b1" }, + "@core/unknownutil@4.2.0": { + "integrity": "cc0609f2e9fcfd68783c8c34d588261464114770d83047e93eaa1e13732aaedb" + }, "@cross/runtime@1.0.0": { "integrity": "dddecdf99182df13d50279d1e473f715e83d41961c5c22edd7bb0c4c3cf8a76a" }, @@ -41,6 +48,18 @@ }, "@std/internal@1.0.1": { "integrity": "6f8c7544d06a11dd256c8d6ba54b11ed870aac6c5aeafff499892662c57673e6" + }, + "@std/json@1.0.0": { + "integrity": "985c1e544918d42e4e84072fc739ac4a19c3a5093292c99742ffcdd03fb6a268" + }, + "@std/jsonc@1.0.0": { + "integrity": "835da212e586f3ef94ab25e8f0e8a7711a86fddbee95ad40c34d6b3d74da1a1b", + "dependencies": [ + "jsr:@std/json@^1.0.0" + ] + }, + "@std/path@1.0.2": { + "integrity": "a452174603f8c620bd278a380c596437a9eef50c891c64b85812f735245d9ec7" } }, "npm": { @@ -54,9 +73,12 @@ "workspace": { "dependencies": [ "jsr:@core/iterutil@^0.6.0", + "jsr:@core/unknownutil@^4.2.0", "jsr:@cross/test@^0.0.9", "jsr:@std/assert@^1.0.2", - "jsr:@std/async@^1.0.2" + "jsr:@std/async@^1.0.2", + "jsr:@std/jsonc@^1.0.0", + "jsr:@std/path@^1.0.2" ], "packageJson": { "dependencies": [ diff --git a/mod_test.ts b/mod_test.ts new file mode 100644 index 0000000..70f9016 --- /dev/null +++ b/mod_test.ts @@ -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 { + 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 { + 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); +} diff --git a/package-lock.json b/package-lock.json index a4445b5..b6f5db5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,9 +6,12 @@ "": { "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" } }, "node_modules/@core/iterutil": { @@ -17,6 +20,12 @@ "resolved": "https://npm.jsr.io/~/11/@jsr/core__iterutil/0.6.0-pre.0.tgz", "integrity": "sha512-O/ka3467LURyXdWqvorYUPQirCaEQOueYwO7RSnKRDd1aGYK0yzfEvfGZkYwYC2PRT745+MOi4lsX6SKKMs97A==" }, + "node_modules/@core/unknownutil": { + "name": "@jsr/core__unknownutil", + "version": "4.2.0", + "resolved": "https://npm.jsr.io/~/11/@jsr/core__unknownutil/4.2.0.tgz", + "integrity": "sha512-HA5TxLa7E1mSNwiG1oRPfeq09SSrr6OH9TIeM5ECy14Vzv3hnsxxQO4il6Nt24HwMwFt2NkJ/RUqWD07Kbyg4g==" + }, "node_modules/@cross/test": { "name": "@jsr/cross__test", "version": "0.0.9", @@ -31,11 +40,32 @@ "resolved": "https://npm.jsr.io/~/11/@jsr/cross__runtime/1.0.0.tgz", "integrity": "sha512-wUtjVBTk65ae4AKQRnxD5x3h4vVmopdKAYie/uS01Qolii2XQ81bKtRTvJ4kx133GYYgIAgyl3ihQ0OK8LcPmQ==" }, + "node_modules/@jsr/std__bytes": { + "version": "1.0.2", + "resolved": "https://npm.jsr.io/~/11/@jsr/std__bytes/1.0.2.tgz", + "integrity": "sha512-bkZ1rllRB1qsxFbPqtO1VAYTW2+3ZDmf6pcy8xihKS33r0Z1ly6/E/5DoapnJsNy05LdnANUySWt5kj/awgGdg==" + }, "node_modules/@jsr/std__internal": { "version": "1.0.1", "resolved": "https://npm.jsr.io/~/11/@jsr/std__internal/1.0.1.tgz", "integrity": "sha512-ssI1kvluIero6cCfiWNmYItqCR8QpQB+STBJoe/xQVZ79SDpoqjK5VF2Eq/2M+Dz8WbqHVmrXRCaGN162x+Ebw==" }, + "node_modules/@jsr/std__json": { + "version": "1.0.0-rc.3", + "resolved": "https://npm.jsr.io/~/11/@jsr/std__json/1.0.0-rc.3.tgz", + "integrity": "sha512-nsHLvMmWTir390Ce3BUlteMF94vqRGpy3MVBi1fGmX7PqnWjpkThBmZJ9vpxME5HAkmA2sBaAOd0FqfQYlR0hw==", + "dependencies": { + "@jsr/std__streams": "^1.0.0-rc.4" + } + }, + "node_modules/@jsr/std__streams": { + "version": "1.0.2", + "resolved": "https://npm.jsr.io/~/11/@jsr/std__streams/1.0.2.tgz", + "integrity": "sha512-xaB3PAJKs5wkXmPvoetMatHjXDWiDTwacFGqxmioFZyZzsQ72mJ4v5C9srw0C1KDpCKtEIuZSJWhTwMSziNNgQ==", + "dependencies": { + "@jsr/std__bytes": "^1.0.2-rc.3" + } + }, "node_modules/@std/assert": { "name": "@jsr/std__assert", "version": "1.0.2", @@ -50,6 +80,21 @@ "version": "1.0.3", "resolved": "https://npm.jsr.io/~/11/@jsr/std__async/1.0.3.tgz", "integrity": "sha512-j5NZqYHN/czhfjBKh0jvPU5IRhP3Y5Lk7X3qL5ghw0gDSwI8h/kzlxSMV98ML0L6tXN9SvZU8lqa8Q5evtL4sA==" + }, + "node_modules/@std/jsonc": { + "name": "@jsr/std__jsonc", + "version": "1.0.0-rc.3", + "resolved": "https://npm.jsr.io/~/11/@jsr/std__jsonc/1.0.0-rc.3.tgz", + "integrity": "sha512-4qWZ9mrCieAfQQSdLuSPIUqShG0vJbzA0jmm1ON58VbfQGmftRgC1vfVqRAOpgBwm5GhDZzI+MLhRRqEAF8XSg==", + "dependencies": { + "@jsr/std__json": "^1.0.0-rc.3" + } + }, + "node_modules/@std/path": { + "name": "@jsr/std__path", + "version": "1.0.2", + "resolved": "https://npm.jsr.io/~/11/@jsr/std__path/1.0.2.tgz", + "integrity": "sha512-VadQVUlJZhIjRi8RcDQcNzqKcowfEdqntIXhphae0MeHaC1y60OiFealO25WTzBTHqBC58KFNlM7KWH+tepgOg==" } } } diff --git a/package.json b/package.json index 7f52a41..05d991f 100644 --- a/package.json +++ b/package.json @@ -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" } } From 827a56e1c35f35ed95c3c3e390149bb51e65ed67 Mon Sep 17 00:00:00 2001 From: Alisue Date: Wed, 21 Aug 2024 12:53:52 +0900 Subject: [PATCH 2/2] fix: fix `mod.ts` to export new features of v1.1.0 --- mod.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mod.ts b/mod.ts index 69c649a..a21a350 100644 --- a/mod.ts +++ b/mod.ts @@ -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";