Skip to content

Commit

Permalink
fix: fix dry run not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Powroznik committed Oct 24, 2024
1 parent a167b5c commit 51dc7cf
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ relative-to-alias-resolver --project <path-to-project> --tsconfig <path-to-tscon
- `-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

Expand Down
2 changes: 1 addition & 1 deletion src/createFileList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Options } from "@/index";
*/
export default async function createFileList(
projectPath: string,
ignorePatterns: string[]
ignorePatterns: string[],
): Promise<string[]> {
const fileList: string[] = [];

Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
7 changes: 5 additions & 2 deletions src/processFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 51dc7cf

Please sign in to comment.