Skip to content

Commit

Permalink
Fix ProgressData#deletedCount (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhanqu authored May 24, 2022
1 parent c12fddd commit 7b4c881
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 7 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ module.exports = async (patterns, {force, dryRun, cwd = process.cwd(), onProgres
});
}

const mapper = async (file, fileIndex) => {
let deletedCount = 0;

const mapper = async file => {
file = path.resolve(cwd, file);

if (!force) {
Expand All @@ -85,23 +87,19 @@ module.exports = async (patterns, {force, dryRun, cwd = process.cwd(), onProgres
await rimrafP(file, rimrafOptions);
}

deletedCount += 1;

onProgress({
totalCount: files.length,
deletedCount: fileIndex,
percent: fileIndex / files.length
deletedCount,
percent: deletedCount / files.length
});

return file;
};

const removedFiles = await pMap(files, mapper, options);

onProgress({
totalCount: files.length,
deletedCount: files.length,
percent: 1
});

removedFiles.sort((a, b) => a.localeCompare(b));

return removedFiles;
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ await del(patterns, {

```js
{
totalFiles: number,
deletedFiles: number,
totalCount: number,
deletedCount: number,
percent: number
}
```
Expand Down

0 comments on commit 7b4c881

Please sign in to comment.