-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathinstall.js
More file actions
74 lines (61 loc) · 2.13 KB
/
install.js
File metadata and controls
74 lines (61 loc) · 2.13 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'use strict';
const path = require('path');
const stripAnsi = require('strip-ansi');
const createOptions = require('../create-options');
const spawn = require('../spawn');
const timeout = require('../timeout');
function install(packageManager, context, next) {
const options =
createOptions(
path.join(context.path, context.module.name), context);
let args = ['install'];
context.emit('data', 'info', context.module.name + ' ' + packageManager +
':',
packageManager + ' install started');
context.emit('data', 'verbose', context.module.name + ' ' + packageManager +
':',
'Using temp directory: "' + options.env['npm_config_tmp'] + '"');
if (context.module.install) {
args = args.concat(context.module.install);
}
const packageManagerBin = packageManager === 'npm'
? context.npmPath
: context.yarnPath;
const binDirectory = path.dirname(packageManagerBin);
options.env.PATH = binDirectory + ':' + process.env.PATH;
const proc = spawn(packageManagerBin, args, options);
const finish = timeout(context, proc, next, 'Install');
proc.stderr.on('data', function (chunk) {
context.testError.append(chunk);
if (context.module.stripAnsi) {
chunk = stripAnsi(chunk.toString());
chunk = chunk.replace(/\r/g, '\n');
}
context.emit('data', 'warn', context.module.name +
' ' + packageManager + '-install:',
chunk.toString());
});
proc.stdout.on('data', function (chunk) {
context.testOutput.append(chunk);
if (context.module.stripAnsi) {
chunk = stripAnsi(chunk.toString());
chunk = chunk.replace(/\r/g, '\n');
}
context.emit('data', 'verbose', context.module.name +
' ' + packageManager + '-install:',
chunk.toString());
});
proc.on('error', function() {
return finish(new Error('Install Failed'));
});
proc.on('close', function(code) {
if (code > 0) {
return finish(Error('Install Failed'));
}
context.emit('data', 'info', context.module.name + ' ' +
packageManager + ':',
packageManager + ' install successfully completed');
return finish(null, context);
});
}
module.exports = install;