1.4 KiB
1.4 KiB
name, description, license, triggers
| name | description | license | triggers | |||
|---|---|---|---|---|---|---|
| alias-guardian | Refactors relative imports into tsconfig/Vite aliases (e.g., `@/components`) to keep imports consistent and resilient to file moves. | MIT |
|
Alias Guardian
When to use this skill
- Run after adding
tsconfigpath aliases or when many long relative imports exist. - Triggered by prompts to convert
../../..style imports to@/aliases.
Instructions
-
First Step: Ensure
tsconfig.jsonhaspathsconfigured ("@/*": ["src/*"]) andvite.config.tssupports the aliases (viavite-tsconfig-pathsor manualresolve.alias). -
Second Step: Use an AST-based tool (e.g.,
jscodeshift,ts-morph) or a controlled regex to find and replace relative import paths. Prefer AST to avoid accidental matches. -
Third Step: Update affected files' imports to the alias form and run TypeScript to verify no resolution errors.
Examples
- Before:
import PaperCard from '../../components/molecules/PaperCard' - After:
import PaperCard from '@/components/molecules/PaperCard'
Additional Resources
- ts-morph: https://github.com/dsherret/ts-morph
- jscodeshift: https://github.com/facebook/jscodeshift
Notes
- Always run tests and TypeScript type-check after mass refactors; commit in a dedicated branch and use Git to move files safely.