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

Exclude certain files from being copied #4

Open
oogali opened this issue Oct 17, 2022 · 6 comments
Open

Exclude certain files from being copied #4

oogali opened this issue Oct 17, 2022 · 6 comments

Comments

@oogali
Copy link

oogali commented Oct 17, 2022

I've been using this plugin for a month now to simplify publishing static files into the resulting build and I'm pleased with it so far. Due to some quirks in the project I'm working on, I need to exclude certain files from being copied.

While I know I can override the filter function as an optional argument, it would require me to re-implement the entire logic of filter function which seems a bit excessive.

I can spin up a PR to add this functionality but I'm looking for guidance for the best way to implement this...

My thoughts are I could take one of the following approaches:

  1. Add a new exclude argument to the options object and have the built-in filter function evaluate that when it's called (e.g. if source file name with leading directory stripped matches an element in the excluded array, then return false).

  2. Export the filter function to allow it to be reused externally, then one doesn't have to choose between your filter logic and their filter logic.

The problem I see with option 1 is this would make the API and documentation a bit clunky since it requires a caveat in giant bold letters that exclude will be ignored if the filter function is overridden.

Whether option 2 is palatable is up to you and your preferences.

What are your thoughts?

@nickjj
Copy link
Owner

nickjj commented Oct 17, 2022

Hi,

If you were to re-implement the filter function what would it look like?

@oogali
Copy link
Author

oogali commented Oct 17, 2022

What I'd prefer to do is something along the lines of...

import copyStaticFiles, { filter } from 'esbuild-copy-static-files'

const EXCLUDED_FILES = [...]

function excludeFilter(src, dst) {
  if (EXCLUDED_FILES.find(f => src === f) {
    return false;
  }

  return filter(src, dst)
}
...
  plugins: [
    copyStaticFiles({ filter: excludeFilter })
  ]
}

@oogali
Copy link
Author

oogali commented Oct 17, 2022

Otherwise, to cover my use case, I'd end up duplicating all of your filter() code and the functions it depends on into my external function just to pass it back in to your scope as an argument.

@ianchanning
Copy link

Yes - I think this would be an excellent addition - exporting the filter function to be able to re-use it is very useful.

@ianchanning
Copy link

Ha, I'm actually looking into re-using the filter function and I've just realised that 90% of this plugin is the filter function and its dependencies.

@nickjj
Copy link
Owner

nickjj commented Apr 15, 2023

Yep! Feel free to open a PR if you want to arrive at a solution that lets you:

  • Define a custom filter function (current behavior)
  • Augment / extend the existing filter function with a new filter function of your choosing

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

3 participants