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

@frantisekstanko/tsconfig-alias-converter

v0.3.0

Published

Convert relative imports to TypeScript path aliases based on tsconfig.json

Readme

tsconfig-alias-converter

CI npm version License: MIT codecov Bundle Size TypeScript

Convert relative imports to TypeScript path aliases automatically, based on your tsconfig.json configuration.

Features

  • 🎯 Zero configuration - Reads path aliases directly from tsconfig.json
  • 🚀 CLI tool - Easy to integrate into your workflow
  • 📦 Programmatic API - Use it in your own tools
  • 🔒 Type-safe - Full TypeScript support
  • 🏗️ Clean architecture - Well-structured and maintainable code

Installation

npm install --save-dev @frantisekstanko/tsconfig-alias-converter

Usage

CLI

Convert imports in specific files:

npx tsconfig-alias-converter src/**/*.ts

Specify a custom tsconfig path:

npx tsconfig-alias-converter src/**/*.ts --tsconfig=./tsconfig.build.json

Programmatic API

import { TsconfigAliasConverter } from '@frantisekstanko/tsconfig-alias-converter'

const result = TsconfigAliasConverter.processFiles(
  ['src/file1.ts', 'src/file2.ts'],
  './tsconfig.json',
)

console.log(`Modified ${result.modifiedCount} of ${result.totalCount} files`)

Advanced Usage

Use individual components for more control:

import {
  TsconfigReader,
  ImportRewriter,
  FileProcessor,
} from '@frantisekstanko/tsconfig-alias-converter'

const aliasConfigs = TsconfigReader.readAliasConfigurations('./tsconfig.json')
const rewriter = new ImportRewriter(aliasConfigs)
const processor = new FileProcessor(rewriter)

const wasModified = processor.processFile('./src/example.ts')

How It Works

Given a tsconfig.json with path aliases:

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

The tool will convert relative imports:

import { helper } from '../../../utils/helper.js'
import { config } from '../../config.js'

To alias imports:

import { helper } from '@/utils/helper.js'
import { config } from '@/config.js'

Integration

With package.json scripts

{
  "scripts": {
    "fix-imports": "tsconfig-alias-converter src/**/*.ts tests/**/*.ts"
  }
}

With git hooks (using husky)

npx husky add .husky/pre-commit "npm run fix-imports"

With lint-staged

{
  "lint-staged": {
    "*.ts": ["tsconfig-alias-converter"]
  }
}

API

TsconfigAliasConverter.processFiles(filePaths, tsconfigPath?)

Process multiple files and convert their imports.

  • filePaths: Array of file paths to process
  • tsconfigPath: Optional path to tsconfig.json (defaults to ./tsconfig.json)
  • Returns: { modifiedCount: number, totalCount: number }

TsconfigReader.readAliasConfigurations(tsconfigPath)

Read and parse path alias configurations from tsconfig.json.

  • tsconfigPath: Path to tsconfig.json
  • Returns: AliasConfiguration[]

ImportRewriter

Rewrite imports in file content.

const rewriter = new ImportRewriter(aliasConfigurations)
const { modified, content } = rewriter.rewriteImportsInFile(
  filePath,
  fileContent,
)

FileProcessor

Process files on disk.

const processor = new FileProcessor(importRewriter)
const wasModified = processor.processFile(filePath)

Requirements

  • Node.js >= 20.0.0
  • npm >= 10.0.0

License

MIT © Frantisek Stanko