From e3c14e2ac1741d442569286287654cf9c9bd2bd8 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 19 Mar 2019 09:48:19 +1300 Subject: [PATCH 1/6] remove unused file --- run-standalone.js | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100755 run-standalone.js diff --git a/run-standalone.js b/run-standalone.js deleted file mode 100755 index e63f547..0000000 --- a/run-standalone.js +++ /dev/null @@ -1,31 +0,0 @@ -#! /usr/bin/env node - -var path = require('path') -var fs = require('fs') - -if (process.argv.length !== 3) { - console.error(`usage: ${process.argv[1]} pluginPath`) - process.exit(1) -} - -const pluginPath = process.argv[2] -try { - fs.statSync(pluginPath) -} catch (e) { - console.error('could not locate specified pluginPath') - console.warn('exception:', e) - process.exit(1) -} - -var {child, manifest} = require('./run')(pluginPath) -var api = require('muxrpc/api')({}, manifest, child) - -api.callback('bob', function (err, value) { - if (err) throw err - console.error('from cb', value) - api.hello('DARRYL', function (err, value) { - if (err) throw err - console.error('from hello', value) - process.exit() - }) -}) From 4873929c793808a5a67b119415e4e115f89214c8 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 19 Mar 2019 09:53:25 +1300 Subject: [PATCH 2/6] if package.json has ssb.outOfProcess run as a separate process, otherwise require it directly --- index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a51e6b7..cf62bb1 100644 --- a/index.js +++ b/index.js @@ -192,7 +192,14 @@ module.exports.loadUserPlugins = function (createSsbServer, config) { if (createSsbServer.plugins.some(plug => plug.name === name)) throw new Error('already loaded plugin named:'+name) - var plugin = require(path.join(nodeModulesPath, module_name)) + var pkg = require(path.join(nodeModulesPath, module_name, 'package.json')) + var plugin + if(pkg.ssb && pkg.ssb.outOfProcess) { + plugin = load(path.join(nodeModulesPath, module_name), name) + } else { + plugin = require(path.join(nodeModulesPath, module_name)) + } + if(!plugin || plugin.name !== name) throw new Error('plugin at:'+module_name+' expected name:'+name+' but had:'+(plugin||{}).name) assertSsbServerPlugin(plugin) @@ -225,3 +232,4 @@ function validatePluginName (name) { return true } + From 4df6edc05e690c15c839d59bc734bfd38d744e32 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 2 Apr 2019 15:25:00 +1300 Subject: [PATCH 3/6] nename to ssb-plugins --- README.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 38b4746..a615c6b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ssb-plugins2 +# ssb-plugins proof of concept muxrpc plugins as separate process diff --git a/package.json b/package.json index 5c5f302..56be2da 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "ssb-plugins2", + "name": "ssb-plugins", "description": "", "version": "0.0.0", "homepage": "https://github.com/dominictarr/ssb-plugins2", From d9a39a377597d960f161e4e3f4bc2571f3755bcd Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 9 Apr 2019 13:26:24 +1200 Subject: [PATCH 4/6] nimraf isn't used --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 56be2da..fdf0878 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,6 @@ "muxrpc": "^6.4.0", "muxrpc-validation": "^3.0.0", "mv": "^2.1.1", - "nimraf": "^1.1.0", "osenv": "^0.1.5", "pull-cat": "^1.1.11", "pull-many": "^1.0.8", @@ -35,3 +34,4 @@ "author": "Dominic Tarr (http://dominictarr.com)", "license": "MIT" } + From 58dbd78d4fa54863dc8756fc70f4985b7f5b7cf0 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Sat, 11 May 2019 12:46:10 +1200 Subject: [PATCH 5/6] muxrpc@3.1 style help --- help.js | 41 +++++++++++++++++++++++++++++++++++++++++ index.js | 13 ++++++++++--- 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 help.js diff --git a/help.js b/help.js new file mode 100644 index 0000000..3aef82e --- /dev/null +++ b/help.js @@ -0,0 +1,41 @@ + +var Module = { + single: 'module', + args: { + module: { + type: 'string', + description: 'a module@version-range string' + } + } +} + +function desc(d, type) { + return Object.assign({ + description: d, + type: type + }, Module) +} + +module.exports = { + description: 'manage ssb plugins', + commands: { + install: desc('install a plugin', 'source'), + uninstall: desc('remove a plugin', 'source'), + enable: desc('enable an installed plugin, must restart ssb-server afterwards', 'async'), + disable: desc('disable an installed plugin (without uninstalling), must restart ssb-server afterwards', 'async'), + } +} + + + + + + + + + + + + + + diff --git a/index.js b/index.js index cf62bb1..c05732f 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,14 @@ var valid = require('muxrpc-validation')({}) module.exports = { name: 'plugins', version: '1.0.0', - manifest: mdm.manifest(fs.readFileSync(path.join(__dirname, 'api.md'), 'utf8')), + manifest: { + install: 'source', + uninstall: 'source', + enable: 'async', + disable: 'async', + help: 'sync' + } +//mdm.manifest(fs.readFileSync(path.join(__dirname, 'api.md'), 'utf8')), permissions: { master: {allow: ['install', 'uninstall', 'enable', 'disable']} }, @@ -174,7 +181,8 @@ module.exports = { return p }, 'string', 'object?'), enable: valid.async(configPluginEnabled(true), 'string'), - disable: valid.async(configPluginEnabled(false), 'string') + disable: valid.async(configPluginEnabled(false), 'string'), + help: function () { return require('./help') } } } } @@ -232,4 +240,3 @@ function validatePluginName (name) { return true } - From 4a04c3338acaacda57394c5b315122e864e8bbee Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Sat, 11 May 2019 12:48:23 +1200 Subject: [PATCH 6/6] accept arg as an object with single {module: ...} property --- index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/index.js b/index.js index c05732f..94fa891 100644 --- a/index.js +++ b/index.js @@ -15,6 +15,10 @@ var mdm = require('mdmanifest') var explain = require('explain-error') var valid = require('muxrpc-validation')({}) +function isObject(o) { + return o && 'object' === typeof o +} + module.exports = { name: 'plugins', version: '1.0.0', @@ -37,6 +41,7 @@ module.exports = { // helper to enable/disable plugins function configPluginEnabled (b) { return function (pluginName, cb) { + if(isObject(pluginName)) pluginName = pluginName.module checkInstalled(pluginName, function (err) { if (err) return cb(err) @@ -65,6 +70,7 @@ module.exports = { // write the plugin config to ~/.ssb/config function writePluginConfig (pluginName, value) { + var cfgPath = path.join(config.path, 'config') // load ~/.ssb/config let existingConfig @@ -93,6 +99,7 @@ module.exports = { return { install: valid.source(function (pluginName, opts) { + if(isObject(pluginName)) pluginName = pluginName.module var p = pushable() var dryRun = opts && opts['dry-run'] var from = opts && opts.from @@ -164,6 +171,7 @@ module.exports = { ]) }, 'string', 'object?'), uninstall: valid.source(function (pluginName, opts) { + if(isObject(pluginName)) pluginName = pluginName.module var p = pushable() if (!pluginName || typeof pluginName !== 'string') return pull.error(new Error('plugin name is required')) @@ -240,3 +248,5 @@ function validatePluginName (name) { return true } + +