Skip to content

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

Description

@Lakes41

Background

The @guildpass/env package currently hardcodes .js file imports for schemas (./schemas/dashboard.js, ./schemas/access-api.js, etc.). This tight coupling to output file format causes failures when:

  1. TypeScript configuration changes (e.g., switching from .js to .ts imports)
  2. Build output location shifts
  3. The package is consumed differently (e.g., directly from source in development, or bundled)

Problem

Explicit .js imports in packages/env/src/index.ts or similar:

import * as dashboardSchema from './schemas/dashboard.js';
import * as accessApiSchema from './schemas/access-api.js';

Assume:

  • Files are always compiled to .js format
  • Output is always in a specific directory structure
  • Runtime resolution matches TypeScript's emit strategy

This breaks when:

  • TypeScript configuration changes
  • ESM vs. CommonJS strategies shift
  • Source files are consumed directly (e.g., in tests or development)

Expected Outcome

  • Schema imports use TypeScript syntax (.ts or no extension)
  • Build system handles .js output transparently
  • Package works in multiple consumption modes (compiled, bundled, or source)
  • Tests and docs reference schemas via stable import paths

Suggested Implementation

  1. Change schema imports in packages/env/src/ from:

    import * as dashboardSchema from './schemas/dashboard.js';

    To:

    import * as dashboardSchema from './schemas/dashboard';
    // OR
    import * as dashboardSchema from './schemas/dashboard.js' assert { type: 'json' }; // if JSON
  2. Update packages/env/tsconfig.json to ensure consistent module resolution:

    {
      "compilerOptions": {
        "moduleResolution": "bundler",
        "resolveJsonModule": true
      }
    }
  3. If schemas are separate modules, ensure they export types properly:

    // schemas/dashboard.ts
    export const dashboardSchema = { /* ... */ };
    export type DashboardSchema = typeof dashboardSchema;
  4. Update imports throughout packages/env/src/ consistently

  5. Add TypeScript triple-slash directives if needed:

    /// <reference path="./schemas/dashboard.d.ts" />
  6. Test with pnpm build -r --filter @guildpass/env and verify downstream builds (apps/dashboard, etc.) succeed

Acceptance Criteria

  • No hardcoded .js extensions in source imports
  • Schema imports use relative paths without file extensions (TypeScript resolution)
  • packages/env builds successfully with new import strategy
  • All downstream packages (apps/dashboard, etc.) resolve schemas correctly
  • Types are properly exported and inferred
  • Tests and documentation reflect new import patterns

Affected Files/Directories

  • packages/env/src/index.ts (or all source files with schema imports)
  • packages/env/src/schemas/*.ts
  • packages/env/tsconfig.json
  • Any consumer files importing from @guildpass/env

Metadata

Metadata

Assignees

Labels

Third CampaignOfficial FWC26 campaign issue — eligible for campaign scoring and rewardsadvancedAdvanced difficulty tasks requiring significant domain knowledge and implementation effortrefactorCode restructuring without changing external behavior or APItype-safetyTypeScript type system improvements and strict type enforcement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions