diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 7e8acac..1fdc05e 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,6 +1,8 @@ # These are supported funding model platforms -github: [lambdalisue] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +github: [ + lambdalisue, +] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username diff --git a/.scripts/gen-mod.ts b/.scripts/gen-mod.ts index 1edf172..620a036 100644 --- a/.scripts/gen-mod.ts +++ b/.scripts/gen-mod.ts @@ -1,8 +1,13 @@ -import { fromFileUrl, globToRegExp, join, relative } from "@std/path"; +import { + fromFileUrl, + globToRegExp, + join, + relative, + toFileUrl, +} from "@std/path"; import { map } from "@core/iterutil/map"; import { flatMap } from "@core/iterutil/async/flat-map"; - -const decoder = new TextDecoder(); +import { doc } from "@deno/doc"; const excludes = [ "mod.ts", @@ -11,47 +16,6 @@ const excludes = [ "_*.ts", ]; -type DenoDocEntry = { - name: string; - location: { - filename: string; - }; - declarationKind: string; - jsDoc: { - doc: string; - }; - kind: string; -}; - -function isDenoDocEntry(x: unknown): x is DenoDocEntry { - if (x == null || typeof x !== "object") return false; - if (typeof (x as DenoDocEntry).name !== "string") return false; - if (typeof (x as DenoDocEntry).location !== "object") return false; - if (typeof (x as DenoDocEntry).location.filename !== "string") return false; - if (typeof (x as DenoDocEntry).declarationKind !== "string") return false; - if (typeof (x as DenoDocEntry).jsDoc !== "object") return false; - if (typeof (x as DenoDocEntry).jsDoc.doc !== "string") return false; - if (typeof (x as DenoDocEntry).kind !== "string") return false; - return true; -} - -async function listDenoDocEntries(path: string): Promise { - const cmd = new Deno.Command(Deno.execPath(), { - args: ["doc", "--json", path], - stdout: "piped", - stderr: "piped", - }); - const { success, stdout, stderr } = await cmd.output(); - if (!success) { - throw new Error(decoder.decode(stderr)); - } - const json = JSON.parse(decoder.decode(stdout)); - if (!Array.isArray(json)) { - throw new Error(`Expected array but got ${JSON.stringify(json)}`); - } - return json.filter(isDenoDocEntry); -} - async function* iterModules(path: string): AsyncIterable { const patterns = excludes.map((p) => globToRegExp(p)); for await (const entry of Deno.readDir(path)) { @@ -66,15 +30,16 @@ async function generateModTs( ): Promise { const path = fromFileUrl(import.meta.resolve(`../${namespace}/`)); const exports = (await Array.fromAsync( - flatMap(iterModules(path), (x) => listDenoDocEntries(x)), + flatMap(iterModules(path), (x) => doc(toFileUrl(x).href)), )) + .filter((x) => !!x.jsDoc?.doc) .filter((x) => x.kind === "function") .filter((x) => x.declarationKind === "export") .filter((x) => x.name.startsWith(namespace)) .map((x) => ({ path: relative(path, fromFileUrl(x.location.filename)), name: x.name, - doc: x.jsDoc.doc, + doc: x.jsDoc!.doc!, })) .toSorted((a, b) => a.name.localeCompare(b.name)); const lines = [ diff --git a/deno.jsonc b/deno.jsonc index 9c1ebc1..2c2538d 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -75,6 +75,7 @@ "@core/iterutil": "jsr:@core/iterutil@^0.3.0", "@core/unknownutil": "./mod.ts", "@deno/dnt": "jsr:@deno/dnt@^0.41.1", + "@deno/doc": "jsr:@deno/doc@^0.153.0", "@std/assert": "jsr:@std/assert@^1.0.4", "@std/jsonc": "jsr:@std/jsonc@^1.0.0", "@std/path": "jsr:@std/path@^1.0.2", @@ -85,7 +86,7 @@ "test": "deno test -A --doc --parallel --shuffle", "test:coverage": "deno task test --coverage=.coverage", "coverage": "deno coverage .coverage", - "gen": "deno run --allow-run=deno --allow-read --allow-write=. .scripts/gen-mod.ts", + "gen": "deno run --allow-net=jsr.io --allow-env --allow-read --allow-write=. .scripts/gen-mod.ts", "update": "deno run --allow-env --allow-read --allow-write=. --allow-run=git,deno --allow-net=jsr.io,registry.npmjs.org jsr:@molt/cli ./*.ts", "update:commit": "deno task -q update --commit --prefix deps: --pre-commit=fmt,lint" }