From 75860ec81c237ac3537772cb140a50417ad48bf3 Mon Sep 17 00:00:00 2001 From: foxriver76 Date: Mon, 3 Jun 2024 08:43:05 +0200 Subject: [PATCH] chore: release v3.1.5 * (foxriver76) provide up-to-date types --- README.md | 3 ++ build/cjs/controllerTools.js | 44 +++++++++++------------- build/cjs/controllerTools.js.map | 6 ++-- build/cjs/helpers.js | 27 ++++++--------- build/cjs/helpers.js.map | 4 +-- build/cjs/index.js | 16 ++------- build/cjs/index.js.map | 4 +-- build/cjs/utils.js | 54 ++++++++++++++--------------- build/cjs/utils.js.map | 6 ++-- build/esm/controllerTools.js | 58 +++++++++++++++----------------- build/esm/helpers.js | 25 ++++++-------- build/esm/index.js | 16 +++------ build/esm/utils.js | 55 +++++++++++++++--------------- package-lock.json | 18 +++++----- package.json | 4 +-- tsconfig.json | 1 + 16 files changed, 156 insertions(+), 185 deletions(-) diff --git a/README.md b/README.md index 2a3161b..37e27d5 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,9 @@ If you find errors in the definitions, e.g., function calls that should be allow Placeholder for the next version (at the beginning of the line): ### **WORK IN PROGRESS** --> +### 3.1.5 (2024-06-03) +* (foxriver76) provide up-to-date types + ### 3.1.4 (2024-04-19) - (foxriver76) fixes for adapters which are written in ESM diff --git a/build/cjs/controllerTools.js b/build/cjs/controllerTools.js index 7eddec2..9828baf 100644 --- a/build/cjs/controllerTools.js +++ b/build/cjs/controllerTools.js @@ -35,60 +35,56 @@ var import_helpers = require("./helpers.js"); var utils = __toESM(require("./utils.js")); var import_node_module = require("node:module"); const import_meta = {}; -var require2 = (0, import_node_module.createRequire)(import_meta.url || "file://" + __filename); -var controllerCommonModulesInternal; +const require2 = (0, import_node_module.createRequire)(import_meta.url || "file://" + __filename); +let controllerCommonModulesInternal; function resolveControllerTools() { - var importPath = (0, import_helpers.tryResolvePackage)(["@iobroker/js-controller-common"]); + let importPath = (0, import_helpers.tryResolvePackage)(["@iobroker/js-controller-common"]); if (importPath) { try { controllerCommonModulesInternal = require2(importPath); - var tools = controllerCommonModulesInternal.tools; + const { tools } = controllerCommonModulesInternal; if (tools) return tools; - } catch (_a) { + } catch { } } importPath = (0, import_helpers.tryResolvePackage)(["@iobroker/js-controller-common"], [path.join(utils.controllerDir, "node_modules")]); if (importPath) { try { controllerCommonModulesInternal = require2(importPath); - var tools = controllerCommonModulesInternal.tools; + const { tools } = controllerCommonModulesInternal; if (tools) return tools; - } catch (_b) { + } catch { } } importPath = path.join(utils.controllerDir, "lib"); try { - var tools = require2(path.join(importPath, "tools")); + const tools = require2(path.join(importPath, "tools")); if (tools) return tools; - } catch (_c) { + } catch { } throw new Error("Cannot resolve tools module"); } -var controllerToolsInternal = resolveControllerTools(); -function resolveNamedModule(name, exportName) { - if (exportName === void 0) { - exportName = name; - } - if (controllerCommonModulesInternal === null || controllerCommonModulesInternal === void 0 ? void 0 : controllerCommonModulesInternal[exportName]) +const controllerToolsInternal = resolveControllerTools(); +function resolveNamedModule(name, exportName = name) { + if (controllerCommonModulesInternal == null ? void 0 : controllerCommonModulesInternal[exportName]) return controllerCommonModulesInternal[exportName]; - var importPaths = [ + const importPaths = [ path.join(utils.controllerDir, "build/cjs/lib", name), path.join(utils.controllerDir, "build/lib", name), path.join(utils.controllerDir, "lib", name) ]; - for (var _i = 0, importPaths_1 = importPaths; _i < importPaths_1.length; _i++) { - var importPath = importPaths_1[_i]; + for (const importPath of importPaths) { try { - var module_1 = require2(importPath); - if (module_1) - return module_1; - } catch (_a) { + const module2 = require2(importPath); + if (module2) + return module2; + } catch { } } - throw new Error("Cannot resolve JS-Controller module ".concat(name, ".js")); + throw new Error(`Cannot resolve JS-Controller module ${name}.js`); } function pattern2RegEx(pattern) { return controllerToolsInternal.pattern2RegEx(pattern); @@ -114,7 +110,7 @@ function getLocalAddress() { function getListenAllAddress() { return controllerToolsInternal.getListenAllAddress(); } -var commonTools = { +const commonTools = { pattern2RegEx, getAdapterDir, getInstalledInfo, diff --git a/build/cjs/controllerTools.js.map b/build/cjs/controllerTools.js.map index d1488d3..45322c5 100644 --- a/build/cjs/controllerTools.js.map +++ b/build/cjs/controllerTools.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../esm/controllerTools.js"], - "sourcesContent": ["import * as path from \"node:path\";\nimport { tryResolvePackage } from \"./helpers.js\";\nimport * as utils from \"./utils.js\";\nimport { createRequire } from \"node:module\";\n// eslint-disable-next-line unicorn/prefer-module\nvar require = createRequire(import.meta.url || \"file://\" + __filename);\nexport var controllerCommonModulesInternal;\nfunction resolveControllerTools() {\n // Attempt 1: Resolve @iobroker/js-controller-common from here - JS-Controller 4.1+\n var importPath = tryResolvePackage([\"@iobroker/js-controller-common\"]);\n if (importPath) {\n try {\n controllerCommonModulesInternal = require(importPath);\n var tools = controllerCommonModulesInternal.tools;\n if (tools)\n return tools;\n }\n catch (_a) {\n // did not work, continue\n }\n }\n // Attempt 2: Resolve @iobroker/js-controller-common in JS-Controller dir - JS-Controller 4.1+\n importPath = tryResolvePackage([\"@iobroker/js-controller-common\"], [path.join(utils.controllerDir, \"node_modules\")]);\n if (importPath) {\n try {\n controllerCommonModulesInternal = require(importPath);\n var tools = controllerCommonModulesInternal.tools;\n if (tools)\n return tools;\n }\n catch (_b) {\n // did not work, continue\n }\n }\n // Attempt 3: Legacy resolve - until JS-Controller 4.0\n importPath = path.join(utils.controllerDir, \"lib\");\n try {\n // This was a default export prior to the TS migration\n var tools = require(path.join(importPath, \"tools\"));\n if (tools)\n return tools;\n }\n catch (_c) {\n // did not work, continue\n }\n throw new Error(\"Cannot resolve tools module\");\n //return process.exit(10);\n}\n/** The collection of utility functions in JS-Controller, formerly `lib/tools.js` */\nexport var controllerToolsInternal = resolveControllerTools();\n// Export a subset of the utilties in controllerTools\n/**\n * Resolve a module that is either exported by @iobroker/js-controller-common (new controllers) or located in the controller's `lib` directory (old controllers).\n * @param name - The filename of the module to resolve\n * @param exportName - The name under which the module may be exported. Defaults to `name`.\n */\nexport function resolveNamedModule(name, exportName) {\n if (exportName === void 0) { exportName = name; }\n // The requested module might be moved to @iobroker/js-controller-common and exported from there\n if (controllerCommonModulesInternal === null || controllerCommonModulesInternal === void 0 ? void 0 : controllerCommonModulesInternal[exportName])\n return controllerCommonModulesInternal[exportName];\n // Otherwise it was not moved yet, or we're dealing with JS-Controller <= 4.0\n var importPaths = [\n // Attempt 1: JS-Controller 6+\n path.join(utils.controllerDir, \"build/cjs/lib\", name),\n // Attempt 2: JS-Controller 4.1+\n path.join(utils.controllerDir, \"build/lib\", name),\n // Attempt 3: JS-Controller <= 4.0\n path.join(utils.controllerDir, \"lib\", name),\n ];\n for (var _i = 0, importPaths_1 = importPaths; _i < importPaths_1.length; _i++) {\n var importPath = importPaths_1[_i];\n try {\n // This was a default export prior to the TS migration\n var module_1 = require(importPath);\n if (module_1)\n return module_1;\n }\n catch (_a) {\n // did not work, continue\n }\n }\n throw new Error(\"Cannot resolve JS-Controller module \".concat(name, \".js\"));\n //return process.exit(10);\n}\n// TODO: Import types from @iobroker/js-controller-common and iobroker.js-controller\n/**\n * Converts a pattern to match object IDs into a RegEx string that can be used in `new RegExp(...)`\n * @param pattern The pattern to convert\n * @returns The RegEx string\n */\nfunction pattern2RegEx(pattern) {\n return controllerToolsInternal.pattern2RegEx(pattern);\n}\n/**\n * Finds the adapter directory of a given adapter\n *\n * @param adapter name of the adapter, e.g. hm-rpc\n * @returns path to adapter directory or null if no directory found\n */\nfunction getAdapterDir(adapter) {\n return controllerToolsInternal.getAdapterDir(adapter);\n}\n/**\n * Get list of all installed adapters and controller version on this host\n * @param hostJsControllerVersion Version of the running js-controller, will be included in the returned information if provided\n * @returns object containing information about installed host\n */\nfunction getInstalledInfo(hostJsControllerVersion) {\n return controllerToolsInternal.getInstalledInfo(hostJsControllerVersion);\n}\n/**\n * Checks if we are running inside a docker container\n */\nfunction isDocker() {\n return controllerToolsInternal.isDocker();\n}\n/**\n * Checks if given ip address is matching ipv4 or ipv6 localhost\n * @param ip ipv4 or ipv6 address\n */\nfunction isLocalAddress(ip) {\n return controllerToolsInternal.isLocalAddress(ip);\n}\n/**\n * Checks if given ip address is matching ipv4 or ipv6 \"listen all\" address\n * @param ip ipv4 or ipv6 address\n */\nfunction isListenAllAddress(ip) {\n return controllerToolsInternal.isListenAllAddress(ip);\n}\n/**\n * Retrieve the localhost address according to the configured DNS resolution strategy\n */\nfunction getLocalAddress() {\n return controllerToolsInternal.getLocalAddress();\n}\n/**\n * Get the ip to listen to all addresses according to configured DNS resolution strategy\n */\nfunction getListenAllAddress() {\n return controllerToolsInternal.getListenAllAddress();\n}\nexport var commonTools = {\n pattern2RegEx: pattern2RegEx,\n getAdapterDir: getAdapterDir,\n getInstalledInfo: getInstalledInfo,\n isDocker: isDocker,\n getLocalAddress: getLocalAddress,\n getListenAllAddress: getListenAllAddress,\n isLocalAddress: isLocalAddress,\n isListenAllAddress: isListenAllAddress,\n // TODO: Add more methods from lib/tools.js as needed\n password: resolveNamedModule(\"password\"),\n session: resolveNamedModule(\"session\"),\n zipFiles: resolveNamedModule(\"zipFiles\"),\n // TODO: expose more (internal) controller modules as needed\n};\n"], - "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,WAAsB;AACtB,qBAAkC;AAClC,YAAuB;AACvB,yBAA8B;AAH9B;AAKA,IAAIA,eAAU,kCAAc,YAAY,OAAO,YAAY,UAAU;AAC9D,IAAI;AACX,SAAS,yBAAyB;AAE9B,MAAI,iBAAa,kCAAkB,CAAC,gCAAgC,CAAC;AACrE,MAAI,YAAY;AACZ,QAAI;AACA,wCAAkCA,SAAQ,UAAU;AACpD,UAAI,QAAQ,gCAAgC;AAC5C,UAAI;AACA,eAAO;AAAA,IACf,SACO,IAAP;AAAA,IAEA;AAAA,EACJ;AAEA,mBAAa,kCAAkB,CAAC,gCAAgC,GAAG,CAAC,KAAK,KAAK,MAAM,eAAe,cAAc,CAAC,CAAC;AACnH,MAAI,YAAY;AACZ,QAAI;AACA,wCAAkCA,SAAQ,UAAU;AACpD,UAAI,QAAQ,gCAAgC;AAC5C,UAAI;AACA,eAAO;AAAA,IACf,SACO,IAAP;AAAA,IAEA;AAAA,EACJ;AAEA,eAAa,KAAK,KAAK,MAAM,eAAe,KAAK;AACjD,MAAI;AAEA,QAAI,QAAQA,SAAQ,KAAK,KAAK,YAAY,OAAO,CAAC;AAClD,QAAI;AACA,aAAO;AAAA,EACf,SACO,IAAP;AAAA,EAEA;AACA,QAAM,IAAI,MAAM,6BAA6B;AAEjD;AAEO,IAAI,0BAA0B,uBAAuB;AAOrD,SAAS,mBAAmB,MAAM,YAAY;AACjD,MAAI,eAAe,QAAQ;AAAE,iBAAa;AAAA,EAAM;AAEhD,MAAI,oCAAoC,QAAQ,oCAAoC,SAAS,SAAS,gCAAgC;AAClI,WAAO,gCAAgC;AAE3C,MAAI,cAAc;AAAA,IAEd,KAAK,KAAK,MAAM,eAAe,iBAAiB,IAAI;AAAA,IAEpD,KAAK,KAAK,MAAM,eAAe,aAAa,IAAI;AAAA,IAEhD,KAAK,KAAK,MAAM,eAAe,OAAO,IAAI;AAAA,EAC9C;AACA,WAAS,KAAK,GAAG,gBAAgB,aAAa,KAAK,cAAc,QAAQ,MAAM;AAC3E,QAAI,aAAa,cAAc;AAC/B,QAAI;AAEA,UAAI,WAAWA,SAAQ,UAAU;AACjC,UAAI;AACA,eAAO;AAAA,IACf,SACO,IAAP;AAAA,IAEA;AAAA,EACJ;AACA,QAAM,IAAI,MAAM,uCAAuC,OAAO,MAAM,KAAK,CAAC;AAE9E;AAOA,SAAS,cAAc,SAAS;AAC5B,SAAO,wBAAwB,cAAc,OAAO;AACxD;AAOA,SAAS,cAAc,SAAS;AAC5B,SAAO,wBAAwB,cAAc,OAAO;AACxD;AAMA,SAAS,iBAAiB,yBAAyB;AAC/C,SAAO,wBAAwB,iBAAiB,uBAAuB;AAC3E;AAIA,SAAS,WAAW;AAChB,SAAO,wBAAwB,SAAS;AAC5C;AAKA,SAAS,eAAe,IAAI;AACxB,SAAO,wBAAwB,eAAe,EAAE;AACpD;AAKA,SAAS,mBAAmB,IAAI;AAC5B,SAAO,wBAAwB,mBAAmB,EAAE;AACxD;AAIA,SAAS,kBAAkB;AACvB,SAAO,wBAAwB,gBAAgB;AACnD;AAIA,SAAS,sBAAsB;AAC3B,SAAO,wBAAwB,oBAAoB;AACvD;AACO,IAAI,cAAc;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,UAAU,mBAAmB,UAAU;AAAA,EACvC,SAAS,mBAAmB,SAAS;AAAA,EACrC,UAAU,mBAAmB,UAAU;AAE3C;", - "names": ["require"] + "sourcesContent": ["import * as path from \"node:path\";\nimport { tryResolvePackage } from \"./helpers.js\";\nimport * as utils from \"./utils.js\";\nimport { createRequire } from \"node:module\";\n// eslint-disable-next-line unicorn/prefer-module\nconst require = createRequire(import.meta.url || \"file://\" + __filename);\nexport let controllerCommonModulesInternal;\nfunction resolveControllerTools() {\n // Attempt 1: Resolve @iobroker/js-controller-common from here - JS-Controller 4.1+\n let importPath = tryResolvePackage([\"@iobroker/js-controller-common\"]);\n if (importPath) {\n try {\n controllerCommonModulesInternal = require(importPath);\n const { tools } = controllerCommonModulesInternal;\n if (tools)\n return tools;\n }\n catch {\n // did not work, continue\n }\n }\n // Attempt 2: Resolve @iobroker/js-controller-common in JS-Controller dir - JS-Controller 4.1+\n importPath = tryResolvePackage([\"@iobroker/js-controller-common\"], [path.join(utils.controllerDir, \"node_modules\")]);\n if (importPath) {\n try {\n controllerCommonModulesInternal = require(importPath);\n const { tools } = controllerCommonModulesInternal;\n if (tools)\n return tools;\n }\n catch {\n // did not work, continue\n }\n }\n // Attempt 3: Legacy resolve - until JS-Controller 4.0\n importPath = path.join(utils.controllerDir, \"lib\");\n try {\n // This was a default export prior to the TS migration\n const tools = require(path.join(importPath, \"tools\"));\n if (tools)\n return tools;\n }\n catch {\n // did not work, continue\n }\n throw new Error(\"Cannot resolve tools module\");\n //return process.exit(10);\n}\n/** The collection of utility functions in JS-Controller, formerly `lib/tools.js` */\nexport const controllerToolsInternal = resolveControllerTools();\n// Export a subset of the utilties in controllerTools\n/**\n * Resolve a module that is either exported by @iobroker/js-controller-common (new controllers) or located in the controller's `lib` directory (old controllers).\n * @param name - The filename of the module to resolve\n * @param exportName - The name under which the module may be exported. Defaults to `name`.\n */\nexport function resolveNamedModule(name, exportName = name) {\n // The requested module might be moved to @iobroker/js-controller-common and exported from there\n if (controllerCommonModulesInternal?.[exportName])\n return controllerCommonModulesInternal[exportName];\n // Otherwise it was not moved yet, or we're dealing with JS-Controller <= 4.0\n const importPaths = [\n // Attempt 1: JS-Controller 6+\n path.join(utils.controllerDir, \"build/cjs/lib\", name),\n // Attempt 2: JS-Controller 4.1+\n path.join(utils.controllerDir, \"build/lib\", name),\n // Attempt 3: JS-Controller <= 4.0\n path.join(utils.controllerDir, \"lib\", name),\n ];\n for (const importPath of importPaths) {\n try {\n // This was a default export prior to the TS migration\n const module = require(importPath);\n if (module)\n return module;\n }\n catch {\n // did not work, continue\n }\n }\n throw new Error(`Cannot resolve JS-Controller module ${name}.js`);\n //return process.exit(10);\n}\n// TODO: Import types from @iobroker/js-controller-common and iobroker.js-controller\n/**\n * Converts a pattern to match object IDs into a RegEx string that can be used in `new RegExp(...)`\n * @param pattern The pattern to convert\n * @returns The RegEx string\n */\nfunction pattern2RegEx(pattern) {\n return controllerToolsInternal.pattern2RegEx(pattern);\n}\n/**\n * Finds the adapter directory of a given adapter\n *\n * @param adapter name of the adapter, e.g. hm-rpc\n * @returns path to adapter directory or null if no directory found\n */\nfunction getAdapterDir(adapter) {\n return controllerToolsInternal.getAdapterDir(adapter);\n}\n/**\n * Get list of all installed adapters and controller version on this host\n * @param hostJsControllerVersion Version of the running js-controller, will be included in the returned information if provided\n * @returns object containing information about installed host\n */\nfunction getInstalledInfo(hostJsControllerVersion) {\n return controllerToolsInternal.getInstalledInfo(hostJsControllerVersion);\n}\n/**\n * Checks if we are running inside a docker container\n */\nfunction isDocker() {\n return controllerToolsInternal.isDocker();\n}\n/**\n * Checks if given ip address is matching ipv4 or ipv6 localhost\n * @param ip ipv4 or ipv6 address\n */\nfunction isLocalAddress(ip) {\n return controllerToolsInternal.isLocalAddress(ip);\n}\n/**\n * Checks if given ip address is matching ipv4 or ipv6 \"listen all\" address\n * @param ip ipv4 or ipv6 address\n */\nfunction isListenAllAddress(ip) {\n return controllerToolsInternal.isListenAllAddress(ip);\n}\n/**\n * Retrieve the localhost address according to the configured DNS resolution strategy\n */\nfunction getLocalAddress() {\n return controllerToolsInternal.getLocalAddress();\n}\n/**\n * Get the ip to listen to all addresses according to configured DNS resolution strategy\n */\nfunction getListenAllAddress() {\n return controllerToolsInternal.getListenAllAddress();\n}\nexport const commonTools = {\n pattern2RegEx,\n getAdapterDir,\n getInstalledInfo,\n isDocker,\n getLocalAddress,\n getListenAllAddress,\n isLocalAddress,\n isListenAllAddress,\n // TODO: Add more methods from lib/tools.js as needed\n password: resolveNamedModule(\"password\"),\n session: resolveNamedModule(\"session\"),\n zipFiles: resolveNamedModule(\"zipFiles\"),\n // TODO: expose more (internal) controller modules as needed\n};\n"], + "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,WAAsB;AACtB,qBAAkC;AAClC,YAAuB;AACvB,yBAA8B;AAH9B;AAKA,MAAMA,eAAU,kCAAc,YAAY,OAAO,YAAY,UAAU;AAChE,IAAI;AACX,SAAS,yBAAyB;AAE9B,MAAI,iBAAa,kCAAkB,CAAC,gCAAgC,CAAC;AACrE,MAAI,YAAY;AACZ,QAAI;AACA,wCAAkCA,SAAQ,UAAU;AACpD,YAAM,EAAE,MAAM,IAAI;AAClB,UAAI;AACA,eAAO;AAAA,IACf,QACA;AAAA,IAEA;AAAA,EACJ;AAEA,mBAAa,kCAAkB,CAAC,gCAAgC,GAAG,CAAC,KAAK,KAAK,MAAM,eAAe,cAAc,CAAC,CAAC;AACnH,MAAI,YAAY;AACZ,QAAI;AACA,wCAAkCA,SAAQ,UAAU;AACpD,YAAM,EAAE,MAAM,IAAI;AAClB,UAAI;AACA,eAAO;AAAA,IACf,QACA;AAAA,IAEA;AAAA,EACJ;AAEA,eAAa,KAAK,KAAK,MAAM,eAAe,KAAK;AACjD,MAAI;AAEA,UAAM,QAAQA,SAAQ,KAAK,KAAK,YAAY,OAAO,CAAC;AACpD,QAAI;AACA,aAAO;AAAA,EACf,QACA;AAAA,EAEA;AACA,QAAM,IAAI,MAAM,6BAA6B;AAEjD;AAEO,MAAM,0BAA0B,uBAAuB;AAOvD,SAAS,mBAAmB,MAAM,aAAa,MAAM;AAExD,MAAI,mFAAkC;AAClC,WAAO,gCAAgC;AAE3C,QAAM,cAAc;AAAA,IAEhB,KAAK,KAAK,MAAM,eAAe,iBAAiB,IAAI;AAAA,IAEpD,KAAK,KAAK,MAAM,eAAe,aAAa,IAAI;AAAA,IAEhD,KAAK,KAAK,MAAM,eAAe,OAAO,IAAI;AAAA,EAC9C;AACA,aAAW,cAAc,aAAa;AAClC,QAAI;AAEA,YAAMC,UAASD,SAAQ,UAAU;AACjC,UAAIC;AACA,eAAOA;AAAA,IACf,QACA;AAAA,IAEA;AAAA,EACJ;AACA,QAAM,IAAI,MAAM,uCAAuC,SAAS;AAEpE;AAOA,SAAS,cAAc,SAAS;AAC5B,SAAO,wBAAwB,cAAc,OAAO;AACxD;AAOA,SAAS,cAAc,SAAS;AAC5B,SAAO,wBAAwB,cAAc,OAAO;AACxD;AAMA,SAAS,iBAAiB,yBAAyB;AAC/C,SAAO,wBAAwB,iBAAiB,uBAAuB;AAC3E;AAIA,SAAS,WAAW;AAChB,SAAO,wBAAwB,SAAS;AAC5C;AAKA,SAAS,eAAe,IAAI;AACxB,SAAO,wBAAwB,eAAe,EAAE;AACpD;AAKA,SAAS,mBAAmB,IAAI;AAC5B,SAAO,wBAAwB,mBAAmB,EAAE;AACxD;AAIA,SAAS,kBAAkB;AACvB,SAAO,wBAAwB,gBAAgB;AACnD;AAIA,SAAS,sBAAsB;AAC3B,SAAO,wBAAwB,oBAAoB;AACvD;AACO,MAAM,cAAc;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,UAAU,mBAAmB,UAAU;AAAA,EACvC,SAAS,mBAAmB,SAAS;AAAA,EACrC,UAAU,mBAAmB,UAAU;AAE3C;", + "names": ["require", "module"] } diff --git a/build/cjs/helpers.js b/build/cjs/helpers.js index 29b3d93..66ea9c7 100644 --- a/build/cjs/helpers.js +++ b/build/cjs/helpers.js @@ -33,39 +33,34 @@ var path = __toESM(require("node:path")); var import_node_module = require("node:module"); var url = __toESM(require("node:url")); const import_meta = {}; -var require2 = (0, import_node_module.createRequire)(import_meta.url || "file://" + __filename); -var thisDir = url.fileURLToPath( +const require2 = (0, import_node_module.createRequire)(import_meta.url || "file://" + __filename); +const thisDir = url.fileURLToPath( new URL(".", import_meta.url || "file://" + __filename) ); function tryResolvePackage(possiblePaths, lookupPaths) { - for (var _i = 0, possiblePaths_1 = possiblePaths; _i < possiblePaths_1.length; _i++) { - var pkg = possiblePaths_1[_i]; + for (const pkg of possiblePaths) { try { - var possiblePath = require2.resolve("".concat(pkg, "/package.json"), (lookupPaths === null || lookupPaths === void 0 ? void 0 : lookupPaths.length) ? { paths: lookupPaths } : void 0); + const possiblePath = require2.resolve(`${pkg}/package.json`, (lookupPaths == null ? void 0 : lookupPaths.length) ? { paths: lookupPaths } : void 0); if (fs.existsSync(possiblePath)) { return path.dirname(possiblePath); } - } catch (_a) { + } catch { } } } -function scanForPackage(possiblePaths, startDir) { - if (startDir === void 0) { - startDir = thisDir; - } - var curDir = path.join(startDir, "../node_modules"); +function scanForPackage(possiblePaths, startDir = thisDir) { + let curDir = path.join(startDir, "../node_modules"); while (true) { - for (var _i = 0, possiblePaths_2 = possiblePaths; _i < possiblePaths_2.length; _i++) { - var pkg = possiblePaths_2[_i]; - var possiblePath = path.join(curDir, pkg, "package.json"); + for (const pkg of possiblePaths) { + const possiblePath = path.join(curDir, pkg, "package.json"); try { if (fs.existsSync(possiblePath) && JSON.parse(fs.readFileSync(possiblePath, "utf8")).name === pkg.toLowerCase()) { return path.dirname(possiblePath); } - } catch (_a) { + } catch { } } - var parentDir = path.dirname(curDir); + const parentDir = path.dirname(curDir); if (parentDir === curDir) { break; } diff --git a/build/cjs/helpers.js.map b/build/cjs/helpers.js.map index fbe629a..2aaf61f 100644 --- a/build/cjs/helpers.js.map +++ b/build/cjs/helpers.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../esm/helpers.js"], - "sourcesContent": ["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { createRequire } from \"node:module\";\nimport * as url from \"node:url\";\n// eslint-disable-next-line unicorn/prefer-module\nvar require = createRequire(import.meta.url || \"file://\" + __filename);\nvar thisDir = url.fileURLToPath(\n// eslint-disable-next-line unicorn/prefer-module\nnew URL(\".\", import.meta.url || \"file://\" + __filename));\n/**\n * Tries to resolve a package using Node.js resolution.\n * Directory names differing from the package name and alternate lookup paths can be passed.\n */\nexport function tryResolvePackage(possiblePaths, lookupPaths) {\n for (var _i = 0, possiblePaths_1 = possiblePaths; _i < possiblePaths_1.length; _i++) {\n var pkg = possiblePaths_1[_i];\n try {\n // package.json is guaranteed to be in the module root folder\n // so once that is resolved, take the dirname and we're done\n var possiblePath = require.resolve(\"\".concat(pkg, \"/package.json\"), (lookupPaths === null || lookupPaths === void 0 ? void 0 : lookupPaths.length) ? { paths: lookupPaths } : undefined);\n if (fs.existsSync(possiblePath)) {\n return path.dirname(possiblePath);\n }\n }\n catch (_a) {\n /* not found */\n }\n }\n}\n/**\n * Scans for a package by walking up the directory tree and inspecting package.json\n * Directory names differing from the package name and an alternate start dir can be passed.\n */\nexport function scanForPackage(possiblePaths, startDir) {\n if (startDir === void 0) { startDir = thisDir; }\n // We start in the node_modules subfolder of adapter-core, which is the deepest we should be able to expect the controller\n var curDir = path.join(startDir, \"../node_modules\");\n while (true) {\n for (var _i = 0, possiblePaths_2 = possiblePaths; _i < possiblePaths_2.length; _i++) {\n var pkg = possiblePaths_2[_i];\n var possiblePath = path.join(curDir, pkg, \"package.json\");\n try {\n // If package.json exists in the directory and its name field matches, we've found js-controller\n if (fs.existsSync(possiblePath) &&\n JSON.parse(fs.readFileSync(possiblePath, \"utf8\")).name ===\n pkg.toLowerCase()) {\n return path.dirname(possiblePath);\n }\n }\n catch (_a) {\n // don't care\n }\n }\n // Nothing found here, go up one level\n var parentDir = path.dirname(curDir);\n if (parentDir === curDir) {\n // we've reached the root without finding js-controller\n break;\n }\n curDir = parentDir;\n }\n}\n"], - "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAoB;AACpB,WAAsB;AACtB,yBAA8B;AAC9B,UAAqB;AAHrB;AAKA,IAAIA,eAAU,kCAAc,YAAY,OAAO,YAAY,UAAU;AACrE,IAAI,UAAU,IAAI;AAAA,EAElB,IAAI,IAAI,KAAK,YAAY,OAAO,YAAY,UAAU;AAAC;AAKhD,SAAS,kBAAkB,eAAe,aAAa;AAC1D,WAAS,KAAK,GAAG,kBAAkB,eAAe,KAAK,gBAAgB,QAAQ,MAAM;AACjF,QAAI,MAAM,gBAAgB;AAC1B,QAAI;AAGA,UAAI,eAAeA,SAAQ,QAAQ,GAAG,OAAO,KAAK,eAAe,IAAI,gBAAgB,QAAQ,gBAAgB,SAAS,SAAS,YAAY,UAAU,EAAE,OAAO,YAAY,IAAI,MAAS;AACvL,UAAI,GAAG,WAAW,YAAY,GAAG;AAC7B,eAAO,KAAK,QAAQ,YAAY;AAAA,MACpC;AAAA,IACJ,SACO,IAAP;AAAA,IAEA;AAAA,EACJ;AACJ;AAKO,SAAS,eAAe,eAAe,UAAU;AACpD,MAAI,aAAa,QAAQ;AAAE,eAAW;AAAA,EAAS;AAE/C,MAAI,SAAS,KAAK,KAAK,UAAU,iBAAiB;AAClD,SAAO,MAAM;AACT,aAAS,KAAK,GAAG,kBAAkB,eAAe,KAAK,gBAAgB,QAAQ,MAAM;AACjF,UAAI,MAAM,gBAAgB;AAC1B,UAAI,eAAe,KAAK,KAAK,QAAQ,KAAK,cAAc;AACxD,UAAI;AAEA,YAAI,GAAG,WAAW,YAAY,KAC1B,KAAK,MAAM,GAAG,aAAa,cAAc,MAAM,CAAC,EAAE,SAC9C,IAAI,YAAY,GAAG;AACvB,iBAAO,KAAK,QAAQ,YAAY;AAAA,QACpC;AAAA,MACJ,SACO,IAAP;AAAA,MAEA;AAAA,IACJ;AAEA,QAAI,YAAY,KAAK,QAAQ,MAAM;AACnC,QAAI,cAAc,QAAQ;AAEtB;AAAA,IACJ;AACA,aAAS;AAAA,EACb;AACJ;", + "sourcesContent": ["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { createRequire } from \"node:module\";\nimport * as url from \"node:url\";\n// eslint-disable-next-line unicorn/prefer-module\nconst require = createRequire(import.meta.url || \"file://\" + __filename);\nconst thisDir = url.fileURLToPath(\n// eslint-disable-next-line unicorn/prefer-module\nnew URL(\".\", import.meta.url || \"file://\" + __filename));\n/**\n * Tries to resolve a package using Node.js resolution.\n * Directory names differing from the package name and alternate lookup paths can be passed.\n */\nexport function tryResolvePackage(possiblePaths, lookupPaths) {\n for (const pkg of possiblePaths) {\n try {\n // package.json is guaranteed to be in the module root folder\n // so once that is resolved, take the dirname and we're done\n const possiblePath = require.resolve(`${pkg}/package.json`, lookupPaths?.length ? { paths: lookupPaths } : undefined);\n if (fs.existsSync(possiblePath)) {\n return path.dirname(possiblePath);\n }\n }\n catch {\n /* not found */\n }\n }\n}\n/**\n * Scans for a package by walking up the directory tree and inspecting package.json\n * Directory names differing from the package name and an alternate start dir can be passed.\n */\nexport function scanForPackage(possiblePaths, startDir = thisDir) {\n // We start in the node_modules subfolder of adapter-core, which is the deepest we should be able to expect the controller\n let curDir = path.join(startDir, \"../node_modules\");\n while (true) {\n for (const pkg of possiblePaths) {\n const possiblePath = path.join(curDir, pkg, \"package.json\");\n try {\n // If package.json exists in the directory and its name field matches, we've found js-controller\n if (fs.existsSync(possiblePath) &&\n JSON.parse(fs.readFileSync(possiblePath, \"utf8\")).name ===\n pkg.toLowerCase()) {\n return path.dirname(possiblePath);\n }\n }\n catch {\n // don't care\n }\n }\n // Nothing found here, go up one level\n const parentDir = path.dirname(curDir);\n if (parentDir === curDir) {\n // we've reached the root without finding js-controller\n break;\n }\n curDir = parentDir;\n }\n}\n"], + "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAoB;AACpB,WAAsB;AACtB,yBAA8B;AAC9B,UAAqB;AAHrB;AAKA,MAAMA,eAAU,kCAAc,YAAY,OAAO,YAAY,UAAU;AACvE,MAAM,UAAU,IAAI;AAAA,EAEpB,IAAI,IAAI,KAAK,YAAY,OAAO,YAAY,UAAU;AAAC;AAKhD,SAAS,kBAAkB,eAAe,aAAa;AAC1D,aAAW,OAAO,eAAe;AAC7B,QAAI;AAGA,YAAM,eAAeA,SAAQ,QAAQ,GAAG,qBAAoB,2CAAa,UAAS,EAAE,OAAO,YAAY,IAAI,MAAS;AACpH,UAAI,GAAG,WAAW,YAAY,GAAG;AAC7B,eAAO,KAAK,QAAQ,YAAY;AAAA,MACpC;AAAA,IACJ,QACA;AAAA,IAEA;AAAA,EACJ;AACJ;AAKO,SAAS,eAAe,eAAe,WAAW,SAAS;AAE9D,MAAI,SAAS,KAAK,KAAK,UAAU,iBAAiB;AAClD,SAAO,MAAM;AACT,eAAW,OAAO,eAAe;AAC7B,YAAM,eAAe,KAAK,KAAK,QAAQ,KAAK,cAAc;AAC1D,UAAI;AAEA,YAAI,GAAG,WAAW,YAAY,KAC1B,KAAK,MAAM,GAAG,aAAa,cAAc,MAAM,CAAC,EAAE,SAC9C,IAAI,YAAY,GAAG;AACvB,iBAAO,KAAK,QAAQ,YAAY;AAAA,QACpC;AAAA,MACJ,QACA;AAAA,MAEA;AAAA,IACJ;AAEA,UAAM,YAAY,KAAK,QAAQ,MAAM;AACrC,QAAI,cAAc,QAAQ;AAEtB;AAAA,IACJ;AACA,aAAS;AAAA,EACb;AACJ;", "names": ["require"] } diff --git a/build/cjs/index.js b/build/cjs/index.js index 66b308e..192cc26 100644 --- a/build/cjs/index.js +++ b/build/cjs/index.js @@ -37,25 +37,15 @@ var utils = __toESM(require("./utils.js")); var import_types = require("@iobroker/types"); var import_controllerTools2 = require("./controllerTools.js"); __reExport(esm_exports, require("./utils.js"), module.exports); -var __assign = function() { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) - if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; function getAbsoluteDefaultDataDir() { return path.join(utils.controllerDir, import_controllerTools.controllerToolsInternal.getDefaultDataDir()); } function getAbsoluteInstanceDataDir(adapterObject) { return path.join(getAbsoluteDefaultDataDir(), adapterObject.namespace); } -var EXIT_CODES = Object.freeze(__assign({}, (0, import_controllerTools.resolveNamedModule)("exitCodes", "EXIT_CODES"))); +const EXIT_CODES = Object.freeze({ + ...(0, import_controllerTools.resolveNamedModule)("exitCodes", "EXIT_CODES") +}); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { EXIT_CODES, diff --git a/build/cjs/index.js.map b/build/cjs/index.js.map index ebcc0f0..0a2df74 100644 --- a/build/cjs/index.js.map +++ b/build/cjs/index.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../esm/index.js"], - "sourcesContent": ["var __assign = (this && this.__assign) || function () {\n __assign = Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n};\nimport * as path from \"node:path\";\nimport { controllerToolsInternal, resolveNamedModule, } from \"./controllerTools.js\";\nimport * as utils from \"./utils.js\";\nimport \"@iobroker/types\";\n// Export utility methods to be used in adapters\nexport { commonTools } from \"./controllerTools.js\";\nexport * from \"./utils.js\";\n/**\n * Returns the absolute path of the data directory for the current host. On linux, this is usually `/opt/iobroker/iobroker-data`.\n */\nexport function getAbsoluteDefaultDataDir() {\n return path.join(utils.controllerDir, controllerToolsInternal.getDefaultDataDir());\n}\n/**\n * Returns the absolute path of the data directory for the current adapter instance.\n * On linux, this is usually `/opt/iobroker/iobroker-data/.`\n */\nexport function getAbsoluteInstanceDataDir(adapterObject) {\n return path.join(getAbsoluteDefaultDataDir(), adapterObject.namespace);\n}\n// TODO: Expose some system utilities here, e.g. for installing npm modules (GH#1)\nexport var EXIT_CODES = Object.freeze(__assign({}, resolveNamedModule(\"exitCodes\", \"EXIT_CODES\")));\n"], - "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,WAAsB;AACtB,6BAA6D;AAC7D,YAAuB;AACvB,mBAAO;AAEP,IAAAA,0BAA4B;AAC5B,wBAAc,uBAjBd;AAAA,IAAI,WAAsC,WAAY;AAClD,aAAW,OAAO,UAAU,SAAS,GAAG;AACpC,aAAS,GAAG,IAAI,GAAG,IAAI,UAAU,QAAQ,IAAI,GAAG,KAAK;AACjD,UAAI,UAAU;AACd,eAAS,KAAK;AAAG,YAAI,OAAO,UAAU,eAAe,KAAK,GAAG,CAAC;AAC1D,YAAE,KAAK,EAAE;AAAA,IACjB;AACA,WAAO;AAAA,EACX;AACA,SAAO,SAAS,MAAM,MAAM,SAAS;AACzC;AAWO,SAAS,4BAA4B;AACxC,SAAO,KAAK,KAAK,MAAM,eAAe,+CAAwB,kBAAkB,CAAC;AACrF;AAKO,SAAS,2BAA2B,eAAe;AACtD,SAAO,KAAK,KAAK,0BAA0B,GAAG,cAAc,SAAS;AACzE;AAEO,IAAI,aAAa,OAAO,OAAO,SAAS,CAAC,OAAG,2CAAmB,aAAa,YAAY,CAAC,CAAC;", + "sourcesContent": ["import * as path from \"node:path\";\nimport { controllerToolsInternal, resolveNamedModule, } from \"./controllerTools.js\";\nimport * as utils from \"./utils.js\";\nimport \"@iobroker/types\";\n// Export utility methods to be used in adapters\nexport { commonTools } from \"./controllerTools.js\";\nexport * from \"./utils.js\";\n/**\n * Returns the absolute path of the data directory for the current host. On linux, this is usually `/opt/iobroker/iobroker-data`.\n */\nexport function getAbsoluteDefaultDataDir() {\n return path.join(utils.controllerDir, controllerToolsInternal.getDefaultDataDir());\n}\n/**\n * Returns the absolute path of the data directory for the current adapter instance.\n * On linux, this is usually `/opt/iobroker/iobroker-data/.`\n */\nexport function getAbsoluteInstanceDataDir(adapterObject) {\n return path.join(getAbsoluteDefaultDataDir(), adapterObject.namespace);\n}\n// TODO: Expose some system utilities here, e.g. for installing npm modules (GH#1)\nexport const EXIT_CODES = Object.freeze({\n // Create a shallow copy so compact adapters cannot overwrite the dict in js-controller\n ...resolveNamedModule(\"exitCodes\", \"EXIT_CODES\"),\n});\n"], + "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,WAAsB;AACtB,6BAA6D;AAC7D,YAAuB;AACvB,mBAAO;AAEP,IAAAA,0BAA4B;AAC5B,wBAAc,uBANd;AAUO,SAAS,4BAA4B;AACxC,SAAO,KAAK,KAAK,MAAM,eAAe,+CAAwB,kBAAkB,CAAC;AACrF;AAKO,SAAS,2BAA2B,eAAe;AACtD,SAAO,KAAK,KAAK,0BAA0B,GAAG,cAAc,SAAS;AACzE;AAEO,MAAM,aAAa,OAAO,OAAO;AAAA,EAEpC,OAAG,2CAAmB,aAAa,YAAY;AACnD,CAAC;", "names": ["import_controllerTools"] } diff --git a/build/cjs/utils.js b/build/cjs/utils.js index 1a00dc8..0a4a111 100644 --- a/build/cjs/utils.js +++ b/build/cjs/utils.js @@ -36,10 +36,10 @@ var import_node_module = require("node:module"); var import_helpers = require("./helpers.js"); const import_meta = {}; var _a; -var require2 = (0, import_node_module.createRequire)(import_meta.url || "file://" + __filename); +const require2 = (0, import_node_module.createRequire)(import_meta.url || "file://" + __filename); function getControllerDir(isInstall) { - var possibilities = ["iobroker.js-controller", "ioBroker.js-controller"]; - var controllerDir2 = (0, import_helpers.tryResolvePackage)(possibilities); + const possibilities = ["iobroker.js-controller", "ioBroker.js-controller"]; + let controllerDir2 = (0, import_helpers.tryResolvePackage)(possibilities); if (controllerDir2) return controllerDir2; controllerDir2 = (0, import_helpers.scanForPackage)(possibilities); @@ -52,46 +52,46 @@ function getControllerDir(isInstall) { return process.exit(); } } -var controllerDir = getControllerDir(!!((_a = process === null || process === void 0 ? void 0 : process.argv) === null || _a === void 0 ? void 0 : _a.includes("--install"))); +const controllerDir = getControllerDir(!!((_a = process == null ? void 0 : process.argv) == null ? void 0 : _a.includes("--install"))); function resolveAdapterConstructor() { - var adapterPath = (0, import_helpers.tryResolvePackage)(["@iobroker/js-controller-adapter"]); + let adapterPath = (0, import_helpers.tryResolvePackage)(["@iobroker/js-controller-adapter"]); if (adapterPath) { try { - var Adapter_1 = require2(adapterPath).Adapter; - if (Adapter_1) - return Adapter_1; - } catch (_a2) { + const { Adapter: Adapter2 } = require2(adapterPath); + if (Adapter2) + return Adapter2; + } catch { } } adapterPath = (0, import_helpers.tryResolvePackage)(["@iobroker/js-controller-adapter"], [path.join(controllerDir, "node_modules")]); if (adapterPath) { try { - var Adapter_2 = require2(adapterPath).Adapter; - if (Adapter_2) - return Adapter_2; - } catch (_b) { + const { Adapter: Adapter2 } = require2(adapterPath); + if (Adapter2) + return Adapter2; + } catch { } } adapterPath = path.join(controllerDir, "build/cjs/lib/adapter.js"); try { - var Adapter_3 = require2(adapterPath); - if (Adapter_3) - return Adapter_3; - } catch (_c) { + const Adapter2 = require2(adapterPath); + if (Adapter2) + return Adapter2; + } catch { } adapterPath = path.join(controllerDir, "build/lib/adapter.js"); try { - var Adapter_4 = require2(adapterPath); - if (Adapter_4) - return Adapter_4; - } catch (_d) { + const Adapter2 = require2(adapterPath); + if (Adapter2) + return Adapter2; + } catch { } adapterPath = path.join(controllerDir, "lib/adapter.js"); try { - var Adapter_5 = require2(adapterPath); - if (Adapter_5) - return Adapter_5; - } catch (_e) { + const Adapter2 = require2(adapterPath); + if (Adapter2) + return Adapter2; + } catch { } throw new Error("Cannot resolve adapter class"); return process.exit(10); @@ -99,8 +99,8 @@ function resolveAdapterConstructor() { function getConfig() { return JSON.parse(fs.readFileSync(path.join(controllerDir, "conf/iobroker.json"), "utf8")); } -var adapter = resolveAdapterConstructor(); -var Adapter = adapter; +const adapter = resolveAdapterConstructor(); +const Adapter = adapter; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Adapter, diff --git a/build/cjs/utils.js.map b/build/cjs/utils.js.map index 223647c..e6a6669 100644 --- a/build/cjs/utils.js.map +++ b/build/cjs/utils.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../esm/utils.js"], - "sourcesContent": ["var _a;\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { createRequire } from \"node:module\";\nimport { scanForPackage, tryResolvePackage } from \"./helpers.js\";\n// eslint-disable-next-line unicorn/prefer-module\nvar require = createRequire(import.meta.url || \"file://\" + __filename);\n/**\n * Resolves the root directory of JS-Controller and returns it or exits the process\n * @param isInstall Whether the adapter is run in \"install\" mode or if it should execute normally\n */\nfunction getControllerDir(isInstall) {\n // Find the js-controller location\n var possibilities = [\"iobroker.js-controller\", \"ioBroker.js-controller\"];\n // First try to let Node.js resolve the package by itself\n var controllerDir = tryResolvePackage(possibilities);\n // Apparently, checking vs null/undefined may miss the odd case of controllerPath being \"\"\n // Thus we check for falsyness, which includes failing on an empty path\n if (controllerDir)\n return controllerDir;\n // As a fallback solution, we walk up the directory tree until we reach the root or find js-controller\n controllerDir = scanForPackage(possibilities);\n if (controllerDir)\n return controllerDir;\n if (!isInstall) {\n console.log(\"Cannot find js-controller\");\n return process.exit(10);\n }\n else {\n return process.exit();\n }\n}\n/** The root directory of JS-Controller */\nexport var controllerDir = getControllerDir(!!((_a = process === null || process === void 0 ? void 0 : process.argv) === null || _a === void 0 ? void 0 : _a.includes(\"--install\")));\nfunction resolveAdapterConstructor() {\n // Attempt 1: Resolve @iobroker/js-controller-adapter from here - JS-Controller 4.1+\n var adapterPath = tryResolvePackage([\"@iobroker/js-controller-adapter\"]);\n if (adapterPath) {\n try {\n var Adapter_1 = require(adapterPath).Adapter;\n if (Adapter_1)\n return Adapter_1;\n }\n catch (_a) {\n // did not work, continue\n }\n }\n // Attempt 2: Resolve @iobroker/js-controller-adapter in JS-Controller dir - JS-Controller 4.1+\n adapterPath = tryResolvePackage([\"@iobroker/js-controller-adapter\"], [path.join(controllerDir, \"node_modules\")]);\n if (adapterPath) {\n try {\n var Adapter_2 = require(adapterPath).Adapter;\n if (Adapter_2)\n return Adapter_2;\n }\n catch (_b) {\n // did not work, continue\n }\n }\n // Attempt 3: JS-Controller 6+ with adapter stub\n adapterPath = path.join(controllerDir, \"build/cjs/lib/adapter.js\");\n try {\n // This was a default export prior to the TS migration\n var Adapter_3 = require(adapterPath);\n if (Adapter_3)\n return Adapter_3;\n }\n catch (_c) {\n // did not work, continue\n }\n // Attempt 4: JS-Controller 4.1+ with adapter stub\n adapterPath = path.join(controllerDir, \"build/lib/adapter.js\");\n try {\n // This was a default export prior to the TS migration\n var Adapter_4 = require(adapterPath);\n if (Adapter_4)\n return Adapter_4;\n }\n catch (_d) {\n // did not work, continue\n }\n // Attempt 5: Legacy resolve - until JS-Controller 4.0\n adapterPath = path.join(controllerDir, \"lib/adapter.js\");\n try {\n // This was a default export prior to the TS migration\n var Adapter_5 = require(adapterPath);\n if (Adapter_5)\n return Adapter_5;\n }\n catch (_e) {\n // did not work, continue\n }\n throw new Error(\"Cannot resolve adapter class\");\n return process.exit(10);\n}\n/** Reads the configuration file of JS-Controller */\nexport function getConfig() {\n return JSON.parse(fs.readFileSync(path.join(controllerDir, \"conf/iobroker.json\"), \"utf8\"));\n}\n/** Creates a new adapter instance */\nexport var adapter = resolveAdapterConstructor();\n/** Creates a new adapter instance */\nexport var Adapter = adapter;\n"], - "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,SAAoB;AACpB,WAAsB;AACtB,yBAA8B;AAC9B,qBAAkD;AAJlD;AAAA,IAAI;AAMJ,IAAIA,eAAU,kCAAc,YAAY,OAAO,YAAY,UAAU;AAKrE,SAAS,iBAAiB,WAAW;AAEjC,MAAI,gBAAgB,CAAC,0BAA0B,wBAAwB;AAEvE,MAAIC,qBAAgB,kCAAkB,aAAa;AAGnD,MAAIA;AACA,WAAOA;AAEX,EAAAA,qBAAgB,+BAAe,aAAa;AAC5C,MAAIA;AACA,WAAOA;AACX,MAAI,CAAC,WAAW;AACZ,YAAQ,IAAI,2BAA2B;AACvC,WAAO,QAAQ,KAAK,EAAE;AAAA,EAC1B,OACK;AACD,WAAO,QAAQ,KAAK;AAAA,EACxB;AACJ;AAEO,IAAI,gBAAgB,iBAAiB,CAAC,GAAG,KAAK,YAAY,QAAQ,YAAY,SAAS,SAAS,QAAQ,UAAU,QAAQ,OAAO,SAAS,SAAS,GAAG,SAAS,WAAW,EAAE;AACnL,SAAS,4BAA4B;AAEjC,MAAI,kBAAc,kCAAkB,CAAC,iCAAiC,CAAC;AACvE,MAAI,aAAa;AACb,QAAI;AACA,UAAI,YAAYD,SAAQ,WAAW,EAAE;AACrC,UAAI;AACA,eAAO;AAAA,IACf,SACOE,KAAP;AAAA,IAEA;AAAA,EACJ;AAEA,oBAAc,kCAAkB,CAAC,iCAAiC,GAAG,CAAC,KAAK,KAAK,eAAe,cAAc,CAAC,CAAC;AAC/G,MAAI,aAAa;AACb,QAAI;AACA,UAAI,YAAYF,SAAQ,WAAW,EAAE;AACrC,UAAI;AACA,eAAO;AAAA,IACf,SACO,IAAP;AAAA,IAEA;AAAA,EACJ;AAEA,gBAAc,KAAK,KAAK,eAAe,0BAA0B;AACjE,MAAI;AAEA,QAAI,YAAYA,SAAQ,WAAW;AACnC,QAAI;AACA,aAAO;AAAA,EACf,SACO,IAAP;AAAA,EAEA;AAEA,gBAAc,KAAK,KAAK,eAAe,sBAAsB;AAC7D,MAAI;AAEA,QAAI,YAAYA,SAAQ,WAAW;AACnC,QAAI;AACA,aAAO;AAAA,EACf,SACO,IAAP;AAAA,EAEA;AAEA,gBAAc,KAAK,KAAK,eAAe,gBAAgB;AACvD,MAAI;AAEA,QAAI,YAAYA,SAAQ,WAAW;AACnC,QAAI;AACA,aAAO;AAAA,EACf,SACO,IAAP;AAAA,EAEA;AACA,QAAM,IAAI,MAAM,8BAA8B;AAC9C,SAAO,QAAQ,KAAK,EAAE;AAC1B;AAEO,SAAS,YAAY;AACxB,SAAO,KAAK,MAAM,GAAG,aAAa,KAAK,KAAK,eAAe,oBAAoB,GAAG,MAAM,CAAC;AAC7F;AAEO,IAAI,UAAU,0BAA0B;AAExC,IAAI,UAAU;", - "names": ["require", "controllerDir", "_a"] + "sourcesContent": ["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { createRequire } from \"node:module\";\nimport { scanForPackage, tryResolvePackage } from \"./helpers.js\";\n// eslint-disable-next-line unicorn/prefer-module\nconst require = createRequire(import.meta.url || \"file://\" + __filename);\n/**\n * Resolves the root directory of JS-Controller and returns it or exits the process\n * @param isInstall Whether the adapter is run in \"install\" mode or if it should execute normally\n */\nfunction getControllerDir(isInstall) {\n // Find the js-controller location\n const possibilities = [\"iobroker.js-controller\", \"ioBroker.js-controller\"];\n // First try to let Node.js resolve the package by itself\n let controllerDir = tryResolvePackage(possibilities);\n // Apparently, checking vs null/undefined may miss the odd case of controllerPath being \"\"\n // Thus we check for falsyness, which includes failing on an empty path\n if (controllerDir)\n return controllerDir;\n // As a fallback solution, we walk up the directory tree until we reach the root or find js-controller\n controllerDir = scanForPackage(possibilities);\n if (controllerDir)\n return controllerDir;\n if (!isInstall) {\n console.log(\"Cannot find js-controller\");\n return process.exit(10);\n }\n else {\n return process.exit();\n }\n}\n/** The root directory of JS-Controller */\nexport const controllerDir = getControllerDir(!!process?.argv?.includes(\"--install\"));\nfunction resolveAdapterConstructor() {\n // Attempt 1: Resolve @iobroker/js-controller-adapter from here - JS-Controller 4.1+\n let adapterPath = tryResolvePackage([\"@iobroker/js-controller-adapter\"]);\n if (adapterPath) {\n try {\n const { Adapter } = require(adapterPath);\n if (Adapter)\n return Adapter;\n }\n catch {\n // did not work, continue\n }\n }\n // Attempt 2: Resolve @iobroker/js-controller-adapter in JS-Controller dir - JS-Controller 4.1+\n adapterPath = tryResolvePackage([\"@iobroker/js-controller-adapter\"], [path.join(controllerDir, \"node_modules\")]);\n if (adapterPath) {\n try {\n const { Adapter } = require(adapterPath);\n if (Adapter)\n return Adapter;\n }\n catch {\n // did not work, continue\n }\n }\n // Attempt 3: JS-Controller 6+ with adapter stub\n adapterPath = path.join(controllerDir, \"build/cjs/lib/adapter.js\");\n try {\n // This was a default export prior to the TS migration\n const Adapter = require(adapterPath);\n if (Adapter)\n return Adapter;\n }\n catch {\n // did not work, continue\n }\n // Attempt 4: JS-Controller 4.1+ with adapter stub\n adapterPath = path.join(controllerDir, \"build/lib/adapter.js\");\n try {\n // This was a default export prior to the TS migration\n const Adapter = require(adapterPath);\n if (Adapter)\n return Adapter;\n }\n catch {\n // did not work, continue\n }\n // Attempt 5: Legacy resolve - until JS-Controller 4.0\n adapterPath = path.join(controllerDir, \"lib/adapter.js\");\n try {\n // This was a default export prior to the TS migration\n const Adapter = require(adapterPath);\n if (Adapter)\n return Adapter;\n }\n catch {\n // did not work, continue\n }\n throw new Error(\"Cannot resolve adapter class\");\n return process.exit(10);\n}\n/** Reads the configuration file of JS-Controller */\nexport function getConfig() {\n return JSON.parse(fs.readFileSync(path.join(controllerDir, \"conf/iobroker.json\"), \"utf8\"));\n}\n/** Creates a new adapter instance */\nexport const adapter = resolveAdapterConstructor();\n/** Creates a new adapter instance */\nexport const Adapter = adapter;\n"], + "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAoB;AACpB,WAAsB;AACtB,yBAA8B;AAC9B,qBAAkD;AAHlD;AAAA;AAKA,MAAMA,eAAU,kCAAc,YAAY,OAAO,YAAY,UAAU;AAKvE,SAAS,iBAAiB,WAAW;AAEjC,QAAM,gBAAgB,CAAC,0BAA0B,wBAAwB;AAEzE,MAAIC,qBAAgB,kCAAkB,aAAa;AAGnD,MAAIA;AACA,WAAOA;AAEX,EAAAA,qBAAgB,+BAAe,aAAa;AAC5C,MAAIA;AACA,WAAOA;AACX,MAAI,CAAC,WAAW;AACZ,YAAQ,IAAI,2BAA2B;AACvC,WAAO,QAAQ,KAAK,EAAE;AAAA,EAC1B,OACK;AACD,WAAO,QAAQ,KAAK;AAAA,EACxB;AACJ;AAEO,MAAM,gBAAgB,iBAAiB,CAAC,GAAC,wCAAS,SAAT,mBAAe,SAAS,aAAY;AACpF,SAAS,4BAA4B;AAEjC,MAAI,kBAAc,kCAAkB,CAAC,iCAAiC,CAAC;AACvE,MAAI,aAAa;AACb,QAAI;AACA,YAAM,EAAE,SAAAC,SAAQ,IAAIF,SAAQ,WAAW;AACvC,UAAIE;AACA,eAAOA;AAAA,IACf,QACA;AAAA,IAEA;AAAA,EACJ;AAEA,oBAAc,kCAAkB,CAAC,iCAAiC,GAAG,CAAC,KAAK,KAAK,eAAe,cAAc,CAAC,CAAC;AAC/G,MAAI,aAAa;AACb,QAAI;AACA,YAAM,EAAE,SAAAA,SAAQ,IAAIF,SAAQ,WAAW;AACvC,UAAIE;AACA,eAAOA;AAAA,IACf,QACA;AAAA,IAEA;AAAA,EACJ;AAEA,gBAAc,KAAK,KAAK,eAAe,0BAA0B;AACjE,MAAI;AAEA,UAAMA,WAAUF,SAAQ,WAAW;AACnC,QAAIE;AACA,aAAOA;AAAA,EACf,QACA;AAAA,EAEA;AAEA,gBAAc,KAAK,KAAK,eAAe,sBAAsB;AAC7D,MAAI;AAEA,UAAMA,WAAUF,SAAQ,WAAW;AACnC,QAAIE;AACA,aAAOA;AAAA,EACf,QACA;AAAA,EAEA;AAEA,gBAAc,KAAK,KAAK,eAAe,gBAAgB;AACvD,MAAI;AAEA,UAAMA,WAAUF,SAAQ,WAAW;AACnC,QAAIE;AACA,aAAOA;AAAA,EACf,QACA;AAAA,EAEA;AACA,QAAM,IAAI,MAAM,8BAA8B;AAC9C,SAAO,QAAQ,KAAK,EAAE;AAC1B;AAEO,SAAS,YAAY;AACxB,SAAO,KAAK,MAAM,GAAG,aAAa,KAAK,KAAK,eAAe,oBAAoB,GAAG,MAAM,CAAC;AAC7F;AAEO,MAAM,UAAU,0BAA0B;AAE1C,MAAM,UAAU;", + "names": ["require", "controllerDir", "Adapter"] } diff --git a/build/esm/controllerTools.js b/build/esm/controllerTools.js index aab3ae6..ac0992a 100644 --- a/build/esm/controllerTools.js +++ b/build/esm/controllerTools.js @@ -3,19 +3,19 @@ import { tryResolvePackage } from "./helpers.js"; import * as utils from "./utils.js"; import { createRequire } from "node:module"; // eslint-disable-next-line unicorn/prefer-module -var require = createRequire(import.meta.url || "file://" + __filename); -export var controllerCommonModulesInternal; +const require = createRequire(import.meta.url || "file://" + __filename); +export let controllerCommonModulesInternal; function resolveControllerTools() { // Attempt 1: Resolve @iobroker/js-controller-common from here - JS-Controller 4.1+ - var importPath = tryResolvePackage(["@iobroker/js-controller-common"]); + let importPath = tryResolvePackage(["@iobroker/js-controller-common"]); if (importPath) { try { controllerCommonModulesInternal = require(importPath); - var tools = controllerCommonModulesInternal.tools; + const { tools } = controllerCommonModulesInternal; if (tools) return tools; } - catch (_a) { + catch { // did not work, continue } } @@ -24,11 +24,11 @@ function resolveControllerTools() { if (importPath) { try { controllerCommonModulesInternal = require(importPath); - var tools = controllerCommonModulesInternal.tools; + const { tools } = controllerCommonModulesInternal; if (tools) return tools; } - catch (_b) { + catch { // did not work, continue } } @@ -36,31 +36,30 @@ function resolveControllerTools() { importPath = path.join(utils.controllerDir, "lib"); try { // This was a default export prior to the TS migration - var tools = require(path.join(importPath, "tools")); + const tools = require(path.join(importPath, "tools")); if (tools) return tools; } - catch (_c) { + catch { // did not work, continue } throw new Error("Cannot resolve tools module"); //return process.exit(10); } /** The collection of utility functions in JS-Controller, formerly `lib/tools.js` */ -export var controllerToolsInternal = resolveControllerTools(); +export const controllerToolsInternal = resolveControllerTools(); // Export a subset of the utilties in controllerTools /** * Resolve a module that is either exported by @iobroker/js-controller-common (new controllers) or located in the controller's `lib` directory (old controllers). * @param name - The filename of the module to resolve * @param exportName - The name under which the module may be exported. Defaults to `name`. */ -export function resolveNamedModule(name, exportName) { - if (exportName === void 0) { exportName = name; } +export function resolveNamedModule(name, exportName = name) { // The requested module might be moved to @iobroker/js-controller-common and exported from there - if (controllerCommonModulesInternal === null || controllerCommonModulesInternal === void 0 ? void 0 : controllerCommonModulesInternal[exportName]) + if (controllerCommonModulesInternal?.[exportName]) return controllerCommonModulesInternal[exportName]; // Otherwise it was not moved yet, or we're dealing with JS-Controller <= 4.0 - var importPaths = [ + const importPaths = [ // Attempt 1: JS-Controller 6+ path.join(utils.controllerDir, "build/cjs/lib", name), // Attempt 2: JS-Controller 4.1+ @@ -68,19 +67,18 @@ export function resolveNamedModule(name, exportName) { // Attempt 3: JS-Controller <= 4.0 path.join(utils.controllerDir, "lib", name), ]; - for (var _i = 0, importPaths_1 = importPaths; _i < importPaths_1.length; _i++) { - var importPath = importPaths_1[_i]; + for (const importPath of importPaths) { try { // This was a default export prior to the TS migration - var module_1 = require(importPath); - if (module_1) - return module_1; + const module = require(importPath); + if (module) + return module; } - catch (_a) { + catch { // did not work, continue } } - throw new Error("Cannot resolve JS-Controller module ".concat(name, ".js")); + throw new Error(`Cannot resolve JS-Controller module ${name}.js`); //return process.exit(10); } // TODO: Import types from @iobroker/js-controller-common and iobroker.js-controller @@ -141,15 +139,15 @@ function getLocalAddress() { function getListenAllAddress() { return controllerToolsInternal.getListenAllAddress(); } -export var commonTools = { - pattern2RegEx: pattern2RegEx, - getAdapterDir: getAdapterDir, - getInstalledInfo: getInstalledInfo, - isDocker: isDocker, - getLocalAddress: getLocalAddress, - getListenAllAddress: getListenAllAddress, - isLocalAddress: isLocalAddress, - isListenAllAddress: isListenAllAddress, +export const commonTools = { + pattern2RegEx, + getAdapterDir, + getInstalledInfo, + isDocker, + getLocalAddress, + getListenAllAddress, + isLocalAddress, + isListenAllAddress, // TODO: Add more methods from lib/tools.js as needed password: resolveNamedModule("password"), session: resolveNamedModule("session"), diff --git a/build/esm/helpers.js b/build/esm/helpers.js index 7daff34..5cb4ecf 100644 --- a/build/esm/helpers.js +++ b/build/esm/helpers.js @@ -3,8 +3,8 @@ import * as path from "node:path"; import { createRequire } from "node:module"; import * as url from "node:url"; // eslint-disable-next-line unicorn/prefer-module -var require = createRequire(import.meta.url || "file://" + __filename); -var thisDir = url.fileURLToPath( +const require = createRequire(import.meta.url || "file://" + __filename); +const thisDir = url.fileURLToPath( // eslint-disable-next-line unicorn/prefer-module new URL(".", import.meta.url || "file://" + __filename)); /** @@ -12,17 +12,16 @@ new URL(".", import.meta.url || "file://" + __filename)); * Directory names differing from the package name and alternate lookup paths can be passed. */ export function tryResolvePackage(possiblePaths, lookupPaths) { - for (var _i = 0, possiblePaths_1 = possiblePaths; _i < possiblePaths_1.length; _i++) { - var pkg = possiblePaths_1[_i]; + for (const pkg of possiblePaths) { try { // package.json is guaranteed to be in the module root folder // so once that is resolved, take the dirname and we're done - var possiblePath = require.resolve("".concat(pkg, "/package.json"), (lookupPaths === null || lookupPaths === void 0 ? void 0 : lookupPaths.length) ? { paths: lookupPaths } : undefined); + const possiblePath = require.resolve(`${pkg}/package.json`, lookupPaths?.length ? { paths: lookupPaths } : undefined); if (fs.existsSync(possiblePath)) { return path.dirname(possiblePath); } } - catch (_a) { + catch { /* not found */ } } @@ -31,14 +30,12 @@ export function tryResolvePackage(possiblePaths, lookupPaths) { * Scans for a package by walking up the directory tree and inspecting package.json * Directory names differing from the package name and an alternate start dir can be passed. */ -export function scanForPackage(possiblePaths, startDir) { - if (startDir === void 0) { startDir = thisDir; } +export function scanForPackage(possiblePaths, startDir = thisDir) { // We start in the node_modules subfolder of adapter-core, which is the deepest we should be able to expect the controller - var curDir = path.join(startDir, "../node_modules"); + let curDir = path.join(startDir, "../node_modules"); while (true) { - for (var _i = 0, possiblePaths_2 = possiblePaths; _i < possiblePaths_2.length; _i++) { - var pkg = possiblePaths_2[_i]; - var possiblePath = path.join(curDir, pkg, "package.json"); + for (const pkg of possiblePaths) { + const possiblePath = path.join(curDir, pkg, "package.json"); try { // If package.json exists in the directory and its name field matches, we've found js-controller if (fs.existsSync(possiblePath) && @@ -47,12 +44,12 @@ export function scanForPackage(possiblePaths, startDir) { return path.dirname(possiblePath); } } - catch (_a) { + catch { // don't care } } // Nothing found here, go up one level - var parentDir = path.dirname(curDir); + const parentDir = path.dirname(curDir); if (parentDir === curDir) { // we've reached the root without finding js-controller break; diff --git a/build/esm/index.js b/build/esm/index.js index fd123da..1ba4f42 100644 --- a/build/esm/index.js +++ b/build/esm/index.js @@ -1,14 +1,3 @@ -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; import * as path from "node:path"; import { controllerToolsInternal, resolveNamedModule, } from "./controllerTools.js"; import * as utils from "./utils.js"; @@ -30,4 +19,7 @@ export function getAbsoluteInstanceDataDir(adapterObject) { return path.join(getAbsoluteDefaultDataDir(), adapterObject.namespace); } // TODO: Expose some system utilities here, e.g. for installing npm modules (GH#1) -export var EXIT_CODES = Object.freeze(__assign({}, resolveNamedModule("exitCodes", "EXIT_CODES"))); +export const EXIT_CODES = Object.freeze({ + // Create a shallow copy so compact adapters cannot overwrite the dict in js-controller + ...resolveNamedModule("exitCodes", "EXIT_CODES"), +}); diff --git a/build/esm/utils.js b/build/esm/utils.js index 54ab6e6..239fcc5 100644 --- a/build/esm/utils.js +++ b/build/esm/utils.js @@ -1,19 +1,18 @@ -var _a; import * as fs from "node:fs"; import * as path from "node:path"; import { createRequire } from "node:module"; import { scanForPackage, tryResolvePackage } from "./helpers.js"; // eslint-disable-next-line unicorn/prefer-module -var require = createRequire(import.meta.url || "file://" + __filename); +const require = createRequire(import.meta.url || "file://" + __filename); /** * Resolves the root directory of JS-Controller and returns it or exits the process * @param isInstall Whether the adapter is run in "install" mode or if it should execute normally */ function getControllerDir(isInstall) { // Find the js-controller location - var possibilities = ["iobroker.js-controller", "ioBroker.js-controller"]; + const possibilities = ["iobroker.js-controller", "ioBroker.js-controller"]; // First try to let Node.js resolve the package by itself - var controllerDir = tryResolvePackage(possibilities); + let controllerDir = tryResolvePackage(possibilities); // Apparently, checking vs null/undefined may miss the odd case of controllerPath being "" // Thus we check for falsyness, which includes failing on an empty path if (controllerDir) @@ -31,17 +30,17 @@ function getControllerDir(isInstall) { } } /** The root directory of JS-Controller */ -export var controllerDir = getControllerDir(!!((_a = process === null || process === void 0 ? void 0 : process.argv) === null || _a === void 0 ? void 0 : _a.includes("--install"))); +export const controllerDir = getControllerDir(!!process?.argv?.includes("--install")); function resolveAdapterConstructor() { // Attempt 1: Resolve @iobroker/js-controller-adapter from here - JS-Controller 4.1+ - var adapterPath = tryResolvePackage(["@iobroker/js-controller-adapter"]); + let adapterPath = tryResolvePackage(["@iobroker/js-controller-adapter"]); if (adapterPath) { try { - var Adapter_1 = require(adapterPath).Adapter; - if (Adapter_1) - return Adapter_1; + const { Adapter } = require(adapterPath); + if (Adapter) + return Adapter; } - catch (_a) { + catch { // did not work, continue } } @@ -49,11 +48,11 @@ function resolveAdapterConstructor() { adapterPath = tryResolvePackage(["@iobroker/js-controller-adapter"], [path.join(controllerDir, "node_modules")]); if (adapterPath) { try { - var Adapter_2 = require(adapterPath).Adapter; - if (Adapter_2) - return Adapter_2; + const { Adapter } = require(adapterPath); + if (Adapter) + return Adapter; } - catch (_b) { + catch { // did not work, continue } } @@ -61,33 +60,33 @@ function resolveAdapterConstructor() { adapterPath = path.join(controllerDir, "build/cjs/lib/adapter.js"); try { // This was a default export prior to the TS migration - var Adapter_3 = require(adapterPath); - if (Adapter_3) - return Adapter_3; + const Adapter = require(adapterPath); + if (Adapter) + return Adapter; } - catch (_c) { + catch { // did not work, continue } // Attempt 4: JS-Controller 4.1+ with adapter stub adapterPath = path.join(controllerDir, "build/lib/adapter.js"); try { // This was a default export prior to the TS migration - var Adapter_4 = require(adapterPath); - if (Adapter_4) - return Adapter_4; + const Adapter = require(adapterPath); + if (Adapter) + return Adapter; } - catch (_d) { + catch { // did not work, continue } // Attempt 5: Legacy resolve - until JS-Controller 4.0 adapterPath = path.join(controllerDir, "lib/adapter.js"); try { // This was a default export prior to the TS migration - var Adapter_5 = require(adapterPath); - if (Adapter_5) - return Adapter_5; + const Adapter = require(adapterPath); + if (Adapter) + return Adapter; } - catch (_e) { + catch { // did not work, continue } throw new Error("Cannot resolve adapter class"); @@ -98,6 +97,6 @@ export function getConfig() { return JSON.parse(fs.readFileSync(path.join(controllerDir, "conf/iobroker.json"), "utf8")); } /** Creates a new adapter instance */ -export var adapter = resolveAdapterConstructor(); +export const adapter = resolveAdapterConstructor(); /** Creates a new adapter instance */ -export var Adapter = adapter; +export const Adapter = adapter; diff --git a/package-lock.json b/package-lock.json index e8d23b9..0c0a9b8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@iobroker/adapter-core", - "version": "3.1.4", + "version": "3.1.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@iobroker/adapter-core", - "version": "3.1.4", + "version": "3.1.5", "license": "MIT", "devDependencies": { "@alcalzone/esm2cjs": "^1.1.2", @@ -42,7 +42,7 @@ "npm": ">=7.0.0" }, "peerDependencies": { - "@iobroker/types": "^5.0.11" + "@iobroker/types": "^6.0.0" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -558,9 +558,9 @@ "dev": true }, "node_modules/@iobroker/types": { - "version": "5.0.11", - "resolved": "https://registry.npmjs.org/@iobroker/types/-/types-5.0.11.tgz", - "integrity": "sha512-H96EQbum1mUVxO8gklWoW+G8R3sJLo2OOrGQHsjPrtKvmYU+UCLOjOMh9TjsYMvwGhPz86Bp8xlZSp5WifmbUA==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/@iobroker/types/-/types-6.0.0.tgz", + "integrity": "sha512-BBtOT1smz5QHwcxqokgyMBw8aT46uZ/fe9DybHha+DjyTWIhrt0sogoGYFYSV64xKEPpFvSl+RpVh9GGnNUpGA==", "peer": true, "engines": { "node": ">=12.0.0" @@ -5502,9 +5502,9 @@ "dev": true }, "@iobroker/types": { - "version": "5.0.11", - "resolved": "https://registry.npmjs.org/@iobroker/types/-/types-5.0.11.tgz", - "integrity": "sha512-H96EQbum1mUVxO8gklWoW+G8R3sJLo2OOrGQHsjPrtKvmYU+UCLOjOMh9TjsYMvwGhPz86Bp8xlZSp5WifmbUA==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/@iobroker/types/-/types-6.0.0.tgz", + "integrity": "sha512-BBtOT1smz5QHwcxqokgyMBw8aT46uZ/fe9DybHha+DjyTWIhrt0sogoGYFYSV64xKEPpFvSl+RpVh9GGnNUpGA==", "peer": true }, "@jridgewell/resolve-uri": { diff --git a/package.json b/package.json index 7cf38fe..980e011 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@iobroker/adapter-core", - "version": "3.1.4", + "version": "3.1.5", "description": "Core module to be used in ioBroker adapters. Acts as the bridge to js-controller.", "engines": { "npm": ">=7.0.0" @@ -80,6 +80,6 @@ "typescript": "^5.4.5" }, "peerDependencies": { - "@iobroker/types": "^5.0.11" + "@iobroker/types": "^6.0.0" } } diff --git a/tsconfig.json b/tsconfig.json index 3c7dbb3..1424512 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "compileOnSave": true, "compilerOptions": { + "target": "ESNext", "noEmit": true, "noEmitOnError": true, "module": "ES2020",