Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38,673 changes: 19,757 additions & 18,916 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +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": "~2.0.1",
"@iobroker/plugin-base": "~3.0.3",
"deep-clone": "^3.0.3",
"fs-extra": "^11.3.2",
"jsonwebtoken": "^9.0.0",
Expand Down
146 changes: 83 additions & 63 deletions packages/adapter/src/lib/adapter/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import fs from 'fs-extra';
import type { CommandResult } from '@alcalzone/pak';
import * as url from 'node:url';

import { PluginHandler } from '@iobroker/plugin-base';
import { PluginHandler, type IoPackageFile } from '@iobroker/plugin-base';
import {
EXIT_CODES,
getObjectsConstructor,
Expand Down Expand Up @@ -61,7 +61,7 @@ import {
SYSTEM_ADMIN_GROUP,
SYSTEM_ADMIN_USER,
} from '@/lib/adapter/constants.js';
import type { PluginHandlerSettings } from '@iobroker/plugin-base/types';
import type { PluginHandlerSettings } from '@iobroker/plugin-base';
import type {
AdapterOptions,
AliasDetails,
Expand Down Expand Up @@ -706,7 +706,7 @@ export class AdapterClass extends EventEmitter {
/** An array of instances, that support auto subscribe */
private autoSubscribe: string[] = [];
private defaultHistory: null | string = null;
private pluginHandler?: InstanceType<typeof PluginHandler>;
private pluginHandler?: PluginHandler;
private _reportInterval?: null | NodeJS.Timeout;
private getPortRunning: null | InternalGetPortOptions = null;
private readonly _namespaceRegExp: RegExp;
Expand Down Expand Up @@ -1494,68 +1494,83 @@ export class AdapterClass extends EventEmitter {
}
this.terminated = true;

this.pluginHandler && this.pluginHandler.destroyAll();

if (this._reportInterval) {
clearInterval(this._reportInterval);
this._reportInterval = null;
}
if (this._restartScheduleJob) {
this._restartScheduleJob.cancel();
this._restartScheduleJob = null;
}

let _reason = 'Without reason';
let _exitCode: number;
let shutdownStarted = false;
const shutdownLogic: () => void = () => {
if (shutdownStarted) {
return;
}
shutdownStarted = true;

if (typeof reason === 'number') {
// Only the exit code was passed
exitCode = reason;
_reason = 'Without reason';
} else if (reason && typeof reason === 'string') {
_reason = reason;
}
if (this._reportInterval) {
clearInterval(this._reportInterval);
this._reportInterval = null;
}
if (this._restartScheduleJob) {
this._restartScheduleJob.cancel();
this._restartScheduleJob = null;
}

if (typeof exitCode !== 'number') {
_exitCode = !this._config.isInstall ? EXIT_CODES.ADAPTER_REQUESTED_TERMINATION : EXIT_CODES.NO_ERROR;
} else {
_exitCode = exitCode;
}
let _reason = 'Without reason';
let _exitCode: number;

const isNotCritical =
_exitCode === EXIT_CODES.ADAPTER_REQUESTED_TERMINATION ||
_exitCode === EXIT_CODES.START_IMMEDIATELY_AFTER_STOP ||
_exitCode === EXIT_CODES.NO_ERROR;
const text = `${this.namespaceLog} Terminated (${Validator.getErrorText(_exitCode)}): ${_reason}`;
if (isNotCritical) {
this._logger.info(text);
} else {
this._logger.warn(text);
}
setTimeout(async () => {
// give last states some time to get handled
if (this.#states) {
try {
await this.#states.destroy();
} catch {
// ignore
}
if (typeof reason === 'number') {
// Only the exit code was passed
exitCode = reason;
_reason = 'Without reason';
} else if (reason && typeof reason === 'string') {
_reason = reason;
}
if (this.#objects) {
try {
await this.#objects.destroy();
} catch {
//ignore
}

if (typeof exitCode !== 'number') {
_exitCode = !this._config.isInstall ? EXIT_CODES.ADAPTER_REQUESTED_TERMINATION : EXIT_CODES.NO_ERROR;
} else {
_exitCode = exitCode;
}
if (this.startedInCompactMode) {
this.emit('exit', _exitCode, reason);
this.#states = null;
this.#objects = null;

const isNotCritical =
_exitCode === EXIT_CODES.ADAPTER_REQUESTED_TERMINATION ||
_exitCode === EXIT_CODES.START_IMMEDIATELY_AFTER_STOP ||
_exitCode === EXIT_CODES.NO_ERROR;
const text = `${this.namespaceLog} Terminated (${Validator.getErrorText(_exitCode)}): ${_reason}`;
if (isNotCritical) {
this._logger.info(text);
} else {
process.exit(_exitCode);
this._logger.warn(text);
}
}, 500);
setTimeout(async () => {
// give last states some time to get handled
if (this.#states) {
try {
await this.#states.destroy();
} catch {
// ignore
}
}
if (this.#objects) {
try {
await this.#objects.destroy();
} catch {
//ignore
}
}
if (this.startedInCompactMode) {
this.emit('exit', _exitCode, reason);
this.#states = null;
this.#objects = null;
} else {
process.exit(_exitCode);
}
}, 500);
};

if (this.pluginHandler) {
this.pluginHandler
.destroyAll()
.then(() => shutdownLogic())
.catch(() => shutdownLogic());
} else {
shutdownLogic();
}
}

// external signature
Expand Down Expand Up @@ -11070,11 +11085,16 @@ export class AdapterClass extends EventEmitter {
this.pluginHandler.getPluginConfig(pluginName) || {},
thisDir,
);
// @ts-expect-error objects and state object version conflicts that are none
this.pluginHandler.setDatabaseForPlugin(pluginName, this.#objects, this.#states);
this.pluginHandler.initPlugin(pluginName, this.adapterConfig || {});

await this.pluginHandler.initPlugin(
pluginName,
(this.adapterConfig || {}) as IoPackageFile,
);
}
} else {
if (!this.pluginHandler.destroy(pluginName)) {
if (!(await this.pluginHandler.destroy(pluginName))) {
this._logger.info(
`${this.namespaceLog} Plugin ${pluginName} could not be disabled. Please restart adapter to disable it.`,
);
Expand Down Expand Up @@ -11488,8 +11508,9 @@ export class AdapterClass extends EventEmitter {
if (!this.pluginHandler) {
return;
}
// @ts-expect-error objects and state object version conflicts that are none
this.pluginHandler.setDatabaseForPlugins(this.#objects, this.#states);
await this.pluginHandler.initPlugins(adapterConfig || {});
await this.pluginHandler.initPlugins((adapterConfig || {}) as IoPackageFile);
if (!this.#states || !this.#objects || this.terminated) {
// if adapterState was destroyed, we should not continue
return;
Expand Down Expand Up @@ -12156,8 +12177,7 @@ export class AdapterClass extends EventEmitter {
// @ts-expect-error
log: this._logger,
iobrokerConfig: this._config,
// @ts-expect-error
parentPackage: this.pack,
parentPackage: this.pack!,
controllerVersion,
};

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"dependencies": {
"@iobroker/js-controller-common": "file:../common",
"@iobroker/js-controller-common-db": "file:../common-db",
"@iobroker/plugin-base": "~2.0.1",
"@iobroker/plugin-base": "~3.0.3",
"axios": "^1.12.0",
"chokidar": "^3.5.3",
"debug": "^4.3.4",
"debug": "^4.4.3",
"deep-clone": "^3.0.3",
"event-stream": "^4.0.1",
"fs-extra": "^11.3.2",
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/lib/setup/dbConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { setTimeout as wait } from 'node:timers/promises';
import type { Client as StatesRedisClient } from '@iobroker/db-states-redis';
import type { Client as ObjectsInRedisClient } from '@iobroker/db-objects-redis';
import path from 'node:path';
import type { PluginHandlerSettings } from '@iobroker/plugin-base/types';
import type { InternalAdapterJsonConfig, PluginHandlerSettings } from '@iobroker/plugin-base';
import { PluginHandler } from '@iobroker/plugin-base';

let pluginHandler: InstanceType<typeof PluginHandler>;
Expand Down Expand Up @@ -359,7 +359,7 @@ export async function resetDbConnect(): Promise<void> {
}

if (pluginHandler) {
pluginHandler.destroyAll();
await pluginHandler.destroyAll();
}
}

Expand Down Expand Up @@ -403,14 +403,15 @@ function initializePlugins(config: Record<string, any>): Promise<void> {
error: (msg: string) => console.log(msg),
level: 'warn',
},
iobrokerConfig: config,
iobrokerConfig: config as InternalAdapterJsonConfig,
parentPackage: packageJson,
controllerVersion: ioPackage.common.version,
};

pluginHandler = new PluginHandler(pluginSettings);
pluginHandler.addPlugins(ioPackage.common.plugins, tools.getControllerDir()); // Plugins from io-package have priority over ...
pluginHandler.addPlugins(config.plugins, tools.getControllerDir()); // ... plugins from iobroker.json
// @ts-expect-error objects and state object version conflicts that are none
pluginHandler.setDatabaseForPlugins(objects, states);

return pluginHandler.initPlugins(ioPackage);
Expand Down
6 changes: 3 additions & 3 deletions packages/controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"@iobroker/js-controller-cli": "file:../cli",
"@iobroker/js-controller-common": "file:../common",
"@iobroker/js-controller-common-db": "file:../common-db",
"@iobroker/plugin-base": "~2.0.1",
"@iobroker/plugin-sentry": "~2.0.4",
"@iobroker/plugin-base": "~3.0.3",
"@iobroker/plugin-sentry": "~3.0.0",
"axios": "^1.12.0",
"cron-parser": "^4.9.0",
"debug": "^4.3.4",
"debug": "^4.4.3",
"decache": "^4.6.1",
"deep-clone": "^3.0.3",
"fs-extra": "^11.3.2",
Expand Down
12 changes: 7 additions & 5 deletions packages/controller/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import type { Client as StatesClient } from '@iobroker/db-states-redis';
import { Upload, PacketManager, type UpgradePacket } from '@iobroker/js-controller-cli';
import decache from 'decache';
import cronParser from 'cron-parser';
import type { PluginHandlerSettings } from '@iobroker/plugin-base/types';
import type { PluginHandlerSettings } from '@iobroker/plugin-base';
import type { GetDiskInfoResponse } from '@iobroker/js-controller-common-db/tools';
import { DEFAULT_DISK_WARNING_LEVEL, getCronExpression, getDiskWarningLevel } from '@/lib/utils.js';
import { AdapterAutoUpgradeManager } from '@/lib/adapterAutoUpgradeManager.js';
Expand Down Expand Up @@ -615,11 +615,12 @@ function createStates(onConnect: () => void): void {
pluginHandler.getPluginConfig(pluginName)!,
controllerDir,
);
// @ts-expect-error objects and state object version conflicts that are none
pluginHandler.setDatabaseForPlugin(pluginName, objects, states);
pluginHandler.initPlugin(pluginName, ioPackage);
await pluginHandler.initPlugin(pluginName, ioPackage);
}
} else {
if (!pluginHandler.destroy(pluginName)) {
if (!(await pluginHandler.destroy(pluginName))) {
logger.info(
`${hostLogPrefix} Plugin ${pluginName} could not be disabled. Please restart ioBroker to disable it.`,
);
Expand Down Expand Up @@ -704,6 +705,7 @@ async function initializeController(): Promise<void> {
if (connected === null) {
connected = true;
if (!isStopping) {
// @ts-expect-error objects and state object version conflicts that are none
pluginHandler.setDatabaseForPlugins(objects, states);
await pluginHandler.initPlugins(ioPackage);
states.subscribe(`${hostObjectPrefix}.plugins.*`);
Expand Down Expand Up @@ -3006,7 +3008,7 @@ async function processMessage(msg: ioBroker.SendableMessage): Promise<null | voi
const extraInfo: Record<string, unknown> = msg.message.extraInfo;

const sentryObj = (
pluginHandler.getPluginInstance('sentry') as InstanceType<typeof SentryPlugin> | null
pluginHandler.getPluginInstance('sentry') as InstanceType<typeof SentryPlugin.default> | null
)?.getSentryObject();

if (!sentryObj) {
Expand Down Expand Up @@ -5141,7 +5143,7 @@ function stop(force?: boolean, callback?: () => void): void {
}

stopInstances(force, async wasForced => {
pluginHandler.destroyAll();
await pluginHandler.destroyAll();
notificationHandler && notificationHandler.storeNotifications();

try {
Expand Down
6 changes: 3 additions & 3 deletions packages/types-dev/objects.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ declare global {
tmpdir: ReturnType<(typeof os)['tmpdir']>;
};
hardware: {
/** Return value of os.cpu but property `times` could be removed from every entry */
/** Return value of `os.cpu` but property `times` could be removed from every entry */
cpus: (Omit<ReturnType<(typeof os)['cpus']>[number], 'times'> &
Partial<Pick<ReturnType<(typeof os)['cpus']>[number], 'times'>>)[];
totalmem: ReturnType<(typeof os)['totalmem']>;
Expand Down Expand Up @@ -1052,7 +1052,7 @@ declare global {
version: string;
/** Array of blocked versions, each entry represents a semver range */
blockedVersions: string[];
/** If true the unsafe perm flag is needed on install */
/** If true, the unsafe perm flag is needed on install */
unsafePerm?: boolean;
/** If given, the packet name differs from the adapter name, e.g. because it is a scoped package */
packetName?: string;
Expand All @@ -1068,7 +1068,7 @@ declare global {
name: Required<ioBroker.Translated>;
/** Time of repository update */
repoTime: string;
/** Time when repository was last read/fetched */
/** Time when the repository was last read/fetched */
repoReadTime?: string;
}

Expand Down
Loading