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,KAAK,CAAC,qCAAqC,iBAAiB,CAAC,IAAI,GAAG,CAAC,CAAC;qBACjF;iBACF;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,IAAI,KAAK,CAAC,wBAAwB,YAAY,CAAC,WAAW,IAAI,GAAI,CAAW,CAAC,OAAO,CAAC,CAAC;aAC9F;SACF;IACH,CAAC;CACF;AA/FD,oCA+FC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport * as path from 'path';\nimport * as resolve from 'resolve';\n\nimport type { IApiDocumenterPluginManifest, IFeatureDefinition } from './IApiDocumenterPluginManifest';\nimport {\n MarkdownDocumenterFeature,\n type MarkdownDocumenterFeatureContext\n} from './MarkdownDocumenterFeature';\nimport { PluginFeatureInitialization } from './PluginFeature';\nimport type { DocumenterConfig } from '../documenters/DocumenterConfig';\n\ninterface ILoadedPlugin {\n packageName: string;\n manifest: IApiDocumenterPluginManifest;\n}\n\nexport class PluginLoader {\n public markdownDocumenterFeature: MarkdownDocumenterFeature | undefined;\n\n public load(\n documenterConfig: DocumenterConfig,\n createContext: () => MarkdownDocumenterFeatureContext\n ): void {\n const configFileFolder: string = path.dirname(documenterConfig.configFilePath);\n for (const configPlugin of documenterConfig.configFile.plugins || []) {\n try {\n // Look for the package name in the same place as the config file\n const resolvedEntryPointPath: string = resolve.sync(configPlugin.packageName, {\n basedir: configFileFolder\n });\n\n // Load the package\n const entryPoint:\n | { apiDocumenterPluginManifest?: IApiDocumenterPluginManifest }\n | undefined = require(resolvedEntryPointPath);\n\n if (!entryPoint) {\n throw new Error('Invalid entry point');\n }\n\n if (!entryPoint.apiDocumenterPluginManifest) {\n throw new Error(\n `The package is not an API documenter plugin;` +\n ` the \"apiDocumenterPluginManifest\" export was not found`\n );\n }\n\n const manifest: IApiDocumenterPluginManifest = entryPoint.apiDocumenterPluginManifest;\n\n if (manifest.manifestVersion !== 1000) {\n throw new Error(\n `The plugin is not compatible with this version of API Documenter;` +\n ` unsupported manifestVersion`\n );\n }\n\n const loadedPlugin: ILoadedPlugin = {\n packageName: configPlugin.packageName,\n manifest\n };\n\n const featureDefinitionsByName: Map<string, IFeatureDefinition> = new Map<\n string,\n IFeatureDefinition\n >();\n for (const featureDefinition of manifest.features) {\n featureDefinitionsByName.set(featureDefinition.featureName, featureDefinition);\n }\n\n for (const featureName of configPlugin.enabledFeatureNames) {\n const featureDefinition: IFeatureDefinition | undefined = featureDefinitionsByName.get(featureName);\n if (!featureDefinition) {\n throw new Error(\n `The plugin ${loadedPlugin.packageName} does not have a feature with name \"${featureName}\"`\n );\n }\n\n if (featureDefinition.kind === 'MarkdownDocumenterFeature') {\n if (this.markdownDocumenterFeature) {\n throw new Error('A MarkdownDocumenterFeature is already loaded');\n }\n\n const initialization: PluginFeatureInitialization = new PluginFeatureInitialization();\n initialization._context = createContext();\n\n let markdownDocumenterFeature: MarkdownDocumenterFeature | undefined = undefined;\n try {\n markdownDocumenterFeature = new featureDefinition.subclass(initialization);\n } catch (e) {\n throw new Error(`Failed to construct feature subclass:\\n` + (e as Error).toString());\n }\n if (!(markdownDocumenterFeature instanceof MarkdownDocumenterFeature)) {\n throw new Error('The constructed subclass was not an instance of MarkdownDocumenterFeature');\n }\n\n try {\n markdownDocumenterFeature.onInitialized();\n } catch (e) {\n throw new Error('Error occurred during the onInitialized() event: ' + (e as Error).toString());\n }\n\n this.markdownDocumenterFeature = markdownDocumenterFeature;\n } else {\n throw new Error(`Unknown feature definition kind: \"${featureDefinition.kind}\"`);\n }\n }\n } catch (e) {\n throw new Error(`Error loading plugin ${configPlugin.packageName}: ` + (e as Error).message);\n }\n }\n }\n}\n"]} |