Skip to content

Commit a9f30d5

Browse files
committed
Fix propagation of env when building addons (for using extra in desktop app)
1 parent c32ac40 commit a9f30d5

2 files changed

Lines changed: 13 additions & 30 deletions

File tree

core/cb.addons/addon.js

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,6 @@ var pkg = require("../../package.json");
1010

1111
var utils = require("../utils");
1212

13-
var exec = function(command, options) {
14-
15-
var deferred = Q.defer();
16-
var childProcess;
17-
18-
var args = Array.prototype.slice.call(arguments, 0);
19-
args.push(function(err, stdout, stderr) {
20-
if (err) {
21-
err.message += command + ' (exited with error code ' + err.code + ')';
22-
err.stdout = stdout;
23-
err.stderr = stderr;
24-
deferred.reject(err);
25-
}
26-
else {
27-
deferred.resolve({
28-
childProcess: childProcess,
29-
stdout: stdout,
30-
stderr: stderr
31-
});
32-
}
33-
});
34-
35-
childProcess = child_process.exec.apply(child_process, args);
36-
37-
return deferred.promise;
38-
}
3913

4014
var Addon = function(_rootPath, options) {
4115
this.root = _rootPath;
@@ -167,7 +141,9 @@ var Addon = function(_rootPath, options) {
167141
return Q.nfcall(fs.unlink, output).fail(function() {
168142
return Q();
169143
}).then(function() {
170-
return exec(command)
144+
return utils.exec(command, {
145+
env: process.env
146+
})
171147
}).then(function() {
172148
logger.log("Finished", that.infos.name, "optimization");
173149
return Q(that);
@@ -188,7 +164,10 @@ var Addon = function(_rootPath, options) {
188164
}
189165
}
190166
logger.log("Install dependencies for", this.root);
191-
return exec("cd "+this.root+" && npm install .").then(function() {
167+
return utils.exec("npm install .", {
168+
cwd: this.root,
169+
env: process.env
170+
}).then(function() {
192171
return Q(that);
193172
});
194173
};

core/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ var cp = require('child_process');
66

77

88
// Generate callbacks for exec functions
9-
function _execHandler(deffered) {
9+
function _execHandler(command, deffered) {
1010
return function(error, stdout, stderr) {
1111
if(error) {
12+
error.message += command + ' (exited with error code ' + error.code + ')';
13+
error.stdout = stdout;
14+
error.stderr = stderr;
15+
1216
return deffered.reject(error);
1317
}
1418
return deffered.resolve({
@@ -23,7 +27,7 @@ function simpleExecBuilder(execFunction) {
2327
return function(command) {
2428
var deffered = Q.defer();
2529

26-
var args = _.toArray(arguments).concat(_execHandler(deffered));
30+
var args = _.toArray(arguments).concat(_execHandler(command, deffered));
2731

2832
// Call exec function
2933
execFunction.apply(null, args);

0 commit comments

Comments
 (0)