index.cjs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. "use strict";
  2. //#region rolldown:runtime
  3. var __create = Object.create;
  4. var __defProp = Object.defineProperty;
  5. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  6. var __getOwnPropNames = Object.getOwnPropertyNames;
  7. var __getProtoOf = Object.getPrototypeOf;
  8. var __hasOwnProp = Object.prototype.hasOwnProperty;
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
  11. key = keys[i];
  12. if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
  13. get: ((k) => from[k]).bind(null, key),
  14. enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
  15. });
  16. }
  17. return to;
  18. };
  19. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
  20. value: mod,
  21. enumerable: true
  22. }) : target, mod));
  23. //#endregion
  24. const pathe = __toESM(require("pathe"));
  25. const picomatch = __toESM(require("picomatch"));
  26. //#region src/path.ts
  27. function normalizePath(filename) {
  28. return filename.replaceAll("\\", "/");
  29. }
  30. //#endregion
  31. //#region src/utils.ts
  32. const isArray = Array.isArray;
  33. function toArray(thing) {
  34. if (isArray(thing)) return thing;
  35. if (thing == null) return [];
  36. return [thing];
  37. }
  38. //#endregion
  39. //#region src/filter.ts
  40. const escapeMark = "[_#EsCaPe#_]";
  41. function getMatcherString(id, resolutionBase) {
  42. if (resolutionBase === false || (0, pathe.isAbsolute)(id) || id.startsWith("**")) return normalizePath(id);
  43. const basePath = normalizePath((0, pathe.resolve)(resolutionBase || "")).replaceAll(/[-^$*+?.()|[\]{}]/g, `${escapeMark}$&`);
  44. return (0, pathe.join)(basePath, normalizePath(id)).replaceAll(escapeMark, "\\");
  45. }
  46. function createFilter(include, exclude, options) {
  47. const resolutionBase = options && options.resolve;
  48. const getMatcher = (id) => id instanceof RegExp ? id : { test: (what) => {
  49. const pattern = getMatcherString(id, resolutionBase);
  50. const fn = (0, picomatch.default)(pattern, { dot: true });
  51. const result = fn(what);
  52. return result;
  53. } };
  54. const includeMatchers = toArray(include).map(getMatcher);
  55. const excludeMatchers = toArray(exclude).map(getMatcher);
  56. if (!includeMatchers.length && !excludeMatchers.length) return (id) => typeof id === "string" && !id.includes("\0");
  57. return function result(id) {
  58. if (typeof id !== "string") return false;
  59. if (id.includes("\0")) return false;
  60. const pathId = normalizePath(id);
  61. for (const matcher of excludeMatchers) {
  62. if (matcher instanceof RegExp) matcher.lastIndex = 0;
  63. if (matcher.test(pathId)) return false;
  64. }
  65. for (const matcher of includeMatchers) {
  66. if (matcher instanceof RegExp) matcher.lastIndex = 0;
  67. if (matcher.test(pathId)) return true;
  68. }
  69. return !includeMatchers.length;
  70. };
  71. }
  72. //#endregion
  73. exports.createFilter = createFilter
  74. exports.normalizePath = normalizePath
  75. exports.toArray = toArray