/
install-yarn.js
51 lines (42 loc) · 1.45 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
45
46
47
48
49
50
51
// do it inline in sync way
// to make it work in non-npm environment
var yarnBin
, executioner
, path = require('path')
, node = process.argv[0]
;
const matched = `${path.sep}bin${path.sep}yarn.js`
if (process.env['npm_execpath'] && process.env['npm_execpath'].includes(matched)) {
yarnBin = path.resolve(process.env['npm_execpath']);
}
// 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, config, done) {
var ignoreWorkspaceRootCheck = '';
var originalArgv;
// adjust for workspace support
if (config.workspaces) {
ignoreWorkspaceRootCheck = '--ignore-workspace-root-check';
}
var options = {
node : node,
yarn : yarnBin,
// escape package names@versions
packages: packages.map((pkg) => '"' + pkg + '"').join(' '),
ignoreWorkspaceRootCheck: ignoreWorkspaceRootCheck
};
executioner('"${node}" "${yarn}" add ${ignoreWorkspaceRootCheck} --peer --pure-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 ' + packages.length + ' peerDependencies...');
};
}