-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall-yarn.js
44 lines (38 loc) · 1.32 KB
/
install-yarn.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
// do it inline in sync way
// to make it work in non-npm environment
var yarnBin
, executioner
, path = require('path')
, node = process.argv[0]
;
if (process.env['npm_execpath'] && process.env['npm_execpath'].match(/[\/\\]yarn(-v\d+\.\d+\.\d+)?[\/\\]bin[\/\\]yarn\.js$/)) {
var execPath = process.env['npm_execpath'];
var expectedPath = path.join('bin', 'yarn.js');
if (execPath.slice(-1 * expectedPath.length) === expectedPath) {
yarnBin = path.resolve(execPath, '..', '..', 'lib', 'cli');
}
}
// if no yarn module found, don't expose any function
// to allow upstream modules find alternatives
module.exports = null;
if (yarnBin) {
executioner = require('executioner');
module.exports = function(packages, extra, done) {
var options = {
node : node,
yarn : yarnBin,
// escape package names@versions
packages: packages.map((pkg) => '"' + pkg + '"').join(' ')
};
executioner('"${node}" "${yarn}" add --peer --no-lockfile ${packages}', options, function(error, result) {
if (error) {
console.error('Unable to install peerDependencies', error);
process.exit(1);
return;
}
done(result);
});
// Looks like yarn shows last line from the output of sub-scripts
console.log('Installing peerDependencies as devDependencies...');
};
}