Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

glob.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @fileoverview An inherited `glob.GlobSync` to support .gitignore patterns.
  3. * @author Kael Zhang
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Requirements
  8. //------------------------------------------------------------------------------
  9. const Sync = require("glob").GlobSync,
  10. util = require("util");
  11. //------------------------------------------------------------------------------
  12. // Private
  13. //------------------------------------------------------------------------------
  14. const IGNORE = Symbol("ignore");
  15. /**
  16. * Subclass of `glob.GlobSync`
  17. * @param {string} pattern Pattern to be matched.
  18. * @param {Object} options `options` for `glob`
  19. * @param {function()} shouldIgnore Method to check whether a directory should be ignored.
  20. * @constructor
  21. */
  22. function GlobSync(pattern, options, shouldIgnore) {
  23. /**
  24. * We don't put this thing to argument `options` to avoid
  25. * further problems, such as `options` validation.
  26. *
  27. * Use `Symbol` as much as possible to avoid confliction.
  28. */
  29. this[IGNORE] = shouldIgnore;
  30. Sync.call(this, pattern, options);
  31. }
  32. util.inherits(GlobSync, Sync);
  33. /* eslint no-underscore-dangle: ["error", { "allow": ["_readdir", "_mark"] }] */
  34. GlobSync.prototype._readdir = function(abs, inGlobStar) {
  35. /**
  36. * `options.nodir` makes `options.mark` as `true`.
  37. * Mark `abs` first
  38. * to make sure `"node_modules"` will be ignored immediately with ignore pattern `"node_modules/"`.
  39. *
  40. * There is a built-in cache about marked `File.Stat` in `glob`, so that we could not worry about the extra invocation of `this._mark()`
  41. */
  42. const marked = this._mark(abs);
  43. if (this[IGNORE](marked)) {
  44. return null;
  45. }
  46. return Sync.prototype._readdir.call(this, abs, inGlobStar);
  47. };
  48. module.exports = GlobSync;