refactor(env): eliminate hardcoded .js imports via dynamic schema resolution - #358
Merged
Lakes41 merged 1 commit intoAug 24, 2026
Conversation
…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>
Closed
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #338
Refactors
@guildpass/envto eliminate hardcoded.jsfile 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 foraccess-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.tsand../src/validate.ts(source-direct consumption, no emit-format coupling).packages/env/tsconfig.json— enabledallowImportingTsExtensions+rewriteRelativeImportExtensions.tscrewrites.ts→.json emit, so compiled output stays valid Node ESM.packages/env/package.json— bumpedtypescriptdevDependency to^5.7.0(minimum required forrewriteRelativeImportExtensions).Why
.tsextensions 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:tscemits extensionless relative specifiers verbatim, sonode packages/env/dist/cli/index.jsand directimport("@guildpass/env")both fail withERR_MODULE_NOT_FOUND. The repo has no bundler in the build chain (all packages compile with plaintsc), so there is no bundler to resolve those specifiers. Using.tsextensions (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 existingtsc-only build.Verification
pnpm --filter @guildpass/env build— passespnpm --filter @guildpass/env typecheck— passespnpm --filter @guildpass/env test— 7/7 passnode packages/env/dist/cli/index.js --app dashboard— runs correctlyimport("@guildpass/env")in Node ESM — resolves all exportsapps/dashboardtypecheck — unchanged (only pre-existing@guildpass/metricserrors; the@guildpass/metricsand@guildpass/contractsclean-build failures exist onmaintoo)