From 37bc4458e5718c1b0978650c914e315f5de429ec Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Mon, 14 Apr 2025 17:30:01 +0200 Subject: [PATCH] test: :test_tube: Fix failing tests due to incorrect cwd resolving --- app.ts | 6 +++--- bun.lock | 1 + classes/config/schema.ts | 5 +---- packages/client/package.json | 3 ++- packages/client/schemas/common.ts | 1 + pnpm-lock.yaml | 3 +++ routes.ts | 9 ++------- utils/lib.ts | 7 ------- 8 files changed, 13 insertions(+), 22 deletions(-) diff --git a/app.ts b/app.ts index e42f1b9c..0a508049 100644 --- a/app.ts +++ b/app.ts @@ -1,5 +1,6 @@ -import { join } from "node:path"; /* import { prometheus } from "@hono/prometheus"; */ + +import { resolve } from "node:path"; import { getLogger } from "@logtape/logtape"; import { apiReference } from "@scalar/hono-api-reference"; import chalk from "chalk"; @@ -27,7 +28,6 @@ import { routes } from "./routes.ts"; import type { ApiRouteExports, HonoEnv } from "./types/api.ts"; // Extends Zod with OpenAPI schema generation import "zod-openapi/extend"; -import { cwdFromEntrypoint } from "@/lib.ts"; export const appFactory = async (): Promise> => { await configureLoggers(); @@ -122,7 +122,7 @@ export const appFactory = async (): Promise> => { const loader = new PluginLoader(); const plugins = await loader.loadPlugins( - join(cwdFromEntrypoint(), "plugins"), + resolve("./plugins"), config.plugins?.autoload ?? true, config.plugins?.overrides.enabled, config.plugins?.overrides.disabled, diff --git a/bun.lock b/bun.lock index 3f39735e..bc00ed50 100644 --- a/bun.lock +++ b/bun.lock @@ -95,6 +95,7 @@ "@badgateway/oauth2-client": "^2.4.2", "iso-639-1": "^3.1.5", "zod": "^3.24.2", + "zod-openapi": "^4.2.4", }, }, "packages/plugin-kit": { diff --git a/classes/config/schema.ts b/classes/config/schema.ts index 8bc8fcc6..bc47e6f7 100644 --- a/classes/config/schema.ts +++ b/classes/config/schema.ts @@ -5,7 +5,6 @@ import { generateVAPIDKeys } from "web-push"; import { z } from "zod"; import { ZodError } from "zod"; import { fromZodError } from "zod-validation-error"; -import { cwdFromEntrypoint } from "@/lib.ts"; import { ProxiableUrl } from "~/classes/media/url.ts"; import { RolePermission } from "~/packages/client/schemas/permissions.ts"; @@ -402,9 +401,7 @@ export const ConfigSchema = z }), frontend: z.strictObject({ enabled: z.boolean().default(true), - path: z - .string() - .default(env.VERSIA_FRONTEND_PATH || cwdFromEntrypoint()), + path: z.string().default(env.VERSIA_FRONTEND_PATH || "frontend"), routes: z.strictObject({ home: urlPath.default("/"), login: urlPath.default("/oauth/authorize"), diff --git a/packages/client/package.json b/packages/client/package.json index cd615d24..ad42ca2e 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -65,6 +65,7 @@ "dependencies": { "@badgateway/oauth2-client": "^2.4.2", "iso-639-1": "^3.1.5", - "zod": "^3.24.2" + "zod": "^3.24.2", + "zod-openapi": "^4.2.4" } } diff --git a/packages/client/schemas/common.ts b/packages/client/schemas/common.ts index 621bb019..e3eeef6f 100644 --- a/packages/client/schemas/common.ts +++ b/packages/client/schemas/common.ts @@ -1,5 +1,6 @@ import ISO6391 from "iso-639-1"; import { z } from "zod"; +import "zod-openapi/extend"; export const Id = z.string().uuid(); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4f861b05..a6543da4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -257,6 +257,9 @@ importers: zod: specifier: ^3.24.2 version: 3.24.2 + zod-openapi: + specifier: ^4.2.4 + version: 4.2.4(zod@3.24.2) packages/plugin-kit: dependencies: diff --git a/routes.ts b/routes.ts index f35ad188..aa0a7f3a 100644 --- a/routes.ts +++ b/routes.ts @@ -1,18 +1,13 @@ -import { join } from "node:path"; import { FileSystemRouter } from "bun"; -import { cwdFromEntrypoint } from "@/lib.ts"; // Returns the route filesystem path when given a URL export const routeMatcher = new FileSystemRouter({ style: "nextjs", - dir: `${cwdFromEntrypoint()}/api`, + dir: "api", fileExtensions: [".ts", ".js"], }); export const routes = Object.fromEntries( Object.entries(routeMatcher.routes) .filter(([route]) => !route.endsWith(".test")) - .map(([route, path]) => [ - route, - path.replace(join(cwdFromEntrypoint()), "."), - ]), + .map(([route, path]) => [route, path]), ) as Record; diff --git a/utils/lib.ts b/utils/lib.ts index 4fc63578..a5cb0dac 100644 --- a/utils/lib.ts +++ b/utils/lib.ts @@ -1,6 +1,3 @@ -import { dirname } from "node:path"; -import { main } from "bun"; - type ElementWithId = { id: string }; export const mergeAndDeduplicate = ( @@ -12,7 +9,3 @@ export const mergeAndDeduplicate = ( (element, index, self) => index === self.findIndex((t) => t.id === element.id), ); - -export const cwdFromEntrypoint = (): string => { - return dirname(main); -};