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

relative-import-fixer

v1.1.8

Published

CLI tool for TypeScript projects that removes unnecessary relative imports and replaces them with absolute imports based on the paths configured

Readme

relative-import-fixer

MIT License

Demo

Demo

Description

relative-import-fixer is a CLI tool for TypeScript projects that removes unnecessary relative imports and replaces them with absolute imports based on the paths configured in tsconfig.json.

It also checks for uncommitted git changes before running to ensure your working directory is clean and to prevent accidental loss of work.

This tool uses ts-morph to manipulate source code and automatically fix imports, keeping your code organized and easy to maintain.


Installation

npm install -g relative-import-fixer
# or install locally in your project
npm install relative-import-fixer

Usage

Run the command in your project root:

npx run-relative-import-fixer
npm run-relative-import-fixer
pnpm run-relative-import-fixer

The script will prompt you for:

  • The path to your tsconfig.json file (default: ./tsconfig.json)
  • The glob pattern for the TS/TSX files to process (default: src/**/*.{ts,tsx})

Before execution, the script verifies that you have no uncommitted changes and that tsconfig.json has absolute paths configured.

🧰 CLI Usage

npx relative-import-fixer [options]

📌 Options

| Flag | Alias | Description | Default | | ------------ | ----- | ------------------------------------------ | ------------------- | | --tsconfig | -t | Path to your tsconfig.json file | tsconfig.json | | --glob | -g | Glob pattern for files to process | src/**/*.{ts,tsx} | | --force | -f | Skips Git dirty check and forces execution | false | | --help | -h | Displays help information | |

📈 Example

npx run-relative-import-fixer -t ./tsconfig.base.json -g apps/student/**/*.{ts,tsx} --force

This will:

  • Skip Git check
  • Use a custom tsconfig path
  • Fix imports in the specified files

How it works

  1. Git status check: ensures no uncommitted changes exist to prevent accidental work loss.

  2. tsconfig.json validation: verifies that compilerOptions.paths contains absolute path mappings.

  3. File processing: loads the specified TS/TSX files using ts-morph and finds relative imports.

  4. Imports removal and fixing: removes relative imports that aren't Node.js built-ins or dependencies and repairs missing imports with absolute paths.

  5. Imports organization: organizes imports in each file for clean and maintainable code.


Main API / Functions

  • checkGitStatusAndExitIfDirty(): checks git status.
  • hasAbsoluteTsconfigPaths(tsconfigPath: string): validates absolute paths in tsconfig.
  • verifyTsConfigFile(tsConfigPath: string): verifies tsconfig file existence.
  • isSideEffectImport(importDecl: ImportDeclaration): verifies if the import is Side Effect Type ex:(import './index.css').
  • isPackageJsonDependency(importName: string): verifies if the import is from the packageJSON libraries.
  • isNodeBuiltin(path: string) : verifies if the import is from the core of Typescript.
  • fixRelativeImports({ globPattern, tsConfigPath }): performs the import transformation from relative to absolute.

Keywords

typescript, imports, import-fixer, relative-imports, ts-morph, code-transformation, cli-tool, nodejs, typescript-transformer, absolute-imports


Used Dependencies

Thanks to the authors and maintainers of the great open source projects that make this tool possible, especially: This project relies on the following main libraries:

  • ts-morph — TypeScript compiler API wrapper for source code manipulation.
  • simple-git — Simple interface for running Git commands in Node.js.

License

MIT License © 2025 Jhoan Hernández