fs-sync.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = Object.setPrototypeOf ||
  4. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6. return function (d, b) {
  7. extendStatics(d, b);
  8. function __() { this.constructor = d; }
  9. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10. };
  11. })();
  12. Object.defineProperty(exports, "__esModule", { value: true });
  13. var fsStat = require("@nodelib/fs.stat");
  14. var fs_1 = require("./fs");
  15. var FileSystemSync = /** @class */ (function (_super) {
  16. __extends(FileSystemSync, _super);
  17. function FileSystemSync() {
  18. return _super !== null && _super.apply(this, arguments) || this;
  19. }
  20. /**
  21. * Use sync API to read entries for Task.
  22. */
  23. FileSystemSync.prototype.read = function (patterns, filter) {
  24. var _this = this;
  25. var entries = [];
  26. patterns.forEach(function (pattern) {
  27. var filepath = _this.getFullEntryPath(pattern);
  28. var entry = _this.getEntry(filepath, pattern);
  29. if (entry === null || !filter(entry)) {
  30. return;
  31. }
  32. entries.push(entry);
  33. });
  34. return entries;
  35. };
  36. /**
  37. * Return entry for the provided path.
  38. */
  39. FileSystemSync.prototype.getEntry = function (filepath, pattern) {
  40. try {
  41. var stat = this.getStat(filepath);
  42. return this.makeEntry(stat, pattern);
  43. }
  44. catch (err) {
  45. return null;
  46. }
  47. };
  48. /**
  49. * Return fs.Stats for the provided path.
  50. */
  51. FileSystemSync.prototype.getStat = function (filepath) {
  52. return fsStat.statSync(filepath, { throwErrorOnBrokenSymlinks: false });
  53. };
  54. return FileSystemSync;
  55. }(fs_1.default));
  56. exports.default = FileSystemSync;