npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ts-path-alias-fixer

v1.1.0

Published

Fix relative path imports in TypeScript/javascript to use custom alias like @/src

Downloads

181

Readme

ts-path-alias-fixer

Fix relative path imports in TypeScript/JavaScript to use custom aliases like @/.

✨ Features

  • Converts long relative paths to clean alias imports
  • Converts relative imports under a base directory (e.g., src/) to a custom alias (e.g., @/).
  • Provides dry-run option to preview the files that would be modified without saving
  • Supports .ts, .tsx, .js, .jsx, .mjs, and .cjs files.
  • Supports TypeScript projects using tsconfig.json paths
  • CLI-based, fast and easy to use
  • Easy to integrate into your build or development workflow.

📦 Installation

Global Install

npm install -g ts-path-alias-fixer

Local Install (recommended)

Install as a development dependency in your project:

npm install --save-dev ts-path-alias-fixer

or with Yarn:

yarn add --dev ts-path-alias-fixer

Usage

CLI Usage

General

Run the CLI tool from your project root (or specify a directory):

npx fix-ts-imports

or if installed globally:

fix-ts-imports

CLI Options

| Options | Descriptions | Default | | ----------- | :-----------------------------------------------: | :--------------------: | | -d, --dir | Project root directory | ./ (Current directory) | | -a, --alias | Alias to replace relative paths with | @ | | -b, --base | Base folder inside the project to replace | src | | --dry-run | Show which files would be modified without saving | false |

Example Usage:

In your project, if there are files which has relative path imports which needs to be modified to use custom path alias as below

Let's say it should convert:

import { greet } from '../utils/helpers';

To:

import { greet } from '@/utils/helpers';

Run with dry-run option:

In your project, before modifying your existing files by using this tool, if you want to check and understand what files will get affected

Preview changes without modifying files:

npx fix-ts-imports --dry-run

Run with custom options:

npx fix-ts-imports --dir ./src --alias @ --base src --dry-run

Example Output

Once you run the cli command as above with dry-run, you should see some output console logs which will indicate how many files would be modified with custom path alias imports and what are their file paths in your project as below

🔍 Dry run: 3 file(s) would be modified.
 - src\index.ts
 - src\utils\helper.ts
 - src\api\v1\index.ts

Run to modify files:

If you are happy with the --dry-run output and want to proceed with the file changes in your project, run this tool as below

npx fix-ts-imports

or

npx fix-ts-imports --dir ./ --alias @ --base src

Example Output

Once you run the cli command as above, you should see some output console logs which will indicate how many files have been modified with custom path alias imports in our project

✅ Imports fixed in 3 file(s).