{"version":3,"file":"dev-mode.cjs","names":[],"sources":["../../src/utils/dev-mode.ts"],"sourcesContent":["/**\n * {@link isDevBuild} stays internal, imported by path (`../utils/dev-mode`)\n * rather than through the `utils` barrel: re-exporting it would make a one-line\n * env read part of the package's public API, with the semver weight that\n * carries, for something no consumer asked for. Every dev-only diagnostic in\n * the SDK routes through it — `grep -rn \"dev-mode\" src/` for the current list,\n * which an enumeration written here would only drift away from.\n *\n * {@link setDevBuild} is public, because a context nothing compiles cannot be\n * detected from the inside. See its doc for when that is.\n */\n\n/**\n * Whether the consuming app was built for development.\n *\n * Reads `process.env.NODE_ENV`, which every supported bundler replaces with a\n * literal **while building the app** — Vite included. That last word is a\n * correction: this doc used to claim Vite substitutes neither half, so every\n * dev-only diagnostic in the SDK was unreachable under `vite dev`. Measured on\n * 2026-09-07 with 0.61.0 installed into a probe app, both from a packed tarball\n * (a real copy under `node_modules`, which Vite pre-bundles) and from a `file:`\n * link (a symlink it does not), reading back the module the dev server actually\n * served:\n *\n * | Vite | `vite dev` | `vite build` |\n * | --- | --- | --- |\n * | 5.4.21, 6.4.3, 7.3.6 | folded to `true` | folded to `false` |\n * | 8.2.2 | `\"development\" !== \"production\"` | folded to `false` |\n *\n * So this answers correctly in a Vite app on its own, in development and in\n * production, pre-bundled or served through the dev server's transform. The\n * wrong belief survived releases because nobody read the served module — the\n * expression is not substituted in a *browser console*, which is where it is\n * natural to go looking.\n *\n * `import.meta.env.DEV` still cannot be used here: Vite would replace it while\n * building *this package*, so the published artifact would carry the constant\n * and every guard behind it would be dead code no app could switch back on.\n *\n * The expression is written out in full, and the failure is caught rather than\n * guarded against. A `typeof process === \"undefined\"` check would read as the\n * careful version and quietly break the environments that work: substitution\n * replaces the member expression `process.env.NODE_ENV` and nothing else, so\n * the guard would return early in front of a literal that had already been\n * swapped in. The identifier itself never exists at runtime — `typeof process`\n * is `\"undefined\"` in the page, measured in the same probe — which is exactly\n * why the read is wrapped in `try` instead.\n *\n * Returns `false` when the read throws, which is the context nothing\n * transformed: a raw service-worker script, a plain `<script type=\"module\">`, a\n * bundler substituting nothing. Staying quiet there is deliberate — a dev-only\n * warning that cannot prove it is in development is better silent than shouting\n * in someone's production console.\n *\n * {@link setDevBuild} overrides all of it and is checked first.\n *\n * @returns Whether development-only diagnostics should run.\n *\n * @example\n * if (isDevBuild()) console.warn(\"[my-app] this prop combination does nothing\");\n *\n * @tempest-limits empty-catch — the only thing the read can throw is the\n * environment answering \"not defined\", which is the return value, not an error\n * worth reporting. Logging it would print on every call in exactly the context\n * that has nowhere to print.\n */\nlet configuredDevBuild: boolean | undefined;\n\n/**\n * Tell the SDK whether the app around it was built for development.\n *\n * Call it once, at bootstrap, from a context {@link isDevBuild} cannot read:\n *\n * ```ts\n * import { setDevBuild } from \"tempest-react-sdk\";\n *\n * setDevBuild(import.meta.env.DEV);\n * ```\n *\n * **When you need it.** Not for an ordinary Vite, webpack, Rspack or Parcel\n * app: all of them substitute `process.env.NODE_ENV` while building the app, so\n * the automatic read already answers correctly there — measured for Vite 5\n * through 8 in {@link isDevBuild}, whose doc carries the table. What is left is\n * the context nothing compiles or nothing configures:\n *\n * - code no bundler transformed — a raw service-worker script registered as a\n *   file of its own, a plain `<script type=\"module\">`;\n * - a staging or QA build that never sets `NODE_ENV=production`, where the\n *   automatic answer is `true` and `parseResponse` would put the raw response\n *   payload in an error string seen by real users. `setDevBuild(false)` closes\n *   that;\n * - a test that wants the other branch, and puts it back on the way out.\n *\n * `import.meta.env.DEV` cannot be read by the SDK on your behalf, which is why\n * the signal is a parameter: Vite would replace it while building *this\n * package*, and the published artifact would ship the constant.\n *\n * The default stays `false` when the read throws. `parseResponse` puts the raw\n * response payload in its message when this is on, so guessing `true` in a\n * context that cannot prove it leaks a payload into a production error string.\n * Silence is the safe default; the report is one line away for anyone who wants\n * it.\n *\n * Passing `undefined` clears the override and returns to automatic detection,\n * which is what a test that set it should do on the way out.\n *\n * @param value - `true` for a development build, `false` for production,\n *     `undefined` to go back to detecting it.\n *\n * @example\n * // A service worker, or any context no bundler transformed\n * setDevBuild(false);\n *\n * @example\n * // A test that flips it, and puts it back\n * afterEach(() => setDevBuild(undefined));\n */\nexport function setDevBuild(value: boolean | undefined): void {\n    configuredDevBuild = value;\n}\n\nexport function isDevBuild(): boolean {\n    if (configuredDevBuild !== undefined) return configuredDevBuild;\n    try {\n        return process.env.NODE_ENV !== \"production\";\n    } catch {\n        return false;\n    }\n}\n"],"mappings":"AAkEA,IAAI,EAmDJ,SAAgB,EAAY,EAAkC,CAC1D,EAAqB,CACzB,CAEA,SAAgB,GAAsB,CAClC,GAAI,IAAuB,IAAA,GAAW,OAAO,EAC7C,GAAI,CACA,OAAA,QAAA,IAAA,WAAgC,YACpC,MAAQ,CACJ,MAAO,EACX,CACJ"}