MCP ts-morph Refactoring Tools

remove_path_alias_by_tsmorph

Convert TypeScript path aliases to relative paths using tsconfig.json for improved portability or project conventions. Specify target files or directories and optionally preview changes with a dry run.

Instructions

[Uses ts-morph] Replaces path aliases (e.g., '@/') with relative paths in import/export statements within the specified target path.

Analyzes the project based on tsconfig.json to resolve aliases and calculate relative paths.

Usage

Use this tool to convert alias paths like import Button from '@/components/Button' to relative paths like import Button from '../../components/Button'. This can be useful for improving portability or adhering to specific project conventions.

  1. Specify the absolute path to the projecttsconfig.json.
  2. Specify the absolute path to the target file or directory where path aliases should be removed.
  3. Optionally, run with dryRun: true to preview the changes without modifying files.

Parameters

  • tsconfigPath (string, required): Absolute path to the projecttsconfig.json file. Must be an absolute path.
  • targetPath (string, required): The absolute path to the file or directory to process. Must be an absolute path.
  • dryRun (boolean, optional): If true, only show intended changes without modifying files. Defaults to false.

Result

  • On success: Returns a message containing the list of file paths modified (or scheduled to be modified if dryRun).
  • On failure: Returns a message indicating the error.

Input Schema

NameRequiredDescriptionDefault
dryRunNoIf true, only show intended changes without modifying files.
targetPathYesAbsolute path to the target file or directory.
tsconfigPathYesAbsolute path to the project's tsconfig.json file.

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "dryRun": { "default": false, "description": "If true, only show intended changes without modifying files.", "type": "boolean" }, "targetPath": { "description": "Absolute path to the target file or directory.", "type": "string" }, "tsconfigPath": { "description": "Absolute path to the project's tsconfig.json file.", "type": "string" } }, "required": [ "tsconfigPath", "targetPath" ], "type": "object" }

You must be authenticated.

Other Tools from MCP ts-morph Refactoring Tools

Related Tools

ID: byunmqla3h