Skip to main content

Paul Armstrong’s profile picture Paul Armstrong

remove-aliasing

Path aliasing, sometimes referred to as import or module resolution, in the earliest and most naïve sense, is a method of overloading the Node Require Resolution Algorithm so that it first looks in some particular defined folders for modules of a given name before looking for installed modules of the same name in node_modules folders. While this seems handy at first glance, in practice, it’s is an unnecessary maintenance overhead in large distributed teams and a sign of poor code organization and architecture. This topic is covered in depth in the article “Import path aliasing is a crutch for poor architecture”.

This project enables you to quickly and automatically remove import path aliasing from your codebase.

Usage

Terminal window
npx remove-aliasing [options] <directory>

Example

Terminal window
npx remove-aliasing@latest --root="src/" --prefix="@/" src/

Input

import { Foo } from '@/components/Foo';
import * as Bar from '@/api/shared/services/bar';

Output

import { Foo } from '../../components/Foo';
import * as Bar from '../../api/shared/services/bar';

Options

OptionAliasTypeDescriptionRequired
--root-rstringDirectory that serves as the root of aliased files
--prefix-pstringImport path prefix, if any
--parserstringParser to use when reading files. Default tsx
--dry-runbooleanDo not actually write, just see what will happen
--verbosity-vnumberShow more information about the transform process. Default 0
--versionShow the program version