-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove concurrency option, and add readme
- Loading branch information
Christopher Powroznik
committed
Oct 24, 2024
1 parent
7d8c871
commit a167b5c
Showing
4 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/*"] | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters