版博士V2.0程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var module$1 = require('module');
  4. var path = require('path');
  5. var node_url = require('node:url');
  6. var vm = require('vm');
  7. var mlly = require('mlly');
  8. var pathe = require('pathe');
  9. var createDebug = require('debug');
  10. var utils = require('./utils.cjs');
  11. var sourceMap = require('./source-map.cjs');
  12. require('fs');
  13. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  14. function _interopNamespace(e) {
  15. if (e && e.__esModule) return e;
  16. var n = Object.create(null);
  17. if (e) {
  18. Object.keys(e).forEach(function (k) {
  19. if (k !== 'default') {
  20. var d = Object.getOwnPropertyDescriptor(e, k);
  21. Object.defineProperty(n, k, d.get ? d : {
  22. enumerable: true,
  23. get: function () { return e[k]; }
  24. });
  25. }
  26. });
  27. }
  28. n["default"] = e;
  29. return Object.freeze(n);
  30. }
  31. var vm__default = /*#__PURE__*/_interopDefaultLegacy(vm);
  32. var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
  33. const { setTimeout, clearTimeout } = globalThis;
  34. const debugExecute = createDebug__default["default"]("vite-node:client:execute");
  35. const debugNative = createDebug__default["default"]("vite-node:client:native");
  36. const clientStub = {
  37. injectQuery: (id) => id,
  38. createHotContext() {
  39. return {
  40. accept: () => {
  41. },
  42. prune: () => {
  43. },
  44. dispose: () => {
  45. },
  46. decline: () => {
  47. },
  48. invalidate: () => {
  49. },
  50. on: () => {
  51. }
  52. };
  53. },
  54. updateStyle(id, css) {
  55. if (typeof document === "undefined")
  56. return;
  57. const element = document.getElementById(id);
  58. if (element)
  59. element.remove();
  60. const head = document.querySelector("head");
  61. const style = document.createElement("style");
  62. style.setAttribute("type", "text/css");
  63. style.id = id;
  64. style.innerHTML = css;
  65. head == null ? void 0 : head.appendChild(style);
  66. }
  67. };
  68. const DEFAULT_REQUEST_STUBS = {
  69. "/@vite/client": clientStub,
  70. "@vite/client": clientStub
  71. };
  72. class ModuleCacheMap extends Map {
  73. normalizePath(fsPath) {
  74. return utils.normalizeModuleId(fsPath);
  75. }
  76. update(fsPath, mod) {
  77. fsPath = this.normalizePath(fsPath);
  78. if (!super.has(fsPath))
  79. super.set(fsPath, mod);
  80. else
  81. Object.assign(super.get(fsPath), mod);
  82. return this;
  83. }
  84. setByModuleId(modulePath, mod) {
  85. return super.set(modulePath, mod);
  86. }
  87. set(fsPath, mod) {
  88. return this.setByModuleId(this.normalizePath(fsPath), mod);
  89. }
  90. getByModuleId(modulePath) {
  91. if (!super.has(modulePath))
  92. super.set(modulePath, {});
  93. return super.get(modulePath);
  94. }
  95. get(fsPath) {
  96. return this.getByModuleId(this.normalizePath(fsPath));
  97. }
  98. deleteByModuleId(modulePath) {
  99. return super.delete(modulePath);
  100. }
  101. delete(fsPath) {
  102. return this.deleteByModuleId(this.normalizePath(fsPath));
  103. }
  104. invalidateModule(mod) {
  105. delete mod.evaluated;
  106. delete mod.resolving;
  107. delete mod.promise;
  108. delete mod.exports;
  109. return true;
  110. }
  111. invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
  112. for (const _id of ids) {
  113. const id = this.normalizePath(_id);
  114. if (invalidated.has(id))
  115. continue;
  116. invalidated.add(id);
  117. const mod = super.get(id);
  118. if (mod == null ? void 0 : mod.importers)
  119. this.invalidateDepTree(mod.importers, invalidated);
  120. super.delete(id);
  121. }
  122. return invalidated;
  123. }
  124. invalidateSubDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
  125. for (const _id of ids) {
  126. const id = this.normalizePath(_id);
  127. if (invalidated.has(id))
  128. continue;
  129. invalidated.add(id);
  130. const subIds = Array.from(super.entries()).filter(([, mod]) => {
  131. var _a;
  132. return (_a = mod.importers) == null ? void 0 : _a.has(id);
  133. }).map(([key]) => key);
  134. subIds.length && this.invalidateSubDepTree(subIds, invalidated);
  135. super.delete(id);
  136. }
  137. return invalidated;
  138. }
  139. getSourceMap(id) {
  140. const cache = this.get(id);
  141. if (cache.map)
  142. return cache.map;
  143. const map = cache.code && sourceMap.extractSourceMap(cache.code);
  144. if (map) {
  145. cache.map = map;
  146. return map;
  147. }
  148. return null;
  149. }
  150. }
  151. class ViteNodeRunner {
  152. constructor(options) {
  153. this.options = options;
  154. this.root = options.root ?? process.cwd();
  155. this.moduleCache = options.moduleCache ?? new ModuleCacheMap();
  156. this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG_RUNNER : false);
  157. }
  158. async executeFile(file) {
  159. const url = `/@fs/${utils.slash(pathe.resolve(file))}`;
  160. return await this.cachedRequest(url, url, []);
  161. }
  162. async executeId(rawId) {
  163. const [id, url] = await this.resolveUrl(rawId);
  164. return await this.cachedRequest(id, url, []);
  165. }
  166. async cachedRequest(id, fsPath, callstack) {
  167. const importee = callstack[callstack.length - 1];
  168. const mod = this.moduleCache.get(fsPath);
  169. if (!mod.importers)
  170. mod.importers = /* @__PURE__ */ new Set();
  171. if (importee)
  172. mod.importers.add(importee);
  173. if (callstack.includes(fsPath) && mod.exports)
  174. return mod.exports;
  175. if (mod.promise)
  176. return mod.promise;
  177. const promise = this.directRequest(id, fsPath, callstack);
  178. Object.assign(mod, { promise, evaluated: false });
  179. try {
  180. return await promise;
  181. } finally {
  182. mod.evaluated = true;
  183. }
  184. }
  185. shouldResolveId(id, _importee) {
  186. return !utils.isInternalRequest(id) && !mlly.isNodeBuiltin(id);
  187. }
  188. async _resolveUrl(id, importer) {
  189. if (importer && id.startsWith(utils.VALID_ID_PREFIX))
  190. importer = void 0;
  191. id = utils.normalizeRequestId(id, this.options.base);
  192. if (!this.shouldResolveId(id))
  193. return [id, id];
  194. const { path, exists } = utils.toFilePath(id, this.root);
  195. if (!this.options.resolveId || exists)
  196. return [id, path];
  197. const resolved = await this.options.resolveId(id, importer);
  198. const resolvedId = resolved ? utils.normalizeRequestId(resolved.id, this.options.base) : id;
  199. const fsPath = resolved ? resolvedId : path;
  200. return [resolvedId, fsPath];
  201. }
  202. async resolveUrl(id, importee) {
  203. const resolveKey = `resolve:${id}`;
  204. this.moduleCache.setByModuleId(resolveKey, { resolving: true });
  205. try {
  206. return await this._resolveUrl(id, importee);
  207. } finally {
  208. this.moduleCache.deleteByModuleId(resolveKey);
  209. }
  210. }
  211. async dependencyRequest(id, fsPath, callstack) {
  212. var _a;
  213. const getStack = () => {
  214. return `stack:
  215. ${[...callstack, fsPath].reverse().map((p) => `- ${p}`).join("\n")}`;
  216. };
  217. let debugTimer;
  218. if (this.debug)
  219. debugTimer = setTimeout(() => console.warn(() => `module ${fsPath} takes over 2s to load.
  220. ${getStack()}`), 2e3);
  221. try {
  222. if (callstack.includes(fsPath)) {
  223. const depExports = (_a = this.moduleCache.get(fsPath)) == null ? void 0 : _a.exports;
  224. if (depExports)
  225. return depExports;
  226. throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
  227. }
  228. return await this.cachedRequest(id, fsPath, callstack);
  229. } finally {
  230. if (debugTimer)
  231. clearTimeout(debugTimer);
  232. }
  233. }
  234. async directRequest(id, fsPath, _callstack) {
  235. const moduleId = utils.normalizeModuleId(fsPath);
  236. const callstack = [..._callstack, moduleId];
  237. const mod = this.moduleCache.getByModuleId(moduleId);
  238. const request = async (dep) => {
  239. const [id2, depFsPath] = await this.resolveUrl(dep, fsPath);
  240. return this.dependencyRequest(id2, depFsPath, callstack);
  241. };
  242. const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
  243. if (id in requestStubs)
  244. return requestStubs[id];
  245. let { code: transformed, externalize } = await this.options.fetchModule(id);
  246. if (externalize) {
  247. debugNative(externalize);
  248. const exports2 = await this.interopedImport(externalize);
  249. mod.exports = exports2;
  250. return exports2;
  251. }
  252. if (transformed == null)
  253. throw new Error(`[vite-node] Failed to load "${id}" imported from ${callstack[callstack.length - 2]}`);
  254. const modulePath = utils.cleanUrl(moduleId);
  255. const href = node_url.pathToFileURL(modulePath).href;
  256. const meta = { url: href };
  257. const exports = /* @__PURE__ */ Object.create(null);
  258. Object.defineProperty(exports, Symbol.toStringTag, {
  259. value: "Module",
  260. enumerable: false,
  261. configurable: false
  262. });
  263. const cjsExports = new Proxy(exports, {
  264. get: (target, p, receiver) => {
  265. if (Reflect.has(target, p))
  266. return Reflect.get(target, p, receiver);
  267. return Reflect.get(Object.prototype, p, receiver);
  268. },
  269. getPrototypeOf: () => Object.prototype,
  270. set: (_, p, value) => {
  271. if (p === "default" && this.shouldInterop(modulePath, { default: value })) {
  272. exportAll(cjsExports, value);
  273. exports.default = value;
  274. return true;
  275. }
  276. if (!Reflect.has(exports, "default"))
  277. exports.default = {};
  278. if (utils.isPrimitive(exports.default)) {
  279. defineExport(exports, p, () => void 0);
  280. return true;
  281. }
  282. exports.default[p] = value;
  283. if (p !== "default")
  284. defineExport(exports, p, () => value);
  285. return true;
  286. }
  287. });
  288. Object.assign(mod, { code: transformed, exports });
  289. const __filename = node_url.fileURLToPath(href);
  290. const moduleProxy = {
  291. set exports(value) {
  292. exportAll(cjsExports, value);
  293. exports.default = value;
  294. },
  295. get exports() {
  296. return cjsExports;
  297. }
  298. };
  299. let hotContext;
  300. if (this.options.createHotContext) {
  301. Object.defineProperty(meta, "hot", {
  302. enumerable: true,
  303. get: () => {
  304. var _a, _b;
  305. hotContext || (hotContext = (_b = (_a = this.options).createHotContext) == null ? void 0 : _b.call(_a, this, `/@fs/${fsPath}`));
  306. return hotContext;
  307. },
  308. set: (value) => {
  309. hotContext = value;
  310. }
  311. });
  312. }
  313. const context = this.prepareContext({
  314. __vite_ssr_import__: request,
  315. __vite_ssr_dynamic_import__: request,
  316. __vite_ssr_exports__: exports,
  317. __vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
  318. __vite_ssr_import_meta__: meta,
  319. require: module$1.createRequire(href),
  320. exports: cjsExports,
  321. module: moduleProxy,
  322. __filename,
  323. __dirname: path.dirname(__filename)
  324. });
  325. debugExecute(__filename);
  326. if (transformed[0] === "#")
  327. transformed = transformed.replace(/^\#\!.*/, (s) => " ".repeat(s.length));
  328. const codeDefinition = `'use strict';async (${Object.keys(context).join(",")})=>{{`;
  329. const code = `${codeDefinition}${transformed}
  330. }}`;
  331. const fn = vm__default["default"].runInThisContext(code, {
  332. filename: __filename,
  333. lineOffset: 0,
  334. columnOffset: -codeDefinition.length
  335. });
  336. await fn(...Object.values(context));
  337. return exports;
  338. }
  339. prepareContext(context) {
  340. return context;
  341. }
  342. shouldInterop(path, mod) {
  343. if (this.options.interopDefault === false)
  344. return false;
  345. return !path.endsWith(".mjs") && "default" in mod;
  346. }
  347. async interopedImport(path) {
  348. const importedModule = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(path);
  349. if (!this.shouldInterop(path, importedModule))
  350. return importedModule;
  351. const { mod, defaultExport } = interopModule(importedModule);
  352. return new Proxy(mod, {
  353. get(mod2, prop) {
  354. if (prop === "default")
  355. return defaultExport;
  356. return mod2[prop] ?? (defaultExport == null ? void 0 : defaultExport[prop]);
  357. },
  358. has(mod2, prop) {
  359. if (prop === "default")
  360. return defaultExport !== void 0;
  361. return prop in mod2 || defaultExport && prop in defaultExport;
  362. },
  363. getOwnPropertyDescriptor(mod2, prop) {
  364. const descriptor = Reflect.getOwnPropertyDescriptor(mod2, prop);
  365. if (descriptor)
  366. return descriptor;
  367. if (prop === "default" && defaultExport !== void 0) {
  368. return {
  369. value: defaultExport,
  370. enumerable: true,
  371. configurable: true
  372. };
  373. }
  374. }
  375. });
  376. }
  377. }
  378. function interopModule(mod) {
  379. if (utils.isPrimitive(mod)) {
  380. return {
  381. mod: { default: mod },
  382. defaultExport: mod
  383. };
  384. }
  385. let defaultExport = "default" in mod ? mod.default : mod;
  386. if (!utils.isPrimitive(defaultExport) && "__esModule" in defaultExport) {
  387. mod = defaultExport;
  388. if ("default" in defaultExport)
  389. defaultExport = defaultExport.default;
  390. }
  391. return { mod, defaultExport };
  392. }
  393. function defineExport(exports, key, value) {
  394. Object.defineProperty(exports, key, {
  395. enumerable: true,
  396. configurable: true,
  397. get: value
  398. });
  399. }
  400. function exportAll(exports, sourceModule) {
  401. if (exports === sourceModule)
  402. return;
  403. if (utils.isPrimitive(sourceModule) || Array.isArray(sourceModule))
  404. return;
  405. for (const key in sourceModule) {
  406. if (key !== "default") {
  407. try {
  408. defineExport(exports, key, () => sourceModule[key]);
  409. } catch (_err) {
  410. }
  411. }
  412. }
  413. }
  414. exports.DEFAULT_REQUEST_STUBS = DEFAULT_REQUEST_STUBS;
  415. exports.ModuleCacheMap = ModuleCacheMap;
  416. exports.ViteNodeRunner = ViteNodeRunner;