haste_fs.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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) { return obj && obj.__esModule ? obj : { default: obj }; }
  18. class HasteFS {
  19. constructor(files) {
  20. this._files = files;
  21. }
  22. getModuleName(file) {
  23. return this._files[file] && this._files[file][(_constants || _load_constants()).default.ID] || null;
  24. }
  25. getDependencies(file) {
  26. return this._files[file] && this._files[file][(_constants || _load_constants()).default.DEPENDENCIES] || null;
  27. }
  28. exists(file) {
  29. return !!this._files[file];
  30. }
  31. getAllFiles() {
  32. return Object.keys(this._files);
  33. }
  34. matchFiles(pattern) {
  35. if (!(pattern instanceof RegExp)) {
  36. pattern = new RegExp(pattern);
  37. }
  38. const files = [];
  39. for (const file in this._files) {
  40. if (pattern.test(file)) {
  41. files.push(file);
  42. }
  43. }
  44. return files;
  45. }
  46. matchFilesWithGlob(globs, root) {
  47. const files = new Set();
  48. for (const file in this._files) {
  49. const filePath = root ? (_path || _load_path()).default.relative(root, file) : file;
  50. if ((0, (_micromatch || _load_micromatch()).default)([filePath], globs).length) {
  51. files.add(file);
  52. }
  53. }
  54. return files;
  55. }
  56. }
  57. exports.default = HasteFS; /**
  58. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  59. *
  60. * This source code is licensed under the MIT license found in the
  61. * LICENSE file in the root directory of this source tree.
  62. *
  63. *
  64. */