core: add resolve check before addon add

This commit is contained in:
undefined committed 2022-10-26 23:34:19 +08:00
1 parent 6a4aa14016
commit 3e918346ff
3 files changed
+21 -4

No files matched your search

+9 -1
View File
@@ -111,7 +111,15 @@ if (!argv.args[0] || argv.args[0] === 'cli') {
}
}
if (operation === 'add' && name) addons.push(name);
if (operation === 'add' && name) {
try {
require.resolve(`${name}/package.json`);
} catch (e) {
console.error(`Addon not found or not available: ${name}`);
return;
}
addons.push(name);
}
addons = Array.from(new Set(addons));
console.log('Current Addons: ', addons);
fs.writeFileSync(addonPath, JSON.stringify(addons, null, 2));