-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Description
Version
18.17.0
Platform
Windows
Subsystem
No response
What steps will reproduce the bug?
Any simple recursive call to cp to recursively copy a director, when there is a filter that does not always return true
I used
await cp('src', 'lib', {
recursive: true,
filter: (source, _destination) => {
console.log(source, _destination, source.endsWith('.css'));
return source.endsWith('.css');
}
});to copy only .css files after creating "lib/" from "src/" with tsc in a React JSX library project, and it stopped right at the top level directory.
I also checked non-promise cp() and cpSync().
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
Expected: Recurse over all files and subdirectories no matter what the filter function returns
What do you see instead?
Recursion stops completely when the filter function returns false. The rest of the not yet visited files and sub directories are ignored and not handled.
Additional information
Note: All directories are definitely present since my example use case copies CSS files from src/ into lib/ after compiling the project with tsc. However, this leaves open the question of what would happen if the destination directory does not exist? Feature question: When using a filter it's possible to skip directories. Of course, one could ask the programmer to handle directories and return true in such cases? Or would it also be okay to add a feature to create any missing directories? Not sure how it behaves right now. In any case, that's only an additional consideration and not the issue of this... issue.