Skip to content

feat: allow from option to be an array of paths#826

Open
CoderSerio wants to merge 2 commits intowebpack:mainfrom
CoderSerio:main
Open

feat: allow from option to be an array of paths#826
CoderSerio wants to merge 2 commits intowebpack:mainfrom
CoderSerio:main

Conversation

@CoderSerio
Copy link
Copy Markdown

Summary

Fixes #631

What kind of change does this PR introduce?

feat:

  • Support copying multiple files from array, and as the same time, maintain the order of files from array
  • Add test file for the feature

Did you add tests for your changes?

Yes :)

Does this PR introduce a breaking change?

No, it's fully backward compatibility

If relevant, what needs to be documented once your changes are merged or what have you already documented?

  • Extend the documented type of from from string to string | string[]
  • From now supports copying multiple files from an array
new CopyPlugin({
  patterns: [
    {
      from: ["LICENSE", "README.md", "package.json"],
      to: "dist/",
    },
  ],
});

Use of AI

I've read the AI policy, and been clear totally about my code, and there are steps I used AI to collaborate:

  1. Confirm the original behavior of the from config field to make sure there was no misunderstanding
  2. Speed up test-driven development by generating initial test cases(I've reviewd them all)
  3. Review whether the cache index design was reasonable and validate the logic,and it proved that in math (that's cool, and the thing I could not do the same
The previous additive encoding strategy (`p + i`) can cause collisions because different `(p, i)` pairs may produce the same result, such as `(0, 5)` and `(5, 0)`.

The new encoding strategy (`K * p + i`), with the constraint `0 <= i < K`, is collision-free within the valid range. If `K * p1 + i1 = K * p2 + i2`, then `K * (p1 - p2) = i2 - i1`; since the right-hand side must be smaller than `K` in absolute value while also being divisible by `K`, it can only be `0`, which means `p1 = p2` and `i1 = i2`.

Intuitively, this works like combining the pattern index and the file index as digits in a mixed-radix number system. As long as `i` never reaches `K`, the lower part can never overflow into the higher part. Human beings reinventing positional notation to avoid cache collisions. Civilization limps onward.
  1. Perform a basic review of the code to help identify any obvious bugs

- Support copying multiple files from array
- Maintain order of files from array
- Full backward compatibility
- Add comprehensive test coverage (11 tests)

Fixes webpack#631
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Apr 4, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: CoderSerio / name: CoderSerio (8fdf7d9)
  • ✅ login: CoderSerio / name: 碳苯 Carbon (abb5e4a)

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

Successfully merging this pull request may close these issues.

Allow from to be array of paths / glob, respect order

1 participant