forked from microsoft/fluentui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetAffectedPackages.js
31 lines (26 loc) · 1.1 KB
/
getAffectedPackages.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
const { spawnSync } = require('child_process');
const findGitRoot = require('./findGitRoot');
/**
* Indicator of what packages have been affected by changes
* e.g. need to trigger a build
*
* @param {string} since - Commit to compare against
* @returns {Set<string>} - Set of packages that are affected by in the current branch
*/
function getAffectedPackages(since = 'origin/master') {
const gitRoot = findGitRoot();
const res = spawnSync('yarn', ['lage', 'info', '--since', since], { cwd: gitRoot, shell: true });
if (res.status !== 0) {
console.error(res.stderr);
throw new Error(`yarn lage info --since ${since} failed with status ${res.status}`);
}
// Lage uses npmlog which defaults all output to stderr
const output = res.stderr.toString().replace(/\b(info)\b/g, '');
// Lage uses npmlog which defaults all output to stderr
const info = JSON.parse(output);
if (!info.scope || !Array.isArray(info.scope)) {
throw new Error(`command \`yarn lage info ${since}\` failed to return the scope`);
}
return new Set(info.scope);
}
exports.getAffectedPackages = getAffectedPackages;