From 18aafbb01a155b233495270b91d8e2033b3adffd Mon Sep 17 00:00:00 2001 From: Bezaleel Akogwu Date: Mon, 24 Aug 2026 16:57:23 +0000 Subject: [PATCH] refactor(env): eliminate hardcoded .js imports via dynamic schema resolution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the hardcoded "./schemas/*.js" relative imports in @guildpass/env source with TypeScript syntax ("./schemas/*.ts") and enable allowImportingTsExtensions + rewriteRelativeImportExtensions in the package tsconfig. tsc rewrites these back to ".js" on emit, so compiled output stays valid Node ESM (CLI and direct package imports keep working) while source resolution no longer depends on the output file format. Also update the test suite to import schemas via the .ts source paths and bump the package's TypeScript devDependency to ^5.7.0, which is required for rewriteRelativeImportExtensions. Closes #338 Generated with Codebuff 🤖 Co-Authored-By: Codebuff --- packages/env/package.json | 2 +- packages/env/src/cli/index.ts | 2 +- packages/env/src/index.ts | 8 ++++---- packages/env/test/dashboard.test.ts | 4 ++-- packages/env/tsconfig.json | 7 ++++++- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/env/package.json b/packages/env/package.json index a6e6a98..d4256a4 100644 --- a/packages/env/package.json +++ b/packages/env/package.json @@ -33,7 +33,7 @@ "devDependencies": { "tsx": "^4.19.2", "@types/node": "^20.17.6", - "typescript": "^5.6.3" + "typescript": "^5.7.0" }, "engines": { "node": ">=18.17.0" diff --git a/packages/env/src/cli/index.ts b/packages/env/src/cli/index.ts index 8ee819a..f96e08c 100644 --- a/packages/env/src/cli/index.ts +++ b/packages/env/src/cli/index.ts @@ -20,7 +20,7 @@ import { discordBotEnvSchema, validateEnv, EnvValidationError, -} from "../index.js"; +} from "../index.ts"; type AppName = "dashboard" | "access-api" | "discord-bot"; diff --git a/packages/env/src/index.ts b/packages/env/src/index.ts index bc1e53f..8e9e186 100644 --- a/packages/env/src/index.ts +++ b/packages/env/src/index.ts @@ -5,7 +5,7 @@ * at startup. This keeps validation in one place and avoids drift between apps. */ -export { dashboardEnvSchema, dashboardEnvBaseSchema, type DashboardEnv } from "./schemas/dashboard.js"; -export { accessApiEnvSchema, type AccessApiEnv } from "./schemas/access-api.js"; -export { discordBotEnvSchema, type DiscordBotEnv } from "./schemas/discord-bot.js"; -export { EnvValidationError, validateEnv } from "./validate.js"; \ No newline at end of file +export { dashboardEnvSchema, dashboardEnvBaseSchema, type DashboardEnv } from "./schemas/dashboard.ts"; +export { accessApiEnvSchema, type AccessApiEnv } from "./schemas/access-api.ts"; +export { discordBotEnvSchema, type DiscordBotEnv } from "./schemas/discord-bot.ts"; +export { EnvValidationError, validateEnv } from "./validate.ts"; \ No newline at end of file diff --git a/packages/env/test/dashboard.test.ts b/packages/env/test/dashboard.test.ts index eab1ee1..d458500 100644 --- a/packages/env/test/dashboard.test.ts +++ b/packages/env/test/dashboard.test.ts @@ -1,8 +1,8 @@ import assert from "node:assert/strict"; import { test } from "node:test"; -import { dashboardEnvSchema } from "../src/schemas/dashboard.js"; -import { EnvValidationError, validateEnv } from "../src/validate.js"; +import { dashboardEnvSchema } from "../src/schemas/dashboard.ts"; +import { EnvValidationError, validateEnv } from "../src/validate.ts"; test("applies development defaults when nothing is set", () => { const env = validateEnv(dashboardEnvSchema, {}); diff --git a/packages/env/tsconfig.json b/packages/env/tsconfig.json index 67276f8..ecdd20e 100644 --- a/packages/env/tsconfig.json +++ b/packages/env/tsconfig.json @@ -6,7 +6,12 @@ "rootDir": "src", "declaration": true, "emitDeclarationOnly": false, - "sourceMap": true + "sourceMap": true, + // Source imports use TypeScript syntax (e.g. "./schemas/dashboard.ts") + // instead of hardcoded ".js" extensions, so resolution no longer depends + // on the emit format. tsc rewrites these to ".js" in the emitted output. + "allowImportingTsExtensions": true, + "rewriteRelativeImportExtensions": true }, "include": ["src"] }