rename_filesystem_entry_by_tsmorph
Renames or moves TypeScript/JavaScript files and folders, automatically rewriting all import and export paths that reference them. Supports batch operations for efficient code reorganization.
Instructions
[ts-morph] Rename or move one or more TypeScript/JavaScript files and/or folders, and automatically rewrite every import/export path that references them.
When to use
Renaming or moving any .ts/.tsx/.js/.jsx file or directory (single or batch).
Prefer this over
mv+ manual import fixing. This tool resolves references via the type checker, so it handles relative paths, path aliases (@/), and barrel imports (from '.',from '..') that grep cannot reliably find.Use batch mode (multiple entries in
renames) when reorganizing several files at once -- a single AST pass is much faster than running the tool repeatedly.
When NOT to use
Renaming a symbol inside a file ->
rename_symbol_by_tsmorph.Moving a single symbol (not the whole file) to another file ->
move_symbol_to_file_by_tsmorph.
Critical constraints
Path aliases in updated imports are REWRITTEN AS RELATIVE PATHS (e.g.,
@/foo->../foo). If you want to keep aliases, runremove_path_alias_by_tsmorphseparately beforehand, or accept the conversion.Barrel imports like
import X from '../components'are rewritten to point at the resolved index file (e.g.,'../components/index.tsx').Default exports declared via a bare identifier (
export default Foo;) may not be updated correctly. Default function/class declarations (export default function foo() {}) are handled.All paths (
tsconfigPath,oldPath,newPath) MUST be absolute.The tool refuses to run on path conflicts (target already exists, duplicate destinations).
Tips
Run with
dryRun: truefirst for any non-trivial rename to inspect the affected file list.timeoutSecondsdefaults to 120; raise it for very large projects or huge batch renames.
Result
Returns the list of modified (or to-be-modified, in dryRun) file paths, plus status and processing time. On timeout the operation is cancelled and an error is returned.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tsconfigPath | Yes | Absolute path to the project's tsconfig.json file. | |
| renames | Yes | An array of rename operations, each with oldPath and newPath. | |
| dryRun | No | If true, only show intended changes without modifying files. | |
| timeoutSeconds | No | Maximum time in seconds allowed for the operation before it times out. Defaults to 120. |