MCPcopy
hub / github.com/homebridge/homebridge / loadPackageJSON

Method loadPackageJSON

src/pluginManager.ts:444–468  ·  view source on GitHub ↗
(pluginPath: string)

Source from the content-addressed store, hash-verified

442 }
443
444 private static loadPackageJSON(pluginPath: string): PackageJSON {
445 const packageJsonPath = join(pluginPath, 'package.json')
446 let packageJson: PackageJSON
447
448 if (!existsSync(packageJsonPath)) {
449 throw new Error(`Plugin ${pluginPath} does not contain a package.json.`)
450 }
451
452 try {
453 packageJson = JSON.parse(readFileSync(packageJsonPath, { encoding: 'utf8' })) // attempt to parse package.json
454 } catch (error: any) {
455 throw new Error(`Plugin ${pluginPath} contains an invalid package.json. Error: ${error}`)
456 }
457
458 if (!packageJson.name || !PluginManager.isQualifiedPluginIdentifier(packageJson.name)) {
459 throw new Error(`Plugin ${pluginPath} does not have a package name that begins with 'homebridge-' or '@scope/homebridge-.`)
460 }
461
462 // verify that it's tagged with the correct keyword
463 if (!packageJson.keywords || !packageJson.keywords.includes('homebridge-plugin')) {
464 throw new Error(`Plugin ${pluginPath} package.json does not contain the keyword 'homebridge-plugin'.`)
465 }
466
467 return packageJson
468 }
469
470 private loadDefaultPaths(): void {
471 if (this.strictPluginResolution) {

Callers 1

loadPluginMethod · 0.80

Calls 1

Tested by

no test coverage detected