remove_path_alias_by_tsmorph
Converts TypeScript path alias imports and exports to relative paths using tsconfig.json path mappings, enabling standardization on relative paths for a codebase subset.
Instructions
[ts-morph] Convert path-alias imports/exports (e.g., @/components/Button) to relative paths (../../components/Button) within a target file or directory.
When to use
Standardizing on relative paths for a subset of the codebase.
Preparing for a large
rename_filesystem_entry_by_tsmorphrun when you want to control alias rewriting explicitly (note:rename_filesystem_entry_by_tsmorphalready rewrites aliases to relative paths automatically; run this tool first only if you want the conversion to be a separate, reviewable commit).Prefer this over manual find/replace -- relative path computation is error-prone across nested directories.
When NOT to use
The project has no
pathsmapping intsconfig.json(this tool has nothing to do).You want to ADD aliases or change one alias to another (not supported).
Critical constraints
Aliases are read from the
pathsoption of the project'stsconfig.json. Only those aliases are resolved.targetPathmay be a single file OR a directory. Directory targets process every.ts/.tsxfile under it.All paths (
tsconfigPath,targetPath) MUST be absolute.
Tips
Run with
dryRun: truefirst when applying to a directory, to confirm the scope.
Result
Returns the list of modified (or to-be-modified, in dryRun) file paths, plus status and processing time.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tsconfigPath | Yes | Absolute path to the project's tsconfig.json file. | |
| targetPath | Yes | Absolute path to the target file or directory. | |
| dryRun | No | If true, only show intended changes without modifying files. |