Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues #415

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 23 additions & 31 deletions components/plugins/class.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ module.exports = class Plugin extends Item {
//Object.assign(this, obj);
//this._id = String(obj._id);

let json = {};

Object.defineProperty(this, "logger", {
value: logger.create(`plugins/${this.uuid}`),
configurable: false,
Expand All @@ -52,31 +50,6 @@ module.exports = class Plugin extends Item {
writable: true
});

try {

let file = path.resolve(process.cwd(), "plugins", this.uuid, "package.json");
let content = fs.readFileSync(file);
json = JSON.parse(content);

} catch (err) {
if (err.code === "ENOENT") {

this.logger.warn(err, `package.json for plugin "${this.name}" not found.`);

} else {

this.logger.warn(err);

}
}

Object.defineProperty(this, "package", {
value: json,
configurable: false,
enumerable: false,
writable: false,
});

}

static schema() {
Expand Down Expand Up @@ -111,13 +84,33 @@ module.exports = class Plugin extends Item {
// feedback
logger.debug(`Start plugin "${this.name}"...`);

let json = {};
let plugin = path.resolve(process.cwd(), "plugins", this.uuid);
let compatible = semver.satisfies(pkg.version, this.package?.backend);
let file = path.resolve(plugin, "package.json");

// 1) check if plugin is compatible
try {

let content = fs.readFileSync(file);
json = JSON.parse(content);

if (!semver.satisfies(pkg.version, json?.backend)) {
this.logger.warn(`Plugin "${this.name}" is incompatible. It may work not properly or break something!`);
}

} catch (err) {

this.logger.warn(err, `Could not check plugin compatibility for plugin "${this.name}"`);

if (err.code === "ENOENT") {
this.logger.warn(`package.json for plugin "${this.name}" not found, try to start it anyway...`);
} else {
this.logger.error(err);
}

if (!compatible) {
logger.warn(`Starting incomptaible plugin "${this.name}". It may work not properly or break something!`);
}

// 2) start plugin
if (fs.existsSync(plugin)) {

let init = (dependencies, cb) => {
Expand Down Expand Up @@ -160,7 +153,6 @@ module.exports = class Plugin extends Item {
};

init[Symbol.for("uuid")] = this.uuid;
init[Symbol.for("compatible")] = compatible;

try {

Expand Down
Loading