Skip to content

Commit

Permalink
BREAKING: Stop exposing internal things from mod.ts (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
uki00a authored Jan 4, 2021
1 parent 0f3fe9b commit ff6cc68
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

- name: Check mod.ts
run: |
deno run --allow-read --allow-write tools/make_mod.ts
deno run --allow-read --allow-write --allow-run tools/make_mod.ts
git diff --exit-code
- name: Run lint
Expand Down
77 changes: 68 additions & 9 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,69 @@
// Generated by tools/make_mod.ts. Don't edit.
export * from "./command.ts";
export * from "./connection.ts";
export * from "./errors.ts";
export * from "./executor.ts";
export * from "./io.ts";
export * from "./pipeline.ts";
export * from "./pubsub.ts";
export * from "./redis.ts";
export * from "./stream.ts";
export { connect, parseURL } from "./redis.ts";
export {
ConnectionClosedError,
EOFError,
ErrorReplyError,
InvalidStateError,
SubscriptionClosedError,
} from "./errors.ts";
export type { RedisCommands } from "./command.ts";
export type { Connection, RedisConnectionOptions } from "./connection.ts";
export type {
ArrayReply,
Bulk,
BulkNil,
BulkReply,
BulkString,
ConditionalArray,
ErrorReply,
Integer,
IntegerReply,
Raw,
RawReplyOrError,
RedisRawReply,
Status,
StatusReply,
} from "./io.ts";
export type { RedisPipeline } from "./pipeline.ts";
export type { RedisPubSubMessage, RedisSubscription } from "./pubsub.ts";
export type { Redis, RedisConnectOptions } from "./redis.ts";
export type {
StartEndCount,
XAddFieldValues,
XClaimJustXId,
XClaimMessages,
XClaimOpts,
XClaimReply,
XConsumerDetail,
XGroupDetail,
XId,
XIdAdd,
XIdCreateGroup,
XIdGroupRead,
XIdInput,
XIdNeg,
XIdPos,
XInfoConsumer,
XInfoConsumersReply,
XInfoGroup,
XInfoGroupsReply,
XInfoStreamFullReply,
XInfoStreamReply,
XKeyId,
XKeyIdGroup,
XKeyIdGroupLike,
XKeyIdLike,
XMaxlen,
XMessage,
XPendingConsumer,
XPendingCount,
XPendingReply,
XReadGroupOpts,
XReadIdData,
XReadOpts,
XReadReply,
XReadReplyRaw,
XReadStream,
XReadStreamRaw,
} from "./stream.ts";
3 changes: 1 addition & 2 deletions tests/general_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { parseURL } from "../mod.ts";
import { ErrorReplyError } from "../errors.ts";
import { ErrorReplyError, parseURL } from "../mod.ts";
import {
assert,
assertEquals,
Expand Down
2 changes: 1 addition & 1 deletion tests/pipeline_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorReplyError } from "../errors.ts";
import { ErrorReplyError } from "../mod.ts";
import {
assert,
assertEquals,
Expand Down
3 changes: 1 addition & 2 deletions tests/stream_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ErrorReplyError } from "../errors.ts";
import { Redis } from "../mod.ts";
import { ErrorReplyError, Redis } from "../mod.ts";
import { parseXId } from "../stream.ts";
import { delay } from "../vendor/https/deno.land/std/async/mod.ts";
import {
Expand Down
72 changes: 68 additions & 4 deletions tools/make_mod.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,77 @@
#!/usr/bin/env deno run --allow-read --allow-write
#!/usr/bin/env deno run --allow-read --allow-write --allow-run

const encoder = new TextEncoder();
const decoder = new TextDecoder();

interface Node {
kind: string;
name: string;
}

async function doc(fileName: string): Promise<Array<Node>> {
const deno = Deno.run({
cmd: [Deno.execPath(), "doc", "--json", fileName],
stdout: "piped",
});
try {
const out = await Deno.readAll(deno.stdout);
return JSON.parse(decoder.decode(out));
} finally {
deno.stdout.close();
deno.close();
}
}

async function fmt(content: string): Promise<string> {
const deno = Deno.run({
cmd: [Deno.execPath(), "fmt", "-"],
stdin: "piped",
stdout: "piped",
});
try {
await Deno.writeAll(deno.stdin, encoder.encode(content));
deno.stdin.close();
const formattedContent = decoder.decode(await Deno.readAll(deno.stdout));
return formattedContent;
} finally {
deno.stdout.close();
deno.close();
}
}

const files = [...Deno.readDirSync(".")].filter((f) => {
const name = f.name;
if (!name || name === "mod.ts") return false;
return name.endsWith(".ts") && !name.endsWith("_test.ts") &&
!name.endsWith(".d.ts");
}).map((f) => f.name).sort();
let content = "// Generated by tools/make_mod.ts. Don't edit.\n";
let content = `// Generated by tools/make_mod.ts. Don't edit.\n`;

// Expose public functions from redis.ts.
{
const fileName = "redis.ts";
const functions = (await doc(fileName)).filter((node) => {
return node.kind === "function";
}).map((node) => node.name);
content += `export { ${functions.join(",")} } from "./${fileName}";\n`;
}

// Expose public classes from errors.ts
{
const fileName = "errors.ts";
const classes = (await doc(fileName)).filter((node) => {
return node.kind === "class";
}).map((node) => node.name);
content += `export { ${classes.join(",")} } from "./${fileName}";\n`;
}

// Expose types from *.ts.
for (const f of files) {
content += `export * from "./${f}";\n`;
const types = (await doc(f)).filter((node) => {
return node.kind === "interface" || node.kind === "typeAlias";
}).map((node) => node.name);
if (types.length > 0) {
content += `export type { ${types.join(",")} } from "./${f}"\n`;
}
}
Deno.writeFileSync("mod.ts", new TextEncoder().encode(content));
Deno.writeFileSync("mod.ts", encoder.encode(await fmt(content)));

0 comments on commit ff6cc68

Please sign in to comment.