市场夺宝奇兵
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.

319 lines
11 KiB

  1. import { __commonJS, __toESM } from "./dep-lCKrEJQm.js";
  2. import { readFileSync } from "node:fs";
  3. import path, { resolve } from "node:path";
  4. import { fileURLToPath } from "node:url";
  5. import readline from "node:readline";
  6. //#region ../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
  7. var require_picocolors = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js": ((exports, module) => {
  8. let p = process || {}, argv = p.argv || [], env = p.env || {};
  9. let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
  10. let formatter = (open, close, replace = open) => (input) => {
  11. let string = "" + input, index = string.indexOf(close, open.length);
  12. return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
  13. };
  14. let replaceClose = (string, close, replace, index) => {
  15. let result = "", cursor = 0;
  16. do {
  17. result += string.substring(cursor, index) + replace;
  18. cursor = index + close.length;
  19. index = string.indexOf(close, cursor);
  20. } while (~index);
  21. return result + string.substring(cursor);
  22. };
  23. let createColors = (enabled = isColorSupported) => {
  24. let f = enabled ? formatter : () => String;
  25. return {
  26. isColorSupported: enabled,
  27. reset: f("\x1B[0m", "\x1B[0m"),
  28. bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
  29. dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
  30. italic: f("\x1B[3m", "\x1B[23m"),
  31. underline: f("\x1B[4m", "\x1B[24m"),
  32. inverse: f("\x1B[7m", "\x1B[27m"),
  33. hidden: f("\x1B[8m", "\x1B[28m"),
  34. strikethrough: f("\x1B[9m", "\x1B[29m"),
  35. black: f("\x1B[30m", "\x1B[39m"),
  36. red: f("\x1B[31m", "\x1B[39m"),
  37. green: f("\x1B[32m", "\x1B[39m"),
  38. yellow: f("\x1B[33m", "\x1B[39m"),
  39. blue: f("\x1B[34m", "\x1B[39m"),
  40. magenta: f("\x1B[35m", "\x1B[39m"),
  41. cyan: f("\x1B[36m", "\x1B[39m"),
  42. white: f("\x1B[37m", "\x1B[39m"),
  43. gray: f("\x1B[90m", "\x1B[39m"),
  44. bgBlack: f("\x1B[40m", "\x1B[49m"),
  45. bgRed: f("\x1B[41m", "\x1B[49m"),
  46. bgGreen: f("\x1B[42m", "\x1B[49m"),
  47. bgYellow: f("\x1B[43m", "\x1B[49m"),
  48. bgBlue: f("\x1B[44m", "\x1B[49m"),
  49. bgMagenta: f("\x1B[45m", "\x1B[49m"),
  50. bgCyan: f("\x1B[46m", "\x1B[49m"),
  51. bgWhite: f("\x1B[47m", "\x1B[49m"),
  52. blackBright: f("\x1B[90m", "\x1B[39m"),
  53. redBright: f("\x1B[91m", "\x1B[39m"),
  54. greenBright: f("\x1B[92m", "\x1B[39m"),
  55. yellowBright: f("\x1B[93m", "\x1B[39m"),
  56. blueBright: f("\x1B[94m", "\x1B[39m"),
  57. magentaBright: f("\x1B[95m", "\x1B[39m"),
  58. cyanBright: f("\x1B[96m", "\x1B[39m"),
  59. whiteBright: f("\x1B[97m", "\x1B[39m"),
  60. bgBlackBright: f("\x1B[100m", "\x1B[49m"),
  61. bgRedBright: f("\x1B[101m", "\x1B[49m"),
  62. bgGreenBright: f("\x1B[102m", "\x1B[49m"),
  63. bgYellowBright: f("\x1B[103m", "\x1B[49m"),
  64. bgBlueBright: f("\x1B[104m", "\x1B[49m"),
  65. bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
  66. bgCyanBright: f("\x1B[106m", "\x1B[49m"),
  67. bgWhiteBright: f("\x1B[107m", "\x1B[49m")
  68. };
  69. };
  70. module.exports = createColors();
  71. module.exports.createColors = createColors;
  72. }) });
  73. //#endregion
  74. //#region src/node/constants.ts
  75. const { version } = JSON.parse(readFileSync(new URL("../../package.json", new URL("../../../src/node/constants.ts", import.meta.url))).toString());
  76. const ROLLUP_HOOKS = [
  77. "options",
  78. "buildStart",
  79. "buildEnd",
  80. "renderStart",
  81. "renderError",
  82. "renderChunk",
  83. "writeBundle",
  84. "generateBundle",
  85. "banner",
  86. "footer",
  87. "augmentChunkHash",
  88. "outputOptions",
  89. "renderDynamicImport",
  90. "resolveFileUrl",
  91. "resolveImportMeta",
  92. "intro",
  93. "outro",
  94. "closeBundle",
  95. "closeWatcher",
  96. "load",
  97. "moduleParsed",
  98. "watchChange",
  99. "resolveDynamicImport",
  100. "resolveId",
  101. "shouldTransformCachedModule",
  102. "transform",
  103. "onLog"
  104. ];
  105. const VERSION = version;
  106. const DEFAULT_MAIN_FIELDS = [
  107. "browser",
  108. "module",
  109. "jsnext:main",
  110. "jsnext"
  111. ];
  112. const DEFAULT_CLIENT_MAIN_FIELDS = Object.freeze(DEFAULT_MAIN_FIELDS);
  113. const DEFAULT_SERVER_MAIN_FIELDS = Object.freeze(DEFAULT_MAIN_FIELDS.filter((f) => f !== "browser"));
  114. /**
  115. * A special condition that would be replaced with production or development
  116. * depending on NODE_ENV env variable
  117. */
  118. const DEV_PROD_CONDITION = `development|production`;
  119. const DEFAULT_CONDITIONS = [
  120. "module",
  121. "browser",
  122. "node",
  123. DEV_PROD_CONDITION
  124. ];
  125. const DEFAULT_CLIENT_CONDITIONS = Object.freeze(DEFAULT_CONDITIONS.filter((c) => c !== "node"));
  126. const DEFAULT_SERVER_CONDITIONS = Object.freeze(DEFAULT_CONDITIONS.filter((c) => c !== "browser"));
  127. const DEFAULT_EXTERNAL_CONDITIONS = Object.freeze(["node", "module-sync"]);
  128. /**
  129. * The browser versions that are included in the Baseline Widely Available on 2025-05-01.
  130. *
  131. * This value would be bumped on each major release of Vite.
  132. *
  133. * The value is generated by `pnpm generate-target` script.
  134. */
  135. const ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET = [
  136. "chrome107",
  137. "edge107",
  138. "firefox104",
  139. "safari16"
  140. ];
  141. const DEFAULT_CONFIG_FILES = [
  142. "vite.config.js",
  143. "vite.config.mjs",
  144. "vite.config.ts",
  145. "vite.config.cjs",
  146. "vite.config.mts",
  147. "vite.config.cts"
  148. ];
  149. const JS_TYPES_RE = /\.(?:j|t)sx?$|\.mjs$/;
  150. const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
  151. const OPTIMIZABLE_ENTRY_RE = /\.[cm]?[jt]s$/;
  152. const SPECIAL_QUERY_RE = /[?&](?:worker|sharedworker|raw|url)\b/;
  153. /**
  154. * Prefix for resolved fs paths, since windows paths may not be valid as URLs.
  155. */
  156. const FS_PREFIX = `/@fs/`;
  157. const CLIENT_PUBLIC_PATH = `/@vite/client`;
  158. const ENV_PUBLIC_PATH = `/@vite/env`;
  159. const VITE_PACKAGE_DIR = resolve(fileURLToPath(new URL("../../../src/node/constants.ts", import.meta.url)), "../../..");
  160. const CLIENT_ENTRY = resolve(VITE_PACKAGE_DIR, "dist/client/client.mjs");
  161. const ENV_ENTRY = resolve(VITE_PACKAGE_DIR, "dist/client/env.mjs");
  162. const CLIENT_DIR = path.dirname(CLIENT_ENTRY);
  163. const KNOWN_ASSET_TYPES = [
  164. "apng",
  165. "bmp",
  166. "png",
  167. "jpe?g",
  168. "jfif",
  169. "pjpeg",
  170. "pjp",
  171. "gif",
  172. "svg",
  173. "ico",
  174. "webp",
  175. "avif",
  176. "cur",
  177. "jxl",
  178. "mp4",
  179. "webm",
  180. "ogg",
  181. "mp3",
  182. "wav",
  183. "flac",
  184. "aac",
  185. "opus",
  186. "mov",
  187. "m4a",
  188. "vtt",
  189. "woff2?",
  190. "eot",
  191. "ttf",
  192. "otf",
  193. "webmanifest",
  194. "pdf",
  195. "txt"
  196. ];
  197. const DEFAULT_ASSETS_RE = new RegExp(`\\.(` + KNOWN_ASSET_TYPES.join("|") + `)(\\?.*)?$`, "i");
  198. const DEP_VERSION_RE = /[?&](v=[\w.-]+)\b/;
  199. const loopbackHosts = new Set([
  200. "localhost",
  201. "127.0.0.1",
  202. "::1",
  203. "0000:0000:0000:0000:0000:0000:0000:0001"
  204. ]);
  205. const wildcardHosts = new Set([
  206. "0.0.0.0",
  207. "::",
  208. "0000:0000:0000:0000:0000:0000:0000:0000"
  209. ]);
  210. const DEFAULT_DEV_PORT = 5173;
  211. const DEFAULT_PREVIEW_PORT = 4173;
  212. const DEFAULT_ASSETS_INLINE_LIMIT = 4096;
  213. const defaultAllowedOrigins = /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/;
  214. const METADATA_FILENAME = "_metadata.json";
  215. const ERR_OPTIMIZE_DEPS_PROCESSING_ERROR = "ERR_OPTIMIZE_DEPS_PROCESSING_ERROR";
  216. const ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR = "ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR";
  217. //#endregion
  218. //#region src/node/logger.ts
  219. var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
  220. const LogLevels = {
  221. silent: 0,
  222. error: 1,
  223. warn: 2,
  224. info: 3
  225. };
  226. let lastType;
  227. let lastMsg;
  228. let sameCount = 0;
  229. function clearScreen() {
  230. const repeatCount = process.stdout.rows - 2;
  231. const blank = repeatCount > 0 ? "\n".repeat(repeatCount) : "";
  232. console.log(blank);
  233. readline.cursorTo(process.stdout, 0, 0);
  234. readline.clearScreenDown(process.stdout);
  235. }
  236. let timeFormatter;
  237. function getTimeFormatter() {
  238. timeFormatter ??= new Intl.DateTimeFormat(void 0, {
  239. hour: "numeric",
  240. minute: "numeric",
  241. second: "numeric"
  242. });
  243. return timeFormatter;
  244. }
  245. function createLogger(level = "info", options = {}) {
  246. if (options.customLogger) return options.customLogger;
  247. const loggedErrors = /* @__PURE__ */ new WeakSet();
  248. const { prefix = "[vite]", allowClearScreen = true, console: console$1 = globalThis.console } = options;
  249. const thresh = LogLevels[level];
  250. const canClearScreen = allowClearScreen && process.stdout.isTTY && !process.env.CI;
  251. const clear = canClearScreen ? clearScreen : () => {};
  252. function format(type, msg, options$1 = {}) {
  253. if (options$1.timestamp) {
  254. let tag = "";
  255. if (type === "info") tag = import_picocolors.default.cyan(import_picocolors.default.bold(prefix));
  256. else if (type === "warn") tag = import_picocolors.default.yellow(import_picocolors.default.bold(prefix));
  257. else tag = import_picocolors.default.red(import_picocolors.default.bold(prefix));
  258. const environment = options$1.environment ? options$1.environment + " " : "";
  259. return `${import_picocolors.default.dim(getTimeFormatter().format(/* @__PURE__ */ new Date()))} ${tag} ${environment}${msg}`;
  260. } else return msg;
  261. }
  262. function output(type, msg, options$1 = {}) {
  263. if (thresh >= LogLevels[type]) {
  264. const method = type === "info" ? "log" : type;
  265. if (options$1.error) loggedErrors.add(options$1.error);
  266. if (canClearScreen) if (type === lastType && msg === lastMsg) {
  267. sameCount++;
  268. clear();
  269. console$1[method](format(type, msg, options$1), import_picocolors.default.yellow(`(x${sameCount + 1})`));
  270. } else {
  271. sameCount = 0;
  272. lastMsg = msg;
  273. lastType = type;
  274. if (options$1.clear) clear();
  275. console$1[method](format(type, msg, options$1));
  276. }
  277. else console$1[method](format(type, msg, options$1));
  278. }
  279. }
  280. const warnedMessages = /* @__PURE__ */ new Set();
  281. const logger = {
  282. hasWarned: false,
  283. info(msg, opts) {
  284. output("info", msg, opts);
  285. },
  286. warn(msg, opts) {
  287. logger.hasWarned = true;
  288. output("warn", msg, opts);
  289. },
  290. warnOnce(msg, opts) {
  291. if (warnedMessages.has(msg)) return;
  292. logger.hasWarned = true;
  293. output("warn", msg, opts);
  294. warnedMessages.add(msg);
  295. },
  296. error(msg, opts) {
  297. logger.hasWarned = true;
  298. output("error", msg, opts);
  299. },
  300. clearScreen(type) {
  301. if (thresh >= LogLevels[type]) clear();
  302. },
  303. hasErrorLogged(error) {
  304. return loggedErrors.has(error);
  305. }
  306. };
  307. return logger;
  308. }
  309. function printServerUrls(urls, optionsHost, info) {
  310. const colorUrl = (url) => import_picocolors.default.cyan(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
  311. for (const url of urls.local) info(` ${import_picocolors.default.green("➜")} ${import_picocolors.default.bold("Local")}: ${colorUrl(url)}`);
  312. for (const url of urls.network) info(` ${import_picocolors.default.green("➜")} ${import_picocolors.default.bold("Network")}: ${colorUrl(url)}`);
  313. if (urls.network.length === 0 && optionsHost === void 0) info(import_picocolors.default.dim(` ${import_picocolors.default.green("➜")} ${import_picocolors.default.bold("Network")}: use `) + import_picocolors.default.bold("--host") + import_picocolors.default.dim(" to expose"));
  314. }
  315. //#endregion
  316. export { CLIENT_DIR, CLIENT_ENTRY, CLIENT_PUBLIC_PATH, CSS_LANGS_RE, DEFAULT_ASSETS_INLINE_LIMIT, DEFAULT_ASSETS_RE, DEFAULT_CLIENT_CONDITIONS, DEFAULT_CLIENT_MAIN_FIELDS, DEFAULT_CONFIG_FILES, DEFAULT_DEV_PORT, DEFAULT_EXTERNAL_CONDITIONS, DEFAULT_PREVIEW_PORT, DEFAULT_SERVER_CONDITIONS, DEFAULT_SERVER_MAIN_FIELDS, DEP_VERSION_RE, DEV_PROD_CONDITION, ENV_ENTRY, ENV_PUBLIC_PATH, ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR, ERR_OPTIMIZE_DEPS_PROCESSING_ERROR, ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET, FS_PREFIX, JS_TYPES_RE, KNOWN_ASSET_TYPES, LogLevels, METADATA_FILENAME, OPTIMIZABLE_ENTRY_RE, ROLLUP_HOOKS, SPECIAL_QUERY_RE, VERSION, VITE_PACKAGE_DIR, createLogger, defaultAllowedOrigins, loopbackHosts, printServerUrls, require_picocolors, wildcardHosts };