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: handle invalid manifest.json files in checkIncompatibleAddOns function #495

Merged
merged 4 commits into from
Nov 17, 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
44 changes: 24 additions & 20 deletions src/renderer/utils/IncompatibleAddOnsCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,34 @@ export class IncompatibleAddOnsCheck {
const dirEntries = fs.readdirSync(filePath);

if (dirEntries.includes(manifestFileName)) {
const manifest = JSON.parse(fs.readFileSync(path.join(filePath, manifestFileName), 'utf8'));
try {
const manifest = JSON.parse(fs.readFileSync(path.join(filePath, manifestFileName), 'utf8'));

for (const item of addon.incompatibleAddons) {
// This checks the configuration item properties (if set) against the manifest.json file
// entry property values. If all properties match, the add-on is considered incompatible.
// packageVersion syntax follows: https://www.npmjs.com/package/semver
// Future improvement would be to allow for regular expressions in the configuration item.
const titleMatches = !item.title || manifest.title === item.title;
const creatorMatches = !item.creator || manifest.creator === item.creator;
const packageVersionTargeted =
!item.packageVersion || semverSatisfies(manifest.package_version, item.packageVersion);
for (const item of addon.incompatibleAddons) {
// This checks the configuration item properties (if set) against the manifest.json file
// entry property values. If all properties match, the add-on is considered incompatible.
// packageVersion syntax follows: https://www.npmjs.com/package/semver
// Future improvement would be to allow for regular expressions in the configuration item.
const titleMatches = !item.title || manifest.title === item.title;
const creatorMatches = !item.creator || manifest.creator === item.creator;
const packageVersionTargeted =
!item.packageVersion || semverSatisfies(manifest.package_version, item.packageVersion);

if (titleMatches && creatorMatches && packageVersionTargeted) {
// Also write this to the log as this info might be useful for support.
console.log(`Incompatible Add-On found: ${manifest.title}: ${item.description}`);
if (titleMatches && creatorMatches && packageVersionTargeted) {
// Also write this to the log as this info might be useful for support.
console.log(`Incompatible Add-On found: ${manifest.title}: ${item.description}`);

incompatibleAddons.push({
title: item.title,
creator: item.creator,
packageVersion: item.packageVersion,
folder: entry,
description: item.description,
});
incompatibleAddons.push({
title: item.title,
creator: item.creator,
packageVersion: item.packageVersion,
folder: entry,
description: item.description,
});
}
}
} catch (e) {
console.warn(`Failed to read or parse manifest.json in ${filePath}:`, e.message);
}
}
}
Expand Down
Loading