Skip to content

Commit ff6cc68

Browse files
authored
BREAKING: Stop exposing internal things from mod.ts (#170)
1 parent 0f3fe9b commit ff6cc68

6 files changed

Lines changed: 140 additions & 19 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929

3030
- name: Check mod.ts
3131
run: |
32-
deno run --allow-read --allow-write tools/make_mod.ts
32+
deno run --allow-read --allow-write --allow-run tools/make_mod.ts
3333
git diff --exit-code
3434
3535
- name: Run lint

mod.ts

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,69 @@
11
// Generated by tools/make_mod.ts. Don't edit.
2-
export * from "./command.ts";
3-
export * from "./connection.ts";
4-
export * from "./errors.ts";
5-
export * from "./executor.ts";
6-
export * from "./io.ts";
7-
export * from "./pipeline.ts";
8-
export * from "./pubsub.ts";
9-
export * from "./redis.ts";
10-
export * from "./stream.ts";
2+
export { connect, parseURL } from "./redis.ts";
3+
export {
4+
ConnectionClosedError,
5+
EOFError,
6+
ErrorReplyError,
7+
InvalidStateError,
8+
SubscriptionClosedError,
9+
} from "./errors.ts";
10+
export type { RedisCommands } from "./command.ts";
11+
export type { Connection, RedisConnectionOptions } from "./connection.ts";
12+
export type {
13+
ArrayReply,
14+
Bulk,
15+
BulkNil,
16+
BulkReply,
17+
BulkString,
18+
ConditionalArray,
19+
ErrorReply,
20+
Integer,
21+
IntegerReply,
22+
Raw,
23+
RawReplyOrError,
24+
RedisRawReply,
25+
Status,
26+
StatusReply,
27+
} from "./io.ts";
28+
export type { RedisPipeline } from "./pipeline.ts";
29+
export type { RedisPubSubMessage, RedisSubscription } from "./pubsub.ts";
30+
export type { Redis, RedisConnectOptions } from "./redis.ts";
31+
export type {
32+
StartEndCount,
33+
XAddFieldValues,
34+
XClaimJustXId,
35+
XClaimMessages,
36+
XClaimOpts,
37+
XClaimReply,
38+
XConsumerDetail,
39+
XGroupDetail,
40+
XId,
41+
XIdAdd,
42+
XIdCreateGroup,
43+
XIdGroupRead,
44+
XIdInput,
45+
XIdNeg,
46+
XIdPos,
47+
XInfoConsumer,
48+
XInfoConsumersReply,
49+
XInfoGroup,
50+
XInfoGroupsReply,
51+
XInfoStreamFullReply,
52+
XInfoStreamReply,
53+
XKeyId,
54+
XKeyIdGroup,
55+
XKeyIdGroupLike,
56+
XKeyIdLike,
57+
XMaxlen,
58+
XMessage,
59+
XPendingConsumer,
60+
XPendingCount,
61+
XPendingReply,
62+
XReadGroupOpts,
63+
XReadIdData,
64+
XReadOpts,
65+
XReadReply,
66+
XReadReplyRaw,
67+
XReadStream,
68+
XReadStreamRaw,
69+
} from "./stream.ts";

tests/general_test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { parseURL } from "../mod.ts";
2-
import { ErrorReplyError } from "../errors.ts";
1+
import { ErrorReplyError, parseURL } from "../mod.ts";
32
import {
43
assert,
54
assertEquals,

tests/pipeline_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ErrorReplyError } from "../errors.ts";
1+
import { ErrorReplyError } from "../mod.ts";
22
import {
33
assert,
44
assertEquals,

tests/stream_test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { ErrorReplyError } from "../errors.ts";
2-
import { Redis } from "../mod.ts";
1+
import { ErrorReplyError, Redis } from "../mod.ts";
32
import { parseXId } from "../stream.ts";
43
import { delay } from "../vendor/https/deno.land/std/async/mod.ts";
54
import {

tools/make_mod.ts

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,77 @@
1-
#!/usr/bin/env deno run --allow-read --allow-write
1+
#!/usr/bin/env deno run --allow-read --allow-write --allow-run
2+
3+
const encoder = new TextEncoder();
4+
const decoder = new TextDecoder();
5+
6+
interface Node {
7+
kind: string;
8+
name: string;
9+
}
10+
11+
async function doc(fileName: string): Promise<Array<Node>> {
12+
const deno = Deno.run({
13+
cmd: [Deno.execPath(), "doc", "--json", fileName],
14+
stdout: "piped",
15+
});
16+
try {
17+
const out = await Deno.readAll(deno.stdout);
18+
return JSON.parse(decoder.decode(out));
19+
} finally {
20+
deno.stdout.close();
21+
deno.close();
22+
}
23+
}
24+
25+
async function fmt(content: string): Promise<string> {
26+
const deno = Deno.run({
27+
cmd: [Deno.execPath(), "fmt", "-"],
28+
stdin: "piped",
29+
stdout: "piped",
30+
});
31+
try {
32+
await Deno.writeAll(deno.stdin, encoder.encode(content));
33+
deno.stdin.close();
34+
const formattedContent = decoder.decode(await Deno.readAll(deno.stdout));
35+
return formattedContent;
36+
} finally {
37+
deno.stdout.close();
38+
deno.close();
39+
}
40+
}
241

342
const files = [...Deno.readDirSync(".")].filter((f) => {
443
const name = f.name;
544
if (!name || name === "mod.ts") return false;
645
return name.endsWith(".ts") && !name.endsWith("_test.ts") &&
746
!name.endsWith(".d.ts");
847
}).map((f) => f.name).sort();
9-
let content = "// Generated by tools/make_mod.ts. Don't edit.\n";
48+
let content = `// Generated by tools/make_mod.ts. Don't edit.\n`;
49+
50+
// Expose public functions from redis.ts.
51+
{
52+
const fileName = "redis.ts";
53+
const functions = (await doc(fileName)).filter((node) => {
54+
return node.kind === "function";
55+
}).map((node) => node.name);
56+
content += `export { ${functions.join(",")} } from "./${fileName}";\n`;
57+
}
58+
59+
// Expose public classes from errors.ts
60+
{
61+
const fileName = "errors.ts";
62+
const classes = (await doc(fileName)).filter((node) => {
63+
return node.kind === "class";
64+
}).map((node) => node.name);
65+
content += `export { ${classes.join(",")} } from "./${fileName}";\n`;
66+
}
67+
68+
// Expose types from *.ts.
1069
for (const f of files) {
11-
content += `export * from "./${f}";\n`;
70+
const types = (await doc(f)).filter((node) => {
71+
return node.kind === "interface" || node.kind === "typeAlias";
72+
}).map((node) => node.name);
73+
if (types.length > 0) {
74+
content += `export type { ${types.join(",")} } from "./${f}"\n`;
75+
}
1276
}
13-
Deno.writeFileSync("mod.ts", new TextEncoder().encode(content));
77+
Deno.writeFileSync("mod.ts", encoder.encode(await fmt(content)));

0 commit comments

Comments
 (0)