{"version":3,"file":"format.cjs","names":[],"sources":["../src/format.ts"],"sourcesContent":["import type { core } from \"zod\";\nimport type { GuardFail } from \"./guard\";\nimport type { StandardValidationIssue } from \"./types\";\n\nexport function formatZodError(issues: core.$ZodIssue[]): string {\n  return issues\n    .map((issue) => {\n      const path = issue.path.length > 0 ? issue.path.join(\".\") : \"(root)\";\n      return `  \\x1B[31m✗\\x1B[0m ${path.padEnd(28)} ${issue.message}`;\n    })\n    .join(\"\\n\");\n}\n\nexport function formatStandardSchemaError(issues: StandardValidationIssue[]): string {\n  return issues\n    .map((issue) => {\n      const path =\n        issue.path.length > 0\n          ? issue.path\n              .map((seg) =>\n                typeof seg === \"object\" && seg !== null && \"key\" in seg\n                  ? String(seg.key)\n                  : String(seg),\n              )\n              .join(\".\")\n          : \"(root)\";\n      return `  \\x1B[31m✗\\x1B[0m ${path.padEnd(28)} ${issue.message}`;\n    })\n    .join(\"\\n\");\n}\n\nconst YELLOW = \"\\x1B[33m\";\nconst BOLD_YELLOW = \"\\x1B[1;33m\";\nconst CYAN = \"\\x1B[36m\";\nconst RESET = \"\\x1B[0m\";\n\nconst BOX_WIDTH = 66;\n// 1 left border + 2 left spaces + content + 1 right border = BOX_WIDTH\n// content area = BOX_WIDTH - 4\nconst CONTENT_AREA = BOX_WIDTH - 4;\n\n/** Maximum visible character length for an importer path inside the warning box. */\nexport const IMPORTER_MAX_LEN = CONTENT_AREA - \"Found in: \".length;\n\n/**\n * Truncates an importer path to fit within maxLen visible characters.\n * Adds a leading '…' when truncation occurs so the rightmost (most specific) part is preserved.\n */\nexport function truncateImporter(importerPath: string, maxLen: number): string {\n  if (importerPath.length <= maxLen) return importerPath;\n  return `\\u2026${importerPath.slice(-(maxLen - 1))}`;\n}\n\nfunction boxTop(): string {\n  return `${YELLOW}\\u250C${\"─\".repeat(BOX_WIDTH - 2)}\\u2510${RESET}`;\n}\n\nfunction boxBottom(): string {\n  return `${YELLOW}\\u2514${\"─\".repeat(BOX_WIDTH - 2)}\\u2518${RESET}`;\n}\n\nfunction boxLine(visibleText: string, renderedText = visibleText): string {\n  const rightPad = \" \".repeat(Math.max(0, CONTENT_AREA - visibleText.length));\n  return `${YELLOW}\\u2502${RESET}  ${renderedText}${rightPad}${YELLOW}\\u2502${RESET}`;\n}\n\n/**\n * Renders the colored terminal warning box for 'warn' mode.\n * Every line is exactly 66 characters wide (visible chars, excluding ANSI codes),\n * assuming Vite environment names are short (≤19 chars). Longer names will extend\n * the line beyond 66 chars without crashing — Math.max(0) prevents negative padding.\n * Use in logger.warn() calls — not in log files.\n */\nexport function formatGuardWarning(fail: GuardFail): string {\n  const importerDisplay =\n    fail.importer === undefined ? \"(unknown)\" : truncateImporter(fail.importer, IMPORTER_MAX_LEN);\n\n  const warnTitle = \"To enforce now:  onClientAccessOfServerModule: 'error'\";\n  const stubTitle = \"To silence:      onClientAccessOfServerModule: 'stub'\";\n\n  return [\n    boxTop(),\n    boxLine(\n      \"[vite-env] DEPRECATION WARNING\",\n      `${BOLD_YELLOW}[vite-env] DEPRECATION WARNING${RESET}`,\n    ),\n    boxLine(\"\"),\n    boxLine(`virtual:env/server was imported from the \"${fail.envName}\"`),\n    boxLine(\"environment. This will be a hard build error in 1.0.0.\"),\n    boxLine(\"\"),\n    boxLine(warnTitle, `To enforce now:  ${CYAN}onClientAccessOfServerModule: 'error'${RESET}`),\n    boxLine(stubTitle, `To silence:      ${CYAN}onClientAccessOfServerModule: 'stub'${RESET}`),\n    boxLine(\"\"),\n    boxLine(`Found in: ${importerDisplay}`),\n    boxBottom(),\n  ].join(\"\\n\");\n}\n\n/**\n * Renders the plain-text hard error message thrown in 'error' mode.\n * No ANSI — thrown as an Error message, not printed via logger.\n */\nexport function formatHardError(fail: GuardFail): string {\n  const importerLine = fail.importer ?? \"(unknown)\";\n  return [\n    `[vite-env] virtual:env/server is not available in the \"${fail.envName}\" environment.`,\n    ``,\n    `  Server-only modules cannot be imported from client code.`,\n    `  Add this environment to serverEnvironments if intentional:`,\n    ``,\n    `    ViteEnv({ serverEnvironments: ['ssr', '${fail.envName}'] })`,\n    ``,\n    `  Or change enforcement:`,\n    ``,\n    `    ViteEnv({ onClientAccessOfServerModule: 'stub' })`,\n    ``,\n    `  Imported from: ${importerLine}`,\n  ].join(\"\\n\");\n}\n\n/**\n * Renders a single ANSI-free log entry for vite-env-warnings.log.\n * Uses the same (unknown) convention as formatGuardWarning for missing importers.\n */\nexport function formatGuardLogEntry(fail: GuardFail, timestamp: string): string {\n  const importerLine = fail.importer ?? \"(unknown)\";\n  return [\n    `[${timestamp}] virtual:env/server accessed from \"${fail.envName}\" environment`,\n    `  Importer: ${importerLine}`,\n  ].join(\"\\n\");\n}\n"],"mappings":";;AAIA,SAAgB,eAAe,QAAkC;AAC/D,QAAO,OACJ,KAAK,UAAU;AAEd,SAAO,uBADM,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,KAAK,IAAI,GAAG,UAC1B,OAAO,GAAG,CAAC,GAAG,MAAM;GACtD,CACD,KAAK,KAAK;;AAGf,SAAgB,0BAA0B,QAA2C;AACnF,QAAO,OACJ,KAAK,UAAU;AAWd,SAAO,uBATL,MAAM,KAAK,SAAS,IAChB,MAAM,KACH,KAAK,QACJ,OAAO,QAAQ,YAAY,QAAQ,QAAQ,SAAS,MAChD,OAAO,IAAI,IAAI,GACf,OAAO,IAAI,CAChB,CACA,KAAK,IAAI,GACZ,UAC4B,OAAO,GAAG,CAAC,GAAG,MAAM;GACtD,CACD,KAAK,KAAK;;AAGf,MAAM,SAAS;AACf,MAAM,cAAc;AACpB,MAAM,OAAO;AACb,MAAM,QAAQ;AAEd,MAAM,YAAY;AAGlB,MAAM,eAAe,YAAY;;AAGjC,MAAa,mBAAmB,eAAe;;;;;AAM/C,SAAgB,iBAAiB,cAAsB,QAAwB;AAC7E,KAAI,aAAa,UAAU,OAAQ,QAAO;AAC1C,QAAO,SAAS,aAAa,MAAM,EAAE,SAAS,GAAG;;AAGnD,SAAS,SAAiB;AACxB,QAAO,GAAG,OAA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