Skip to content

Commit f5d31e6

Browse files
authoredAug 30, 2023
Add path to onProgress event (#155)
1 parent e9b0d71 commit f5d31e6

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed
 

‎index.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ export type ProgressData = {
1515
Completed percentage. A value between `0` and `1`.
1616
*/
1717
readonly percent: number;
18+
19+
/**
20+
The absolute path of the deleted file or directory.
21+
22+
It will not be present if nothing was deleted.
23+
*/
24+
readonly path?: string;
1825
};
1926

2027
export type Options = {

‎index.js

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export async function deleteAsync(patterns, {force, dryRun, cwd = process.cwd(),
9393
totalCount: files.length,
9494
deletedCount,
9595
percent: deletedCount / files.length,
96+
path: file,
9697
});
9798

9899
return file;

‎readme.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,13 @@ await deleteAsync(patterns, {
153153
{
154154
totalCount: number,
155155
deletedCount: number,
156-
percent: number
156+
percent: number,
157+
path?: string
157158
}
158159
```
159160

160161
- `percent` is a value between `0` and `1`
162+
- `path` is the absolute path of the deleted file or directory. It will not be present if nothing was deleted.
161163

162164
## CLI
163165

‎test.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -378,25 +378,27 @@ test('onProgress option - progress of single file', async t => {
378378
totalCount: 1,
379379
deletedCount: 1,
380380
percent: 1,
381+
path: t.context.tmp,
381382
});
382383
});
383384

384385
test('onProgress option - progress of multiple files', async t => {
385-
let report;
386+
const reports = [];
386387

387388
const sourcePath = process.platform === 'win32' ? path.resolve(`${t.context.tmp}/*`).replace(/\\/g, '/') : `${t.context.tmp}/*`;
388389

389390
await deleteAsync(sourcePath, {
390391
cwd: __dirname,
391392
force: true,
392393
onProgress(event) {
393-
report = event;
394+
reports.push(event);
394395
},
395396
});
396397

397-
t.deepEqual(report, {
398-
totalCount: 4,
399-
deletedCount: 4,
400-
percent: 1,
401-
});
398+
t.is(reports.length, 4);
399+
t.deepEqual(reports.map(r => r.totalCount), [4, 4, 4, 4]);
400+
t.deepEqual(reports.map(r => r.deletedCount).sort(), [1, 2, 3, 4]);
401+
402+
const expectedPaths = ['1', '2', '3', '4'].map(x => path.join(t.context.tmp, `${x}.tmp`));
403+
t.deepEqual(reports.map(r => r.path).sort(), expectedPaths.sort());
402404
});

0 commit comments

Comments
 (0)
Please sign in to comment.