Skip to content

Commit

Permalink
Merge pull request #415 from mStirner/dev
Browse files Browse the repository at this point in the history
Fix issues
  • Loading branch information
mStirner authored Jan 16, 2024
2 parents 0dedbc7 + fbdc4c4 commit 5209ec9
Showing 1 changed file with 23 additions and 31 deletions.
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

0 comments on commit 5209ec9

Please sign in to comment.