assertNoDuplicates throw with more context (#10419)
When users see errors like
```
Duplicate plugin/preset detected.
If you'd like to use two separate instances of a plugin,
they need separate names, e.g.
plugins: [
['some-plugin', {}],
['some-plugin', {}, 'some unique name'],
]
```
It can be difficult to determine the source of the conflict, especially
in a larger build system.
This commit outputs what is known about the plugins that actually
conflict, which can be helpful for users to determine the root cause of
the conflict.
Partially addresses #9778
This commit is contained in:
parent
a219b6de7a
commit
fa5a40c8d5
@ -345,6 +345,7 @@ function assertNoDuplicates(items: Array<UnloadedDescriptor>): void {
|
||||
}
|
||||
|
||||
if (nameMap.has(item.name)) {
|
||||
const conflicts = items.filter(i => i.value === item.value);
|
||||
throw new Error(
|
||||
[
|
||||
`Duplicate plugin/preset detected.`,
|
||||
@ -355,6 +356,9 @@ function assertNoDuplicates(items: Array<UnloadedDescriptor>): void {
|
||||
` ['some-plugin', {}],`,
|
||||
` ['some-plugin', {}, 'some unique name'],`,
|
||||
` ]`,
|
||||
``,
|
||||
`Duplicates detected are:`,
|
||||
`${JSON.stringify(conflicts, null, 2)}`,
|
||||
].join("\n"),
|
||||
);
|
||||
}
|
||||
|
||||
@ -27,14 +27,19 @@ describe("option-manager", () => {
|
||||
return { plugin, calls };
|
||||
}
|
||||
|
||||
it("should throw if a plugin is repeated", () => {
|
||||
const { calls, plugin } = makePlugin();
|
||||
it("should throw if a plugin is repeated, with information about the repeated plugin", () => {
|
||||
const { calls, plugin } = makePlugin("my-plugin");
|
||||
|
||||
expect(() => {
|
||||
loadOptions({
|
||||
plugins: [plugin, plugin],
|
||||
plugins: [
|
||||
[plugin, undefined, "my-plugin"],
|
||||
[plugin, undefined, "my-plugin"],
|
||||
],
|
||||
});
|
||||
}).toThrow(/Duplicate plugin\/preset detected/);
|
||||
}).toThrow(
|
||||
/Duplicate plugin\/preset detected.*Duplicates detected are.*my-plugin.*my-plugin/ms,
|
||||
);
|
||||
expect(calls).toEqual([]);
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user