-
-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ProgressData#deletedCount
#142
Conversation
// @jopemachine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for correcting this :)
It was my mistake when occurred in changing the call order of onProgress
.
The below function call should be removed since the last element will be called twice by the line.
Lines 99 to 103 in 7fbeca0
onProgress({ | |
totalCount: files.length, | |
deletedCount: files.length, | |
percent: 1 | |
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I think using fileIndex
through mapper's argument here was another mistake.
deletedCount
should be in ascending order semantically, but because the mapper
function is async, it will be called in order mapper
's promise resolve.
It means the below test will break.
Line 381 in 7fbeca0
test('onProgress option - progress of multiple files', async t => { |
I think probably this should be fixed with like below codes.
let fileIndex = 1;
const mapper = async (file) => {
// ...
onProgress({
totalCount: files.length,
deletedCount: fileIndex,
percent: fileIndex / files.length
});
++fileIndex;
// ...
}
let count = 0
const mapper = async (file, fileIndex) => {
file = path.resolve(cwd, file);
if (!force) {
safeCheck(file, cwd);
}
if (!dryRun) {
await rimrafP(file, rimrafOptions);
}
count += 1
onProgress({
totalCount: files.length,
deletedCount: count,
percent: count / files.length
});
return file;
}; Agree your point, but i think we should replace |
I agree the variable needs be renamed, but I think |
In the doc, the {
totalFiles: number,
deletedFiles: number,
percent: number
}
|
Thanks for correcting. That should be |
@sindresorhus |
Thanks, everyone :) |
deletedCount
should start from1