This repository was archived by the owner on Jan 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeno_api.ts
More file actions
67 lines (57 loc) · 1.52 KB
/
deno_api.ts
File metadata and controls
67 lines (57 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import type * as ddoc from "./deno_doc_json.ts";
import type * as info from "./deno_info_json.ts";
const decoder = new TextDecoder();
export async function getDenoData(
specifier?: string,
{ private: priv }: { private?: boolean } = {},
): Promise<{ doc: ddoc.DocNode[]; info: info.FileInfo | null }> {
let proc_d;
let proc_i;
try {
proc_d = Deno.run({
cmd: [
"deno",
"doc",
"--json",
...(priv ? ["--private"] : []),
specifier ?? "--builtin",
],
stdin: "null",
stdout: "piped",
stderr: "piped",
});
const stdout = decoder.decode(await proc_d.output());
const stderr = decoder.decode(await proc_d.stderrOutput());
const { success } = await proc_d.status();
if (!success) {
throw { stderr };
}
const doc_j: ddoc.DocNode[] = JSON.parse(stdout);
let info_j: info.FileInfo | null = null;
if (specifier !== undefined) {
proc_i = Deno.run({
cmd: [
"deno",
"info",
"--json",
"--unstable",
specifier,
],
stdin: "null",
stdout: "piped",
stderr: "piped",
});
const stdout = decoder.decode(await proc_i.output());
const stderr = decoder.decode(await proc_i.stderrOutput());
const { success } = await proc_i.status();
if (!success) {
throw { stderr };
}
info_j = JSON.parse(stdout);
}
return { doc: doc_j, info: info_j };
} finally {
proc_d?.close();
proc_i?.close();
}
}