mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-29 11:49:13 -04: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
|
@ -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…
Add table
Add a link
Reference in a new issue