Skip to content

Commit

Permalink
fix!: handle glob patterns ending with /** in CopyRspackPlugin (#8803)
Browse files Browse the repository at this point in the history
fix: handle glob patterns ending with /** in CopyRspackPlugin
  • Loading branch information
inottn authored Dec 24, 2024
1 parent 1ca49a8 commit ea5baa5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crates/rspack_plugin_copy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,17 @@ impl CopyRspackPlugin {
}
FromType::Glob => {
need_add_context_to_dependency = true;
if Path::new(orig_from).is_absolute() {
let glob_query = if Path::new(orig_from).is_absolute() {
orig_from.into()
} else {
context.join(orig_from).as_str().to_string()
};
// A glob pattern ending with /** should match all files within a directory, not just the directory itself.
// Since the standard glob only matches directories, we append /* to align with webpack's behavior.
if glob_query.ends_with("/**") {
format!("{glob_query}/*")
} else {
glob_query
}
}
};
Expand Down
16 changes: 16 additions & 0 deletions tests/plugin-test/copy-plugin/CopyPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,22 @@ describe("CopyPlugin", () => {
.catch(done);
});

it('should work when "from" is a glob ending with /**', done => {
runEmit({
expectedAssetKeys: [
"directory/nested/nestedfile.txt",
"directory/nested/deep-nested/deepnested.txt"
],
patterns: [
{
from: "directory/nested/**"
}
]
})
.then(done)
.catch(done);
});

it.skip("should exclude path with linux path segment separators", done => {
runEmit({
expectedAssetKeys: [
Expand Down

0 comments on commit ea5baa5

Please sign in to comment.