From d0ab7df462e0629578ec93e27e6dd86562d05232 Mon Sep 17 00:00:00 2001 From: foxriver76 Date: Fri, 19 Apr 2024 16:26:15 +0200 Subject: [PATCH] fixes for adapters which are written in ESM --- README.md | 9 +++++++-- build/cjs/controllerTools.js | 4 ++-- build/cjs/controllerTools.js.map | 2 +- build/cjs/index.d.ts | 6 +++--- build/cjs/index.js | 8 ++++---- build/cjs/index.js.map | 4 ++-- build/cjs/utils.js | 2 +- build/cjs/utils.js.map | 2 +- build/esm/controllerTools.js | 4 ++-- build/esm/index.d.ts | 6 +++--- build/esm/index.js | 8 ++++---- build/esm/utils.js | 2 +- src/controllerTools.ts | 4 ++-- src/index.ts | 13 ++++++++----- src/utils.ts | 2 +- 15 files changed, 42 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index ba6c18c..3daaaf3 100644 --- a/README.md +++ b/README.md @@ -113,13 +113,18 @@ If you find errors in the definitions, e.g. function calls that should be allowe Placeholder for the next version (at the beginning of the line): ### **WORK IN PROGRESS** --> + +### **WORK IN PROGRESS** + + - (foxriver76) fixes for adapters which are written in ESM + ### 3.1.3 (2024-04-19) -- (foxriver76) fixes for cjs adapters + - (foxriver76) fixes for cjs adapters ### 3.1.2 (2024-04-19) -- (foxriver76) fixes for adapters which are written in ESM + - (foxriver76) fixes for adapters which are written in ESM ### 3.1.1 (2024-04-19) diff --git a/build/cjs/controllerTools.js b/build/cjs/controllerTools.js index 2445c20..7eddec2 100644 --- a/build/cjs/controllerTools.js +++ b/build/cjs/controllerTools.js @@ -31,8 +31,8 @@ __export(controllerTools_exports, { }); module.exports = __toCommonJS(controllerTools_exports); var path = __toESM(require("node:path")); -var import_helpers = require("./helpers"); -var utils = __toESM(require("./utils")); +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); diff --git a/build/cjs/controllerTools.js.map b/build/cjs/controllerTools.js.map index eee9167..d1488d3 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\";\nimport * as utils from \"./utils\";\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"], + "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;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,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"] } diff --git a/build/cjs/index.d.ts b/build/cjs/index.d.ts index 4d86efa..59f46c4 100644 --- a/build/cjs/index.d.ts +++ b/build/cjs/index.d.ts @@ -1,7 +1,7 @@ -import { ExitCodes } from "./exitCodes"; +import { ExitCodes } from "./exitCodes.js"; import "@iobroker/types"; -export { commonTools } from "./controllerTools"; -export * from "./utils"; +export { commonTools } from "./controllerTools.js"; +export * from "./utils.js"; /** * Returns the absolute path of the data directory for the current host. On linux, this is usually `/opt/iobroker/iobroker-data`. */ diff --git a/build/cjs/index.js b/build/cjs/index.js index caac98e..66b308e 100644 --- a/build/cjs/index.js +++ b/build/cjs/index.js @@ -32,11 +32,11 @@ __export(esm_exports, { }); module.exports = __toCommonJS(esm_exports); var path = __toESM(require("node:path")); -var import_controllerTools = require("./controllerTools"); -var utils = __toESM(require("./utils")); +var import_controllerTools = require("./controllerTools.js"); +var utils = __toESM(require("./utils.js")); var import_types = require("@iobroker/types"); -var import_controllerTools2 = require("./controllerTools"); -__reExport(esm_exports, require("./utils"), module.exports); +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++) { diff --git a/build/cjs/index.js.map b/build/cjs/index.js.map index 1bfb0fd..ebcc0f0 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\";\nimport * as utils from \"./utils\";\nimport \"@iobroker/types\";\n// Export utility methods to be used in adapters\nexport { commonTools } from \"./controllerTools\";\nexport * from \"./utils\";\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,6BAA4D;AAC5D,YAAuB;AACvB,mBAAO;AAEP,IAAAA,0BAA4B;AAC5B,wBAAc,oBAjBd;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": ["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;", "names": ["import_controllerTools"] } diff --git a/build/cjs/utils.js b/build/cjs/utils.js index 220d093..1a00dc8 100644 --- a/build/cjs/utils.js +++ b/build/cjs/utils.js @@ -33,7 +33,7 @@ module.exports = __toCommonJS(utils_exports); var fs = __toESM(require("node:fs")); var path = __toESM(require("node:path")); var import_node_module = require("node:module"); -var import_helpers = require("./helpers"); +var import_helpers = require("./helpers.js"); const import_meta = {}; var _a; var require2 = (0, import_node_module.createRequire)(import_meta.url || "file://" + __filename); diff --git a/build/cjs/utils.js.map b/build/cjs/utils.js.map index c9845ac..223647c 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\";\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"], + "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,YA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644 --- a/build/esm/controllerTools.js +++ b/build/esm/controllerTools.js @@ -1,6 +1,6 @@ import * as path from "node:path"; -import { tryResolvePackage } from "./helpers"; -import * as utils from "./utils"; +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); diff --git a/build/esm/index.d.ts b/build/esm/index.d.ts index 4d86efa..59f46c4 100644 --- a/build/esm/index.d.ts +++ b/build/esm/index.d.ts @@ -1,7 +1,7 @@ -import { ExitCodes } from "./exitCodes"; +import { ExitCodes } from "./exitCodes.js"; import "@iobroker/types"; -export { commonTools } from "./controllerTools"; -export * from "./utils"; +export { commonTools } from "./controllerTools.js"; +export * from "./utils.js"; /** * Returns the absolute path of the data directory for the current host. On linux, this is usually `/opt/iobroker/iobroker-data`. */ diff --git a/build/esm/index.js b/build/esm/index.js index b00709f..fd123da 100644 --- a/build/esm/index.js +++ b/build/esm/index.js @@ -10,12 +10,12 @@ var __assign = (this && this.__assign) || function () { return __assign.apply(this, arguments); }; import * as path from "node:path"; -import { controllerToolsInternal, resolveNamedModule } from "./controllerTools"; -import * as utils from "./utils"; +import { controllerToolsInternal, resolveNamedModule, } from "./controllerTools.js"; +import * as utils from "./utils.js"; import "@iobroker/types"; // Export utility methods to be used in adapters -export { commonTools } from "./controllerTools"; -export * from "./utils"; +export { commonTools } from "./controllerTools.js"; +export * from "./utils.js"; /** * Returns the absolute path of the data directory for the current host. On linux, this is usually `/opt/iobroker/iobroker-data`. */ diff --git a/build/esm/utils.js b/build/esm/utils.js index 73dd312..54ab6e6 100644 --- a/build/esm/utils.js +++ b/build/esm/utils.js @@ -2,7 +2,7 @@ var _a; import * as fs from "node:fs"; import * as path from "node:path"; import { createRequire } from "node:module"; -import { scanForPackage, tryResolvePackage } from "./helpers"; +import { scanForPackage, tryResolvePackage } from "./helpers.js"; // eslint-disable-next-line unicorn/prefer-module var require = createRequire(import.meta.url || "file://" + __filename); /** diff --git a/src/controllerTools.ts b/src/controllerTools.ts index 97a888e..5c28255 100644 --- a/src/controllerTools.ts +++ b/src/controllerTools.ts @@ -1,6 +1,6 @@ import * as path from "node:path"; -import { tryResolvePackage } from "./helpers"; -import * as utils from "./utils"; +import { tryResolvePackage } from "./helpers.js"; +import * as utils from "./utils.js"; import { createRequire } from "node:module"; // eslint-disable-next-line unicorn/prefer-module diff --git a/src/index.ts b/src/index.ts index 105e9dc..c15729a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,15 @@ import * as path from "node:path"; -import { controllerToolsInternal, resolveNamedModule } from "./controllerTools"; -import { ExitCodes } from "./exitCodes"; -import * as utils from "./utils"; +import { + controllerToolsInternal, + resolveNamedModule, +} from "./controllerTools.js"; +import { ExitCodes } from "./exitCodes.js"; +import * as utils from "./utils.js"; import "@iobroker/types"; // Export utility methods to be used in adapters -export { commonTools } from "./controllerTools"; -export * from "./utils"; +export { commonTools } from "./controllerTools.js"; +export * from "./utils.js"; /** * Returns the absolute path of the data directory for the current host. On linux, this is usually `/opt/iobroker/iobroker-data`. diff --git a/src/utils.ts b/src/utils.ts index 99dc909..a2f255e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,7 @@ import * as fs from "node:fs"; import * as path from "node:path"; import { createRequire } from "node:module"; -import { scanForPackage, tryResolvePackage } from "./helpers"; +import { scanForPackage, tryResolvePackage } from "./helpers.js"; // eslint-disable-next-line unicorn/prefer-module const require = createRequire(import.meta.url || "file://" + __filename);