版博士V2.0程序
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.
 
 
 
 

65 lines
1.9 KiB

  1. import { relative } from 'pathe';
  2. import 'std-env';
  3. import '@vitest/runner/utils';
  4. import { g as getWorkerState } from './chunk-utils-global.fd174983.js';
  5. import '@vitest/utils';
  6. var _a;
  7. const isNode = typeof process < "u" && typeof process.stdout < "u" && !((_a = process.versions) == null ? void 0 : _a.deno) && !globalThis.window;
  8. const isWindows = isNode && process.platform === "win32";
  9. const getRunMode = () => getWorkerState().config.mode;
  10. const isRunningInBenchmark = () => getRunMode() === "benchmark";
  11. const relativePath = relative;
  12. function resetModules(modules, resetMocks = false) {
  13. const skipPaths = [
  14. /\/vitest\/dist\//,
  15. /\/vite-node\/dist\//,
  16. /vitest-virtual-\w+\/dist/,
  17. /@vitest\/dist/,
  18. ...!resetMocks ? [/^mock:/] : []
  19. ];
  20. modules.forEach((mod, path) => {
  21. if (skipPaths.some((re) => re.test(path)))
  22. return;
  23. modules.invalidateModule(mod);
  24. });
  25. }
  26. function removeUndefinedValues(obj) {
  27. for (const key in Object.keys(obj)) {
  28. if (obj[key] === void 0)
  29. delete obj[key];
  30. }
  31. return obj;
  32. }
  33. function getCallLastIndex(code) {
  34. let charIndex = -1;
  35. let inString = null;
  36. let startedBracers = 0;
  37. let endedBracers = 0;
  38. let beforeChar = null;
  39. while (charIndex <= code.length) {
  40. beforeChar = code[charIndex];
  41. charIndex++;
  42. const char = code[charIndex];
  43. const isCharString = char === '"' || char === "'" || char === "`";
  44. if (isCharString && beforeChar !== "\\") {
  45. if (inString === char)
  46. inString = null;
  47. else if (!inString)
  48. inString = char;
  49. }
  50. if (!inString) {
  51. if (char === "(")
  52. startedBracers++;
  53. if (char === ")")
  54. endedBracers++;
  55. }
  56. if (startedBracers && endedBracers && startedBracers === endedBracers)
  57. return charIndex;
  58. }
  59. return null;
  60. }
  61. export { isNode as a, relativePath as b, removeUndefinedValues as c, isWindows as d, getCallLastIndex as g, isRunningInBenchmark as i, resetModules as r };