Describe the bug
When the Docusaurus configuration file contains a plugins entry with at least one plugin defined in a non-array way (e.g. a function), the command docusaurus gen-api-docs <id> -p <plugin-id> stops working.
Expected behavior
docusaurus gen-api-docs <id> -p <plugin-id> should support plugins defined in other forms other than an array/tuple, as per the official documentation.
Current behavior
When running the gen-api-docs command with a plugin ID (-p argument), it tries to look it up in the plugins configuration entry in the Docusaurus configuration file (ref). The lookup function incorrectly assumes all elements in plugins are defined as arrays and a tries to read a plugin[1].id field, resulting in a TypeError: Cannot read properties of undefined (reading 'id') error if the plugin is not defined as an array/tuple (ref).
Possible solution
The getPluginConfig should guard against data[1] being undefined:
function getPluginConfig(plugins: any[], pluginId: string): any {
return plugins.filter((data) => data[1]?.id === pluginId)[0][1];
}
Alternatively, since we only care about the docusaurus-plugin-openapi-docs instances, we could just call getPluginConfig here with the result of getPluginInstances (defined a few lines above):
const pluginConfig = getPluginConfig(pluginInstances, pluginId);
Steps to reproduce
- Bootstrap a new
Docusaurus application following the steps on the README of this repo
- Edit
plugins in docusaurus.config.ts, adding a non-array plugin to it. E.g.:
plugins: [
...,
() => ({
postBuild() {
console.log('Build finished');
},
}),
],
- Run
docusaurus gen-api-docs {id} -p {pluginId} with valid IDs based on the config
- The following error pop up in your console:
OpenAPI docs plugin ID '{pluginId}' not found.
Screenshots
Context
Your Environment
Relevant dependencies:
"@docusaurus/core": "^3.8.1",
"@docusaurus/mdx-loader": "^3.8.1",
"@docusaurus/plugin-content-docs": "^3.8.1",
"@docusaurus/preset-classic": "^3.8.1",
"@docusaurus/theme-classic": "^3.8.1",
"@docusaurus/theme-common": "^3.8.1",
"docusaurus-plugin-openapi-docs": "^4.5.1",
"docusaurus-theme-openapi-docs": "^4.5.1",
Node@20.19.2
Describe the bug
When the
Docusaurusconfiguration file contains apluginsentry with at least one plugin defined in a non-array way (e.g. a function), the commanddocusaurus gen-api-docs <id> -p <plugin-id>stops working.Expected behavior
docusaurus gen-api-docs <id> -p <plugin-id>should support plugins defined in other forms other than an array/tuple, as per the official documentation.Current behavior
When running the
gen-api-docscommand with a plugin ID (-pargument), it tries to look it up in thepluginsconfiguration entry in theDocusaurusconfiguration file (ref). The lookup function incorrectly assumes all elements inpluginsare defined as arrays and a tries to read aplugin[1].idfield, resulting in aTypeError: Cannot read properties of undefined (reading 'id')error if the plugin is not defined as an array/tuple (ref).Possible solution
The
getPluginConfigshould guard againstdata[1]being undefined:Alternatively, since we only care about the
docusaurus-plugin-openapi-docsinstances, we could just callgetPluginConfighere with the result ofgetPluginInstances(defined a few lines above):Steps to reproduce
Docusaurusapplication following the steps on theREADMEof this repopluginsindocusaurus.config.ts, adding a non-array plugin to it. E.g.:docusaurus gen-api-docs {id} -p {pluginId}with valid IDs based on the configOpenAPI docs plugin ID '{pluginId}' not found.Screenshots
Context
Your Environment
Relevant dependencies:
Node@20.19.2