No Description

settings.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.DEFAULT_FILE_SYSTEM_ADAPTER = void 0;
  4. const fs = require("fs");
  5. const os = require("os");
  6. /**
  7. * The `os.cpus` method can return zero. We expect the number of cores to be greater than zero.
  8. * https://github.com/nodejs/node/blob/7faeddf23a98c53896f8b574a6e66589e8fb1eb8/lib/os.js#L106-L107
  9. */
  10. const CPU_COUNT = Math.max(os.cpus().length, 1);
  11. exports.DEFAULT_FILE_SYSTEM_ADAPTER = {
  12. lstat: fs.lstat,
  13. lstatSync: fs.lstatSync,
  14. stat: fs.stat,
  15. statSync: fs.statSync,
  16. readdir: fs.readdir,
  17. readdirSync: fs.readdirSync
  18. };
  19. class Settings {
  20. constructor(_options = {}) {
  21. this._options = _options;
  22. this.absolute = this._getValue(this._options.absolute, false);
  23. this.baseNameMatch = this._getValue(this._options.baseNameMatch, false);
  24. this.braceExpansion = this._getValue(this._options.braceExpansion, true);
  25. this.caseSensitiveMatch = this._getValue(this._options.caseSensitiveMatch, true);
  26. this.concurrency = this._getValue(this._options.concurrency, CPU_COUNT);
  27. this.cwd = this._getValue(this._options.cwd, process.cwd());
  28. this.deep = this._getValue(this._options.deep, Infinity);
  29. this.dot = this._getValue(this._options.dot, false);
  30. this.extglob = this._getValue(this._options.extglob, true);
  31. this.followSymbolicLinks = this._getValue(this._options.followSymbolicLinks, true);
  32. this.fs = this._getFileSystemMethods(this._options.fs);
  33. this.globstar = this._getValue(this._options.globstar, true);
  34. this.ignore = this._getValue(this._options.ignore, []);
  35. this.markDirectories = this._getValue(this._options.markDirectories, false);
  36. this.objectMode = this._getValue(this._options.objectMode, false);
  37. this.onlyDirectories = this._getValue(this._options.onlyDirectories, false);
  38. this.onlyFiles = this._getValue(this._options.onlyFiles, true);
  39. this.stats = this._getValue(this._options.stats, false);
  40. this.suppressErrors = this._getValue(this._options.suppressErrors, false);
  41. this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, false);
  42. this.unique = this._getValue(this._options.unique, true);
  43. if (this.onlyDirectories) {
  44. this.onlyFiles = false;
  45. }
  46. if (this.stats) {
  47. this.objectMode = true;
  48. }
  49. }
  50. _getValue(option, value) {
  51. return option === undefined ? value : option;
  52. }
  53. _getFileSystemMethods(methods = {}) {
  54. return Object.assign(Object.assign({}, exports.DEFAULT_FILE_SYSTEM_ADAPTER), methods);
  55. }
  56. }
  57. exports.default = Settings;