index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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) {
  19. return obj && obj.__esModule ? obj : {default: obj};
  20. }
  21. function _asyncToGenerator(fn) {
  22. return function() {
  23. var gen = fn.apply(this, arguments);
  24. return new Promise(function(resolve, reject) {
  25. function step(key, arg) {
  26. try {
  27. var info = gen[key](arg);
  28. var value = info.value;
  29. } catch (error) {
  30. reject(error);
  31. return;
  32. }
  33. if (info.done) {
  34. resolve(value);
  35. } else {
  36. return Promise.resolve(value).then(
  37. function(value) {
  38. step('next', value);
  39. },
  40. function(err) {
  41. step('throw', err);
  42. }
  43. );
  44. }
  45. }
  46. return step('next');
  47. });
  48. };
  49. }
  50. /**
  51. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  52. *
  53. * This source code is licensed under the MIT license found in the
  54. * LICENSE file in the root directory of this source tree.
  55. *
  56. *
  57. */
  58. // This is an arbitrary number. The main goal is to prevent projects with
  59. // many roots (50+) from spawning too many processes at once.
  60. const mutex = (0, (_throat || _load_throat()).default)(5);
  61. const findGitRoot = dir =>
  62. mutex(() => (_git || _load_git()).default.getRoot(dir));
  63. const findHgRoot = dir => mutex(() => (_hg || _load_hg()).default.getRoot(dir));
  64. const getChangedFilesForRoots = (exports.getChangedFilesForRoots = (() => {
  65. var _ref = _asyncToGenerator(function*(roots, options) {
  66. const repos = yield findRepos(roots);
  67. const changedFilesOptions = Object.assign(
  68. {},
  69. {includePaths: roots},
  70. options
  71. );
  72. const gitPromises = Array.from(repos.git).map(function(repo) {
  73. return (_git || _load_git()).default.findChangedFiles(
  74. repo,
  75. changedFilesOptions
  76. );
  77. });
  78. const hgPromises = Array.from(repos.hg).map(function(repo) {
  79. return (_hg || _load_hg()).default.findChangedFiles(
  80. repo,
  81. changedFilesOptions
  82. );
  83. });
  84. const changedFiles = (yield Promise.all(
  85. gitPromises.concat(hgPromises)
  86. )).reduce(function(allFiles, changedFilesInTheRepo) {
  87. for (const file of changedFilesInTheRepo) {
  88. allFiles.add(file);
  89. }
  90. return allFiles;
  91. }, new Set());
  92. return {changedFiles: changedFiles, repos: repos};
  93. });
  94. return function getChangedFilesForRoots(_x, _x2) {
  95. return _ref.apply(this, arguments);
  96. };
  97. })());
  98. const findRepos = (exports.findRepos = (() => {
  99. var _ref2 = _asyncToGenerator(function*(roots) {
  100. const gitRepos = yield Promise.all(
  101. roots.reduce(function(promises, root) {
  102. return promises.concat(findGitRoot(root));
  103. }, [])
  104. );
  105. const hgRepos = yield Promise.all(
  106. roots.reduce(function(promises, root) {
  107. return promises.concat(findHgRoot(root));
  108. }, [])
  109. );
  110. return {
  111. git: new Set(gitRepos.filter(Boolean)),
  112. hg: new Set(hgRepos.filter(Boolean))
  113. };
  114. });
  115. return function findRepos(_x3) {
  116. return _ref2.apply(this, arguments);
  117. };
  118. })());