Skip to content

refactor: migrate cross-boundary relative imports to path aliases#485

Open
gewenyu99 wants to merge 1 commit into
mainfrom
posthog-code/use-path-alias-imports
Open

refactor: migrate cross-boundary relative imports to path aliases#485
gewenyu99 wants to merge 1 commit into
mainfrom
posthog-code/use-path-alias-imports

Conversation

@gewenyu99
Copy link
Copy Markdown
Collaborator

Summary

  • The tsconfig already declared @env, @lib/*, @utils/*, @ui/*, @steps/*, and @frameworks/* aliases, but only @env was actually being used — everything else still leaned on ../../../... chains. This sweep makes the codebase actually use them.
  • Adds non-wildcard @ui and @steps aliases (mirrored in Jest's moduleNameMapper) so directory-style imports like import { getUI } from '@ui' resolve through the package's index.ts. The existing wildcard aliases only handle nested paths.
  • Rewrites every relative import that crossed a top-level src/ boundary to use the appropriate alias. Same-directory imports (./foo) are intentionally left alone.
  • Drops the .js suffix from aliased imports — Jest's mapper can't resolve @lib/foo.js to a .ts file, and the bundler resolves aliased paths without needing the extension.

253 files touched, no behavior changes.

Test plan

  • pnpm build passes (smoke test included)
  • pnpm jest — 645/645 tests pass
  • pnpm lint — 0 errors (pre-existing warnings only)
  • pnpm typecheck clean

The tsconfig already declared `@env`, `@lib/*`, `@utils/*`, `@ui/*`,
`@steps/*`, and `@frameworks/*` aliases, but only `@env` was actually
being used — everything else still leaned on `../../../...` chains.

This sweep:

- Adds non-wildcard `@ui` and `@steps` aliases so directory-style
  imports (`import { getUI } from '@ui'`) resolve via the index file,
  matching how the wildcard aliases handle nested paths.
- Mirrors the same change in Jest's `moduleNameMapper`.
- Rewrites every relative import that crossed a top-level src/
  boundary to use the appropriate alias. Same-directory imports
  (`./foo`) are left alone.
- Drops the `.js` suffix from aliased imports — Jest's mapper can't
  resolve `@lib/foo.js` to a `.ts` file, and the bundler resolves
  alias paths without needing the extension.

No behavior changes. `pnpm build`, `pnpm jest` (645/645), and
`pnpm lint` all clean.

Generated-By: PostHog Code
Task-Id: a03625d7-3f4a-408e-8c35-a57678c42f36
@github-actions
Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci basic-integration
  • /wizard-ci misc
  • /wizard-ci revenue

Test an individual app:

  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
Show more apps
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci misc/quack-quack
  • /wizard-ci revenue/stripe

Results will be posted here when complete.

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.

1 participant