haste_fs.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. var _path;
  6. function _load_path() {
  7. return (_path = _interopRequireDefault(require('path')));
  8. }
  9. var _micromatch;
  10. function _load_micromatch() {
  11. return (_micromatch = _interopRequireDefault(require('micromatch')));
  12. }
  13. var _constants;
  14. function _load_constants() {
  15. return (_constants = _interopRequireDefault(require('./constants')));
  16. }
  17. function _interopRequireDefault(obj) {
  18. return obj && obj.__esModule ? obj : {default: obj};
  19. }
  20. class HasteFS {
  21. constructor(files) {
  22. this._files = files;
  23. }
  24. getModuleName(file) {
  25. return (
  26. (this._files[file] &&
  27. this._files[file][(_constants || _load_constants()).default.ID]) ||
  28. null
  29. );
  30. }
  31. getDependencies(file) {
  32. return (
  33. (this._files[file] &&
  34. this._files[file][
  35. (_constants || _load_constants()).default.DEPENDENCIES
  36. ]) ||
  37. null
  38. );
  39. }
  40. getSha1(file) {
  41. return (
  42. (this._files[file] &&
  43. this._files[file][(_constants || _load_constants()).default.SHA1]) ||
  44. null
  45. );
  46. }
  47. exists(file) {
  48. return !!this._files[file];
  49. }
  50. getAllFiles() {
  51. return Object.keys(this._files);
  52. }
  53. matchFiles(pattern) {
  54. if (!(pattern instanceof RegExp)) {
  55. pattern = new RegExp(pattern);
  56. }
  57. const files = [];
  58. for (const file in this._files) {
  59. if (pattern.test(file)) {
  60. files.push(file);
  61. }
  62. }
  63. return files;
  64. }
  65. matchFilesWithGlob(globs, root) {
  66. const files = new Set();
  67. for (const file in this._files) {
  68. const filePath = root
  69. ? (_path || _load_path()).default.relative(root, file)
  70. : file;
  71. if (
  72. (0, (_micromatch || _load_micromatch()).default)([filePath], globs)
  73. .length
  74. ) {
  75. files.add(file);
  76. }
  77. }
  78. return files;
  79. }
  80. }
  81. exports.default = HasteFS;
  82. /**
  83. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  84. *
  85. * This source code is licensed under the MIT license found in the
  86. * LICENSE file in the root directory of this source tree.
  87. *
  88. *
  89. */