Skip to content

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

Merged
gewenyu99 merged 1 commit into
mainfrom
posthog-code/use-path-alias-imports
May 27, 2026
Merged

chore: migrate cross-boundary relative imports to path aliases#485
gewenyu99 merged 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.

@gewenyu99 gewenyu99 changed the title refactor: migrate cross-boundary relative imports to path aliases chore: migrate cross-boundary relative imports to path aliases May 27, 2026
@gewenyu99 gewenyu99 requested a review from a team May 27, 2026 18:09
@gewenyu99
Copy link
Copy Markdown
Collaborator Author

/wizard-ci basic-integration/next-js

@wizard-ci-bot
Copy link
Copy Markdown

wizard-ci-bot Bot commented May 27, 2026

🧙 Wizard CI Results

Trigger ID: a706439
Workflow: View run

App Confidence PR YARA
basic-integration/next-js/15-app-router-saas 4/5 #1677 (logs)
basic-integration/next-js/15-app-router-todo 4/5 #1675 (logs)
basic-integration/next-js/15-pages-router-saas 4/5 #1678 (logs)
basic-integration/next-js/15-pages-router-todo 5/5 #1676 (logs)

Configuration

Setting Value
Wizard ref posthog-code/use-path-alias-imports
Context Mill ref main
PostHog ref master

Search for trigger ID a706439 in wizard-workbench PRs.

Copy link
Copy Markdown
Collaborator

@daniloc daniloc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hell yeah

@gewenyu99 gewenyu99 merged commit 3641935 into main May 27, 2026
19 checks passed
@gewenyu99 gewenyu99 deleted the posthog-code/use-path-alias-imports branch May 27, 2026 18:58
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.

2 participants