1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.findRepos = exports.getChangedFilesForRoots = void 0;
|
7 |
|
8 | function _throat() {
|
9 | const data = _interopRequireDefault(require('throat'));
|
10 |
|
11 | _throat = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | var _git = _interopRequireDefault(require('./git'));
|
19 |
|
20 | var _hg = _interopRequireDefault(require('./hg'));
|
21 |
|
22 | function _interopRequireDefault(obj) {
|
23 | return obj && obj.__esModule ? obj : {default: obj};
|
24 | }
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | function notEmpty(value) {
|
34 | return value != null;
|
35 | }
|
36 |
|
37 |
|
38 | const mutex = (0, _throat().default)(5);
|
39 |
|
40 | const findGitRoot = dir => mutex(() => _git.default.getRoot(dir));
|
41 |
|
42 | const findHgRoot = dir => mutex(() => _hg.default.getRoot(dir));
|
43 |
|
44 | const getChangedFilesForRoots = async (roots, options) => {
|
45 | const repos = await findRepos(roots);
|
46 | const changedFilesOptions = {
|
47 | includePaths: roots,
|
48 | ...options
|
49 | };
|
50 | const gitPromises = Array.from(repos.git).map(repo =>
|
51 | _git.default.findChangedFiles(repo, changedFilesOptions)
|
52 | );
|
53 | const hgPromises = Array.from(repos.hg).map(repo =>
|
54 | _hg.default.findChangedFiles(repo, changedFilesOptions)
|
55 | );
|
56 | const changedFiles = (
|
57 | await Promise.all(gitPromises.concat(hgPromises))
|
58 | ).reduce((allFiles, changedFilesInTheRepo) => {
|
59 | for (const file of changedFilesInTheRepo) {
|
60 | allFiles.add(file);
|
61 | }
|
62 |
|
63 | return allFiles;
|
64 | }, new Set());
|
65 | return {
|
66 | changedFiles,
|
67 | repos
|
68 | };
|
69 | };
|
70 |
|
71 | exports.getChangedFilesForRoots = getChangedFilesForRoots;
|
72 |
|
73 | const findRepos = async roots => {
|
74 | const gitRepos = await Promise.all(
|
75 | roots.reduce((promises, root) => promises.concat(findGitRoot(root)), [])
|
76 | );
|
77 | const hgRepos = await Promise.all(
|
78 | roots.reduce((promises, root) => promises.concat(findHgRoot(root)), [])
|
79 | );
|
80 | return {
|
81 | git: new Set(gitRepos.filter(notEmpty)),
|
82 | hg: new Set(hgRepos.filter(notEmpty))
|
83 | };
|
84 | };
|
85 |
|
86 | exports.findRepos = findRepos;
|