版博士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.
 
 
 
 

76 lines
2.6 KiB

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