MCPcopy
hub / github.com/homebridge/homebridge / loadPlugin

Method loadPlugin

src/pluginManager.ts:427–442  ·  view source on GitHub ↗
(absolutePath: string)

Source from the content-addressed store, hash-verified

425 }
426
427 public loadPlugin(absolutePath: string): Plugin {
428 const packageJson: PackageJSON = PluginManager.loadPackageJSON(absolutePath)
429
430 const identifier: PluginIdentifier = packageJson.name
431 const name: PluginName = PluginManager.extractPluginName(identifier)
432 const scope = PluginManager.extractPluginScope(identifier) // possibly undefined
433
434 const alreadyInstalled = this.plugins.get(identifier) // check if there is already a plugin with the same Identifier
435 if (alreadyInstalled) {
436 throw new Error(`Warning: skipping plugin found at '${absolutePath}' since we already loaded the same plugin from '${alreadyInstalled.getPluginPath()}'.`)
437 }
438
439 const plugin = new Plugin(name, absolutePath, packageJson, scope)
440 this.plugins.set(identifier, plugin)
441 return plugin
442 }
443
444 private static loadPackageJSON(pluginPath: string): PackageJSON {
445 const packageJsonPath = join(pluginPath, 'package.json')

Callers 1

loadInstalledPluginsMethod · 0.95

Calls 4

loadPackageJSONMethod · 0.80
extractPluginNameMethod · 0.80
extractPluginScopeMethod · 0.80
getPluginPathMethod · 0.80

Tested by

no test coverage detected