/
npm.js
47 lines (35 loc) · 1.18 KB
/
npm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"use strict";
var util = require("util");
var c9util = require("../cloud9.core/util");
var ShellRunner = require("../cloud9.run.shell/shell").Runner;
/**
* Run node scripts with restricted user rights
*/
var exports = module.exports = function setup(options, imports, register) {
var pm = imports["process-manager"];
imports.sandbox.getUnixId(function(err, unixId) {
if (err) return register(err);
pm.addRunner("npm", exports.factory(unixId, imports.sandbox));
register(null, {
"run-npm": {}
});
});
};
exports.factory = function(uid, sandbox) {
return function(args, eventEmitter, eventName, callback) {
var options = {};
c9util.extend(options, args);
options.uid = uid;
options.eventEmitter = eventEmitter;
options.eventName = eventName;
options.args = args.args;
options.command = "npm";
options.sandbox = sandbox;
return new Runner(options, callback);
};
};
var Runner = exports.Runner = function(options, callback) {
ShellRunner.call(this, options, callback);
};
util.inherits(Runner, ShellRunner);
Runner.prototype.name = "npm";