@iobroker/adapter-core
Advanced tools
Comparing version 3.0.4 to 3.0.5
@@ -61,24 +61,21 @@ "use strict"; | ||
// Otherwise it was not moved yet, or we're dealing with JS-Controller <= 4.0 | ||
// Attempt 1: JS-Controller 4.1+ | ||
let importPath = path.join(utils.controllerDir, "build/lib", name); | ||
try { | ||
// This was a default export prior to the TS migration | ||
const module = require(importPath); | ||
if (module) | ||
return module; | ||
const importPaths = [ | ||
// Attempt 1: JS-Controller 5.1+ | ||
path.join(utils.controllerDir, "build/cjs/lib", name), | ||
// Attempt 2: JS-Controller 4.1+ | ||
path.join(utils.controllerDir, "build/lib", name), | ||
// Attempt 3: JS-Controller <= 4.0 | ||
path.join(utils.controllerDir, "lib", name), | ||
]; | ||
for (const importPath of importPaths) { | ||
try { | ||
// This was a default export prior to the TS migration | ||
const module = require(importPath); | ||
if (module) | ||
return module; | ||
} | ||
catch (_a) { | ||
// did not work, continue | ||
} | ||
} | ||
catch (_a) { | ||
// did not work, continue | ||
} | ||
// Attempt 2: JS-Controller <= 4.0 | ||
importPath = path.join(utils.controllerDir, "lib", name); | ||
try { | ||
// This was a default export prior to the TS migration | ||
const module = require(importPath); | ||
if (module) | ||
return module; | ||
} | ||
catch (_b) { | ||
// did not work, continue | ||
} | ||
throw new Error(`Cannot resolve JS-Controller module ${name}.js`); | ||
@@ -85,0 +82,0 @@ //return process.exit(10); |
@@ -37,7 +37,19 @@ "use strict"; | ||
function resolveAdapterConstructor() { | ||
// Attempt 1: Resolve @iobroker/js-controller-adapter from here - JS-Controller 4.1+ | ||
let adapterPath = (0, helpers_1.tryResolvePackage)(["@iobroker/js-controller-adapter"]); | ||
if (adapterPath) { | ||
const adapterPaths = [ | ||
// Attempt 1: Resolve @iobroker/js-controller-adapter from here - JS-Controller 4.1+ | ||
(0, helpers_1.tryResolvePackage)(["@iobroker/js-controller-adapter"]), | ||
// Attempt 2: Resolve @iobroker/js-controller-adapter in JS-Controller dir - JS-Controller 4.1+ | ||
(0, helpers_1.tryResolvePackage)(["@iobroker/js-controller-adapter"], [path.join(exports.controllerDir, "node_modules")]), | ||
// Attempt 3: JS-Controller 4.1+ with adapter stub | ||
path.join(exports.controllerDir, "build/lib/adapter.js"), | ||
// Attempt 4: JS-Controller 5.1+ with adapter stub | ||
path.join(exports.controllerDir, "build/cjs/lib/adapter.js"), | ||
// Attempt 5: Legacy resolve - until JS-Controller 4.0 | ||
path.join(exports.controllerDir, "lib/adapter.js"), | ||
]; | ||
for (const adapterPath of adapterPaths) { | ||
if (!adapterPath) | ||
continue; | ||
try { | ||
const { Adapter } = require(adapterPath); | ||
const Adapter = require(adapterPath); | ||
if (Adapter) | ||
@@ -50,36 +62,2 @@ return Adapter; | ||
} | ||
// Attempt 2: Resolve @iobroker/js-controller-adapter in JS-Controller dir - JS-Controller 4.1+ | ||
adapterPath = (0, helpers_1.tryResolvePackage)(["@iobroker/js-controller-adapter"], [path.join(exports.controllerDir, "node_modules")]); | ||
if (adapterPath) { | ||
try { | ||
const { Adapter } = require(adapterPath); | ||
if (Adapter) | ||
return Adapter; | ||
} | ||
catch (_b) { | ||
// did not work, continue | ||
} | ||
} | ||
// Attempt 3: Legacy resolve - until JS-Controller 4.0 | ||
adapterPath = path.join(exports.controllerDir, "lib/adapter.js"); | ||
try { | ||
// This was a default export prior to the TS migration | ||
const Adapter = require(adapterPath); | ||
if (Adapter) | ||
return Adapter; | ||
} | ||
catch (_c) { | ||
// did not work, continue | ||
} | ||
// Attempt 4: JS-Controller 4.1+ with adapter stub | ||
adapterPath = path.join(exports.controllerDir, "build/lib/adapter.js"); | ||
try { | ||
// This was a default export prior to the TS migration | ||
const Adapter = require(adapterPath); | ||
if (Adapter) | ||
return Adapter; | ||
} | ||
catch (_d) { | ||
// did not work, continue | ||
} | ||
throw new Error("Cannot resolve adapter class"); | ||
@@ -86,0 +64,0 @@ return process.exit(10); |
{ | ||
"name": "@iobroker/adapter-core", | ||
"version": "3.0.4", | ||
"version": "3.0.5", | ||
"description": "Core module to be used in ioBroker adapters. Acts as the bridge to js-controller.", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -116,2 +116,6 @@ # Adapter-Core | ||
--> | ||
### 3.0.5 (2024-03-24) | ||
- (foxriver76) compatibility with next controller with new esm/cjs exports | ||
### 3.0.4 (2023-10-12) | ||
@@ -205,3 +209,3 @@ | ||
Copyright (c) 2018-2023 AlCalzone | ||
Copyright (c) 2018-2024 AlCalzone | ||
@@ -208,0 +212,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
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
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
227
8
33439
519