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

fix!: handle glob patterns ending with /** in CopyRspackPlugin #8803

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading