index.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.findRepos = exports.getChangedFilesForRoots = undefined;
  6. var _git;
  7. function _load_git() {
  8. return _git = _interopRequireDefault(require('./git'));
  9. }
  10. var _hg;
  11. function _load_hg() {
  12. return _hg = _interopRequireDefault(require('./hg'));
  13. }
  14. var _throat;
  15. function _load_throat() {
  16. return _throat = _interopRequireDefault(require('throat'));
  17. }
  18. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  19. function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } /**
  20. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  21. *
  22. * This source code is licensed under the MIT license found in the
  23. * LICENSE file in the root directory of this source tree.
  24. *
  25. *
  26. */
  27. // This is an arbitrary number. The main goal is to prevent projects with
  28. // many roots (50+) from spawning too many processes at once.
  29. const mutex = (0, (_throat || _load_throat()).default)(5);
  30. const findGitRoot = dir => mutex(() => (_git || _load_git()).default.getRoot(dir));
  31. const findHgRoot = dir => mutex(() => (_hg || _load_hg()).default.getRoot(dir));
  32. const getChangedFilesForRoots = exports.getChangedFilesForRoots = (() => {
  33. var _ref = _asyncToGenerator(function* (roots, options) {
  34. const repos = yield findRepos(roots);
  35. const gitPromises = Array.from(repos.git).map(function (repo) {
  36. return (_git || _load_git()).default.findChangedFiles(repo, options);
  37. });
  38. const hgPromises = Array.from(repos.hg).map(function (repo) {
  39. return (_hg || _load_hg()).default.findChangedFiles(repo, options);
  40. });
  41. const changedFiles = (yield Promise.all(gitPromises.concat(hgPromises))).reduce(function (allFiles, changedFilesInTheRepo) {
  42. for (const file of changedFilesInTheRepo) {
  43. allFiles.add(file);
  44. }
  45. return allFiles;
  46. }, new Set());
  47. return { changedFiles, repos };
  48. });
  49. return function getChangedFilesForRoots(_x, _x2) {
  50. return _ref.apply(this, arguments);
  51. };
  52. })();
  53. const findRepos = exports.findRepos = (() => {
  54. var _ref2 = _asyncToGenerator(function* (roots) {
  55. const gitRepos = yield Promise.all(roots.reduce(function (promises, root) {
  56. return promises.concat(findGitRoot(root));
  57. }, []));
  58. const hgRepos = yield Promise.all(roots.reduce(function (promises, root) {
  59. return promises.concat(findHgRoot(root));
  60. }, []));
  61. return {
  62. git: new Set(gitRepos.filter(Boolean)),
  63. hg: new Set(hgRepos.filter(Boolean))
  64. };
  65. });
  66. return function findRepos(_x3) {
  67. return _ref2.apply(this, arguments);
  68. };
  69. })();