Skip to content

Commit

Permalink
[chore]: Migrate to plugin-base and plugin-sentry v2 (#2781)
Browse files Browse the repository at this point in the history
* migrate to plugin base v2 and sentry v2

* finish off migration

* resolve merge conflicts

* another pack lock update trial

* new try node v 20

* pack lock
  • Loading branch information
foxriver76 authored Jul 12, 2024
1 parent ce8cf50 commit f4f04aa
Show file tree
Hide file tree
Showing 8 changed files with 15,406 additions and 15,413 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18
20
30,258 changes: 15,129 additions & 15,129 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions packages/adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"@iobroker/db-states-redis": "file:../db-states-redis",
"@iobroker/js-controller-common": "file:../common",
"@iobroker/js-controller-common-db": "file:../common-db",
"@iobroker/plugin-base": "~1.2.1",
"@iobroker/plugin-sentry": "~1.2.1",
"@iobroker/plugin-base": "~2.0.1",
"deep-clone": "^3.0.3",
"fs-extra": "^11.1.0",
"jsonwebtoken": "^9.0.0",
Expand Down
516 changes: 255 additions & 261 deletions packages/adapter/src/lib/adapter/adapter.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dependencies": {
"@iobroker/js-controller-common": "file:../common",
"@iobroker/js-controller-common-db": "file:../common-db",
"@iobroker/plugin-base": "~2.0.1",
"axios": "^1.6.3",
"chokidar": "^3.5.3",
"debug": "^4.3.4",
Expand Down
6 changes: 2 additions & 4 deletions packages/cli/src/lib/setup/dbConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ export async function exitApplicationSave(exitCode?: number): Promise<never> {
*
* @param config - parsed content of iobroker.json
*/
function initializePlugins(config: Record<string, any>): Promise<void> {
async function initializePlugins(config: Record<string, any>): Promise<void> {
const ioPackage = fs.readJsonSync(path.join(tools.getControllerDir(), 'io-package.json'));
const packageJson = fs.readJsonSync(path.join(tools.getControllerDir(), 'package.json'));
const hostname = tools.getHostName();
Expand Down Expand Up @@ -413,9 +413,7 @@ function initializePlugins(config: Record<string, any>): Promise<void> {
pluginHandler.addPlugins(config.plugins, tools.getControllerDir()); // ... plugins from iobroker.json
pluginHandler.setDatabaseForPlugins(objects, states);

return new Promise(resolve => {
pluginHandler.initPlugins(ioPackage, () => resolve());
});
await pluginHandler.initPlugins(ioPackage);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"@iobroker/js-controller-cli": "file:../cli",
"@iobroker/js-controller-common": "file:../common",
"@iobroker/js-controller-common-db": "file:../common-db",
"@iobroker/plugin-base": "~1.2.1",
"@iobroker/plugin-sentry": "~1.2.1",
"@iobroker/plugin-base": "~2.0.1",
"@iobroker/plugin-sentry": "~2.0.4",
"axios": "^1.6.3",
"cron-parser": "^4.9.0",
"debug": "^4.3.4",
Expand Down
29 changes: 15 additions & 14 deletions packages/controller/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
SYSTEM_REPOSITORIES_ID
} from '@iobroker/js-controller-common-db/constants';
import { PluginHandler } from '@iobroker/plugin-base';
import type SentryPlugin from '@iobroker/plugin-sentry';
import { BlocklistManager } from '@/lib/blocklistManager.js';
import type { Client as ObjectsClient } from '@iobroker/db-objects-redis';
import type { Client as StatesClient } from '@iobroker/db-states-redis';
Expand Down Expand Up @@ -613,8 +614,8 @@ function createStates(onConnect: () => void): void {
}
if (pluginHandler.isPluginActive(pluginName) !== state.val) {
if (state.val) {
if (!pluginHandler.isPluginInstanciated(pluginName)) {
pluginHandler.instanciatePlugin(
if (!pluginHandler.isPluginInstantiated(pluginName)) {
pluginHandler.instantiatePlugin(
pluginName,
pluginHandler.getPluginConfig(pluginName)!,
controllerDir
Expand Down Expand Up @@ -709,16 +710,15 @@ async function initializeController(): Promise<void> {
connected = true;
if (!isStopping) {
pluginHandler.setDatabaseForPlugins(objects, states);
pluginHandler.initPlugins(ioPackage, async () => {
states!.subscribe(`${hostObjectPrefix}.plugins.*`);

// Do not start if we're still stopping the instances
await checkHost();
startMultihost(config);
setMeta();
started = true;
getInstances();
});
await pluginHandler.initPlugins(ioPackage);
states!.subscribe(`${hostObjectPrefix}.plugins.*`);

// Do not start if we're still stopping the instances
await checkHost();
startMultihost(config);
setMeta();
started = true;
getInstances();
}
} else {
connected = true;
Expand Down Expand Up @@ -3012,8 +3012,9 @@ async function processMessage(msg: ioBroker.SendableMessage): Promise<null | voi
const level: string = msg.message.level;
const extraInfo: Record<string, unknown> = msg.message.extraInfo;

// @ts-expect-error Plugin is not well typed and SentryPlugin has no types at all currently
const sentryObj = pluginHandler.getPluginInstance('sentry')?.getSentryObject();
const sentryObj = (
pluginHandler.getPluginInstance('sentry') as InstanceType<typeof SentryPlugin> | null
)?.getSentryObject();

if (!sentryObj) {
logger.debug(`${hostLogPrefix} Do not send message "${message}" to Sentry, because it is disabled`);
Expand Down

0 comments on commit f4f04aa

Please sign in to comment.