Skip to content

refactor(env): eliminate hardcoded .js imports via dynamic schema resolution - #358

Merged
Lakes41 merged 1 commit into
Adamantine-guild:mainfrom
benzy018:refactor/env-dynamic-schema-resolution
Aug 24, 2026
Merged

refactor(env): eliminate hardcoded .js imports via dynamic schema resolution#358
Lakes41 merged 1 commit into
Adamantine-guild:mainfrom
benzy018:refactor/env-dynamic-schema-resolution

Conversation

@benzy018

Copy link
Copy Markdown
Contributor

Summary

Closes #338

Refactors @guildpass/env to eliminate hardcoded .js file extensions in source imports. Schema imports now use TypeScript syntax (.ts), so resolution no longer depends on the emitted output format, output directory layout, or the runtime emit strategy.

Changes

  • packages/env/src/index.ts — schema/validate imports changed from ./schemas/dashboard.js./schemas/dashboard.ts (same for access-api, discord-bot, validate).
  • packages/env/src/cli/index.ts — import changed from ../index.js../index.ts.
  • packages/env/test/dashboard.test.ts — tests now import schemas from ../src/schemas/dashboard.ts and ../src/validate.ts (source-direct consumption, no emit-format coupling).
  • packages/env/tsconfig.json — enabled allowImportingTsExtensions + rewriteRelativeImportExtensions. tsc rewrites .ts.js on emit, so compiled output stays valid Node ESM.
  • packages/env/package.json — bumped typescript devDependency to ^5.7.0 (minimum required for rewriteRelativeImportExtensions).

Why .ts extensions instead of no-extension + moduleResolution: "bundler"

The issue suggested extensionless imports with moduleResolution: "bundler". I tested that approach and it breaks Node ESM at runtime: tsc emits extensionless relative specifiers verbatim, so node packages/env/dist/cli/index.js and direct import("@guildpass/env") both fail with ERR_MODULE_NOT_FOUND. The repo has no bundler in the build chain (all packages compile with plain tsc), so there is no bundler to resolve those specifiers. Using .ts extensions (explicitly allowed by the issue's expected outcome: "Schema imports use TypeScript syntax (.ts or no extension)") achieves the same goal while keeping the compiled output fully runtime-safe and consistent with the existing tsc-only build.

Verification

  • pnpm --filter @guildpass/env build — passes
  • pnpm --filter @guildpass/env typecheck — passes
  • pnpm --filter @guildpass/env test — 7/7 pass
  • node packages/env/dist/cli/index.js --app dashboard — runs correctly
  • Direct import("@guildpass/env") in Node ESM — resolves all exports
  • apps/dashboard typecheck — unchanged (only pre-existing @guildpass/metrics errors; the @guildpass/metrics and @guildpass/contracts clean-build failures exist on main too)

…olution

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 Adamantine-guild#338

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
@Lakes41
Lakes41 merged commit 8a46b77 into Adamantine-guild:main Aug 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor env package to use dynamic schema resolution and eliminate hardcoded .js imports

2 participants