版博士V2.0程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { fileURLToPath, pathToFileURL } from 'node:url';
  2. import { existsSync } from 'node:fs';
  3. import { resolve } from 'pathe';
  4. const isWindows = process.platform === "win32";
  5. function slash(str) {
  6. return str.replace(/\\/g, "/");
  7. }
  8. const VALID_ID_PREFIX = "/@id/";
  9. function normalizeRequestId(id, base) {
  10. if (base && id.startsWith(base))
  11. id = `/${id.slice(base.length)}`;
  12. return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^file:/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?&/, "?").replace(/\?+$/, "");
  13. }
  14. const queryRE = /\?.*$/s;
  15. const hashRE = /#.*$/s;
  16. const cleanUrl = (url) => url.replace(hashRE, "").replace(queryRE, "");
  17. const internalRequests = [
  18. "@vite/client",
  19. "@vite/env"
  20. ];
  21. const internalRequestRegexp = new RegExp(`^/?(${internalRequests.join("|")})$`);
  22. const isInternalRequest = (id) => {
  23. return internalRequestRegexp.test(id);
  24. };
  25. function normalizeModuleId(id) {
  26. return id.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^file:\//, "/").replace(/^node:/, "").replace(/^\/+/, "/");
  27. }
  28. function isPrimitive(v) {
  29. return v !== Object(v);
  30. }
  31. function toFilePath(id, root) {
  32. let { absolute, exists } = (() => {
  33. if (id.startsWith("/@fs/"))
  34. return { absolute: id.slice(4), exists: true };
  35. if (!id.startsWith(root) && id.startsWith("/")) {
  36. const resolved = resolve(root, id.slice(1));
  37. if (existsSync(cleanUrl(resolved)))
  38. return { absolute: resolved, exists: true };
  39. } else if (id.startsWith(root) && existsSync(cleanUrl(id))) {
  40. return { absolute: id, exists: true };
  41. }
  42. return { absolute: id, exists: false };
  43. })();
  44. if (absolute.startsWith("//"))
  45. absolute = absolute.slice(1);
  46. return {
  47. path: isWindows && absolute.startsWith("/") ? slash(fileURLToPath(pathToFileURL(absolute.slice(1)).href)) : absolute,
  48. exists
  49. };
  50. }
  51. function toArray(array) {
  52. if (array === null || array === void 0)
  53. array = [];
  54. if (Array.isArray(array))
  55. return array;
  56. return [array];
  57. }
  58. export { VALID_ID_PREFIX, cleanUrl, hashRE, isInternalRequest, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, slash, toArray, toFilePath };