mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
Run npm in a separate worker process
This commit is contained in:
parent
44f817da01
commit
b8870a7586
4 changed files with 47 additions and 3 deletions
|
@ -27,7 +27,7 @@
|
|||
"nodemailer" : "0.3.x",
|
||||
"jsdom-nocontextifiy" : "0.2.10",
|
||||
"async-stacktrace" : "0.0.2",
|
||||
"npm" : "1.2.x",
|
||||
"npm" : "*",
|
||||
"ejs" : "0.6.1",
|
||||
"graceful-fs" : "1.1.5",
|
||||
"slide" : "1.1.3",
|
||||
|
@ -40,7 +40,8 @@
|
|||
"swagger-node-express" : "1.2.3",
|
||||
"channels" : "0.0.x",
|
||||
"jsonminify" : "0.2.2",
|
||||
"measured" : "0.1.3"
|
||||
"measured" : "0.1.3",
|
||||
"rpc-stream" : "1.0.x"
|
||||
},
|
||||
"bin": { "etherpad-lite": "./node/server.js" },
|
||||
"devDependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
|
||||
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
|
||||
var npm = require("npm");
|
||||
var npm = require("./npm-master");
|
||||
|
||||
var npmIsLoaded = false;
|
||||
var withNpm = function (npmfn) {
|
||||
|
|
19
src/static/js/pluginfw/npm-master.js
Normal file
19
src/static/js/pluginfw/npm-master.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
/**
|
||||
* This module exposes the same methods as installer.js, but runs them in a separate child process
|
||||
*/
|
||||
var child_process = require('child_process')
|
||||
, rpc = require('rpc-stream')
|
||||
|
||||
var worker = child_process.fork(__dirname+'/npm-worker', {silent:true})
|
||||
|
||||
var client = rpc()
|
||||
|
||||
worker.stdout.pipe(client).pipe(worker.stdin)
|
||||
|
||||
worker.stderr.pipe(process.stdout)
|
||||
|
||||
module.exports = {
|
||||
commands: client.wrap(['install', 'uninstall', 'search'])
|
||||
, load: function(opts, cb) {cb()}
|
||||
, on: function(){}
|
||||
}
|
24
src/static/js/pluginfw/npm-worker.js
Normal file
24
src/static/js/pluginfw/npm-worker.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* This is a worker that should be run using child_process.fork (see installer-master.js for reference)
|
||||
* Stdin and stdout are connected to an rpc server exposing the methods of installer.js
|
||||
*/
|
||||
var RPC = require('rpc-stream')
|
||||
, npm = require('npm')
|
||||
|
||||
npm.load({}, function (er) {
|
||||
if(er) throw er
|
||||
})
|
||||
console.log = function() {process.stderr.write(Array.prototype.slice(arguments).join('')+'\n')}
|
||||
|
||||
var server = RPC({
|
||||
search: function(args, cb) {
|
||||
npm.commands.search.apply(npm, Array.prototype.concat(args, [cb]))
|
||||
}
|
||||
, install: function(args, cb) {
|
||||
npm.commands.install.apply(npm, Array.prototype.concat(args, [cb]))
|
||||
}
|
||||
, uninstall: function(args, cb) {
|
||||
npm.commands.uninstall.apply(npm, Array.prototype.concat(args, [cb]))
|
||||
}
|
||||
})
|
||||
process.stdin.pipe(server).pipe(process.stdout)
|
Loading…
Reference in a new issue