diff --git a/README.md b/README.md index b28ceb9..eb3f93f 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,6 @@ relative-to-alias-resolver --project --tsconfig `: 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 `: A comma-separated list of regex patterns for paths to ignore. Defaults to `["node_modules"]`. -- `-c, --concurrency `: The number of promises to allow at once when editing the project. Defaults to `5`. #### Example diff --git a/src/createFileList.ts b/src/createFileList.ts index a49864d..0bda85e 100644 --- a/src/createFileList.ts +++ b/src/createFileList.ts @@ -12,7 +12,7 @@ import { Options } from "@/index"; */ export default async function createFileList( projectPath: string, - ignorePatterns: string[] + ignorePatterns: string[], ): Promise { const fileList: string[] = []; diff --git a/src/index.ts b/src/index.ts index 117af62..aee12b5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,9 +24,9 @@ export default async function main(options: Options) { // 4. Create a list of all the files in the project const fileList = await createFileList( options.project, - options.ignoreDirectories + options.ignoreDirectories, ); // 5. process the files - await processFiles(fileList, paths); + await processFiles(fileList, paths, options.dryRun); } diff --git a/src/processFiles.ts b/src/processFiles.ts index e16ebb3..c62d240 100644 --- a/src/processFiles.ts +++ b/src/processFiles.ts @@ -5,7 +5,8 @@ import { resolve } from "node:path"; export default async function processFiles( fileList: string[], - paths: { [key: string]: string[] } + paths: { [key: string]: string[] }, + dryRun: boolean ) { async function processFile(filePath: string) { // 1. read the file contents @@ -43,7 +44,9 @@ export default async function processFiles( const modifiedContents = recast.print(ast).code; // 5. write the modified contents back to the file - await fs.writeFile(filePath, modifiedContents); + if (!dryRun) { + await fs.writeFile(filePath, modifiedContents); + } } await Promise.all(fileList.map(processFile));