fix: resolve config in browser throws an error (#1699)

This commit is contained in:
volodymyr-rutskyi
2024-08-30 16:48:08 +03:00
committed by GitHub
parent 732cc75a16
commit feac9d8acc
2 changed files with 12 additions and 10 deletions

View File

@@ -0,0 +1,5 @@
---
"@redocly/openapi-core": patch
---
Fixed an issue where resolving config in the browser always threw an error.

View File

@@ -117,7 +117,7 @@ function getDefaultPluginPath(configPath: string): string | undefined {
return pluginPath;
}
}
return undefined;
return;
}
export async function resolvePlugins(
@@ -128,12 +128,6 @@ export async function resolvePlugins(
// TODO: implement or reuse Resolver approach so it will work in node and browser envs
const requireFunc = async (plugin: string | Plugin): Promise<ImportedPlugin | undefined> => {
if (isBrowser && isString(plugin)) {
logger.error(`Cannot load ${plugin}. Plugins aren't supported in browser yet.`);
return undefined;
}
if (isString(plugin)) {
try {
const maybeAbsolutePluginPath = path.resolve(path.dirname(configPath), plugin);
@@ -372,7 +366,10 @@ async function resolveAndMergeNestedStyleguideConfig(
if (parentConfigPaths.includes(configPath)) {
throw new Error(`Circular dependency in config file: "${configPath}"`);
}
const plugins = getUniquePlugins(
const plugins = isBrowser
? // In browser, we don't support plugins from config file yet
[defaultPlugin]
: getUniquePlugins(
await resolvePlugins([...(styleguideConfig?.plugins || []), defaultPlugin], configPath)
);
const pluginPaths = styleguideConfig?.plugins