Skip to content

Commit

Permalink
fix: remove concurrency option, and add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Powroznik committed Oct 24, 2024
1 parent 7d8c871 commit a167b5c
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 8 deletions.
82 changes: 82 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Relative to Alias Resolver

## Overview

The **Relative to Alias Resolver** is a tool designed to convert a TypeScript project from using relative imports to alias imports. This can help improve the readability and maintainability of your codebase by using more descriptive import paths.

## Features

- Converts relative imports to alias imports based on your `tsconfig.json` configuration.
- Supports both CommonJS and ES Module formats.
- Provides a CLI for easy integration into your build process.
- Includes options for dry runs and concurrency control.

## Installation

To install the package cli, use npm:

```bash
npm install -g relative-to-alias-resolver
```

if you intend to use the library in your project, you can install it locally:

```bash
npm install relative-to-alias-resolver
```

## Usage

### CLI

The package provides a command-line interface to perform the conversion. You can use it as follows:

```bash
relative-to-alias-resolver --project <path-to-project> --tsconfig <path-to-tsconfig>
```

#### Options

- `-p, --project <path>`: The path to the project to generate alias imports for. Defaults to the current directory.
- `-t, --tsconfig <path>`: The path to the `tsconfig.json` file to use for the project. Defaults to `./tsconfig.json`.
- `-d, --dry-run`: Run the command in dry run mode. Defaults to `true`.
- `-i, --ignore <patterns>`: A comma-separated list of regex patterns for paths to ignore. Defaults to `["node_modules"]`.
- `-c, --concurrency <number>`: The number of promises to allow at once when editing the project. Defaults to `5`.

#### Example

```bash
relative-to-alias-resolver --project ./src --tsconfig ./tsconfig.json
```

### Library

The library can be used to convert relative imports to alias imports in a TypeScript project.

```typescript
import { resolveRelativeToAlias } from "relative-to-alias-resolver";

resolveRelativeToAlias({
projectPath: "./src",
tsconfigPath: "./tsconfig.json",
dryRun: true,
ignore: ["node_modules"],
});
```

## Configuration

The tool relies on the `tsconfig.json` file to determine the base URL and paths for aliasing. Ensure your `tsconfig.json` is correctly configured with the `baseUrl` and `paths` properties.

Example `tsconfig.json`:

```json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "relative-to-alias-resolver",
"version": "1.0.1",
"description": "converts a typescript from from relative imports to alias imports",
"description": "Converts a typescript project from relative imports to alias imports.",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.js",
"type": "module",
Expand Down
6 changes: 0 additions & 6 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ program
(value) => value.split(","),
["node_modules"]
)
.option(
"-c, --concurrency <number>",
"The number of promises to allow at once when editing the project.",
(value) => parseInt(value),
5
)
.action(main);

program.parse(process.argv);
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export interface Options {
tsconfig: string;
dryRun: boolean;
ignoreDirectories: string[];
concurrency: number;
}

export default async function main(options: Options) {
Expand Down

0 comments on commit a167b5c

Please sign in to comment.