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

alias-solver

v1.0.1

Published

Convert relative imports to alias-based imports automatically — and back. Auto-detects tsconfig, vite, and webpack alias configs.

Readme

alias-solver

A CLI tool that automatically converts relative imports (../../foo) to alias-based imports (@/foo) — and back. Works out of the box: auto-detects existing alias configs, or generates them from your folder structure if none exist.

Features

  • Zero-config: no aliases configured? The tool scans your src/ folders and generates them for you
  • Auto-detection of existing alias config from tsconfig / vite / webpack
  • Converts relative imports → alias imports
  • Reverts alias imports → relative imports (--revert)
  • Dry-run mode to preview changes before applying
  • Targets a specific file or directory with --path
  • Handles import, require(), dynamic import(), and export ... from statements
  • Picks the most specific alias (e.g. @ui/ over @components/ over @/)
  • Colorized terminal output showing every change
  • Fully idempotent — running twice produces no extra changes

Quick start

No install needed — just run in your project:

npx alias-solver

That's it. If your project has no alias config, the tool will:

  1. Scan your src/ (or app/, lib/) directory
  2. Generate aliases based on folder names (@components/*, @utils/*, etc.)
  3. Write them to tsconfig.json
  4. Convert all relative imports to alias imports

Installation

# Use directly (no install)
npx alias-solver

# Or install globally
npm install -g alias-solver

# Or install locally in your project
npm install --save-dev alias-solver

Usage

alias-solver [options]

Options:
  -d, --dry-run      Preview changes without modifying files
  -r, --revert       Revert alias imports back to relative paths
  -p, --path <p>     Target a specific file or directory
  -R, --recursive    With --path, include subdirectories (default: direct files only)
  -h, --help         Show help
  -v, --version      Show version

Convert relative → alias

alias-solver

Preview changes first

alias-solver --dry-run

Revert alias → relative

alias-solver --revert

Target a specific folder (direct files only)

alias-solver --path src/hooks
# Only processes files directly in src/hooks/ (useAuth.ts, useTheme.ts)
# Does NOT touch files in subdirectories

Target a folder recursively

alias-solver --path src/components --recursive
# Processes all files in src/components/ AND all subdirectories
# (ui/buttons/Button.tsx, layout/sidebar/Sidebar.tsx, etc.)

Target a single file

alias-solver --path src/pages/dashboard/Dashboard.tsx

Combine flags

All flags work together. --revert respects --path and --recursive:

# Revert only direct files in src/hooks/
alias-solver --revert -p src/hooks

# Revert all files in src/components/ and subdirectories
alias-solver --revert -p src/components -R

# Preview a scoped revert without modifying anything
alias-solver --revert --dry-run -p src/components -R

How it works

With existing config

If your project already has aliases defined in tsconfig.json, vite.config, or webpack.config, the tool reads them and converts imports accordingly.

Without config (auto-generation)

If no aliases are found, the tool scans your source directory and generates them automatically:

src/
├── components/    →  @components/*
├── hooks/         →  @hooks/*
├── lib/           →  @lib/*
├── pages/         →  @pages/*
├── services/      →  @services/*
├── store/         →  @store/*
├── types/         →  (via catch-all @/*)
└── utils/         →  @utils/*

Plus catch-all:      @/*  →  src/*

The generated aliases are written to tsconfig.json automatically, then imports are converted.

Note: Folder names that conflict with npm scopes (like types) are skipped as dedicated aliases and handled by the catch-all @/* instead (e.g. @/types).

Example

Before:

import { Sidebar } from '../../components/layout/sidebar/Sidebar';
import { BarChart } from './widgets/charts/BarChart';
import { useAuth } from '../../hooks/useAuth';
import { User } from '../../types';

After:

import { Sidebar } from '@components/layout/sidebar/Sidebar';
import { BarChart } from '@pages/dashboard/widgets/charts/BarChart';
import { useAuth } from '@hooks/useAuth';
import { User } from '@/types';

Supported alias configurations

tsconfig.json (recommended)

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"],
      "@components/*": ["src/components/*"],
      "@utils/*": ["src/utils/*"]
    }
  }
}

vite.config.ts

export default defineConfig({
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
      '@components': path.resolve(__dirname, 'src/components'),
    },
  },
});

webpack.config.js

module.exports = {
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
      '@components': path.resolve(__dirname, 'src/components'),
    },
  },
};

Detection priority: tsconfig.json > vite.config.{ts,js} > webpack.config.{js,ts} > auto-generation from folders.

Warning: Avoid naming an alias @types/* — it conflicts with npm's @types scope (used for DefinitelyTyped packages like @types/node). Use the catch-all @/* instead, which produces @/types.

Man page

After installing globally, you can view the manual:

man alias-solver

License

MIT