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 🙏

© 2026 – Pkg Stats / Ryan Hefner

update-imports-with-path-alias

v1.0.2

Published

NPX tool for updating TypeScript import paths based on path aliases defined in tsconfig.json

Readme

update-imports-with-path-alias

An NPX tool that automatically updates import paths in TypeScript and JavaScript projects to use path aliases defined in your tsconfig.json.

What does it do?

When you add path aliases to your tsconfig.json, this tool will scan all your source files and replace relative imports with the new aliased imports.

Features

  • 🚀 Zero installation - Run directly with npx
  • 📁 Auto-discovery - Works with your existing tsconfig.json
  • 🔄 Smart replacement - Converts relative imports to path aliases
  • 🎯 Precise targeting - Only updates imports that match your aliases
  • 💾 Safe operation - Preserves query parameters and hash fragments
  • 📦 Multi-format support - Works with .ts, .tsx, .js, .jsx files

Quick Start

  1. Add path aliases to your tsconfig.json:
{
  "compilerOptions": {
    "paths": {
      "@/*": ["./src/*"],
      "@components/*": ["./src/components/*"],
      "@utils/*": ["./src/utils/*"]
    }
  }
}
  1. Run the tool in your project root:
npx update-imports-with-path-alias

That's it! All your imports will be updated automatically.

Usage

Basic Usage

# Run from your project root directory
npx update-imports-with-path-alias

Typical Workflow

  1. Set up path aliases in your tsconfig.json
  2. Run the tool to update all existing imports
  3. Continue developing with your new path aliases

How It Works

  1. 📖 Reads your project's tsconfig.json
  2. 🔍 Extracts path aliases from compilerOptions.paths
  3. 📂 Scans all .ts, .tsx, .js, .jsx files in src/
  4. 🔄 Replaces relative imports with matching path aliases
  5. ✅ Reports which files were updated

Example Transformation

Before (relative imports):

// src/components/Button/Button.tsx
import { validateEmail } from "../../../utils/validation";
import { Modal } from "../../Modal/Modal";
import { Icon } from "../Icon/Icon";

After (path aliases):

// src/components/Button/Button.tsx
import { validateEmail } from "@/utils/validation";
import { Modal } from "@/components/Modal/Modal";
import { Icon } from "@/components/Icon/Icon";

Requirements

  • Node.js 14 or higher
  • tsconfig.json file in your project root with paths configured
  • src directory containing your source files
  • TypeScript or JavaScript project

Why Use This Tool?

Before Path Aliases

import { Button } from "../../../components/ui/Button";
import { useAuth } from "../../../../hooks/useAuth";
import { ApiClient } from "../../../../../services/api";

After Path Aliases

import { Button } from "@/components/ui/Button";
import { useAuth } from "@/hooks/useAuth";
import { ApiClient } from "@/services/api";

Benefits:

  • ✅ Shorter, cleaner imports
  • ✅ Less prone to breaking when moving files
  • ✅ Easier to read and understand
  • ✅ Better IDE autocomplete support

Troubleshooting

No files updated?

  • Ensure your tsconfig.json has paths configured
  • Check that you have a src/ directory with source files
  • Verify you're running the command from your project root

Imports not working after update?

  • Make sure your bundler/compiler supports TypeScript path aliases
  • For Webpack, you may need to configure resolve aliases
  • For Vite, path aliases should work out of the box

Contributing

Contributions are welcome! This tool is designed to be simple and focused.

License

MIT License - feel free to use in your projects!


💡 Tip: Run this tool whenever you add new path aliases to your tsconfig.json to keep your imports consistent!