@iobroker/adapter-core
Advanced tools
Comparing version 2.6.2 to 2.6.3
/// <reference types="iobroker" /> | ||
export { commonTools } from "./controllerTools"; | ||
export * from "./utils"; | ||
@@ -3,0 +4,0 @@ /** |
@@ -17,50 +17,11 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EXIT_CODES = exports.getAbsoluteInstanceDataDir = exports.getAbsoluteDefaultDataDir = void 0; | ||
exports.EXIT_CODES = exports.getAbsoluteInstanceDataDir = exports.getAbsoluteDefaultDataDir = exports.commonTools = void 0; | ||
const path = require("path"); | ||
const helpers_1 = require("./helpers"); | ||
const controllerTools_1 = require("./controllerTools"); | ||
const utils = require("./utils"); | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
// Export all methods that used to be in utils.js | ||
// Export utility methods to be used in adapters | ||
var controllerTools_2 = require("./controllerTools"); | ||
Object.defineProperty(exports, "commonTools", { enumerable: true, get: function () { return controllerTools_2.commonTools; } }); | ||
__exportStar(require("./utils"), exports); | ||
// Export some additional utility methods | ||
function resolveControllerTools() { | ||
// Attempt 1: Resolve @iobroker/js-controller-common from here - JS-Controller 4.1+ | ||
let importPath = (0, helpers_1.tryResolvePackage)(["@iobroker/js-controller-common"]); | ||
if (importPath) { | ||
try { | ||
const { tools } = require(importPath); | ||
if (tools) | ||
return tools; | ||
} | ||
catch (_a) { | ||
// did not work, continue | ||
} | ||
} | ||
// Attempt 2: Resolve @iobroker/js-controller-common in JS-Controller dir - JS-Controller 4.1+ | ||
importPath = (0, helpers_1.tryResolvePackage)(["@iobroker/js-controller-common"], [path.join(utils.controllerDir, "node_modules")]); | ||
if (importPath) { | ||
try { | ||
const { tools } = require(importPath); | ||
if (tools) | ||
return tools; | ||
} | ||
catch (_b) { | ||
// did not work, continue | ||
} | ||
} | ||
// Attempt 3: Legacy resolve - until JS-Controller 4.0 | ||
importPath = path.join(utils.controllerDir, "lib/tools"); | ||
try { | ||
// This was a default export prior to the TS migration | ||
const tools = require(importPath); | ||
if (tools) | ||
return tools; | ||
} | ||
catch (_c) { | ||
// did not work, continue | ||
} | ||
throw new Error("Cannot resolve tools module"); | ||
return process.exit(10); | ||
} | ||
const controllerTools = resolveControllerTools(); | ||
/** | ||
@@ -70,3 +31,3 @@ * Returns the absolute path of the data directory for the current host. On linux, this is usually `/opt/iobroker/iobroker-data`. | ||
function getAbsoluteDefaultDataDir() { | ||
return path.join(utils.controllerDir, controllerTools.getDefaultDataDir()); | ||
return path.join(utils.controllerDir, controllerTools_1.controllerToolsInternal.getDefaultDataDir()); | ||
} | ||
@@ -84,28 +45,6 @@ exports.getAbsoluteDefaultDataDir = getAbsoluteDefaultDataDir; | ||
function resolveExitCodes() { | ||
// Attempt 1: Resolve @iobroker/js-controller-common from here - JS-Controller 4.1+ | ||
let importPath = (0, helpers_1.tryResolvePackage)(["@iobroker/js-controller-common"]); | ||
if (importPath) { | ||
try { | ||
const { EXIT_CODES } = require(importPath); | ||
if (EXIT_CODES) | ||
return EXIT_CODES; | ||
} | ||
catch (_a) { | ||
// did not work, continue | ||
} | ||
} | ||
// Attempt 2: Resolve @iobroker/js-controller-common in JS-Controller dir - JS-Controller 4.1+ | ||
importPath = (0, helpers_1.tryResolvePackage)(["@iobroker/js-controller-common"], [path.join(utils.controllerDir, "node_modules")]); | ||
if (importPath) { | ||
try { | ||
const { EXIT_CODES } = require(importPath); | ||
if (EXIT_CODES) | ||
return EXIT_CODES; | ||
} | ||
catch (_b) { | ||
// did not work, continue | ||
} | ||
} | ||
// Attempt 3: Legacy resolve - until JS-Controller 4.0 | ||
importPath = path.join(utils.controllerDir, "lib/exitCodes"); | ||
if ("EXIT_CODES" in controllerTools_1.controllerToolsInternal) | ||
return controllerTools_1.controllerToolsInternal.EXIT_CODES; | ||
// We're dealing with JS-Controller <= 4.0 | ||
const importPath = path.join(utils.controllerDir, "lib/exitCodes"); | ||
try { | ||
@@ -117,3 +56,3 @@ // This was a default export prior to the TS migration | ||
} | ||
catch (_c) { | ||
catch (_a) { | ||
// did not work, continue | ||
@@ -120,0 +59,0 @@ } |
{ | ||
"name": "@iobroker/adapter-core", | ||
"version": "2.6.2", | ||
"version": "2.6.3", | ||
"description": "Core module to be used in ioBroker adapters. Acts as the bridge to js-controller.", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -61,2 +61,17 @@ # Adapter-Core | ||
### `commonTools` | ||
A collection of various utility methods and modules from JS-Controller. Prefer this over trying to find `lib/tools.js` and similar internal modules from the controller yourself! | ||
Currently, the following **methods** are available: | ||
- `commonTools.pattern2RegEx` - Converts a pattern to match object IDs into a RegEx string that can be used in `new RegExp(...)` | ||
And the following **modules** are exposed: | ||
- `commonTools.password` - Previously exposed as `lib/password.js` in JS-Controller. | ||
- `commonTools.letsEncrypt` - Previously exposed as `lib/letsencrypt.js` in JS-Controller. Note that `letsEncrypt` has a capital `E`! | ||
- `commonTools.session` - Previously exposed as `lib/session.js` in JS-Controller. | ||
- `commonTools.zipFiles` - Previously exposed as `lib/zipFiles.js` in JS-Controller. | ||
## Automatic backup of data files | ||
@@ -94,2 +109,6 @@ | ||
--> | ||
### 2.6.3 (2022-09-13) | ||
- (AlCalzone) Expose more JS-Controller internals under the `commonTools` export | ||
### 2.6.2 (2022-09-07) | ||
@@ -96,0 +115,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34136
20
509
185
12
1