admin/plugins: explicitly call npm with a plugin version

pull/5812/merge^2
webzwo0i 2023-07-08 16:04:55 +02:00
parent 3c9bcf4c4b
commit b858f5dd62
3 changed files with 18 additions and 12 deletions

View File

@ -62,7 +62,7 @@ exports.socketio = (hookName, args, cb) => {
const currentVersion = pluginDefs.plugins[plugin].package.version; const currentVersion = pluginDefs.plugins[plugin].package.version;
return semver.gt(latestVersion, currentVersion); return semver.gt(latestVersion, currentVersion);
}); }).map((plugin) => ({name: plugin, version: results[plugin].version}));
socket.emit('results:updatable', {updatable}); socket.emit('results:updatable', {updatable});
} catch (err) { } catch (err) {
@ -98,8 +98,8 @@ exports.socketio = (hookName, args, cb) => {
} }
}); });
socket.on('install', (pluginName) => { socket.on('install', (pluginName, version) => {
installer.install(pluginName, (err) => { installer.install(pluginName, version, (err) => {
if (err) console.warn(err.stack || err.toString()); if (err) console.warn(err.stack || err.toString());
socket.emit('finished:install', { socket.emit('finished:install', {

View File

@ -123,13 +123,17 @@ $(document).ready(() => {
$('.do-install, .do-update').unbind('click').click(function (e) { $('.do-install, .do-update').unbind('click').click(function (e) {
const $row = $(e.target).closest('tr'); const $row = $(e.target).closest('tr');
const plugin = $row.data('plugin'); const plugin = $row.data('plugin');
const update = $row.find('input.do-update');
// TODO dont store it here in DOM
// version after update or after installing a new package
const version = update.length !== 0 ? update.attr('version') : $row.find('.version').text();
if ($(this).hasClass('do-install')) { if ($(this).hasClass('do-install')) {
$row.remove().appendTo('#installed-plugins'); $row.remove().appendTo('#installed-plugins');
installed.progress.show(plugin, 'Installing'); installed.progress.show(plugin, 'Installing');
} else { } else {
installed.progress.show(plugin, 'Updating'); installed.progress.show(plugin, 'Updating');
} }
socket.emit('install', plugin); socket.emit('install', plugin, version);
installed.messages.hide('nothing-installed'); installed.messages.hide('nothing-installed');
}); });
@ -217,11 +221,13 @@ $(document).ready(() => {
}); });
socket.on('results:updatable', (data) => { socket.on('results:updatable', (data) => {
data.updatable.forEach((pluginName) => { data.updatable.forEach((plugin) => {
const actions = $(`#installed-plugins > tr.${pluginName} .actions`); const {name, version} = plugin;
const actions = $(`#installed-plugins > tr.${name} .actions`);
actions.find('.do-update').remove(); actions.find('.do-update').remove();
// TODO dont store version here in DOM
actions.append( actions.append(
$('<input>').addClass('do-update').attr('type', 'button').attr('value', 'Update')); $('<input>').addClass('do-update').attr('type', 'button').attr('version', version).attr('value', 'Update'));
}); });
updateHandlers(); updateHandlers();
}); });

View File

@ -43,17 +43,17 @@ exports.uninstall = async (pluginName, cb = null) => {
cb(null); cb(null);
}; };
exports.install = async (pluginName, cb = null) => { exports.install = async (pluginName, version, cb = null) => {
cb = wrapTaskCb(cb); cb = wrapTaskCb(cb);
logger.info(`Installing plugin ${pluginName}...`); logger.info(`Installing plugin ${pluginName}@${version}...`);
try { try {
await runCmd(['npm', 'install', pluginName]); await runCmd(['npm', 'install', `${pluginName}@${version}`]);
} catch (err) { } catch (err) {
logger.error(`Failed to install plugin ${pluginName}`); logger.error(`Failed to install plugin ${pluginName}@${version}`);
cb(err || new Error(err)); cb(err || new Error(err));
throw err; throw err;
} }
logger.info(`Successfully installed plugin ${pluginName}`); logger.info(`Successfully installed plugin ${pluginName}@${version}`);
await hooks.aCallAll('pluginInstall', {pluginName}); await hooks.aCallAll('pluginInstall', {pluginName});
await plugins.update(); await plugins.update();
cb(null); cb(null);