Skip to content
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

fs.copy/copySync when filter is return false, it will break copy #1007

Closed
haozi opened this issue Jun 28, 2023 · 5 comments
Closed

fs.copy/copySync when filter is return false, it will break copy #1007

haozi opened this issue Jun 28, 2023 · 5 comments

Comments

@haozi
Copy link

haozi commented Jun 28, 2023

fs.copy(path.join(__dirname, 'src'), path.join(__dirname, 'dist'), {
   filter: (src: string) => {
       return path.extname(src) !== '.js'
   }
})

when I copying a folder, I wish skip file it is not *.js ,but if I return false, it will break copy, the desired purpose is to copy all non-.js files

  • Operating System:
  • Node.js version:
  • fs-extra version:
@RyanZim
Copy link
Collaborator

RyanZim commented Jun 28, 2023

filter is passed all paths, including directories. You'll have to add logic to only run your .js check on files, and return true for directories (note that this will copy empty directories if they do not contain JS files).

@RyanZim RyanZim closed this as completed Jun 28, 2023
@haozi
Copy link
Author

haozi commented Jun 28, 2023

filter is passed all paths, including directories. You'll have to add logic to only run your .js check on files, and return true for directories (note that this will copy empty directories if they do not contain JS files).

but if allow folder return true, it will copy a lot of empty folder

@RyanZim
Copy link
Collaborator

RyanZim commented Jun 28, 2023

Honestly, the filter probably isn't the best tool for the job here, you'd be better off using something like https://www.npmjs.com/package/globby to get a list of JS files, then copying each of them individually.

@haozi
Copy link
Author

haozi commented Jul 4, 2023

Honestly, the filter probably isn't the best tool for the job here, you'd be better off using something like https://www.npmjs.com/package/globby to get a list of JS files, then copying each of them individually.

Could you consider adding support for glob matching in the first parameter?
Like:

fs.copy('src/**/*.png', dest)

@RyanZim
Copy link
Collaborator

RyanZim commented Jul 4, 2023

Glob support adds another entire layer of complexity and edge cases to deal with, it's unlikely we'll add it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants