feat(core): give more hints when plugins have duplicate IDs (#5899)

This commit is contained in:
Joshua Chen 2021-11-10 02:32:55 +08:00 committed by GitHub
parent 1c024470e0
commit eab8c7c010
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View file

@ -1,16 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ensureUniquePluginInstanceIds reject multi instance plugins with same id 1`] = `
"Plugin \\"plugin-docs\\" is used 2 times with id sameId.
To use the same plugin multiple times on a Docusaurus site, you need to assign a unique id to each plugin instance."
"Plugin \\"plugin-docs\\" is used 2 times with ID \\"sameId\\".
To use the same plugin multiple times on a Docusaurus site, you need to assign a unique ID to each plugin instance."
`;
exports[`ensureUniquePluginInstanceIds reject multi instance plugins without id 1`] = `
"Plugin \\"plugin-docs\\" is used 2 times with id default.
To use the same plugin multiple times on a Docusaurus site, you need to assign a unique id to each plugin instance."
"Plugin \\"plugin-docs\\" is used 2 times with ID \\"default\\".
To use the same plugin multiple times on a Docusaurus site, you need to assign a unique ID to each plugin instance.
The plugin ID is \\"default\\" by default. It's possible that the preset you are using already includes a plugin instance, in which case you either want to disable the plugin in the preset (to use a single instance), or assign another ID to your extra plugin instance (to use multiple instances)."
`;
exports[`ensureUniquePluginInstanceIds reject multi instance plugins without id 2`] = `
"Plugin \\"plugin-docs\\" is used 2 times with id default.
To use the same plugin multiple times on a Docusaurus site, you need to assign a unique id to each plugin instance."
"Plugin \\"plugin-docs\\" is used 2 times with ID \\"default\\".
To use the same plugin multiple times on a Docusaurus site, you need to assign a unique ID to each plugin instance.
The plugin ID is \\"default\\" by default. It's possible that the preset you are using already includes a plugin instance, in which case you either want to disable the plugin in the preset (to use a single instance), or assign another ID to your extra plugin instance (to use multiple instances)."
`;

View file

@ -24,7 +24,13 @@ export function ensureUniquePluginInstanceIds(
([pluginId, pluginInstancesWithId]) => {
if (pluginInstancesWithId.length !== 1) {
throw new Error(
`Plugin "${pluginName}" is used ${pluginInstancesWithId.length} times with id ${pluginId}.\nTo use the same plugin multiple times on a Docusaurus site, you need to assign a unique id to each plugin instance.`,
`Plugin "${pluginName}" is used ${
pluginInstancesWithId.length
} times with ID "${pluginId}".\nTo use the same plugin multiple times on a Docusaurus site, you need to assign a unique ID to each plugin instance.${
pluginId === DEFAULT_PLUGIN_ID
? `\n\nThe plugin ID is "${DEFAULT_PLUGIN_ID}" by default. It's possible that the preset you are using already includes a plugin instance, in which case you either want to disable the plugin in the preset (to use a single instance), or assign another ID to your extra plugin instance (to use multiple instances).`
: ''
}`,
);
}
},