homebridge 2.0.0-beta.4 → 2.0.0-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -17
- package/bin/homebridge.js +22 -0
- package/config-sample.json +3 -3
- package/dist/api.d.ts +499 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +223 -0
- package/dist/api.js.map +1 -0
- package/dist/api.spec.d.ts +2 -0
- package/dist/api.spec.d.ts.map +1 -0
- package/dist/api.spec.js +413 -0
- package/dist/api.spec.js.map +1 -0
- package/{lib → dist}/bridgeService.d.ts +19 -10
- package/dist/bridgeService.d.ts.map +1 -0
- package/{lib → dist}/bridgeService.js +85 -117
- package/dist/bridgeService.js.map +1 -0
- package/{lib → dist}/childBridgeFork.d.ts +11 -5
- package/dist/childBridgeFork.d.ts.map +1 -0
- package/{lib → dist}/childBridgeFork.js +93 -44
- package/dist/childBridgeFork.js.map +1 -0
- package/{lib → dist}/childBridgeService.d.ts +37 -7
- package/dist/childBridgeService.d.ts.map +1 -0
- package/{lib → dist}/childBridgeService.js +127 -69
- package/dist/childBridgeService.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +90 -0
- package/dist/cli.js.map +1 -0
- package/dist/externalPortService.d.ts +47 -0
- package/dist/externalPortService.d.ts.map +1 -0
- package/dist/externalPortService.js +105 -0
- package/dist/externalPortService.js.map +1 -0
- package/dist/index.d.ts +141 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/ipcService.d.ts +48 -0
- package/dist/ipcService.d.ts.map +1 -0
- package/{lib → dist}/ipcService.js +12 -14
- package/dist/ipcService.js.map +1 -0
- package/{lib → dist}/logger.d.ts +12 -6
- package/dist/logger.d.ts.map +1 -0
- package/{lib → dist}/logger.js +27 -28
- package/dist/logger.js.map +1 -0
- package/dist/logger.spec.d.ts +2 -0
- package/dist/logger.spec.d.ts.map +1 -0
- package/dist/logger.spec.js +95 -0
- package/dist/logger.spec.js.map +1 -0
- package/dist/matter/ChildBridgeMatterManager.d.ts +96 -0
- package/dist/matter/ChildBridgeMatterManager.d.ts.map +1 -0
- package/dist/matter/ChildBridgeMatterManager.js +399 -0
- package/dist/matter/ChildBridgeMatterManager.js.map +1 -0
- package/dist/matter/ExternalMatterAccessoryPublisher.d.ts +48 -0
- package/dist/matter/ExternalMatterAccessoryPublisher.d.ts.map +1 -0
- package/dist/matter/ExternalMatterAccessoryPublisher.js +73 -0
- package/dist/matter/ExternalMatterAccessoryPublisher.js.map +1 -0
- package/dist/matter/ExternalMatterAccessoryPublisher.spec.d.ts +2 -0
- package/dist/matter/ExternalMatterAccessoryPublisher.spec.d.ts.map +1 -0
- package/dist/matter/ExternalMatterAccessoryPublisher.spec.js +293 -0
- package/dist/matter/ExternalMatterAccessoryPublisher.spec.js.map +1 -0
- package/dist/matter/MatterAPIImpl.d.ts +504 -0
- package/dist/matter/MatterAPIImpl.d.ts.map +1 -0
- package/dist/matter/MatterAPIImpl.js +305 -0
- package/dist/matter/MatterAPIImpl.js.map +1 -0
- package/dist/matter/MatterBridgeManager.d.ts +87 -0
- package/dist/matter/MatterBridgeManager.d.ts.map +1 -0
- package/dist/matter/MatterBridgeManager.js +413 -0
- package/dist/matter/MatterBridgeManager.js.map +1 -0
- package/dist/matter/MatterConfigCollector.d.ts +26 -0
- package/dist/matter/MatterConfigCollector.d.ts.map +1 -0
- package/dist/matter/MatterConfigCollector.js +78 -0
- package/dist/matter/MatterConfigCollector.js.map +1 -0
- package/dist/matter/accessoryCache.d.ts +105 -0
- package/dist/matter/accessoryCache.d.ts.map +1 -0
- package/dist/matter/accessoryCache.js +214 -0
- package/dist/matter/accessoryCache.js.map +1 -0
- package/dist/matter/accessoryCache.spec.d.ts +2 -0
- package/dist/matter/accessoryCache.spec.d.ts.map +1 -0
- package/dist/matter/accessoryCache.spec.js +452 -0
- package/dist/matter/accessoryCache.spec.js.map +1 -0
- package/dist/matter/behaviors/BehaviorRegistry.d.ts +65 -0
- package/dist/matter/behaviors/BehaviorRegistry.d.ts.map +1 -0
- package/dist/matter/behaviors/BehaviorRegistry.js +139 -0
- package/dist/matter/behaviors/BehaviorRegistry.js.map +1 -0
- package/dist/matter/behaviors/BehaviorRegistry.spec.d.ts +2 -0
- package/dist/matter/behaviors/BehaviorRegistry.spec.d.ts.map +1 -0
- package/dist/matter/behaviors/BehaviorRegistry.spec.js +307 -0
- package/dist/matter/behaviors/BehaviorRegistry.spec.js.map +1 -0
- package/dist/matter/behaviors/ColorControlBehavior.d.ts +63 -0
- package/dist/matter/behaviors/ColorControlBehavior.d.ts.map +1 -0
- package/dist/matter/behaviors/ColorControlBehavior.js +223 -0
- package/dist/matter/behaviors/ColorControlBehavior.js.map +1 -0
- package/dist/matter/behaviors/ColorControlBehavior.spec.d.ts +2 -0
- package/dist/matter/behaviors/ColorControlBehavior.spec.d.ts.map +1 -0
- package/dist/matter/behaviors/ColorControlBehavior.spec.js +29 -0
- package/dist/matter/behaviors/ColorControlBehavior.spec.js.map +1 -0
- package/dist/matter/behaviors/DoorLockBehavior.d.ts +20 -0
- package/dist/matter/behaviors/DoorLockBehavior.d.ts.map +1 -0
- package/dist/matter/behaviors/DoorLockBehavior.js +71 -0
- package/dist/matter/behaviors/DoorLockBehavior.js.map +1 -0
- package/dist/matter/behaviors/DoorLockBehavior.spec.d.ts +2 -0
- package/dist/matter/behaviors/DoorLockBehavior.spec.d.ts.map +1 -0
- package/dist/matter/behaviors/DoorLockBehavior.spec.js +120 -0
- package/dist/matter/behaviors/DoorLockBehavior.spec.js.map +1 -0
- package/dist/matter/behaviors/FanControlBehavior.d.ts +20 -0
- package/dist/matter/behaviors/FanControlBehavior.d.ts.map +1 -0
- package/dist/matter/behaviors/FanControlBehavior.js +71 -0
- package/dist/matter/behaviors/FanControlBehavior.js.map +1 -0
- package/dist/matter/behaviors/FanControlBehavior.spec.d.ts +2 -0
- package/dist/matter/behaviors/FanControlBehavior.spec.d.ts.map +1 -0
- package/dist/matter/behaviors/FanControlBehavior.spec.js +23 -0
- package/dist/matter/behaviors/FanControlBehavior.spec.js.map +1 -0
- package/dist/matter/behaviors/IdentifyBehavior.d.ts +20 -0
- package/dist/matter/behaviors/IdentifyBehavior.d.ts.map +1 -0
- package/dist/matter/behaviors/IdentifyBehavior.js +41 -0
- package/dist/matter/behaviors/IdentifyBehavior.js.map +1 -0
- package/dist/matter/behaviors/IdentifyBehavior.spec.d.ts +2 -0
- package/dist/matter/behaviors/IdentifyBehavior.spec.d.ts.map +1 -0
- package/dist/matter/behaviors/IdentifyBehavior.spec.js +64 -0
- package/dist/matter/behaviors/IdentifyBehavior.spec.js.map +1 -0
- package/dist/matter/behaviors/LevelControlBehavior.d.ts +33 -0
- package/dist/matter/behaviors/LevelControlBehavior.d.ts.map +1 -0
- package/dist/matter/behaviors/LevelControlBehavior.js +138 -0
- package/dist/matter/behaviors/LevelControlBehavior.js.map +1 -0
- package/dist/matter/behaviors/LevelControlBehavior.spec.d.ts +2 -0
- package/dist/matter/behaviors/LevelControlBehavior.spec.d.ts.map +1 -0
- package/dist/matter/behaviors/LevelControlBehavior.spec.js +145 -0
- package/dist/matter/behaviors/LevelControlBehavior.spec.js.map +1 -0
- package/dist/matter/behaviors/OnOffBehavior.d.ts +27 -0
- package/dist/matter/behaviors/OnOffBehavior.d.ts.map +1 -0
- package/dist/matter/behaviors/OnOffBehavior.js +95 -0
- package/dist/matter/behaviors/OnOffBehavior.js.map +1 -0
- package/dist/matter/behaviors/OnOffBehavior.spec.d.ts +2 -0
- package/dist/matter/behaviors/OnOffBehavior.spec.d.ts.map +1 -0
- package/dist/matter/behaviors/OnOffBehavior.spec.js +128 -0
- package/dist/matter/behaviors/OnOffBehavior.spec.js.map +1 -0
- package/dist/matter/behaviors/RvcCleanModeBehavior.d.ts +19 -0
- package/dist/matter/behaviors/RvcCleanModeBehavior.d.ts.map +1 -0
- package/dist/matter/behaviors/RvcCleanModeBehavior.js +41 -0
- package/dist/matter/behaviors/RvcCleanModeBehavior.js.map +1 -0
- package/dist/matter/behaviors/RvcCleanModeBehavior.spec.d.ts +2 -0
- package/dist/matter/behaviors/RvcCleanModeBehavior.spec.d.ts.map +1 -0
- package/dist/matter/behaviors/RvcCleanModeBehavior.spec.js +57 -0
- package/dist/matter/behaviors/RvcCleanModeBehavior.spec.js.map +1 -0
- package/dist/matter/behaviors/RvcOperationalStateBehavior.d.ts +22 -0
- package/dist/matter/behaviors/RvcOperationalStateBehavior.d.ts.map +1 -0
- package/dist/matter/behaviors/RvcOperationalStateBehavior.js +86 -0
- package/dist/matter/behaviors/RvcOperationalStateBehavior.js.map +1 -0
- package/dist/matter/behaviors/RvcOperationalStateBehavior.spec.d.ts +2 -0
- package/dist/matter/behaviors/RvcOperationalStateBehavior.spec.d.ts.map +1 -0
- package/dist/matter/behaviors/RvcOperationalStateBehavior.spec.js +55 -0
- package/dist/matter/behaviors/RvcOperationalStateBehavior.spec.js.map +1 -0
- package/dist/matter/behaviors/RvcRunModeBehavior.d.ts +19 -0
- package/dist/matter/behaviors/RvcRunModeBehavior.d.ts.map +1 -0
- package/dist/matter/behaviors/RvcRunModeBehavior.js +41 -0
- package/dist/matter/behaviors/RvcRunModeBehavior.js.map +1 -0
- package/dist/matter/behaviors/RvcRunModeBehavior.spec.d.ts +2 -0
- package/dist/matter/behaviors/RvcRunModeBehavior.spec.d.ts.map +1 -0
- package/dist/matter/behaviors/RvcRunModeBehavior.spec.js +57 -0
- package/dist/matter/behaviors/RvcRunModeBehavior.spec.js.map +1 -0
- package/dist/matter/behaviors/ServiceAreaBehavior.d.ts +21 -0
- package/dist/matter/behaviors/ServiceAreaBehavior.d.ts.map +1 -0
- package/dist/matter/behaviors/ServiceAreaBehavior.js +61 -0
- package/dist/matter/behaviors/ServiceAreaBehavior.js.map +1 -0
- package/dist/matter/behaviors/ServiceAreaBehavior.spec.d.ts +2 -0
- package/dist/matter/behaviors/ServiceAreaBehavior.spec.d.ts.map +1 -0
- package/dist/matter/behaviors/ServiceAreaBehavior.spec.js +53 -0
- package/dist/matter/behaviors/ServiceAreaBehavior.spec.js.map +1 -0
- package/dist/matter/behaviors/ThermostatBehavior.d.ts +22 -0
- package/dist/matter/behaviors/ThermostatBehavior.d.ts.map +1 -0
- package/dist/matter/behaviors/ThermostatBehavior.js +127 -0
- package/dist/matter/behaviors/ThermostatBehavior.js.map +1 -0
- package/dist/matter/behaviors/ThermostatBehavior.spec.d.ts +2 -0
- package/dist/matter/behaviors/ThermostatBehavior.spec.d.ts.map +1 -0
- package/dist/matter/behaviors/ThermostatBehavior.spec.js +23 -0
- package/dist/matter/behaviors/ThermostatBehavior.spec.js.map +1 -0
- package/dist/matter/behaviors/WindowCoveringBehavior.d.ts +31 -0
- package/dist/matter/behaviors/WindowCoveringBehavior.d.ts.map +1 -0
- package/dist/matter/behaviors/WindowCoveringBehavior.js +158 -0
- package/dist/matter/behaviors/WindowCoveringBehavior.js.map +1 -0
- package/dist/matter/behaviors/WindowCoveringBehavior.spec.d.ts +2 -0
- package/dist/matter/behaviors/WindowCoveringBehavior.spec.d.ts.map +1 -0
- package/dist/matter/behaviors/WindowCoveringBehavior.spec.js +27 -0
- package/dist/matter/behaviors/WindowCoveringBehavior.spec.js.map +1 -0
- package/dist/matter/behaviors/index.d.ts +20 -0
- package/dist/matter/behaviors/index.d.ts.map +1 -0
- package/dist/matter/behaviors/index.js +21 -0
- package/dist/matter/behaviors/index.js.map +1 -0
- package/dist/matter/configValidator.d.ts +81 -0
- package/dist/matter/configValidator.d.ts.map +1 -0
- package/dist/matter/configValidator.js +240 -0
- package/dist/matter/configValidator.js.map +1 -0
- package/dist/matter/configValidator.spec.d.ts +2 -0
- package/dist/matter/configValidator.spec.d.ts.map +1 -0
- package/dist/matter/configValidator.spec.js +390 -0
- package/dist/matter/configValidator.spec.js.map +1 -0
- package/dist/matter/errorHandler.d.ts +33 -0
- package/dist/matter/errorHandler.d.ts.map +1 -0
- package/dist/matter/errorHandler.js +113 -0
- package/dist/matter/errorHandler.js.map +1 -0
- package/dist/matter/errorHandler.spec.d.ts +2 -0
- package/dist/matter/errorHandler.spec.d.ts.map +1 -0
- package/dist/matter/errorHandler.spec.js +159 -0
- package/dist/matter/errorHandler.spec.js.map +1 -0
- package/dist/matter/errors.d.ts +178 -0
- package/dist/matter/errors.d.ts.map +1 -0
- package/dist/matter/errors.js +200 -0
- package/dist/matter/errors.js.map +1 -0
- package/dist/matter/index.d.ts +127 -0
- package/dist/matter/index.d.ts.map +1 -0
- package/dist/matter/index.js +23 -0
- package/dist/matter/index.js.map +1 -0
- package/dist/matter/logFormatter.d.ts +19 -0
- package/dist/matter/logFormatter.d.ts.map +1 -0
- package/dist/matter/logFormatter.js +158 -0
- package/dist/matter/logFormatter.js.map +1 -0
- package/dist/matter/logFormatter.spec.d.ts +2 -0
- package/dist/matter/logFormatter.spec.d.ts.map +1 -0
- package/dist/matter/logFormatter.spec.js +252 -0
- package/dist/matter/logFormatter.spec.js.map +1 -0
- package/dist/matter/server.d.ts +336 -0
- package/dist/matter/server.d.ts.map +1 -0
- package/dist/matter/server.js +1810 -0
- package/dist/matter/server.js.map +1 -0
- package/dist/matter/serverHelpers.d.ts +81 -0
- package/dist/matter/serverHelpers.d.ts.map +1 -0
- package/dist/matter/serverHelpers.js +326 -0
- package/dist/matter/serverHelpers.js.map +1 -0
- package/dist/matter/serverHelpers.spec.d.ts +2 -0
- package/dist/matter/serverHelpers.spec.d.ts.map +1 -0
- package/dist/matter/serverHelpers.spec.js +521 -0
- package/dist/matter/serverHelpers.spec.js.map +1 -0
- package/dist/matter/sharedTypes.d.ts +164 -0
- package/dist/matter/sharedTypes.d.ts.map +1 -0
- package/dist/matter/sharedTypes.js +46 -0
- package/dist/matter/sharedTypes.js.map +1 -0
- package/dist/matter/storage.d.ts +135 -0
- package/dist/matter/storage.d.ts.map +1 -0
- package/dist/matter/storage.js +424 -0
- package/dist/matter/storage.js.map +1 -0
- package/dist/matter/storage.spec.d.ts +2 -0
- package/dist/matter/storage.spec.d.ts.map +1 -0
- package/dist/matter/storage.spec.js +570 -0
- package/dist/matter/storage.spec.js.map +1 -0
- package/dist/matter/typeHelpers.d.ts +45 -0
- package/dist/matter/typeHelpers.d.ts.map +1 -0
- package/dist/matter/typeHelpers.js +57 -0
- package/dist/matter/typeHelpers.js.map +1 -0
- package/dist/matter/typeHelpers.spec.d.ts +2 -0
- package/dist/matter/typeHelpers.spec.d.ts.map +1 -0
- package/dist/matter/typeHelpers.spec.js +127 -0
- package/dist/matter/typeHelpers.spec.js.map +1 -0
- package/dist/matter/types.d.ts +826 -0
- package/dist/matter/types.d.ts.map +1 -0
- package/dist/matter/types.js +204 -0
- package/dist/matter/types.js.map +1 -0
- package/{lib → dist}/platformAccessory.d.ts +8 -6
- package/dist/platformAccessory.d.ts.map +1 -0
- package/{lib → dist}/platformAccessory.js +19 -16
- package/dist/platformAccessory.js.map +1 -0
- package/dist/platformAccessory.spec.d.ts +2 -0
- package/dist/platformAccessory.spec.d.ts.map +1 -0
- package/dist/platformAccessory.spec.js +126 -0
- package/dist/platformAccessory.spec.js.map +1 -0
- package/{lib → dist}/plugin.d.ts +2 -3
- package/dist/plugin.d.ts.map +1 -0
- package/{lib → dist}/plugin.js +39 -51
- package/dist/plugin.js.map +1 -0
- package/{lib → dist}/pluginManager.d.ts +3 -3
- package/dist/pluginManager.d.ts.map +1 -0
- package/{lib → dist}/pluginManager.js +76 -81
- package/dist/pluginManager.js.map +1 -0
- package/dist/pluginManager.spec.d.ts +2 -0
- package/dist/pluginManager.spec.d.ts.map +1 -0
- package/dist/pluginManager.spec.js +43 -0
- package/dist/pluginManager.spec.js.map +1 -0
- package/{lib → dist}/server.d.ts +14 -1
- package/dist/server.d.ts.map +1 -0
- package/{lib → dist}/server.js +193 -123
- package/dist/server.js.map +1 -0
- package/dist/server.spec.d.ts +2 -0
- package/dist/server.spec.d.ts.map +1 -0
- package/dist/server.spec.js +57 -0
- package/dist/server.spec.js.map +1 -0
- package/{lib → dist}/storageService.d.ts.map +1 -1
- package/dist/storageService.js +41 -0
- package/dist/storageService.js.map +1 -0
- package/{lib → dist}/user.d.ts +1 -0
- package/dist/user.d.ts.map +1 -0
- package/dist/user.js +32 -0
- package/dist/user.js.map +1 -0
- package/dist/user.spec.d.ts +2 -0
- package/dist/user.spec.d.ts.map +1 -0
- package/dist/user.spec.js +31 -0
- package/dist/user.spec.js.map +1 -0
- package/{lib → dist}/util/mac.d.ts +1 -0
- package/dist/util/mac.d.ts.map +1 -0
- package/dist/util/mac.js +14 -0
- package/dist/util/mac.js.map +1 -0
- package/dist/util/mac.spec.d.ts +2 -0
- package/dist/util/mac.spec.d.ts.map +1 -0
- package/dist/util/mac.spec.js +36 -0
- package/dist/util/mac.spec.js.map +1 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +16 -0
- package/dist/version.js.map +1 -0
- package/dist/version.spec.d.ts +2 -0
- package/dist/version.spec.d.ts.map +1 -0
- package/dist/version.spec.js +20 -0
- package/dist/version.spec.js.map +1 -0
- package/package.json +49 -50
- package/bin/homebridge +0 -17
- package/lib/api.d.ts +0 -210
- package/lib/api.d.ts.map +0 -1
- package/lib/api.js +0 -155
- package/lib/api.js.map +0 -1
- package/lib/bridgeService.d.ts.map +0 -1
- package/lib/bridgeService.js.map +0 -1
- package/lib/childBridgeFork.d.ts.map +0 -1
- package/lib/childBridgeFork.js.map +0 -1
- package/lib/childBridgeService.d.ts.map +0 -1
- package/lib/childBridgeService.js.map +0 -1
- package/lib/cli.d.ts +0 -4
- package/lib/cli.d.ts.map +0 -1
- package/lib/cli.js +0 -111
- package/lib/cli.js.map +0 -1
- package/lib/externalPortService.d.ts +0 -33
- package/lib/externalPortService.d.ts.map +0 -1
- package/lib/externalPortService.js +0 -64
- package/lib/externalPortService.js.map +0 -1
- package/lib/index.d.ts +0 -76
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -72
- package/lib/index.js.map +0 -1
- package/lib/ipcService.d.ts +0 -33
- package/lib/ipcService.d.ts.map +0 -1
- package/lib/ipcService.js.map +0 -1
- package/lib/logger.d.ts.map +0 -1
- package/lib/logger.js.map +0 -1
- package/lib/platformAccessory.d.ts.map +0 -1
- package/lib/platformAccessory.js.map +0 -1
- package/lib/plugin.d.ts.map +0 -1
- package/lib/plugin.js.map +0 -1
- package/lib/pluginManager.d.ts.map +0 -1
- package/lib/pluginManager.js.map +0 -1
- package/lib/server.d.ts.map +0 -1
- package/lib/server.js.map +0 -1
- package/lib/storageService.js +0 -70
- package/lib/storageService.js.map +0 -1
- package/lib/user.d.ts.map +0 -1
- package/lib/user.js +0 -36
- package/lib/user.js.map +0 -1
- package/lib/util/mac.d.ts.map +0 -1
- package/lib/util/mac.js +0 -20
- package/lib/util/mac.js.map +0 -1
- package/lib/version.d.ts.map +0 -1
- package/lib/version.js +0 -21
- package/lib/version.js.map +0 -1
- /package/{lib → dist}/storageService.d.ts +0 -0
- /package/{lib → dist}/version.d.ts +0 -0
package/{lib → dist}/plugin.js
RENAMED
|
@@ -1,27 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const semver_1 = require("semver");
|
|
11
|
-
const logger_1 = require("./logger");
|
|
12
|
-
const pluginManager_1 = require("./pluginManager");
|
|
13
|
-
const version_1 = __importDefault(require("./version"));
|
|
14
|
-
const log = logger_1.Logger.internal;
|
|
15
|
-
// Workaround for https://github.com/microsoft/TypeScript/issues/43329
|
|
16
|
-
const _importDynamic = new Function("modulePath", "return import(modulePath)");
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
import { satisfies } from 'semver';
|
|
6
|
+
import { Logger } from './logger.js';
|
|
7
|
+
import { PluginManager } from './pluginManager.js';
|
|
8
|
+
import getVersion from './version.js';
|
|
9
|
+
const log = Logger.internal;
|
|
17
10
|
/**
|
|
18
11
|
* Represents a loaded Homebridge plugin.
|
|
19
12
|
*/
|
|
20
|
-
class Plugin {
|
|
13
|
+
export class Plugin {
|
|
21
14
|
pluginName;
|
|
22
15
|
scope; // npm package scope
|
|
23
16
|
pluginPath; // like "/usr/local/lib/node_modules/homebridge-lockitron"
|
|
24
|
-
isESM;
|
|
25
17
|
disabled = false; // mark the plugin as disabled
|
|
26
18
|
// ------------------ package.json content ------------------
|
|
27
19
|
version;
|
|
@@ -36,20 +28,20 @@ class Plugin {
|
|
|
36
28
|
this.pluginName = name;
|
|
37
29
|
this.scope = scope;
|
|
38
30
|
this.pluginPath = path;
|
|
39
|
-
this.version = packageJSON.version ||
|
|
40
|
-
this.main =
|
|
31
|
+
this.version = packageJSON.version || '0.0.0';
|
|
32
|
+
this.main = '';
|
|
41
33
|
// figure out the main module
|
|
42
34
|
// exports is available - https://nodejs.org/dist/latest-v14.x/docs/api/packages.html#packages_package_entry_points
|
|
43
35
|
if (packageJSON.exports) {
|
|
44
36
|
// main entrypoint - https://nodejs.org/dist/latest-v14.x/docs/api/packages.html#packages_main_entry_point_export
|
|
45
|
-
if (typeof packageJSON.exports ===
|
|
37
|
+
if (typeof packageJSON.exports === 'string') {
|
|
46
38
|
this.main = packageJSON.exports;
|
|
47
39
|
}
|
|
48
40
|
else { // subpath export - https://nodejs.org/dist/latest-v14.x/docs/api/packages.html#packages_subpath_exports
|
|
49
41
|
// conditional exports - https://nodejs.org/dist/latest-v14.x/docs/api/packages.html#packages_conditional_exports
|
|
50
|
-
const exports = packageJSON.exports.import || packageJSON.exports.require || packageJSON.exports.node || packageJSON.exports.default || packageJSON.exports[
|
|
42
|
+
const exports = packageJSON.exports.import || packageJSON.exports.require || packageJSON.exports.node || packageJSON.exports.default || packageJSON.exports['.'];
|
|
51
43
|
// check if conditional export is nested
|
|
52
|
-
if (typeof exports !==
|
|
44
|
+
if (typeof exports !== 'string') {
|
|
53
45
|
if (exports.import) {
|
|
54
46
|
this.main = exports.import;
|
|
55
47
|
}
|
|
@@ -64,10 +56,8 @@ class Plugin {
|
|
|
64
56
|
}
|
|
65
57
|
// exports search was not successful, fallback to package.main, using index.js as fallback
|
|
66
58
|
if (!this.main) {
|
|
67
|
-
this.main = packageJSON.main ||
|
|
59
|
+
this.main = packageJSON.main || './index.js';
|
|
68
60
|
}
|
|
69
|
-
// check if it is an ESM module
|
|
70
|
-
this.isESM = this.main.endsWith(".mjs") || (this.main.endsWith(".js") && packageJSON.type === "module");
|
|
71
61
|
// very temporary fix for first wave of plugins
|
|
72
62
|
if (packageJSON.peerDependencies && (!packageJSON.engines || !packageJSON.engines.homebridge)) {
|
|
73
63
|
packageJSON.engines = packageJSON.engines || {};
|
|
@@ -79,7 +69,7 @@ class Plugin {
|
|
|
79
69
|
};
|
|
80
70
|
}
|
|
81
71
|
getPluginIdentifier() {
|
|
82
|
-
return (this.scope ? this.scope
|
|
72
|
+
return (this.scope ? `${this.scope}/` : '') + this.pluginName;
|
|
83
73
|
}
|
|
84
74
|
getPluginPath() {
|
|
85
75
|
return this.pluginPath;
|
|
@@ -89,7 +79,7 @@ class Plugin {
|
|
|
89
79
|
throw new Error(`Plugin '${this.getPluginIdentifier()}' tried to register an accessory '${name}' which has already been registered!`);
|
|
90
80
|
}
|
|
91
81
|
if (!this.disabled) {
|
|
92
|
-
log.info(
|
|
82
|
+
log.info('Registering accessory \'%s\'', `${this.getPluginIdentifier()}.${name}`);
|
|
93
83
|
}
|
|
94
84
|
this.registeredAccessories.set(name, constructor);
|
|
95
85
|
}
|
|
@@ -98,12 +88,12 @@ class Plugin {
|
|
|
98
88
|
throw new Error(`Plugin '${this.getPluginIdentifier()}' tried to register a platform '${name}' which has already been registered!`);
|
|
99
89
|
}
|
|
100
90
|
if (!this.disabled) {
|
|
101
|
-
log.info(
|
|
91
|
+
log.info('Registering platform \'%s\'', `${this.getPluginIdentifier()}.${name}`);
|
|
102
92
|
}
|
|
103
93
|
this.registeredPlatforms.set(name, constructor);
|
|
104
94
|
}
|
|
105
95
|
getAccessoryConstructor(accessoryIdentifier) {
|
|
106
|
-
const name =
|
|
96
|
+
const name = PluginManager.getAccessoryName(accessoryIdentifier);
|
|
107
97
|
const constructor = this.registeredAccessories.get(name);
|
|
108
98
|
if (!constructor) {
|
|
109
99
|
throw new Error(`The requested accessory '${name}' was not registered by the plugin '${this.getPluginIdentifier()}'.`);
|
|
@@ -111,20 +101,20 @@ class Plugin {
|
|
|
111
101
|
return constructor;
|
|
112
102
|
}
|
|
113
103
|
getPlatformConstructor(platformIdentifier) {
|
|
114
|
-
const name =
|
|
104
|
+
const name = PluginManager.getPlatformName(platformIdentifier);
|
|
115
105
|
const constructor = this.registeredPlatforms.get(name);
|
|
116
106
|
if (!constructor) {
|
|
117
107
|
throw new Error(`The requested platform '${name}' was not registered by the plugin '${this.getPluginIdentifier()}'.`);
|
|
118
108
|
}
|
|
119
109
|
// If it's a dynamic platform plugin, ensure it's not enabled multiple times.
|
|
120
110
|
if (this.activeDynamicPlatforms.has(name)) {
|
|
121
|
-
throw new Error(
|
|
122
|
-
|
|
111
|
+
throw new Error(`The dynamic platform ${name} from the plugin ${this.getPluginIdentifier()} is configured `
|
|
112
|
+
+ 'times in your config.json.');
|
|
123
113
|
}
|
|
124
114
|
return constructor;
|
|
125
115
|
}
|
|
126
116
|
assignDynamicPlatform(platformIdentifier, platformPlugin) {
|
|
127
|
-
const name =
|
|
117
|
+
const name = PluginManager.getPlatformName(platformIdentifier);
|
|
128
118
|
let platforms = this.activeDynamicPlatforms.get(name);
|
|
129
119
|
if (!platforms) {
|
|
130
120
|
platforms = [];
|
|
@@ -141,42 +131,41 @@ class Plugin {
|
|
|
141
131
|
}
|
|
142
132
|
async load() {
|
|
143
133
|
const context = this.loadContext;
|
|
144
|
-
(
|
|
134
|
+
assert(context, 'Reached illegal state. Plugin state is undefined!');
|
|
145
135
|
this.loadContext = undefined; // free up memory
|
|
146
|
-
// pluck out the
|
|
136
|
+
// pluck out the Homebridge version requirement
|
|
147
137
|
if (!context.engines || !context.engines.homebridge) {
|
|
148
138
|
throw new Error(`Plugin ${this.pluginPath} does not contain the 'homebridge' package in 'engines'.`);
|
|
149
139
|
}
|
|
150
140
|
const versionRequired = context.engines.homebridge;
|
|
151
141
|
const nodeVersionRequired = context.engines.node;
|
|
152
|
-
// make sure the version is satisfied by the currently running version of
|
|
153
|
-
if (!
|
|
142
|
+
// make sure the version is satisfied by the currently running version of Homebridge
|
|
143
|
+
if (!satisfies(getVersion(), versionRequired, { includePrerelease: true })) {
|
|
154
144
|
// TODO - change this back to an error
|
|
155
|
-
log.
|
|
156
|
-
not satisfy the current Homebridge version of ${(
|
|
145
|
+
log.warn(`The plugin "${this.pluginName}" requires a Homebridge version of ${versionRequired} which does \
|
|
146
|
+
not satisfy the current Homebridge version of v${getVersion()}. You may need to update this plugin (or Homebridge) to a newer version. \
|
|
157
147
|
You may face unexpected issues or stability problems running this plugin.`);
|
|
158
148
|
}
|
|
159
149
|
// make sure the version is satisfied by the currently running version of Node
|
|
160
|
-
if (nodeVersionRequired && !
|
|
161
|
-
log.warn(`The plugin "${this.pluginName}" requires Node.js version of ${nodeVersionRequired} which does \
|
|
150
|
+
if (nodeVersionRequired && !satisfies(process.version, nodeVersionRequired)) {
|
|
151
|
+
log.warn(`The plugin "${this.pluginName}" requires a Node.js version of ${nodeVersionRequired} which does \
|
|
162
152
|
not satisfy the current Node.js version of ${process.version}. You may need to upgrade your installation of Node.js - see https://homebridge.io/w/JTKEF`);
|
|
163
153
|
}
|
|
164
154
|
const dependencies = context.dependencies || {};
|
|
165
|
-
if (dependencies.homebridge || dependencies[
|
|
155
|
+
if (dependencies.homebridge || dependencies['hap-nodejs']) {
|
|
166
156
|
log.error(`The plugin "${this.pluginName}" defines 'homebridge' and/or 'hap-nodejs' in their 'dependencies' section, \
|
|
167
157
|
meaning they carry an additional copy of homebridge and hap-nodejs. This not only wastes disk space, but also can cause \
|
|
168
158
|
major incompatibility issues and thus is considered bad practice. Please inform the developer to update their plugin!`);
|
|
169
159
|
}
|
|
170
|
-
const mainPath =
|
|
171
|
-
// try to
|
|
172
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
160
|
+
const mainPath = join(this.pluginPath, this.main);
|
|
161
|
+
// try to import it and grab the exported initialization hook
|
|
173
162
|
// pathToFileURL(specifier).href to turn a path into a "file url"
|
|
174
163
|
// see https://github.com/nodejs/node/issues/31710
|
|
175
|
-
const pluginModules =
|
|
176
|
-
if (typeof pluginModules ===
|
|
164
|
+
const pluginModules = (await import(pathToFileURL(mainPath).href)).default;
|
|
165
|
+
if (typeof pluginModules === 'function') {
|
|
177
166
|
this.pluginInitializer = pluginModules;
|
|
178
167
|
}
|
|
179
|
-
else if (pluginModules && typeof pluginModules.default ===
|
|
168
|
+
else if (pluginModules && typeof pluginModules.default === 'function') {
|
|
180
169
|
this.pluginInitializer = pluginModules.default;
|
|
181
170
|
}
|
|
182
171
|
else {
|
|
@@ -185,10 +174,9 @@ major incompatibility issues and thus is considered bad practice. Please inform
|
|
|
185
174
|
}
|
|
186
175
|
initialize(api) {
|
|
187
176
|
if (!this.pluginInitializer) {
|
|
188
|
-
throw new Error(
|
|
177
|
+
throw new Error('Tried to initialize a plugin which hasn\'t been loaded yet!');
|
|
189
178
|
}
|
|
190
179
|
return this.pluginInitializer(api);
|
|
191
180
|
}
|
|
192
181
|
}
|
|
193
|
-
exports.Plugin = Plugin;
|
|
194
182
|
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAeA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,OAAO,MAAM,cAAc,CAAA;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU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AAC;QAED,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,EAAE,CAAA;QAC/C,IAAI,YAAY,CAAC,UAAU,IAAI,YAAY,CAAC,YAAY,CAAC,EAAE,CAAC;YAC1D,GAAG,CAAC,KAAK,CAAC,eAAe,IAAI,CAAC,UAAU;;sHAEwE,CAAC,CAAA;QACnH,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;QAEjD,6DAA6D;QAC7D,iEAAiE;QACjE,kDAAkD;QAClD,MAAM,aAAa,GAAG,CAAC,MAAM,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAA;QAE1E,IAAI,OAAO,aAAa,KAAK,UAAU,EAAE,CAAC;YACxC,IAAI,CAAC,iBAAiB,GAAG,aAAa,CAAA;QACxC,CAAC;aAAM,IAAI,aAAa,IAAI,OAAO,aAAa,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;YACxE,IAAI,CAAC,iBAAiB,GAAG,aAAa,CAAC,OAAO,CAAA;QAChD,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,UAAU,IAAI,CAAC,UAAU,oDAAoD,CAAC,CAAA;QAChG,CAAC;IACH,CAAC;IAEM,UAAU,CAAC,GAAQ;QACxB,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAA;QAChF,CAAC;QAED,OAAO,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAA;IACpC,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AccessoryIdentifier, AccessoryName, HomebridgeAPI, PlatformIdentifier, PlatformName, PluginIdentifier, PluginName } from
|
|
2
|
-
import { Plugin } from
|
|
1
|
+
import type { AccessoryIdentifier, AccessoryName, HomebridgeAPI, PlatformIdentifier, PlatformName, PluginIdentifier, PluginName } from './api.js';
|
|
2
|
+
import { Plugin } from './plugin.js';
|
|
3
3
|
export interface PackageJSON {
|
|
4
4
|
name: string;
|
|
5
5
|
version: string;
|
|
@@ -10,7 +10,7 @@ export interface PackageJSON {
|
|
|
10
10
|
* When set as module, it marks .js file to be treated as ESM.
|
|
11
11
|
* See https://nodejs.org/dist/latest-v14.x/docs/api/esm.html#esm_enabling
|
|
12
12
|
*/
|
|
13
|
-
type?:
|
|
13
|
+
type?: 'module' | 'commonjs';
|
|
14
14
|
engines?: Record<string, string>;
|
|
15
15
|
dependencies?: Record<string, string>;
|
|
16
16
|
devDependencies?: Record<string, string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginManager.d.ts","sourceRoot":"","sources":["../src/pluginManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,aAAa,EAEb,aAAa,EACb,kBAAkB,EAClB,YAAY,EAEZ,gBAAgB,EAChB,UAAU,EACX,MAAM,UAAU,CAAA;AAUjB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAMpC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IAGnB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IAClE,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;;OAGG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAA;IAE5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACrC,eAAe,CAAC,EAAE,MAAM,CAAC,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AQnE,mBAAmB,CAAC,UAAU,EAAE,mBAAmB,GAAG,kBAAkB,GAAG,gBAAgB;IAI5F,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC;IAoC3C,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAchF,OAAO,CAAC,uBAAuB;IAoB/B,OAAO,CAAC,sBAAsB;IAoBvB,qBAAqB,CAAC,mBAAmB,EAAE,mBAAmB,GAAG,aAAa,GAAG,MAAM;IAgCvF,oBAAoB,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,YAAY,GAAG,MAAM;IAgCnF,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO;IAIhE,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,MAAM,GAAG,SAAS;IAcjE,gCAAgC,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS;IAcvF;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAoErB,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IAiB/C,OAAO,CAAC,MAAM,CAAC,eAAe;IA0B9B,OAAO,CAAC,gBAAgB;IAsCxB,OAAO,CAAC,yBAAyB;CAYlC"}
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const plugin_1 = require("./plugin");
|
|
12
|
-
const log = logger_1.Logger.internal;
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { delimiter, join, resolve } from 'node:path';
|
|
5
|
+
import process from 'node:process';
|
|
6
|
+
import { Logger } from './logger.js';
|
|
7
|
+
import { Plugin } from './plugin.js';
|
|
8
|
+
const log = Logger.internal;
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
const paths = require.resolve.paths('');
|
|
13
11
|
/**
|
|
14
12
|
* Utility which exposes methods to search for installed Homebridge plugins
|
|
15
13
|
*/
|
|
16
|
-
class PluginManager {
|
|
14
|
+
export class PluginManager {
|
|
17
15
|
// name must be prefixed with 'homebridge-' or '@scope/homebridge-'
|
|
18
|
-
static PLUGIN_IDENTIFIER_PATTERN = /^((@[\w-]*)\/)?(homebridge-[\w-]
|
|
16
|
+
static PLUGIN_IDENTIFIER_PATTERN = /^((@[\w-]+(\.[\w-]+)*)\/)?(homebridge-[\w-]+)$/;
|
|
19
17
|
api;
|
|
20
18
|
searchPaths = new Set(); // unique set of search paths we will use to discover installed plugins
|
|
21
19
|
strictPluginResolution = false;
|
|
@@ -31,7 +29,7 @@ class PluginManager {
|
|
|
31
29
|
this.api = api;
|
|
32
30
|
if (options) {
|
|
33
31
|
if (options.customPluginPath) {
|
|
34
|
-
this.searchPaths.add(
|
|
32
|
+
this.searchPaths.add(resolve(process.cwd(), options.customPluginPath));
|
|
35
33
|
}
|
|
36
34
|
this.strictPluginResolution = options.strictPluginResolution || false;
|
|
37
35
|
this.activePlugins = options.activePlugins;
|
|
@@ -44,38 +42,38 @@ class PluginManager {
|
|
|
44
42
|
return PluginManager.PLUGIN_IDENTIFIER_PATTERN.test(identifier);
|
|
45
43
|
}
|
|
46
44
|
static extractPluginName(name) {
|
|
47
|
-
return name.match(PluginManager.PLUGIN_IDENTIFIER_PATTERN)[
|
|
45
|
+
return name.match(PluginManager.PLUGIN_IDENTIFIER_PATTERN)[4];
|
|
48
46
|
}
|
|
49
47
|
static extractPluginScope(name) {
|
|
50
48
|
return name.match(PluginManager.PLUGIN_IDENTIFIER_PATTERN)[2];
|
|
51
49
|
}
|
|
52
50
|
static getAccessoryName(identifier) {
|
|
53
|
-
if (identifier.
|
|
51
|
+
if (!identifier.includes('.')) {
|
|
54
52
|
return identifier;
|
|
55
53
|
}
|
|
56
|
-
return identifier.split(
|
|
54
|
+
return identifier.split('.')[1];
|
|
57
55
|
}
|
|
58
56
|
static getPlatformName(identifier) {
|
|
59
|
-
if (identifier.
|
|
57
|
+
if (!identifier.includes('.')) {
|
|
60
58
|
return identifier;
|
|
61
59
|
}
|
|
62
|
-
return identifier.split(
|
|
60
|
+
return identifier.split('.')[1];
|
|
63
61
|
}
|
|
64
62
|
static getPluginIdentifier(identifier) {
|
|
65
|
-
return identifier.split(
|
|
63
|
+
return identifier.split('.')[0];
|
|
66
64
|
}
|
|
67
65
|
async initializeInstalledPlugins() {
|
|
68
|
-
log.info(
|
|
66
|
+
log.info('---');
|
|
69
67
|
this.loadInstalledPlugins();
|
|
70
68
|
for (const [identifier, plugin] of this.plugins) {
|
|
71
69
|
try {
|
|
72
70
|
await plugin.load();
|
|
73
71
|
}
|
|
74
72
|
catch (error) {
|
|
75
|
-
log.error(
|
|
73
|
+
log.error('====================');
|
|
76
74
|
log.error(`ERROR LOADING PLUGIN ${identifier}:`);
|
|
77
75
|
log.error(error.stack);
|
|
78
|
-
log.error(
|
|
76
|
+
log.error('====================');
|
|
79
77
|
this.plugins.delete(identifier);
|
|
80
78
|
continue;
|
|
81
79
|
}
|
|
@@ -89,7 +87,7 @@ class PluginManager {
|
|
|
89
87
|
log.info(`Loaded plugin: ${identifier}@${plugin.version}`);
|
|
90
88
|
}
|
|
91
89
|
await this.initializePlugin(plugin, identifier);
|
|
92
|
-
log.info(
|
|
90
|
+
log.info('---');
|
|
93
91
|
}
|
|
94
92
|
this.currentInitializingPlugin = undefined;
|
|
95
93
|
}
|
|
@@ -99,17 +97,16 @@ class PluginManager {
|
|
|
99
97
|
await plugin.initialize(this.api); // call the plugin's initializer and pass it our API instance
|
|
100
98
|
}
|
|
101
99
|
catch (error) {
|
|
102
|
-
log.error(
|
|
100
|
+
log.error('====================');
|
|
103
101
|
log.error(`ERROR INITIALIZING PLUGIN ${identifier}:`);
|
|
104
102
|
log.error(error.stack);
|
|
105
|
-
log.error(
|
|
103
|
+
log.error('====================');
|
|
106
104
|
this.plugins.delete(identifier);
|
|
107
|
-
return;
|
|
108
105
|
}
|
|
109
106
|
}
|
|
110
107
|
handleRegisterAccessory(name, constructor, pluginIdentifier) {
|
|
111
108
|
if (!this.currentInitializingPlugin) {
|
|
112
|
-
throw new Error(`Unexpected accessory registration. Plugin ${pluginIdentifier ? `'${pluginIdentifier}' ` :
|
|
109
|
+
throw new Error(`Unexpected accessory registration. Plugin ${pluginIdentifier ? `'${pluginIdentifier}' ` : ''}tried to register outside the initializer function!`);
|
|
113
110
|
}
|
|
114
111
|
if (pluginIdentifier && pluginIdentifier !== this.currentInitializingPlugin.getPluginIdentifier()) {
|
|
115
112
|
log.info(`Plugin '${this.currentInitializingPlugin.getPluginIdentifier()}' tried to register with an incorrect plugin identifier: '${pluginIdentifier}'. Please report this to the developer!`);
|
|
@@ -125,7 +122,7 @@ class PluginManager {
|
|
|
125
122
|
}
|
|
126
123
|
handleRegisterPlatform(name, constructor, pluginIdentifier) {
|
|
127
124
|
if (!this.currentInitializingPlugin) {
|
|
128
|
-
throw new Error(`Unexpected platform registration. Plugin ${pluginIdentifier ? `'${pluginIdentifier}' ` :
|
|
125
|
+
throw new Error(`Unexpected platform registration. Plugin ${pluginIdentifier ? `'${pluginIdentifier}' ` : ''}tried to register outside the initializer function!`);
|
|
129
126
|
}
|
|
130
127
|
if (pluginIdentifier && pluginIdentifier !== this.currentInitializingPlugin.getPluginIdentifier()) {
|
|
131
128
|
log.debug(`Plugin '${this.currentInitializingPlugin.getPluginIdentifier()}' tried to register with an incorrect plugin identifier: '${pluginIdentifier}'. Please report this to the developer!`);
|
|
@@ -141,13 +138,13 @@ class PluginManager {
|
|
|
141
138
|
}
|
|
142
139
|
getPluginForAccessory(accessoryIdentifier) {
|
|
143
140
|
let plugin;
|
|
144
|
-
if (accessoryIdentifier.
|
|
141
|
+
if (!accessoryIdentifier.includes('.')) { // see if it matches exactly one accessory
|
|
145
142
|
let found = this.accessoryToPluginMap.get(accessoryIdentifier);
|
|
146
143
|
if (!found) {
|
|
147
144
|
throw new Error(`No plugin was found for the accessory "${accessoryIdentifier}" in your config.json. Please make sure the corresponding plugin is installed correctly.`);
|
|
148
145
|
}
|
|
149
146
|
if (found.length > 1) {
|
|
150
|
-
const options = found.map(plugin => plugin.getPluginIdentifier()
|
|
147
|
+
const options = found.map(plugin => `${plugin.getPluginIdentifier()}.${accessoryIdentifier}`).join(', ');
|
|
151
148
|
// check if only one of the multiple platforms is not disabled
|
|
152
149
|
found = found.filter(plugin => !plugin.disabled);
|
|
153
150
|
if (found.length !== 1) {
|
|
@@ -155,7 +152,7 @@ class PluginManager {
|
|
|
155
152
|
}
|
|
156
153
|
}
|
|
157
154
|
plugin = found[0];
|
|
158
|
-
accessoryIdentifier = plugin.getPluginIdentifier()
|
|
155
|
+
accessoryIdentifier = `${plugin.getPluginIdentifier()}.${accessoryIdentifier}`;
|
|
159
156
|
}
|
|
160
157
|
else {
|
|
161
158
|
const pluginIdentifier = PluginManager.getPluginIdentifier(accessoryIdentifier);
|
|
@@ -168,13 +165,13 @@ class PluginManager {
|
|
|
168
165
|
}
|
|
169
166
|
getPluginForPlatform(platformIdentifier) {
|
|
170
167
|
let plugin;
|
|
171
|
-
if (platformIdentifier.
|
|
168
|
+
if (!platformIdentifier.includes('.')) { // see if it matches exactly one platform
|
|
172
169
|
let found = this.platformToPluginMap.get(platformIdentifier);
|
|
173
170
|
if (!found) {
|
|
174
171
|
throw new Error(`No plugin was found for the platform "${platformIdentifier}" in your config.json. Please make sure the corresponding plugin is installed correctly.`);
|
|
175
172
|
}
|
|
176
173
|
if (found.length > 1) {
|
|
177
|
-
const options = found.map(plugin => plugin.getPluginIdentifier()
|
|
174
|
+
const options = found.map(plugin => `${plugin.getPluginIdentifier()}.${platformIdentifier}`).join(', ');
|
|
178
175
|
// check if only one of the multiple platforms is not disabled
|
|
179
176
|
found = found.filter(plugin => !plugin.disabled);
|
|
180
177
|
if (found.length !== 1) {
|
|
@@ -182,7 +179,7 @@ class PluginManager {
|
|
|
182
179
|
}
|
|
183
180
|
}
|
|
184
181
|
plugin = found[0];
|
|
185
|
-
platformIdentifier = plugin.getPluginIdentifier()
|
|
182
|
+
platformIdentifier = `${plugin.getPluginIdentifier()}.${platformIdentifier}`;
|
|
186
183
|
}
|
|
187
184
|
else {
|
|
188
185
|
const pluginIdentifier = PluginManager.getPluginIdentifier(platformIdentifier);
|
|
@@ -216,7 +213,7 @@ class PluginManager {
|
|
|
216
213
|
return undefined;
|
|
217
214
|
}
|
|
218
215
|
else if (found.length > 1) {
|
|
219
|
-
const plugins = found.map(plugin => plugin.getPluginIdentifier()).join(
|
|
216
|
+
const plugins = found.map(plugin => plugin.getPluginIdentifier()).join(', ');
|
|
220
217
|
throw new Error(`'${platformName}' is an ambiguous platform name. It was registered by multiple plugins: ${plugins}`);
|
|
221
218
|
}
|
|
222
219
|
else {
|
|
@@ -228,70 +225,68 @@ class PluginManager {
|
|
|
228
225
|
*/
|
|
229
226
|
loadInstalledPlugins() {
|
|
230
227
|
this.loadDefaultPaths();
|
|
231
|
-
this.searchPaths.forEach(searchPath => {
|
|
232
|
-
if (!
|
|
228
|
+
this.searchPaths.forEach((searchPath) => {
|
|
229
|
+
if (!existsSync(searchPath)) { // just because this path is in require.main.paths doesn't mean it necessarily exists!
|
|
233
230
|
return;
|
|
234
231
|
}
|
|
235
|
-
if (
|
|
232
|
+
if (existsSync(join(searchPath, 'package.json'))) { // does this path point inside a single plugin and not a directory containing plugins?
|
|
236
233
|
try {
|
|
237
234
|
this.loadPlugin(searchPath);
|
|
238
235
|
}
|
|
239
236
|
catch (error) {
|
|
240
237
|
log.warn(error.message);
|
|
241
|
-
return;
|
|
242
238
|
}
|
|
243
239
|
}
|
|
244
240
|
else { // read through each directory in this node_modules folder
|
|
245
|
-
const relativePluginPaths =
|
|
246
|
-
.filter(relativePath => {
|
|
241
|
+
const relativePluginPaths = readdirSync(searchPath) // search for directories only
|
|
242
|
+
.filter((relativePath) => {
|
|
247
243
|
try {
|
|
248
|
-
return
|
|
244
|
+
return statSync(resolve(searchPath, relativePath)).isDirectory();
|
|
249
245
|
}
|
|
250
|
-
catch (
|
|
251
|
-
log.debug(`Ignoring path ${
|
|
246
|
+
catch (error) {
|
|
247
|
+
log.debug(`Ignoring path ${resolve(searchPath, relativePath)} - ${error.message}`);
|
|
252
248
|
return false;
|
|
253
249
|
}
|
|
254
250
|
});
|
|
255
251
|
// expand out @scoped plugins
|
|
256
252
|
relativePluginPaths.slice()
|
|
257
|
-
.filter(path => path.charAt(0) ===
|
|
258
|
-
.forEach(scopeDirectory => {
|
|
253
|
+
.filter(path => path.charAt(0) === '@') // is it a scope directory?
|
|
254
|
+
.forEach((scopeDirectory) => {
|
|
259
255
|
// remove scopeDirectory from the path list
|
|
260
256
|
const index = relativePluginPaths.indexOf(scopeDirectory);
|
|
261
257
|
relativePluginPaths.splice(index, 1);
|
|
262
|
-
const absolutePath =
|
|
263
|
-
|
|
258
|
+
const absolutePath = join(searchPath, scopeDirectory);
|
|
259
|
+
readdirSync(absolutePath)
|
|
264
260
|
.filter(name => PluginManager.isQualifiedPluginIdentifier(name))
|
|
265
|
-
.filter(name => {
|
|
261
|
+
.filter((name) => {
|
|
266
262
|
try {
|
|
267
|
-
return
|
|
263
|
+
return statSync(resolve(absolutePath, name)).isDirectory();
|
|
268
264
|
}
|
|
269
|
-
catch (
|
|
270
|
-
log.debug(`Ignoring path ${
|
|
265
|
+
catch (error) {
|
|
266
|
+
log.debug(`Ignoring path ${resolve(absolutePath, name)} - ${error.message}`);
|
|
271
267
|
return false;
|
|
272
268
|
}
|
|
273
269
|
})
|
|
274
|
-
.forEach(name => relativePluginPaths.push(scopeDirectory
|
|
270
|
+
.forEach(name => relativePluginPaths.push(`${scopeDirectory}/${name}`));
|
|
275
271
|
});
|
|
276
272
|
relativePluginPaths
|
|
277
|
-
.filter(pluginIdentifier => {
|
|
273
|
+
.filter((pluginIdentifier) => {
|
|
278
274
|
return PluginManager.isQualifiedPluginIdentifier(pluginIdentifier) // needs to be a valid homebridge plugin name
|
|
279
275
|
&& (!this.activePlugins || this.activePlugins.includes(pluginIdentifier)); // check if activePlugins is restricted and if so is the plugin is contained
|
|
280
276
|
})
|
|
281
|
-
.forEach(pluginIdentifier => {
|
|
277
|
+
.forEach((pluginIdentifier) => {
|
|
282
278
|
try {
|
|
283
|
-
const absolutePath =
|
|
279
|
+
const absolutePath = resolve(searchPath, pluginIdentifier);
|
|
284
280
|
this.loadPlugin(absolutePath);
|
|
285
281
|
}
|
|
286
282
|
catch (error) {
|
|
287
283
|
log.warn(error.message);
|
|
288
|
-
return;
|
|
289
284
|
}
|
|
290
285
|
});
|
|
291
286
|
}
|
|
292
287
|
});
|
|
293
288
|
if (this.plugins.size === 0) {
|
|
294
|
-
log.warn(
|
|
289
|
+
log.warn('No plugins found.');
|
|
295
290
|
}
|
|
296
291
|
}
|
|
297
292
|
loadPlugin(absolutePath) {
|
|
@@ -303,27 +298,27 @@ class PluginManager {
|
|
|
303
298
|
if (alreadyInstalled) {
|
|
304
299
|
throw new Error(`Warning: skipping plugin found at '${absolutePath}' since we already loaded the same plugin from '${alreadyInstalled.getPluginPath()}'.`);
|
|
305
300
|
}
|
|
306
|
-
const plugin = new
|
|
301
|
+
const plugin = new Plugin(name, absolutePath, packageJson, scope);
|
|
307
302
|
this.plugins.set(identifier, plugin);
|
|
308
303
|
return plugin;
|
|
309
304
|
}
|
|
310
305
|
static loadPackageJSON(pluginPath) {
|
|
311
|
-
const packageJsonPath =
|
|
306
|
+
const packageJsonPath = join(pluginPath, 'package.json');
|
|
312
307
|
let packageJson;
|
|
313
|
-
if (!
|
|
308
|
+
if (!existsSync(packageJsonPath)) {
|
|
314
309
|
throw new Error(`Plugin ${pluginPath} does not contain a package.json.`);
|
|
315
310
|
}
|
|
316
311
|
try {
|
|
317
|
-
packageJson = JSON.parse(
|
|
312
|
+
packageJson = JSON.parse(readFileSync(packageJsonPath, { encoding: 'utf8' })); // attempt to parse package.json
|
|
318
313
|
}
|
|
319
|
-
catch (
|
|
320
|
-
throw new Error(`Plugin ${pluginPath} contains an invalid package.json. Error: ${
|
|
314
|
+
catch (error) {
|
|
315
|
+
throw new Error(`Plugin ${pluginPath} contains an invalid package.json. Error: ${error}`);
|
|
321
316
|
}
|
|
322
317
|
if (!packageJson.name || !PluginManager.isQualifiedPluginIdentifier(packageJson.name)) {
|
|
323
318
|
throw new Error(`Plugin ${pluginPath} does not have a package name that begins with 'homebridge-' or '@scope/homebridge-.`);
|
|
324
319
|
}
|
|
325
320
|
// verify that it's tagged with the correct keyword
|
|
326
|
-
if (!packageJson.keywords || !packageJson.keywords.includes(
|
|
321
|
+
if (!packageJson.keywords || !packageJson.keywords.includes('homebridge-plugin')) {
|
|
327
322
|
throw new Error(`Plugin ${pluginPath} package.json does not contain the keyword 'homebridge-plugin'.`);
|
|
328
323
|
}
|
|
329
324
|
return packageJson;
|
|
@@ -338,9 +333,9 @@ class PluginManager {
|
|
|
338
333
|
}
|
|
339
334
|
return;
|
|
340
335
|
}
|
|
341
|
-
if (
|
|
336
|
+
if (paths) {
|
|
342
337
|
// add the paths used by require()
|
|
343
|
-
|
|
338
|
+
paths.forEach(path => this.searchPaths.add(path));
|
|
344
339
|
}
|
|
345
340
|
// THIS SECTION FROM: https://github.com/yeoman/environment/blob/master/lib/resolver.js
|
|
346
341
|
// Adding global npm directories
|
|
@@ -348,33 +343,33 @@ class PluginManager {
|
|
|
348
343
|
// because of bugs in the parsable implementation of `ls` command and mostly
|
|
349
344
|
// performance issues. So, we go with our best bet for now.
|
|
350
345
|
if (process.env.NODE_PATH) {
|
|
351
|
-
process.env
|
|
352
|
-
.
|
|
346
|
+
process.env
|
|
347
|
+
.NODE_PATH
|
|
348
|
+
.split(delimiter)
|
|
353
349
|
.filter(path => !!path) // trim out empty values
|
|
354
350
|
.forEach(path => this.searchPaths.add(path));
|
|
355
351
|
}
|
|
356
352
|
else {
|
|
357
353
|
// Default paths for non-windows systems
|
|
358
|
-
if (process.platform !==
|
|
359
|
-
this.searchPaths.add(
|
|
360
|
-
this.searchPaths.add(
|
|
354
|
+
if (process.platform !== 'win32') {
|
|
355
|
+
this.searchPaths.add('/usr/local/lib/node_modules');
|
|
356
|
+
this.searchPaths.add('/usr/lib/node_modules');
|
|
361
357
|
}
|
|
362
358
|
this.addNpmPrefixToSearchPaths();
|
|
363
359
|
}
|
|
364
360
|
}
|
|
365
361
|
addNpmPrefixToSearchPaths() {
|
|
366
|
-
if (process.platform ===
|
|
367
|
-
this.searchPaths.add(
|
|
362
|
+
if (process.platform === 'win32') {
|
|
363
|
+
this.searchPaths.add(join(process.env.APPDATA, 'npm/node_modules'));
|
|
368
364
|
}
|
|
369
365
|
else {
|
|
370
|
-
this.searchPaths.add(
|
|
366
|
+
this.searchPaths.add(execSync('/bin/echo -n "$(npm -g prefix)/lib/node_modules"', {
|
|
371
367
|
env: Object.assign({
|
|
372
|
-
npm_config_loglevel:
|
|
373
|
-
npm_update_notifier:
|
|
368
|
+
npm_config_loglevel: 'silent',
|
|
369
|
+
npm_update_notifier: 'false',
|
|
374
370
|
}, process.env),
|
|
375
|
-
}).toString(
|
|
371
|
+
}).toString('utf8'));
|
|
376
372
|
}
|
|
377
373
|
}
|
|
378
374
|
}
|
|
379
|
-
exports.PluginManager = PluginManager;
|
|
380
375
|
//# sourceMappingURL=pluginManager.js.map
|