fix(build): 🐛 Modify CLI to properly bundle

This commit is contained in:
Jesse Wierzbinski 2024-05-08 00:24:21 +00:00
parent 0d278e4fa9
commit 6b17b91235
No known key found for this signature in database
9 changed files with 13 additions and 90 deletions

View file

@ -1,18 +0,0 @@
const timeBefore = performance.now();
const requests: Promise<Response>[] = [];
// Repeat 1000 times
for (let i = 0; i < 1000; i++) {
requests.push(
fetch("https://mastodon.social", {
method: "GET",
}),
);
}
await Promise.all(requests);
const timeAfter = performance.now();
console.log(`Time taken: ${timeAfter - timeBefore}ms`);

View file

@ -1 +0,0 @@
//

View file

@ -1,54 +0,0 @@
/**
* Usage: TOKEN=your_token_here bun benchmark:timeline <request_count>
*/
import chalk from "chalk";
import { config } from "config-manager";
const token = process.env.TOKEN;
const requestCount = Number(process.argv[2]) || 100;
if (!token) {
console.log(
`${chalk.red(
"✗",
)} No token provided. Provide one via the TOKEN environment variable.`,
);
process.exit(1);
}
const fetchTimeline = () =>
fetch(new URL("/api/v1/timelines/home", config.http.base_url), {
headers: {
Authorization: `Bearer ${token}`,
},
}).then((res) => res.ok);
const timeNow = performance.now();
const requests = Array.from({ length: requestCount }, () => fetchTimeline());
Promise.all(requests)
.then((results) => {
const timeTaken = performance.now() - timeNow;
if (results.every((t) => t)) {
console.log(`${chalk.green("✓")} All requests succeeded`);
} else {
console.log(
`${chalk.red("✗")} ${
results.filter((t) => !t).length
} requests failed`,
);
}
console.log(
`${chalk.green("✓")} ${
requests.length
} requests fulfilled in ${chalk.bold(
(timeTaken / 1000).toFixed(5),
)}s`,
);
})
.catch((err) => {
console.log(`${chalk.red("✗")} ${err}`);
process.exit(1);
});

View file

@ -10,7 +10,6 @@ await $`rm -rf dist && mkdir dist`;
await Bun.build({ await Bun.build({
entrypoints: [ entrypoints: [
"index.ts", "index.ts",
"cli.ts",
"cli/index.ts", "cli/index.ts",
// Force Bun to include endpoints // Force Bun to include endpoints
...Object.values(routes), ...Object.values(routes),

View file

@ -1,14 +1,11 @@
import { Command } from "@oclif/core"; import { Command } from "@oclif/core";
import { setupDatabase } from "~drizzle/db";
import { consoleLogger } from "@loggers";
export abstract class BaseCommand<T extends typeof Command> extends Command { export abstract class BaseCommand<T extends typeof Command> extends Command {
protected async init(): Promise<void> { protected async init(): Promise<void> {
await super.init(); await super.init();
const { setupDatabase } = await import("~drizzle/db");
const { consoleLogger } = await import("@loggers");
(async () => {
await setupDatabase(consoleLogger, false); await setupDatabase(consoleLogger, false);
})();
} }
} }

View file

@ -2,7 +2,7 @@ import { Args, type Command, Flags, type Interfaces } from "@oclif/core";
import chalk from "chalk"; import chalk from "chalk";
import { and, eq, like } from "drizzle-orm"; import { and, eq, like } from "drizzle-orm";
import { Users } from "~drizzle/schema"; import { Users } from "~drizzle/schema";
import type { User } from "~packages/database-interface/user"; import { User } from "~packages/database-interface/user";
import { BaseCommand } from "./base"; import { BaseCommand } from "./base";
export type FlagsType<T extends typeof Command> = Interfaces.InferredFlags< export type FlagsType<T extends typeof Command> = Interfaces.InferredFlags<
@ -81,8 +81,6 @@ export abstract class UserFinderCommand<
? this.args.identifier.replace(/\*/g, "%") ? this.args.identifier.replace(/\*/g, "%")
: this.args.identifier; : this.args.identifier;
const { User } = await import("~packages/database-interface/user");
return await User.manyFromSql( return await User.manyFromSql(
and( and(
this.flags.type === "id" this.flags.type === "id"

View file

@ -1,13 +1,15 @@
import { execute } from "@oclif/core";
import EmojiAdd from "./commands/emoji/add"; import EmojiAdd from "./commands/emoji/add";
import UserCreate from "./commands/user/create"; import UserCreate from "./commands/user/create";
import UserDelete from "./commands/user/delete"; import UserDelete from "./commands/user/delete";
import UserList from "./commands/user/list"; import UserList from "./commands/user/list";
import UserReset from "./commands/user/reset"; import UserReset from "./commands/user/reset";
// Use "explicit" oclif strategy to avoid issues with oclif's module resolver and bundling
export const commands = { export const commands = {
"user list": UserList, "user:list": UserList,
"user delete": UserDelete, "user:delete": UserDelete,
"user create": UserCreate, "user:create": UserCreate,
"user reset": UserReset, "user:reset": UserReset,
"emoji add": EmojiAdd, "emoji:add": EmojiAdd,
}; };

View file

@ -5,7 +5,7 @@
"dollarSign": "white", "dollarSign": "white",
"flag": "white", "flag": "white",
"flagDefaultValue": "blue", "flagDefaultValue": "blue",
"flagOptions": "white", "flagOptions": "green",
"flagRequired": "red", "flagRequired": "red",
"flagSeparator": "white", "flagSeparator": "white",
"sectionDescription": "white", "sectionDescription": "white",

View file

@ -18,7 +18,7 @@ case "$1" in
"cli") "cli")
# Start the CLI # Start the CLI
shift 1 shift 1
bun run ./cli.js "$@" bun run ./cli/index.js "$@"
;; ;;
*) *)
# Run custom commands # Run custom commands