@warlock.js/core 5.3.1 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/esm/cli/cli-commands.manager.mjs +2 -0
  3. package/esm/cli/cli-commands.manager.mjs.map +1 -1
  4. package/esm/cli/cli-commands.utils.mjs +27 -9
  5. package/esm/cli/cli-commands.utils.mjs.map +1 -1
  6. package/esm/connectors/http-connector.d.mts.map +1 -1
  7. package/esm/connectors/http-connector.mjs +26 -4
  8. package/esm/connectors/http-connector.mjs.map +1 -1
  9. package/esm/database/create-database-action.mjs.map +1 -1
  10. package/esm/database/drop-tables-action.mjs.map +1 -1
  11. package/esm/database/migrate-action.mjs.map +1 -1
  12. package/esm/database/seed-command-action.mjs.map +1 -1
  13. package/esm/database/seeds/seeders.manager.mjs.map +1 -1
  14. package/esm/dev-server/boot-precondition-error.mjs +35 -0
  15. package/esm/dev-server/boot-precondition-error.mjs.map +1 -0
  16. package/esm/dev-server/development-server.mjs +6 -1
  17. package/esm/dev-server/development-server.mjs.map +1 -1
  18. package/esm/dev-server/files-orchestrator.mjs.map +1 -1
  19. package/esm/dev-server/health-checker/checkers/eslint-health-checker.mjs.map +1 -1
  20. package/esm/dev-server/health-checker/checkers/typescript-health-checker.mjs.map +1 -1
  21. package/esm/dev-server/shortcuts.mjs +27 -6
  22. package/esm/dev-server/shortcuts.mjs.map +1 -1
  23. package/esm/dev-server/start-development-server.mjs +3 -1
  24. package/esm/dev-server/start-development-server.mjs.map +1 -1
  25. package/esm/dev-server/supervisor.mjs +15 -0
  26. package/esm/dev-server/supervisor.mjs.map +1 -1
  27. package/esm/generations/add-command.action.mjs.map +1 -1
  28. package/esm/generations/features/access.feature.mjs.map +1 -1
  29. package/esm/generations/features/ai-anthropic.feature.mjs.map +1 -1
  30. package/esm/generations/features/ai-bedrock.feature.mjs.map +1 -1
  31. package/esm/generations/features/ai-google.feature.mjs.map +1 -1
  32. package/esm/generations/features/ai-ollama.feature.mjs.map +1 -1
  33. package/esm/generations/features/ai-openai.feature.mjs.map +1 -1
  34. package/esm/generations/features/ai-panoptic.feature.mjs.map +1 -1
  35. package/esm/generations/features/ai-tools.feature.mjs.map +1 -1
  36. package/esm/generations/features/ai-workspace.feature.mjs.map +1 -1
  37. package/esm/generations/features/ai.feature.mjs.map +1 -1
  38. package/esm/generations/features/herald.feature.mjs.map +1 -1
  39. package/esm/generations/features/image.feature.mjs.map +1 -1
  40. package/esm/generations/features/index.mjs.map +1 -1
  41. package/esm/generations/features/mail.feature.mjs.map +1 -1
  42. package/esm/generations/features/mongodb.feature.mjs.map +1 -1
  43. package/esm/generations/features/mysql.feature.mjs.map +1 -1
  44. package/esm/generations/features/notifications.feature.mjs.map +1 -1
  45. package/esm/generations/features/postgres.feature.mjs.map +1 -1
  46. package/esm/generations/features/react-email.feature.mjs +3 -9
  47. package/esm/generations/features/react-email.feature.mjs.map +1 -1
  48. package/esm/generations/features/react.feature.mjs.map +1 -1
  49. package/esm/generations/features/redis.feature.mjs.map +1 -1
  50. package/esm/generations/features/s3.feature.mjs.map +1 -1
  51. package/esm/generations/features/scheduler.feature.mjs.map +1 -1
  52. package/esm/generations/features/ses.feature.mjs.map +1 -1
  53. package/esm/generations/features/shadcn.feature.mjs.map +1 -1
  54. package/esm/generations/features/shared/patch-tsconfig-include.mjs +85 -0
  55. package/esm/generations/features/shared/patch-tsconfig-include.mjs.map +1 -0
  56. package/esm/generations/features/shared/relocate-conflicting-home-route.mjs +153 -0
  57. package/esm/generations/features/shared/relocate-conflicting-home-route.mjs.map +1 -0
  58. package/esm/generations/features/socket.feature.mjs.map +1 -1
  59. package/esm/generations/features/tailwind.feature.mjs.map +1 -1
  60. package/esm/generations/features/test.feature.mjs.map +1 -1
  61. package/esm/generations/features/types.mjs.map +1 -1
  62. package/esm/generations/features/web.feature.mjs +4 -89
  63. package/esm/generations/features/web.feature.mjs.map +1 -1
  64. package/esm/generations/stubs.mjs +59 -19
  65. package/esm/generations/stubs.mjs.map +1 -1
  66. package/esm/http/boot-port-preflight.d.mts.map +1 -1
  67. package/esm/http/boot-port-preflight.mjs +17 -3
  68. package/esm/http/boot-port-preflight.mjs.map +1 -1
  69. package/esm/http/resolve-bind-port.mjs +51 -0
  70. package/esm/http/resolve-bind-port.mjs.map +1 -0
  71. package/esm/tests/test-helpers.d.mts.map +1 -1
  72. package/esm/tests/test-helpers.mjs +4 -1
  73. package/esm/tests/test-helpers.mjs.map +1 -1
  74. package/esm/utils/detect-environment-overrides.mjs +67 -0
  75. package/esm/utils/detect-environment-overrides.mjs.map +1 -0
  76. package/esm/utils/load-environment.mjs +24 -0
  77. package/esm/utils/load-environment.mjs.map +1 -1
  78. package/esm/utils/report-environment-overrides.mjs +30 -0
  79. package/esm/utils/report-environment-overrides.mjs.map +1 -0
  80. package/esm/validation/types.d.mts +4 -1
  81. package/esm/validation/types.d.mts.map +1 -1
  82. package/llms-full.txt +10 -2
  83. package/package.json +12 -12
  84. package/skills/run-app/SKILL.md +10 -2
@@ -1 +1 @@
1
- {"version":3,"file":"boot-port-preflight.mjs","names":[],"sources":["../../../../../../../core/src/http/boot-port-preflight.ts"],"sourcesContent":["import config from \"@mongez/config\";\nimport { assertPortIsAvailable, PortInUseError } from \"./port-preflight\";\n\n/**\n * Host used when `http.host` is unset — the same default `HttpConnector`\n * binds with, so the probe tests the address the server will actually take.\n */\nconst DEFAULT_BIND_HOST = \"localhost\";\n\n/**\n * Probe the port declared in `src/config/http.ts`, if there is one.\n *\n * Reads config rather than taking arguments because the only honest answer to\n * \"which port will this boot bind\" lives in the loaded config, and the callers\n * that need this check (the generated production entry) run before anything\n * that could hand it over.\n *\n * A no-op for an app with no `http` config, or an `http.port` that is not a\n * usable port number — those apps never bind, so there is nothing to preflight\n * and nothing to fail on.\n *\n * @throws {PortInUseError} when the configured port is already taken.\n */\nexport async function assertConfiguredHttpPortIsFree(): Promise<void> {\n const httpConfig = config.get(\"http\");\n\n if (!httpConfig) {\n return;\n }\n\n const port = Number(httpConfig.port);\n\n if (!Number.isInteger(port) || port <= 0 || port > 65_535) {\n return;\n }\n\n await assertPortIsAvailable(port, httpConfig.host || DEFAULT_BIND_HOST);\n}\n\n/**\n * Fail the boot immediately, and by name, when the http port is already taken.\n *\n * Called from the generated production entry BEFORE the early-phase connectors,\n * because the port is the cheapest thing in the boot to check and the one most\n * likely to be wrong. `HttpConnector` is a LATE-phase connector, so its own\n * preflight is not reached until the database has connected, the cache has\n * connected and every module of app code has been imported — 7-13 seconds of\n * work, all of it discarded, before anyone learns the port was busy. This check\n * costs a bind-and-release on a socket that is never served.\n *\n * It does NOT replace `HttpConnector`'s preflight: a port can be taken in the\n * seconds between the two, and only the connector's check sits immediately\n * before the real `listen()`. This one exists to make the common case fast and\n * legible.\n *\n * Reports through `console.error` and NOT through `log.fatal`: the logger has\n * no channels yet at this point in the boot (the logger connector is part of\n * the early phase this runs ahead of), so a logged message here would reach\n * nobody. stderr always reaches the terminal, and `warlock start` forwards the\n * child's stderr verbatim.\n *\n * A probe that fails for any OTHER reason is deliberately swallowed: this is a\n * fast-fail convenience, and it must never be the thing that stops an app which\n * would otherwise have booted. `HttpConnector` still runs the real check.\n */\nexport async function preflightConfiguredHttpPort(): Promise<void> {\n try {\n await assertConfiguredHttpPortIsFree();\n } catch (error) {\n if (!(error instanceof PortInUseError)) {\n return;\n }\n\n reportPortInUse(error);\n\n process.exit(1);\n }\n}\n\n/**\n * Print the collision the way the developer needs to read it: the errno they\n * grep for, the port and host by name, and the command that names the process\n * holding it — the supervisor cannot discover the owning PID for them, but it\n * can hand them the one line that will.\n */\nfunction reportPortInUse(error: PortInUseError): void {\n const ownerCommand =\n process.platform === \"win32\"\n ? `netstat -ano | findstr :${error.port}`\n : `lsof -i :${error.port}`;\n\n const lines = [\n \"\",\n ` ✖ EADDRINUSE: port ${error.port} is already in use on ${error.host}`,\n ` the application cannot start because something else is already listening there.`,\n ` find the owning process: ${ownerCommand}`,\n ` then stop it, or change http.port in src/config/http.ts and rebuild.`,\n \"\",\n ];\n\n for (const line of lines) {\n console.error(line);\n }\n}\n"],"mappings":";;;;;;;;AAOA,MAAM,oBAAoB;;;;;;;;;;;;;;;AAgB1B,eAAsB,iCAAgD;CACpE,MAAM,aAAa,OAAO,IAAI,MAAM;CAEpC,IAAI,CAAC,YACH;CAGF,MAAM,OAAO,OAAO,WAAW,IAAI;CAEnC,IAAI,CAAC,OAAO,UAAU,IAAI,KAAK,QAAQ,KAAK,OAAO,OACjD;CAGF,MAAM,sBAAsB,MAAM,WAAW,QAAQ,iBAAiB;AACxE;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,eAAsB,8BAA6C;CACjE,IAAI;EACF,MAAM,+BAA+B;CACvC,SAAS,OAAO;EACd,IAAI,EAAE,iBAAiB,iBACrB;EAGF,gBAAgB,KAAK;EAErB,QAAQ,KAAK,CAAC;CAChB;AACF;;;;;;;AAQA,SAAS,gBAAgB,OAA6B;CACpD,MAAM,eACJ,QAAQ,aAAa,UACjB,2BAA2B,MAAM,SACjC,YAAY,MAAM;CAExB,MAAM,QAAQ;EACZ;EACA,wBAAwB,MAAM,KAAK,wBAAwB,MAAM;EACjE;EACA,8BAA8B;EAC9B;EACA;CACF;CAEA,KAAK,MAAM,QAAQ,OACjB,QAAQ,MAAM,IAAI;AAEtB"}
1
+ {"version":3,"file":"boot-port-preflight.mjs","names":[],"sources":["../../../../../../../core/src/http/boot-port-preflight.ts"],"sourcesContent":["import config from \"@mongez/config\";\nimport { assertPortIsAvailable, PortInUseError } from \"./port-preflight\";\nimport { resolveBindPort } from \"./resolve-bind-port\";\n\n/**\n * Mirrors `dev-server/supervisor.ts`'s `BOOT_PRECONDITION_EXIT_CODE`. Kept as\n * its own literal here (rather than imported) so this file — reached by both\n * the dev-preload path and the generated, standalone production entry — never\n * pulls dev-server's supervisor module (child_process, TTY handling, ...)\n * into a production bundle that has no supervisor at all. EX_CONFIG.\n */\nconst BOOT_PRECONDITION_EXIT_CODE = 78;\n\n/**\n * Host used when `http.host` is unset — the same default `HttpConnector`\n * binds with, so the probe tests the address the server will actually take.\n */\nconst DEFAULT_BIND_HOST = \"localhost\";\n\n/**\n * Probe the port declared in `src/config/http.ts`, if there is one.\n *\n * Reads config rather than taking arguments because the only honest answer to\n * \"which port will this boot bind\" lives in the loaded config, and the callers\n * that need this check (the generated production entry) run before anything\n * that could hand it over.\n *\n * A no-op for an app with no `http` config, or an `http.port` that is not a\n * usable port number — those apps never bind, so there is nothing to preflight\n * and nothing to fail on.\n *\n * @throws {PortInUseError} when the configured port is already taken.\n */\nexport async function assertConfiguredHttpPortIsFree(): Promise<void> {\n const httpConfig = config.get(\"http\");\n\n if (!httpConfig) {\n return;\n }\n\n // This runs BEFORE the connectors in the generated production entry, and\n // `preflightConfiguredHttpPort()` below only exits on `PortInUseError` —\n // any other throw is swallowed there. So a bad port must not throw HERE:\n // it stays a no-op, exactly like the previous hand-rolled coercion, and\n // `HttpConnector` (which now also calls `resolveBindPort`) is the one that\n // reports it, a moment later, with a channel a developer will actually see.\n let port: number;\n\n try {\n port = resolveBindPort(httpConfig.port);\n } catch {\n return;\n }\n\n // Port 0 asks the OS to pick a free one, so there is nothing to preflight:\n // probing 0 binds SOME unrelated ephemeral port and \"passes\" without proving\n // anything about the port this boot will end up on. The hand-rolled coercion\n // this replaced skipped 0 by rejecting `port <= 0`; `resolveBindPort` accepts\n // 0 as a legitimate TCP value, so the skip has to be stated here instead of\n // falling out of a range check.\n if (port === 0) {\n return;\n }\n\n await assertPortIsAvailable(port, httpConfig.host || DEFAULT_BIND_HOST);\n}\n\n/**\n * Fail the boot immediately, and by name, when the http port is already taken.\n *\n * Called from the generated production entry BEFORE the early-phase connectors,\n * because the port is the cheapest thing in the boot to check and the one most\n * likely to be wrong. `HttpConnector` is a LATE-phase connector, so its own\n * preflight is not reached until the database has connected, the cache has\n * connected and every module of app code has been imported — 7-13 seconds of\n * work, all of it discarded, before anyone learns the port was busy. This check\n * costs a bind-and-release on a socket that is never served.\n *\n * It does NOT replace `HttpConnector`'s preflight: a port can be taken in the\n * seconds between the two, and only the connector's check sits immediately\n * before the real `listen()`. This one exists to make the common case fast and\n * legible.\n *\n * Reports through `console.error` and NOT through `log.fatal`: the logger has\n * no channels yet at this point in the boot (the logger connector is part of\n * the early phase this runs ahead of), so a logged message here would reach\n * nobody. stderr always reaches the terminal, and `warlock start` forwards the\n * child's stderr verbatim.\n *\n * A probe that fails for any OTHER reason is deliberately swallowed: this is a\n * fast-fail convenience, and it must never be the thing that stops an app which\n * would otherwise have booted. `HttpConnector` still runs the real check.\n */\nexport async function preflightConfiguredHttpPort(): Promise<void> {\n try {\n await assertConfiguredHttpPortIsFree();\n } catch (error) {\n if (!(error instanceof PortInUseError)) {\n return;\n }\n\n reportPortInUse(error);\n\n process.exit(BOOT_PRECONDITION_EXIT_CODE);\n }\n}\n\n/**\n * Print the collision the way the developer needs to read it: the errno they\n * grep for, the port and host by name, and the command that names the process\n * holding it — the supervisor cannot discover the owning PID for them, but it\n * can hand them the one line that will.\n */\nfunction reportPortInUse(error: PortInUseError): void {\n const ownerCommand =\n process.platform === \"win32\"\n ? `netstat -ano | findstr :${error.port}`\n : `lsof -i :${error.port}`;\n\n const lines = [\n \"\",\n ` ✖ EADDRINUSE: port ${error.port} is already in use on ${error.host}`,\n ` the application cannot start because something else is already listening there.`,\n ` find the owning process: ${ownerCommand}`,\n ` then stop it, or change http.port in src/config/http.ts and rebuild.`,\n \"\",\n ];\n\n for (const line of lines) {\n console.error(line);\n }\n}\n"],"mappings":";;;;;;;;;;;;AAWA,MAAM,8BAA8B;;;;;AAMpC,MAAM,oBAAoB;;;;;;;;;;;;;;;AAgB1B,eAAsB,iCAAgD;CACpE,MAAM,aAAa,OAAO,IAAI,MAAM;CAEpC,IAAI,CAAC,YACH;CASF,IAAI;CAEJ,IAAI;EACF,OAAO,gBAAgB,WAAW,IAAI;CACxC,QAAQ;EACN;CACF;CAQA,IAAI,SAAS,GACX;CAGF,MAAM,sBAAsB,MAAM,WAAW,QAAQ,iBAAiB;AACxE;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,eAAsB,8BAA6C;CACjE,IAAI;EACF,MAAM,+BAA+B;CACvC,SAAS,OAAO;EACd,IAAI,EAAE,iBAAiB,iBACrB;EAGF,gBAAgB,KAAK;EAErB,QAAQ,KAAK,2BAA2B;CAC1C;AACF;;;;;;;AAQA,SAAS,gBAAgB,OAA6B;CACpD,MAAM,eACJ,QAAQ,aAAa,UACjB,2BAA2B,MAAM,SACjC,YAAY,MAAM;CAExB,MAAM,QAAQ;EACZ;EACA,wBAAwB,MAAM,KAAK,wBAAwB,MAAM;EACjE;EACA,8BAA8B;EAC9B;EACA;CACF;CAEA,KAAK,MAAM,QAAQ,OACjB,QAAQ,MAAM,IAAI;AAEtB"}
@@ -0,0 +1,51 @@
1
+ import { defaultHttpConfigurations } from "./config.mjs";
2
+
3
+ //#region ../core/src/http/resolve-bind-port.ts
4
+ /**
5
+ * Fallback used only if `defaultHttpConfigurations.port` is ever unset —
6
+ * `HttpConfigurations.port` is typed optional for consumers, but the
7
+ * framework's own default configuration always declares one. Keeps
8
+ * `resolveBindPort`'s return type a plain `number` without an `as`.
9
+ */
10
+ const FALLBACK_PORT = 3e3;
11
+ /**
12
+ * Resolve a raw, possibly-stringy `http.port` value into the number the
13
+ * socket layer will actually bind.
14
+ *
15
+ * `env()` only coerces a `.env` value to a number when it round-trips
16
+ * exactly (`String(Number(v)) === v`), so values like `"03999"`, `" 3999"`,
17
+ * `"+3999"` or `"1e3"` arrive here as strings. `net.Server.listen({ port })`
18
+ * happily accepts every one of those and binds SOMETHING — `"1e3"` binds
19
+ * port 1000 with no diagnostic anywhere — so this is the one place the
20
+ * configured port is turned into a canonical integer before anything binds,
21
+ * logs, or reports it.
22
+ *
23
+ * `undefined`/`null` (no `http.port` configured at all) resolves to the
24
+ * framework default rather than throwing — that case is not misconfiguration.
25
+ *
26
+ * @throws {Error} when the raw value cannot be resolved to a usable TCP port
27
+ * (0-65535, finite integer) — naming the raw value and where to fix it.
28
+ */
29
+ function resolveBindPort(rawPort) {
30
+ if (rawPort === void 0 || rawPort === null) return defaultHttpConfigurations.port ?? FALLBACK_PORT;
31
+ const resolved = Number(String(rawPort).trim());
32
+ if (!Number.isInteger(resolved) || resolved < 0 || resolved > 65535) throw new Error(`Invalid http port ${JSON.stringify(rawPort)}: it does not resolve to a usable TCP port (0-65535, whole number). Fix HTTP_PORT in .env, or http.port in src/config/http.ts.`);
33
+ return resolved;
34
+ }
35
+ /**
36
+ * Whether `rawPort` was already the canonical value `resolveBindPort`
37
+ * returned for it — i.e. nothing needed normalising.
38
+ *
39
+ * Lets a caller print exactly one notice when the configured port and the
40
+ * bound port differ in representation (`"03999"` -> `3999`), and stay silent
41
+ * for the ordinary case (a plain number, or a string that was already
42
+ * canonical).
43
+ */
44
+ function isCanonicalPortValue(rawPort, resolved) {
45
+ if (typeof rawPort === "number" || rawPort === void 0 || rawPort === null) return true;
46
+ return String(rawPort) === String(resolved);
47
+ }
48
+
49
+ //#endregion
50
+ export { isCanonicalPortValue, resolveBindPort };
51
+ //# sourceMappingURL=resolve-bind-port.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-bind-port.mjs","names":[],"sources":["../../../../../../../core/src/http/resolve-bind-port.ts"],"sourcesContent":["import { defaultHttpConfigurations } from \"./config\";\n\n/**\n * Fallback used only if `defaultHttpConfigurations.port` is ever unset —\n * `HttpConfigurations.port` is typed optional for consumers, but the\n * framework's own default configuration always declares one. Keeps\n * `resolveBindPort`'s return type a plain `number` without an `as`.\n */\nconst FALLBACK_PORT = 3000;\n\n/**\n * Resolve a raw, possibly-stringy `http.port` value into the number the\n * socket layer will actually bind.\n *\n * `env()` only coerces a `.env` value to a number when it round-trips\n * exactly (`String(Number(v)) === v`), so values like `\"03999\"`, `\" 3999\"`,\n * `\"+3999\"` or `\"1e3\"` arrive here as strings. `net.Server.listen({ port })`\n * happily accepts every one of those and binds SOMETHING — `\"1e3\"` binds\n * port 1000 with no diagnostic anywhere — so this is the one place the\n * configured port is turned into a canonical integer before anything binds,\n * logs, or reports it.\n *\n * `undefined`/`null` (no `http.port` configured at all) resolves to the\n * framework default rather than throwing — that case is not misconfiguration.\n *\n * @throws {Error} when the raw value cannot be resolved to a usable TCP port\n * (0-65535, finite integer) — naming the raw value and where to fix it.\n */\nexport function resolveBindPort(rawPort: unknown): number {\n if (rawPort === undefined || rawPort === null) {\n return defaultHttpConfigurations.port ?? FALLBACK_PORT;\n }\n\n const resolved = Number(String(rawPort).trim());\n\n if (!Number.isInteger(resolved) || resolved < 0 || resolved > 65_535) {\n throw new Error(\n `Invalid http port ${JSON.stringify(rawPort)}: it does not resolve to a usable TCP port ` +\n `(0-65535, whole number). Fix HTTP_PORT in .env, or http.port in src/config/http.ts.`,\n );\n }\n\n return resolved;\n}\n\n/**\n * Whether `rawPort` was already the canonical value `resolveBindPort`\n * returned for it — i.e. nothing needed normalising.\n *\n * Lets a caller print exactly one notice when the configured port and the\n * bound port differ in representation (`\"03999\"` -> `3999`), and stay silent\n * for the ordinary case (a plain number, or a string that was already\n * canonical).\n */\nexport function isCanonicalPortValue(rawPort: unknown, resolved: number): boolean {\n if (typeof rawPort === \"number\" || rawPort === undefined || rawPort === null) {\n return true;\n }\n\n return String(rawPort) === String(resolved);\n}\n"],"mappings":";;;;;;;;;AAQA,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;AAoBtB,SAAgB,gBAAgB,SAA0B;CACxD,IAAI,YAAY,UAAa,YAAY,MACvC,OAAO,0BAA0B,QAAQ;CAG3C,MAAM,WAAW,OAAO,OAAO,OAAO,CAAC,CAAC,KAAK,CAAC;CAE9C,IAAI,CAAC,OAAO,UAAU,QAAQ,KAAK,WAAW,KAAK,WAAW,OAC5D,MAAM,IAAI,MACR,qBAAqB,KAAK,UAAU,OAAO,EAAE,+HAE/C;CAGF,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,qBAAqB,SAAkB,UAA2B;CAChF,IAAI,OAAO,YAAY,YAAY,YAAY,UAAa,YAAY,MACtE,OAAO;CAGT,OAAO,OAAO,OAAO,MAAM,OAAO,QAAQ;AAC5C"}
@@ -1 +1 @@
1
- {"version":3,"file":"test-helpers.d.mts","names":[],"sources":["../../../../../../../core/src/tests/test-helpers.ts"],"mappings":";;AAYA;;;;AAAgC;AAehC;;AAfgC,iBAAhB,gBAAA;;;;;iBAeM,WAAA,CAAY,IAAA,UAAc,OAAA,GAAS,WAAA,GAAmB,OAAA,CAAQ,QAAA;;;;iBAgD9D,OAAA,CAAQ,IAAA,UAAc,OAAA,GAAS,WAAA,GAAmB,OAAA,CAAQ,QAAA;;;AAhDY;iBAuDtE,QAAA,CACpB,IAAA,UACA,IAAA,YACA,OAAA,GAAS,WAAA,GACR,OAAA,CAAQ,QAAA;;;;iBAOW,OAAA,CACpB,IAAA,UACA,IAAA,YACA,OAAA,GAAS,WAAA,GACR,OAAA,CAAQ,QAAA;;;;iBAOW,UAAA,CAAW,IAAA,UAAc,OAAA,GAAS,WAAA,GAAmB,OAAA,CAAQ,QAAA;;;;iBAO7D,SAAA,CACpB,IAAA,UACA,IAAA,YACA,OAAA,GAAS,WAAA,GACR,OAAA,CAAQ,QAAA;;AAxC6E;AAOxF;iBAwCsB,iBAAA,IAAqB,QAAA,EAAU,QAAA,GAAW,OAAA,CAAQ,CAAA;;;;iBAOlD,UAAA,IAAc,QAAA,EAAU,QAAA,EAAU,cAAA,YAAuB,OAAA,CAAQ,CAAA"}
1
+ {"version":3,"file":"test-helpers.d.mts","names":[],"sources":["../../../../../../../core/src/tests/test-helpers.ts"],"mappings":";;AAaA;;;;AAAgC;AA6BhC;;AA7BgC,iBAAhB,gBAAA;;;;;iBA6BM,WAAA,CAAY,IAAA,UAAc,OAAA,GAAS,WAAA,GAAmB,OAAA,CAAQ,QAAA;;;;iBAgD9D,OAAA,CAAQ,IAAA,UAAc,OAAA,GAAS,WAAA,GAAmB,OAAA,CAAQ,QAAA;;;AAhDY;iBAuDtE,QAAA,CACpB,IAAA,UACA,IAAA,YACA,OAAA,GAAS,WAAA,GACR,OAAA,CAAQ,QAAA;;;;iBAWW,OAAA,CACpB,IAAA,UACA,IAAA,YACA,OAAA,GAAS,WAAA,GACR,OAAA,CAAQ,QAAA;;;;iBAOW,UAAA,CAAW,IAAA,UAAc,OAAA,GAAS,WAAA,GAAmB,OAAA,CAAQ,QAAA;;;;iBAO7D,SAAA,CACpB,IAAA,UACA,IAAA,YACA,OAAA,GAAS,WAAA,GACR,OAAA,CAAQ,QAAA;;AA5C6E;AAOxF;iBAgDsB,iBAAA,IAAqB,QAAA,EAAU,QAAA,GAAW,OAAA,CAAQ,CAAA;;;;iBAOlD,UAAA,IAAc,QAAA,EAAU,QAAA,EAAU,cAAA,YAAuB,OAAA,CAAQ,CAAA"}
@@ -1,5 +1,6 @@
1
1
  import { config } from "../config/config-getter.mjs";
2
2
  import "../config/index.mjs";
3
+ import { getHttpReadyReport } from "../http/ready-report.mjs";
3
4
  import { TEST_SERVER_PORT_ENV_KEY } from "./test-server-port-channel.mjs";
4
5
 
5
6
  //#region ../core/src/tests/test-helpers.ts
@@ -12,7 +13,9 @@ import { TEST_SERVER_PORT_ENV_KEY } from "./test-server-port-channel.mjs";
12
13
  * Get the test server base URL
13
14
  */
14
15
  function getTestServerUrl() {
15
- const port = process.env["WARLOCK_TEST_SERVER_PORT"] || config.key("http.port", 2031);
16
+ const publishedPort = process.env[TEST_SERVER_PORT_ENV_KEY];
17
+ const boundPort = getHttpReadyReport()?.port;
18
+ const port = publishedPort || boundPort || config.key("http.port", 2031);
16
19
  return `http://${config.key("http.host", "localhost")}:${port}`;
17
20
  }
18
21
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"test-helpers.mjs","names":[],"sources":["../../../../../../../core/src/tests/test-helpers.ts"],"sourcesContent":["/**\n * Warlock.js Test Helpers\n *\n * Utilities for testing Warlock.js applications.\n */\n\nimport { config } from \"../config\";\nimport { TEST_SERVER_PORT_ENV_KEY } from \"./test-server-port-channel\";\n\n/**\n * Get the test server base URL\n */\nexport function getTestServerUrl(): string {\n // `startHttpTestServer` publishes the port it actually bound. Test workers are\n // separate processes whose own config resolves `http.port` from `.env`, so\n // without this a suite started on an explicit port would send every request to\n // the `.env` port instead of the one the server is listening on.\n const publishedPort = process.env[TEST_SERVER_PORT_ENV_KEY];\n const port = publishedPort || config.key(\"http.port\", 2031);\n const host = config.key(\"http.host\", \"localhost\");\n return `http://${host}:${port}`;\n}\n\n/**\n * Simple HTTP request helper for test server\n * Uses native fetch - lightweight, no extra dependencies\n */\nexport async function testRequest(path: string, options: RequestInit = {}): Promise<Response> {\n return sendRequest(path, options, false);\n}\n\n/**\n * The single place a request is actually built.\n *\n * `serializedJson` says whether THIS module turned the caller's value into a\n * JSON string. It is the only thing that justifies setting a JSON content type:\n * a `FormData` body carries a multipart boundary the runtime generates, and\n * labelling it `application/json` produces a request no server can parse.\n */\nasync function sendRequest(\n path: string,\n options: RequestInit,\n serializedJson: boolean,\n): Promise<Response> {\n const baseUrl = getTestServerUrl();\n const url = path.startsWith(\"/\") ? `${baseUrl}${path}` : `${baseUrl}/${path}`;\n\n // Normalised through `Headers` rather than object-spread: `RequestInit.headers`\n // may be a record, a `Headers` instance, or a list of `[name, value]` tuples,\n // and spreading the last two silently produces an object with numeric keys —\n // the header is simply lost, with no error anywhere.\n const headers = new Headers(options.headers);\n\n if (serializedJson && !headers.has(\"content-type\")) {\n headers.set(\"content-type\", \"application/json\");\n }\n\n return fetch(url, { ...options, headers });\n}\n\n/**\n * Serialize a body for a JSON request.\n *\n * `undefined` means the caller omitted the argument; every other value —\n * including `false`, `0`, `\"\"` and `null` — is a legal JSON document and must\n * be sent. The old check was `body ? JSON.stringify(body) : undefined`, which\n * dropped all four.\n */\nfunction jsonBody(body: unknown): string | undefined {\n return body === undefined ? undefined : JSON.stringify(body);\n}\n\n/**\n * GET request helper\n */\nexport async function testGet(path: string, options: RequestInit = {}): Promise<Response> {\n return testRequest(path, { ...options, method: \"GET\" });\n}\n\n/**\n * POST request helper\n */\nexport async function testPost(\n path: string,\n body?: unknown,\n options: RequestInit = {},\n): Promise<Response> {\n return sendRequest(path, { ...options, method: \"POST\", body: jsonBody(body) }, body !== undefined);\n}\n\n/**\n * PUT request helper\n */\nexport async function testPut(\n path: string,\n body?: unknown,\n options: RequestInit = {},\n): Promise<Response> {\n return sendRequest(path, { ...options, method: \"PUT\", body: jsonBody(body) }, body !== undefined);\n}\n\n/**\n * DELETE request helper\n */\nexport async function testDelete(path: string, options: RequestInit = {}): Promise<Response> {\n return testRequest(path, { ...options, method: \"DELETE\" });\n}\n\n/**\n * PATCH request helper\n */\nexport async function testPatch(\n path: string,\n body?: unknown,\n options: RequestInit = {},\n): Promise<Response> {\n return sendRequest(path, { ...options, method: \"PATCH\", body: jsonBody(body) }, body !== undefined);\n}\n\n/**\n * Parse JSON response with type safety\n */\nexport async function parseJsonResponse<T>(response: Response): Promise<T> {\n return response.json() as Promise<T>;\n}\n\n/**\n * Assert response status and return parsed JSON\n */\nexport async function expectJson<T>(response: Response, expectedStatus = 200): Promise<T> {\n if (response.status !== expectedStatus) {\n const text = await response.text();\n throw new Error(`Expected status ${expectedStatus}, got ${response.status}. Body: ${text}`);\n }\n return parseJsonResponse<T>(response);\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,SAAgB,mBAA2B;CAMzC,MAAM,OADgB,QAAQ,mCACA,OAAO,IAAI,aAAa,IAAI;CAE1D,OAAO,UADM,OAAO,IAAI,aAAa,WACjB,EAAE,GAAG;AAC3B;;;;;AAMA,eAAsB,YAAY,MAAc,UAAuB,CAAC,GAAsB;CAC5F,OAAO,YAAY,MAAM,SAAS,KAAK;AACzC;;;;;;;;;AAUA,eAAe,YACb,MACA,SACA,gBACmB;CACnB,MAAM,UAAU,iBAAiB;CACjC,MAAM,MAAM,KAAK,WAAW,GAAG,IAAI,GAAG,UAAU,SAAS,GAAG,QAAQ,GAAG;CAMvE,MAAM,UAAU,IAAI,QAAQ,QAAQ,OAAO;CAE3C,IAAI,kBAAkB,CAAC,QAAQ,IAAI,cAAc,GAC/C,QAAQ,IAAI,gBAAgB,kBAAkB;CAGhD,OAAO,MAAM,KAAK;EAAE,GAAG;EAAS;CAAQ,CAAC;AAC3C;;;;;;;;;AAUA,SAAS,SAAS,MAAmC;CACnD,OAAO,SAAS,SAAY,SAAY,KAAK,UAAU,IAAI;AAC7D;;;;AAKA,eAAsB,QAAQ,MAAc,UAAuB,CAAC,GAAsB;CACxF,OAAO,YAAY,MAAM;EAAE,GAAG;EAAS,QAAQ;CAAM,CAAC;AACxD;;;;AAKA,eAAsB,SACpB,MACA,MACA,UAAuB,CAAC,GACL;CACnB,OAAO,YAAY,MAAM;EAAE,GAAG;EAAS,QAAQ;EAAQ,MAAM,SAAS,IAAI;CAAE,GAAG,SAAS,MAAS;AACnG;;;;AAKA,eAAsB,QACpB,MACA,MACA,UAAuB,CAAC,GACL;CACnB,OAAO,YAAY,MAAM;EAAE,GAAG;EAAS,QAAQ;EAAO,MAAM,SAAS,IAAI;CAAE,GAAG,SAAS,MAAS;AAClG;;;;AAKA,eAAsB,WAAW,MAAc,UAAuB,CAAC,GAAsB;CAC3F,OAAO,YAAY,MAAM;EAAE,GAAG;EAAS,QAAQ;CAAS,CAAC;AAC3D;;;;AAKA,eAAsB,UACpB,MACA,MACA,UAAuB,CAAC,GACL;CACnB,OAAO,YAAY,MAAM;EAAE,GAAG;EAAS,QAAQ;EAAS,MAAM,SAAS,IAAI;CAAE,GAAG,SAAS,MAAS;AACpG;;;;AAKA,eAAsB,kBAAqB,UAAgC;CACzE,OAAO,SAAS,KAAK;AACvB;;;;AAKA,eAAsB,WAAc,UAAoB,iBAAiB,KAAiB;CACxF,IAAI,SAAS,WAAW,gBAAgB;EACtC,MAAM,OAAO,MAAM,SAAS,KAAK;EACjC,MAAM,IAAI,MAAM,mBAAmB,eAAe,QAAQ,SAAS,OAAO,UAAU,MAAM;CAC5F;CACA,OAAO,kBAAqB,QAAQ;AACtC"}
1
+ {"version":3,"file":"test-helpers.mjs","names":[],"sources":["../../../../../../../core/src/tests/test-helpers.ts"],"sourcesContent":["/**\n * Warlock.js Test Helpers\n *\n * Utilities for testing Warlock.js applications.\n */\n\nimport { config } from \"../config\";\nimport { getHttpReadyReport } from \"../http/ready-report\";\nimport { TEST_SERVER_PORT_ENV_KEY } from \"./test-server-port-channel\";\n\n/**\n * Get the test server base URL\n */\nexport function getTestServerUrl(): string {\n // `startHttpTestServer` publishes the port it actually bound. Test workers are\n // separate processes whose own config resolves `http.port` from `.env`, so\n // without this a suite started on an explicit port would send every request to\n // the `.env` port instead of the one the server is listening on.\n const publishedPort = process.env[TEST_SERVER_PORT_ENV_KEY];\n\n // Same-process fallback: a test that boots the HTTP connector directly\n // (rather than through `startHttpTestServer`'s cross-process channel) never\n // writes `TEST_SERVER_PORT_ENV_KEY`, so without this the next fallback —\n // `config.key(\"http.port\", 2031)` — was the only source left, and it holds\n // the CONFIGURED port, not the bound one. For `http.port: 0` that is `0`,\n // producing `http://host:0` even though `HttpConnector.start()` had already\n // recorded the real bound port right here in `ready-report.ts`.\n const boundPort = getHttpReadyReport()?.port;\n\n // `config.key`'s default only substitutes for `undefined` — `0` is a\n // defined configured value, not an absent one — so it cannot be trusted to\n // paper over an unresolved port 0 either. `boundPort` is read first for\n // that exact reason.\n const port = publishedPort || boundPort || config.key(\"http.port\", 2031);\n const host = config.key(\"http.host\", \"localhost\");\n return `http://${host}:${port}`;\n}\n\n/**\n * Simple HTTP request helper for test server\n * Uses native fetch - lightweight, no extra dependencies\n */\nexport async function testRequest(path: string, options: RequestInit = {}): Promise<Response> {\n return sendRequest(path, options, false);\n}\n\n/**\n * The single place a request is actually built.\n *\n * `serializedJson` says whether THIS module turned the caller's value into a\n * JSON string. It is the only thing that justifies setting a JSON content type:\n * a `FormData` body carries a multipart boundary the runtime generates, and\n * labelling it `application/json` produces a request no server can parse.\n */\nasync function sendRequest(\n path: string,\n options: RequestInit,\n serializedJson: boolean,\n): Promise<Response> {\n const baseUrl = getTestServerUrl();\n const url = path.startsWith(\"/\") ? `${baseUrl}${path}` : `${baseUrl}/${path}`;\n\n // Normalised through `Headers` rather than object-spread: `RequestInit.headers`\n // may be a record, a `Headers` instance, or a list of `[name, value]` tuples,\n // and spreading the last two silently produces an object with numeric keys —\n // the header is simply lost, with no error anywhere.\n const headers = new Headers(options.headers);\n\n if (serializedJson && !headers.has(\"content-type\")) {\n headers.set(\"content-type\", \"application/json\");\n }\n\n return fetch(url, { ...options, headers });\n}\n\n/**\n * Serialize a body for a JSON request.\n *\n * `undefined` means the caller omitted the argument; every other value —\n * including `false`, `0`, `\"\"` and `null` — is a legal JSON document and must\n * be sent. The old check was `body ? JSON.stringify(body) : undefined`, which\n * dropped all four.\n */\nfunction jsonBody(body: unknown): string | undefined {\n return body === undefined ? undefined : JSON.stringify(body);\n}\n\n/**\n * GET request helper\n */\nexport async function testGet(path: string, options: RequestInit = {}): Promise<Response> {\n return testRequest(path, { ...options, method: \"GET\" });\n}\n\n/**\n * POST request helper\n */\nexport async function testPost(\n path: string,\n body?: unknown,\n options: RequestInit = {},\n): Promise<Response> {\n return sendRequest(\n path,\n { ...options, method: \"POST\", body: jsonBody(body) },\n body !== undefined,\n );\n}\n\n/**\n * PUT request helper\n */\nexport async function testPut(\n path: string,\n body?: unknown,\n options: RequestInit = {},\n): Promise<Response> {\n return sendRequest(path, { ...options, method: \"PUT\", body: jsonBody(body) }, body !== undefined);\n}\n\n/**\n * DELETE request helper\n */\nexport async function testDelete(path: string, options: RequestInit = {}): Promise<Response> {\n return testRequest(path, { ...options, method: \"DELETE\" });\n}\n\n/**\n * PATCH request helper\n */\nexport async function testPatch(\n path: string,\n body?: unknown,\n options: RequestInit = {},\n): Promise<Response> {\n return sendRequest(\n path,\n { ...options, method: \"PATCH\", body: jsonBody(body) },\n body !== undefined,\n );\n}\n\n/**\n * Parse JSON response with type safety\n */\nexport async function parseJsonResponse<T>(response: Response): Promise<T> {\n return response.json() as Promise<T>;\n}\n\n/**\n * Assert response status and return parsed JSON\n */\nexport async function expectJson<T>(response: Response, expectedStatus = 200): Promise<T> {\n if (response.status !== expectedStatus) {\n const text = await response.text();\n throw new Error(`Expected status ${expectedStatus}, got ${response.status}. Body: ${text}`);\n }\n return parseJsonResponse<T>(response);\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,mBAA2B;CAKzC,MAAM,gBAAgB,QAAQ,IAAI;CASlC,MAAM,YAAY,mBAAmB,CAAC,EAAE;CAMxC,MAAM,OAAO,iBAAiB,aAAa,OAAO,IAAI,aAAa,IAAI;CAEvE,OAAO,UADM,OAAO,IAAI,aAAa,WACjB,EAAE,GAAG;AAC3B;;;;;AAMA,eAAsB,YAAY,MAAc,UAAuB,CAAC,GAAsB;CAC5F,OAAO,YAAY,MAAM,SAAS,KAAK;AACzC;;;;;;;;;AAUA,eAAe,YACb,MACA,SACA,gBACmB;CACnB,MAAM,UAAU,iBAAiB;CACjC,MAAM,MAAM,KAAK,WAAW,GAAG,IAAI,GAAG,UAAU,SAAS,GAAG,QAAQ,GAAG;CAMvE,MAAM,UAAU,IAAI,QAAQ,QAAQ,OAAO;CAE3C,IAAI,kBAAkB,CAAC,QAAQ,IAAI,cAAc,GAC/C,QAAQ,IAAI,gBAAgB,kBAAkB;CAGhD,OAAO,MAAM,KAAK;EAAE,GAAG;EAAS;CAAQ,CAAC;AAC3C;;;;;;;;;AAUA,SAAS,SAAS,MAAmC;CACnD,OAAO,SAAS,SAAY,SAAY,KAAK,UAAU,IAAI;AAC7D;;;;AAKA,eAAsB,QAAQ,MAAc,UAAuB,CAAC,GAAsB;CACxF,OAAO,YAAY,MAAM;EAAE,GAAG;EAAS,QAAQ;CAAM,CAAC;AACxD;;;;AAKA,eAAsB,SACpB,MACA,MACA,UAAuB,CAAC,GACL;CACnB,OAAO,YACL,MACA;EAAE,GAAG;EAAS,QAAQ;EAAQ,MAAM,SAAS,IAAI;CAAE,GACnD,SAAS,MACX;AACF;;;;AAKA,eAAsB,QACpB,MACA,MACA,UAAuB,CAAC,GACL;CACnB,OAAO,YAAY,MAAM;EAAE,GAAG;EAAS,QAAQ;EAAO,MAAM,SAAS,IAAI;CAAE,GAAG,SAAS,MAAS;AAClG;;;;AAKA,eAAsB,WAAW,MAAc,UAAuB,CAAC,GAAsB;CAC3F,OAAO,YAAY,MAAM;EAAE,GAAG;EAAS,QAAQ;CAAS,CAAC;AAC3D;;;;AAKA,eAAsB,UACpB,MACA,MACA,UAAuB,CAAC,GACL;CACnB,OAAO,YACL,MACA;EAAE,GAAG;EAAS,QAAQ;EAAS,MAAM,SAAS,IAAI;CAAE,GACpD,SAAS,MACX;AACF;;;;AAKA,eAAsB,kBAAqB,UAAgC;CACzE,OAAO,SAAS,KAAK;AACvB;;;;AAKA,eAAsB,WAAc,UAAoB,iBAAiB,KAAiB;CACxF,IAAI,SAAS,WAAW,gBAAgB;EACtC,MAAM,OAAO,MAAM,SAAS,KAAK;EACjC,MAAM,IAAI,MAAM,mBAAmB,eAAe,QAAQ,SAAS,OAAO,UAAU,MAAM;CAC5F;CACA,OAAO,kBAAqB,QAAQ;AACtC"}
@@ -0,0 +1,67 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+
3
+ //#region ../core/src/utils/detect-environment-overrides.ts
4
+ /**
5
+ * Minimal `KEY=VALUE` line parser: `#` comments, blank lines, and one layer
6
+ * of surrounding quotes.
7
+ *
8
+ * Deliberately NOT `@mongez/dotenv`'s own `parseLine` / `parseValue`: those
9
+ * live in the same module as `loadEnv`, and `tests/unit/utils/load-environment.test.ts`
10
+ * replaces that whole module with `vi.mock("@mongez/dotenv", () => ({ loadEnv:
11
+ * ... }))`. Importing any other named export from `@mongez/dotenv` here would
12
+ * resolve to `undefined` under that mock and crash detection during those
13
+ * tests. Comments, blank lines and a surrounding quote pair are the entire
14
+ * feature set this comparison needs — the actual load still goes through the
15
+ * real `@mongez/dotenv` parser via `loadEnv()`.
16
+ */
17
+ function parseEnvLine(line) {
18
+ const trimmed = line.trim();
19
+ if (!trimmed || trimmed.startsWith("#") || !trimmed.includes("=")) return;
20
+ const separatorIndex = trimmed.indexOf("=");
21
+ const key = trimmed.slice(0, separatorIndex).trim();
22
+ let value = trimmed.slice(separatorIndex + 1).trim();
23
+ const quote = value[0];
24
+ if ((quote === "\"" || quote === "'" || quote === "`") && value.length > 1 && value.endsWith(quote)) value = value.slice(1, -1);
25
+ return [key, value];
26
+ }
27
+ /**
28
+ * Which of the given `.env` files' keys lost to a value the ambient process
29
+ * environment already carried.
30
+ *
31
+ * `snapshot` must be captured BEFORE `loadEnv()` runs: the loader writes into
32
+ * `process.env` for every key the file supplies, so a snapshot taken
33
+ * afterwards can no longer tell an ambient override from a value the loader
34
+ * itself just wrote.
35
+ *
36
+ * `files` should be given in the same order `loadEnv()` actually reads them
37
+ * (`.env.shared` first, then the applicable `.env`/`.env.<NODE_ENV>`), so a
38
+ * key declared in more than one file resolves to the value the real loader
39
+ * would have used absent any ambient override.
40
+ */
41
+ function detectEnvironmentOverrides(files, snapshot) {
42
+ const fileValues = /* @__PURE__ */ new Map();
43
+ for (const file of files) {
44
+ if (!existsSync(file)) continue;
45
+ const lines = readFileSync(file, "utf8").split(/\r\n|\n/);
46
+ for (const line of lines) {
47
+ const parsed = parseEnvLine(line);
48
+ if (!parsed) continue;
49
+ fileValues.set(parsed[0], parsed[1]);
50
+ }
51
+ }
52
+ const overrides = [];
53
+ for (const [key, fileValue] of fileValues) {
54
+ if (!Object.prototype.hasOwnProperty.call(snapshot, key)) continue;
55
+ const effectiveValue = snapshot[key];
56
+ if (effectiveValue !== fileValue) overrides.push({
57
+ key,
58
+ effectiveValue,
59
+ fileValue
60
+ });
61
+ }
62
+ return overrides;
63
+ }
64
+
65
+ //#endregion
66
+ export { detectEnvironmentOverrides };
67
+ //# sourceMappingURL=detect-environment-overrides.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect-environment-overrides.mjs","names":[],"sources":["../../../../../../../core/src/utils/detect-environment-overrides.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\n\n/**\n * One `.env` key whose file value lost to an ambient `process.env` value that\n * was already set before the file was read.\n */\nexport type EnvironmentOverride = {\n key: string;\n effectiveValue: string;\n fileValue: string;\n};\n\n/**\n * Minimal `KEY=VALUE` line parser: `#` comments, blank lines, and one layer\n * of surrounding quotes.\n *\n * Deliberately NOT `@mongez/dotenv`'s own `parseLine` / `parseValue`: those\n * live in the same module as `loadEnv`, and `tests/unit/utils/load-environment.test.ts`\n * replaces that whole module with `vi.mock(\"@mongez/dotenv\", () => ({ loadEnv:\n * ... }))`. Importing any other named export from `@mongez/dotenv` here would\n * resolve to `undefined` under that mock and crash detection during those\n * tests. Comments, blank lines and a surrounding quote pair are the entire\n * feature set this comparison needs — the actual load still goes through the\n * real `@mongez/dotenv` parser via `loadEnv()`.\n */\nfunction parseEnvLine(line: string): [string, string] | undefined {\n const trimmed = line.trim();\n\n if (!trimmed || trimmed.startsWith(\"#\") || !trimmed.includes(\"=\")) {\n return undefined;\n }\n\n const separatorIndex = trimmed.indexOf(\"=\");\n const key = trimmed.slice(0, separatorIndex).trim();\n let value = trimmed.slice(separatorIndex + 1).trim();\n\n const quote = value[0];\n\n if (\n (quote === '\"' || quote === \"'\" || quote === \"`\") &&\n value.length > 1 &&\n value.endsWith(quote)\n ) {\n value = value.slice(1, -1);\n }\n\n return [key, value];\n}\n\n/**\n * Which of the given `.env` files' keys lost to a value the ambient process\n * environment already carried.\n *\n * `snapshot` must be captured BEFORE `loadEnv()` runs: the loader writes into\n * `process.env` for every key the file supplies, so a snapshot taken\n * afterwards can no longer tell an ambient override from a value the loader\n * itself just wrote.\n *\n * `files` should be given in the same order `loadEnv()` actually reads them\n * (`.env.shared` first, then the applicable `.env`/`.env.<NODE_ENV>`), so a\n * key declared in more than one file resolves to the value the real loader\n * would have used absent any ambient override.\n */\nexport function detectEnvironmentOverrides(\n files: string[],\n snapshot: NodeJS.ProcessEnv,\n): EnvironmentOverride[] {\n const fileValues = new Map<string, string>();\n\n for (const file of files) {\n if (!existsSync(file)) {\n continue;\n }\n\n const lines = readFileSync(file, \"utf8\").split(/\\r\\n|\\n/);\n\n for (const line of lines) {\n const parsed = parseEnvLine(line);\n\n if (!parsed) {\n continue;\n }\n\n fileValues.set(parsed[0], parsed[1]);\n }\n }\n\n const overrides: EnvironmentOverride[] = [];\n\n for (const [key, fileValue] of fileValues) {\n if (!Object.prototype.hasOwnProperty.call(snapshot, key)) {\n continue;\n }\n\n const effectiveValue = snapshot[key] as string;\n\n if (effectiveValue !== fileValue) {\n overrides.push({ key, effectiveValue, fileValue });\n }\n }\n\n return overrides;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAyBA,SAAS,aAAa,MAA4C;CAChE,MAAM,UAAU,KAAK,KAAK;CAE1B,IAAI,CAAC,WAAW,QAAQ,WAAW,GAAG,KAAK,CAAC,QAAQ,SAAS,GAAG,GAC9D;CAGF,MAAM,iBAAiB,QAAQ,QAAQ,GAAG;CAC1C,MAAM,MAAM,QAAQ,MAAM,GAAG,cAAc,CAAC,CAAC,KAAK;CAClD,IAAI,QAAQ,QAAQ,MAAM,iBAAiB,CAAC,CAAC,CAAC,KAAK;CAEnD,MAAM,QAAQ,MAAM;CAEpB,KACG,UAAU,QAAO,UAAU,OAAO,UAAU,QAC7C,MAAM,SAAS,KACf,MAAM,SAAS,KAAK,GAEpB,QAAQ,MAAM,MAAM,GAAG,EAAE;CAG3B,OAAO,CAAC,KAAK,KAAK;AACpB;;;;;;;;;;;;;;;AAgBA,SAAgB,2BACd,OACA,UACuB;CACvB,MAAM,6BAAa,IAAI,IAAoB;CAE3C,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,CAAC,WAAW,IAAI,GAClB;EAGF,MAAM,QAAQ,aAAa,MAAM,MAAM,CAAC,CAAC,MAAM,SAAS;EAExD,KAAK,MAAM,QAAQ,OAAO;GACxB,MAAM,SAAS,aAAa,IAAI;GAEhC,IAAI,CAAC,QACH;GAGF,WAAW,IAAI,OAAO,IAAI,OAAO,EAAE;EACrC;CACF;CAEA,MAAM,YAAmC,CAAC;CAE1C,KAAK,MAAM,CAAC,KAAK,cAAc,YAAY;EACzC,IAAI,CAAC,OAAO,UAAU,eAAe,KAAK,UAAU,GAAG,GACrD;EAGF,MAAM,iBAAiB,SAAS;EAEhC,IAAI,mBAAmB,WACrB,UAAU,KAAK;GAAE;GAAK;GAAgB;EAAU,CAAC;CAErD;CAEA,OAAO;AACT"}
@@ -1,3 +1,5 @@
1
+ import { detectEnvironmentOverrides } from "./detect-environment-overrides.mjs";
2
+ import { reportEnvironmentOverrides } from "./report-environment-overrides.mjs";
1
3
  import { loadEnv } from "@mongez/dotenv";
2
4
  import path from "node:path";
3
5
  import { existsSync } from "node:fs";
@@ -44,6 +46,26 @@ function candidateEnvFiles(directory) {
44
46
  return files;
45
47
  }
46
48
  /**
49
+ * The files `loadEnv()` will actually read, in its own read order.
50
+ *
51
+ * Differs from {@link candidateEnvFiles}, which lists every candidate to
52
+ * answer "is there anything to load at all". `loadEnv()` itself only ever
53
+ * reads `.env.shared` (if present) plus ONE of `.env.<NODE_ENV>` /
54
+ * `.env` — the NODE_ENV-specific file when it exists, `.env` otherwise —
55
+ * never both. Override detection has to mirror that exactly, or a key
56
+ * declared only in a file `loadEnv()` would not have touched could be
57
+ * reported as having "lost" a comparison it was never actually part of.
58
+ */
59
+ function resolveLoadedEnvFiles(directory) {
60
+ const files = [];
61
+ const sharedFile = path.join(directory, ".env.shared");
62
+ if (existsSync(sharedFile)) files.push(sharedFile);
63
+ const nodeEnvFile = process.env.NODE_ENV ? path.join(directory, `.env.${process.env.NODE_ENV}`) : void 0;
64
+ const derivedFile = nodeEnvFile && existsSync(nodeEnvFile) ? nodeEnvFile : path.join(directory, ".env");
65
+ if (existsSync(derivedFile)) files.push(derivedFile);
66
+ return files;
67
+ }
68
+ /**
47
69
  * Whether this process has already loaded its env files.
48
70
  *
49
71
  * Two callers reach here on a bootstrapping command — the CLI preload phase and
@@ -79,6 +101,8 @@ async function loadEnvironmentFiles(directory = process.cwd()) {
79
101
  if (environmentLoaded) return;
80
102
  if (!candidateEnvFiles(directory).some((file) => existsSync(file))) return;
81
103
  environmentLoaded = true;
104
+ const processEnvironmentSnapshot = { ...process.env };
105
+ reportEnvironmentOverrides(detectEnvironmentOverrides(resolveLoadedEnvFiles(directory), processEnvironmentSnapshot));
82
106
  await loadEnv(void 0, {
83
107
  ...environmentLoaderOptions,
84
108
  dir: directory
@@ -1 +1 @@
1
- {"version":3,"file":"load-environment.mjs","names":[],"sources":["../../../../../../../core/src/utils/load-environment.ts"],"sourcesContent":["import { loadEnv, type EnvLoaderOptions } from \"@mongez/dotenv\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * Core's env precedence policy, in one place because two callers load env:\n * this module at boot, and the dev server when an `.env` file changes.\n *\n * `@mongez/dotenv` defaults to `precedence: \"file-wins\"`, which is backwards.\n * The `.env` file is a checked-in DEFAULT; a variable already exported into\n * `process.env` is the deliberate, situational override — a second instance on\n * another port, CI pointed at another database, a container's configuration.\n * Under the default, `PORT=6060 warlock dev` produced a server on the `.env`\n * file's 3000 and said nothing. A default that silently beats an explicit\n * instruction is the wrong way round, so core opts into `process-wins`:\n * the file supplies only the keys the environment does not already carry.\n *\n * EMPTY STRING — `FOO=` in the environment counts as SET, and wins, so the\n * file's value is discarded and `env(\"FOO\")` returns `\"\"`. Chosen over\n * \"empty means absent\" because the loader cannot tell a deliberate blanking\n * from an accident, and only one of the two readings is expressible: an\n * operator who wants the file's value can unset the variable, whereas under\n * \"empty means absent\" an operator who wants a blank value has no way to ask\n * for one. It also matches POSIX (an exported empty variable is set), dotenv,\n * dotenv-flow and Vite. Note the consequence: a blank export beats the second\n * argument too, so `env(\"FOO\", \"fallback\")` yields `\"\"`, not the fallback.\n *\n * Keys this loader itself wrote are tracked by the library and are NOT treated\n * as process-provided, so editing `.env` during a dev session still takes\n * effect on reload rather than being pinned by the previous load's own writes.\n */\nexport const environmentLoaderOptions: EnvLoaderOptions = {\n precedence: \"process-wins\",\n};\n\n/**\n * The files `loadEnv()` will look for, in the order it considers them.\n *\n * Mirrors `@mongez/dotenv`'s own resolution — `.env.shared` first, then\n * `.env.<NODE_ENV>` if it exists, else plain `.env` — because the presence\n * check has to ask the same question the loader is about to ask.\n */\nfunction candidateEnvFiles(directory: string): string[] {\n const files = [path.join(directory, \".env\"), path.join(directory, \".env.shared\")];\n\n if (process.env.NODE_ENV) {\n files.push(path.join(directory, `.env.${process.env.NODE_ENV}`));\n }\n\n return files;\n}\n\n/**\n * Whether this process has already loaded its env files.\n *\n * Two callers reach here on a bootstrapping command — the CLI preload phase and\n * `bootstrap()` — and `loadEnv()` defaults to `override: true`, so a second pass\n * re-parses the same files and re-writes `process.env`. Anything set in between\n * (a `warlock.config.ts` module body, a config file, an orchestrator) would be\n * silently clobbered by the later load. Same shape as the defect where a\n * caller's test-server port was overwritten by a re-read of `.env`.\n *\n * A deliberate reload is still possible and still used: the dev server calls\n * `loadEnv()` directly when an `.env` file changes on disk, which is a reload\n * the user asked for rather than an accidental second pass.\n */\nlet environmentLoaded = false;\n\n/**\n * Load `.env` files when there are any, and do nothing when there are not.\n *\n * Loads at most **once per process** — see {@link environmentLoaded}.\n *\n * `@mongez/dotenv`'s `loadEnvFile` **throws** when the file is absent. That was\n * survivable while only `dev` loaded env; now that every command loads it —\n * because `warlock.config.ts` calls `env()` in its module body and had been\n * evaluated against an empty store under every command — an unguarded call\n * would turn \"this project has no .env\" from a non-event into a hard failure\n * of `warlock build`. A project without a `.env` is legitimate: config files\n * carry defaults, and containers inject their own variables.\n *\n * The guard lives here rather than waiting on a fix in `@mongez/dotenv`: core\n * decides its own env policy and must not depend on another package's release\n * schedule to avoid crashing a working build.\n */\nexport async function loadEnvironmentFiles(directory: string = process.cwd()): Promise<void> {\n if (environmentLoaded) {\n return;\n }\n\n const hasEnvFile = candidateEnvFiles(directory).some((file) => existsSync(file));\n\n if (!hasEnvFile) {\n // Not latched: a project may create its `.env` between a command's preload\n // and its bootstrap, and there is nothing to protect from a second override\n // when the first pass loaded nothing.\n return;\n }\n\n environmentLoaded = true;\n\n // `dir` has to be forwarded: `loadEnv()` defaults it to `process.cwd()`, so\n // without this the existence check above asks about `directory` while the\n // load itself reads somewhere else entirely. Identical in production, where\n // `directory` IS `process.cwd()`.\n await loadEnv(undefined, { ...environmentLoaderOptions, dir: directory });\n}\n\n/**\n * Forget that env has been loaded, so the next call loads again.\n *\n * @internal For tests, which run many boots inside one process.\n */\nexport function resetLoadedEnvironment(): void {\n environmentLoaded = false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,2BAA6C,EACxD,YAAY,eACd;;;;;;;;AASA,SAAS,kBAAkB,WAA6B;CACtD,MAAM,QAAQ,CAAC,KAAK,KAAK,WAAW,MAAM,GAAG,KAAK,KAAK,WAAW,aAAa,CAAC;CAEhF,IAAI,QAAQ,IAAI,UACd,MAAM,KAAK,KAAK,KAAK,WAAW,QAAQ,QAAQ,IAAI,UAAU,CAAC;CAGjE,OAAO;AACT;;;;;;;;;;;;;;;AAgBA,IAAI,oBAAoB;;;;;;;;;;;;;;;;;;AAmBxB,eAAsB,qBAAqB,YAAoB,QAAQ,IAAI,GAAkB;CAC3F,IAAI,mBACF;CAKF,IAAI,CAFe,kBAAkB,SAAS,CAAC,CAAC,MAAM,SAAS,WAAW,IAAI,CAEhE,GAIZ;CAGF,oBAAoB;CAMpB,MAAM,QAAQ,QAAW;EAAE,GAAG;EAA0B,KAAK;CAAU,CAAC;AAC1E"}
1
+ {"version":3,"file":"load-environment.mjs","names":[],"sources":["../../../../../../../core/src/utils/load-environment.ts"],"sourcesContent":["import { loadEnv, type EnvLoaderOptions } from \"@mongez/dotenv\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { detectEnvironmentOverrides } from \"./detect-environment-overrides\";\nimport { reportEnvironmentOverrides } from \"./report-environment-overrides\";\n\n/**\n * Core's env precedence policy, in one place because two callers load env:\n * this module at boot, and the dev server when an `.env` file changes.\n *\n * `@mongez/dotenv` defaults to `precedence: \"file-wins\"`, which is backwards.\n * The `.env` file is a checked-in DEFAULT; a variable already exported into\n * `process.env` is the deliberate, situational override — a second instance on\n * another port, CI pointed at another database, a container's configuration.\n * Under the default, `PORT=6060 warlock dev` produced a server on the `.env`\n * file's 3000 and said nothing. A default that silently beats an explicit\n * instruction is the wrong way round, so core opts into `process-wins`:\n * the file supplies only the keys the environment does not already carry.\n *\n * EMPTY STRING — `FOO=` in the environment counts as SET, and wins, so the\n * file's value is discarded and `env(\"FOO\")` returns `\"\"`. Chosen over\n * \"empty means absent\" because the loader cannot tell a deliberate blanking\n * from an accident, and only one of the two readings is expressible: an\n * operator who wants the file's value can unset the variable, whereas under\n * \"empty means absent\" an operator who wants a blank value has no way to ask\n * for one. It also matches POSIX (an exported empty variable is set), dotenv,\n * dotenv-flow and Vite. Note the consequence: a blank export beats the second\n * argument too, so `env(\"FOO\", \"fallback\")` yields `\"\"`, not the fallback.\n *\n * Keys this loader itself wrote are tracked by the library and are NOT treated\n * as process-provided, so editing `.env` during a dev session still takes\n * effect on reload rather than being pinned by the previous load's own writes.\n */\nexport const environmentLoaderOptions: EnvLoaderOptions = {\n precedence: \"process-wins\",\n};\n\n/**\n * The files `loadEnv()` will look for, in the order it considers them.\n *\n * Mirrors `@mongez/dotenv`'s own resolution — `.env.shared` first, then\n * `.env.<NODE_ENV>` if it exists, else plain `.env` — because the presence\n * check has to ask the same question the loader is about to ask.\n */\nfunction candidateEnvFiles(directory: string): string[] {\n const files = [path.join(directory, \".env\"), path.join(directory, \".env.shared\")];\n\n if (process.env.NODE_ENV) {\n files.push(path.join(directory, `.env.${process.env.NODE_ENV}`));\n }\n\n return files;\n}\n\n/**\n * The files `loadEnv()` will actually read, in its own read order.\n *\n * Differs from {@link candidateEnvFiles}, which lists every candidate to\n * answer \"is there anything to load at all\". `loadEnv()` itself only ever\n * reads `.env.shared` (if present) plus ONE of `.env.<NODE_ENV>` /\n * `.env` — the NODE_ENV-specific file when it exists, `.env` otherwise —\n * never both. Override detection has to mirror that exactly, or a key\n * declared only in a file `loadEnv()` would not have touched could be\n * reported as having \"lost\" a comparison it was never actually part of.\n */\nfunction resolveLoadedEnvFiles(directory: string): string[] {\n const files: string[] = [];\n const sharedFile = path.join(directory, \".env.shared\");\n\n if (existsSync(sharedFile)) {\n files.push(sharedFile);\n }\n\n const nodeEnvFile = process.env.NODE_ENV\n ? path.join(directory, `.env.${process.env.NODE_ENV}`)\n : undefined;\n const derivedFile =\n nodeEnvFile && existsSync(nodeEnvFile) ? nodeEnvFile : path.join(directory, \".env\");\n\n if (existsSync(derivedFile)) {\n files.push(derivedFile);\n }\n\n return files;\n}\n\n/**\n * Whether this process has already loaded its env files.\n *\n * Two callers reach here on a bootstrapping command — the CLI preload phase and\n * `bootstrap()` — and `loadEnv()` defaults to `override: true`, so a second pass\n * re-parses the same files and re-writes `process.env`. Anything set in between\n * (a `warlock.config.ts` module body, a config file, an orchestrator) would be\n * silently clobbered by the later load. Same shape as the defect where a\n * caller's test-server port was overwritten by a re-read of `.env`.\n *\n * A deliberate reload is still possible and still used: the dev server calls\n * `loadEnv()` directly when an `.env` file changes on disk, which is a reload\n * the user asked for rather than an accidental second pass.\n */\nlet environmentLoaded = false;\n\n/**\n * Load `.env` files when there are any, and do nothing when there are not.\n *\n * Loads at most **once per process** — see {@link environmentLoaded}.\n *\n * `@mongez/dotenv`'s `loadEnvFile` **throws** when the file is absent. That was\n * survivable while only `dev` loaded env; now that every command loads it —\n * because `warlock.config.ts` calls `env()` in its module body and had been\n * evaluated against an empty store under every command — an unguarded call\n * would turn \"this project has no .env\" from a non-event into a hard failure\n * of `warlock build`. A project without a `.env` is legitimate: config files\n * carry defaults, and containers inject their own variables.\n *\n * The guard lives here rather than waiting on a fix in `@mongez/dotenv`: core\n * decides its own env policy and must not depend on another package's release\n * schedule to avoid crashing a working build.\n */\nexport async function loadEnvironmentFiles(directory: string = process.cwd()): Promise<void> {\n if (environmentLoaded) {\n return;\n }\n\n const hasEnvFile = candidateEnvFiles(directory).some((file) => existsSync(file));\n\n if (!hasEnvFile) {\n // Not latched: a project may create its `.env` between a command's preload\n // and its bootstrap, and there is nothing to protect from a second override\n // when the first pass loaded nothing.\n return;\n }\n\n environmentLoaded = true;\n\n // Snapshot BEFORE `loadEnv()` runs: the loader writes into `process.env` for\n // every key its files supply, so a snapshot taken afterwards could no\n // longer distinguish an ambient override from a value the loader itself\n // just wrote — see `detectEnvironmentOverrides`.\n const processEnvironmentSnapshot = { ...process.env };\n\n // The precedence itself is correct (see `environmentLoaderOptions` above);\n // the defect this guards against is the SILENCE — `.env` losing to an\n // ambient value with no diagnostic at all.\n reportEnvironmentOverrides(\n detectEnvironmentOverrides(resolveLoadedEnvFiles(directory), processEnvironmentSnapshot),\n );\n\n // `dir` has to be forwarded: `loadEnv()` defaults it to `process.cwd()`, so\n // without this the existence check above asks about `directory` while the\n // load itself reads somewhere else entirely. Identical in production, where\n // `directory` IS `process.cwd()`.\n await loadEnv(undefined, { ...environmentLoaderOptions, dir: directory });\n}\n\n/**\n * Forget that env has been loaded, so the next call loads again.\n *\n * @internal For tests, which run many boots inside one process.\n */\nexport function resetLoadedEnvironment(): void {\n environmentLoaded = false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,2BAA6C,EACxD,YAAY,eACd;;;;;;;;AASA,SAAS,kBAAkB,WAA6B;CACtD,MAAM,QAAQ,CAAC,KAAK,KAAK,WAAW,MAAM,GAAG,KAAK,KAAK,WAAW,aAAa,CAAC;CAEhF,IAAI,QAAQ,IAAI,UACd,MAAM,KAAK,KAAK,KAAK,WAAW,QAAQ,QAAQ,IAAI,UAAU,CAAC;CAGjE,OAAO;AACT;;;;;;;;;;;;AAaA,SAAS,sBAAsB,WAA6B;CAC1D,MAAM,QAAkB,CAAC;CACzB,MAAM,aAAa,KAAK,KAAK,WAAW,aAAa;CAErD,IAAI,WAAW,UAAU,GACvB,MAAM,KAAK,UAAU;CAGvB,MAAM,cAAc,QAAQ,IAAI,WAC5B,KAAK,KAAK,WAAW,QAAQ,QAAQ,IAAI,UAAU,IACnD;CACJ,MAAM,cACJ,eAAe,WAAW,WAAW,IAAI,cAAc,KAAK,KAAK,WAAW,MAAM;CAEpF,IAAI,WAAW,WAAW,GACxB,MAAM,KAAK,WAAW;CAGxB,OAAO;AACT;;;;;;;;;;;;;;;AAgBA,IAAI,oBAAoB;;;;;;;;;;;;;;;;;;AAmBxB,eAAsB,qBAAqB,YAAoB,QAAQ,IAAI,GAAkB;CAC3F,IAAI,mBACF;CAKF,IAAI,CAFe,kBAAkB,SAAS,CAAC,CAAC,MAAM,SAAS,WAAW,IAAI,CAEhE,GAIZ;CAGF,oBAAoB;CAMpB,MAAM,6BAA6B,EAAE,GAAG,QAAQ,IAAI;CAKpD,2BACE,2BAA2B,sBAAsB,SAAS,GAAG,0BAA0B,CACzF;CAMA,MAAM,QAAQ,QAAW;EAAE,GAAG;EAA0B,KAAK;CAAU,CAAC;AAC1E"}
@@ -0,0 +1,30 @@
1
+ //#region ../core/src/utils/report-environment-overrides.ts
2
+ /**
3
+ * Key names shaped like a secret. Matched values are redacted in the printed
4
+ * line even though the key itself is still named — knowing WHICH secret was
5
+ * overridden is useful, the value never is.
6
+ */
7
+ const SECRET_KEY_PATTERN = /(PASSWORD|SECRET|TOKEN|KEY|CREDENTIAL|DSN|CONNECTION_STRING)/i;
8
+ const REDACTED_PLACEHOLDER = "<redacted>";
9
+ /**
10
+ * Tell the developer, one line per key, which `.env` values the ambient
11
+ * process environment silently beat.
12
+ *
13
+ * Uses `console.warn` (stderr) rather than the `log` singleton on purpose:
14
+ * this runs from `loadEnvironmentFiles()`, ahead of the logger connector in
15
+ * the boot sequence, so any channel configured through `log.*` has nowhere to
16
+ * deliver to yet. Same reasoning as `console.error` in
17
+ * `src/http/boot-port-preflight.ts`.
18
+ */
19
+ function reportEnvironmentOverrides(overrides) {
20
+ for (const override of overrides) {
21
+ const isSecretShaped = SECRET_KEY_PATTERN.test(override.key);
22
+ const effectiveValue = isSecretShaped ? REDACTED_PLACEHOLDER : override.effectiveValue;
23
+ const fileValue = isSecretShaped ? REDACTED_PLACEHOLDER : override.fileValue;
24
+ console.warn(`[env] ${override.key}=${effectiveValue} is in effect from the process environment, overriding .env's ${override.key}=${fileValue}`);
25
+ }
26
+ }
27
+
28
+ //#endregion
29
+ export { reportEnvironmentOverrides };
30
+ //# sourceMappingURL=report-environment-overrides.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report-environment-overrides.mjs","names":[],"sources":["../../../../../../../core/src/utils/report-environment-overrides.ts"],"sourcesContent":["import type { EnvironmentOverride } from \"./detect-environment-overrides\";\n\n/**\n * Key names shaped like a secret. Matched values are redacted in the printed\n * line even though the key itself is still named — knowing WHICH secret was\n * overridden is useful, the value never is.\n */\nconst SECRET_KEY_PATTERN = /(PASSWORD|SECRET|TOKEN|KEY|CREDENTIAL|DSN|CONNECTION_STRING)/i;\n\nconst REDACTED_PLACEHOLDER = \"<redacted>\";\n\n/**\n * Tell the developer, one line per key, which `.env` values the ambient\n * process environment silently beat.\n *\n * Uses `console.warn` (stderr) rather than the `log` singleton on purpose:\n * this runs from `loadEnvironmentFiles()`, ahead of the logger connector in\n * the boot sequence, so any channel configured through `log.*` has nowhere to\n * deliver to yet. Same reasoning as `console.error` in\n * `src/http/boot-port-preflight.ts`.\n */\nexport function reportEnvironmentOverrides(overrides: EnvironmentOverride[]): void {\n for (const override of overrides) {\n const isSecretShaped = SECRET_KEY_PATTERN.test(override.key);\n const effectiveValue = isSecretShaped ? REDACTED_PLACEHOLDER : override.effectiveValue;\n const fileValue = isSecretShaped ? REDACTED_PLACEHOLDER : override.fileValue;\n\n console.warn(\n `[env] ${override.key}=${effectiveValue} is in effect from the process environment, overriding .env's ${override.key}=${fileValue}`,\n );\n }\n}\n"],"mappings":";;;;;;AAOA,MAAM,qBAAqB;AAE3B,MAAM,uBAAuB;;;;;;;;;;;AAY7B,SAAgB,2BAA2B,WAAwC;CACjF,KAAK,MAAM,YAAY,WAAW;EAChC,MAAM,iBAAiB,mBAAmB,KAAK,SAAS,GAAG;EAC3D,MAAM,iBAAiB,iBAAiB,uBAAuB,SAAS;EACxE,MAAM,YAAY,iBAAiB,uBAAuB,SAAS;EAEnE,QAAQ,KACN,SAAS,SAAS,IAAI,GAAG,eAAe,gEAAgE,SAAS,IAAI,GAAG,WAC1H;CACF;AACF"}
@@ -22,7 +22,10 @@ declare module "@warlock.js/seal" {
22
22
  file: (errorMessage?: string) => FileValidator & StandardSchemaV1<UploadedFile>;
23
23
  localized: <T extends BaseValidator = ScalarValidator & StandardSchemaV1<string | number | boolean>>(valueValidator?: T, errorMessage?: string) => ArrayValidator & {
24
24
  validator: LocalizedEntryValidator<T>;
25
- };
25
+ } & StandardSchemaV1<Array<{
26
+ localeCode: string;
27
+ value: Infer<T>;
28
+ }>>;
26
29
  }
27
30
  interface ScalarValidator {
28
31
  /** Value must be unique in database except current user */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../../../../../../../core/src/validation/types.ts"],"mappings":";;;;;;;;;;;;KAmCK,uBAAA,WAAkC,aAAA,IAAiB,eAAA;EACtD,UAAA,EAAY,eAAA,GAAkB,gBAAA;EAC9B,KAAA,EAAO,CAAA;AAAA,KAEP,gBAAA;EACE,UAAA;EACA,KAAA,EAAO,KAAA,CAAM,CAAA;AAAA;AAAA;EAAA,UAME,UAAA;IACf,IAAA,GAAO,YAAA,cAA0B,aAAA,GAAgB,gBAAA,CAAiB,YAAA;IAClE,SAAA,aACY,aAAA,GAAgB,eAAA,GAAkB,gBAAA,6BAE5C,cAAA,GAAiB,CAAA,EACjB,YAAA,cACG,cAAA;MACH,SAAA,EAAW,uBAAA,CAAwB,CAAA;IAAA;EAAA;EAAA,UAI7B,eAAA;IAlBR;IAoBA,uBAAA,CACE,KAAA,EAAO,UAAA,CAAW,KAAA,YAClB,WAAA,GAAc,OAAA,CAAQ,kCAAA;MACpB,YAAA;IAAA;IAvBU;IA4Bd,qBAAA,CACE,KAAA,EAAO,UAAA,CAAW,KAAA,YAClB,WAAA,GAAc,OAAA,CAAQ,gCAAA;MACpB,YAAA;IAAA;IAxB6B;IA6BjC,uBAAA,CACE,KAAA,EAAO,UAAA,CAAW,KAAA,YAClB,WAAA,GAAc,OAAA,CAAQ,kCAAA;MACpB,YAAA;IAAA;IA9BwB;IAmC5B,qBAAA,CACE,KAAA,EAAO,UAAA,CAAW,KAAA,YAClB,WAAA,GAAc,OAAA,CAAQ,gCAAA;MACpB,YAAA;IAAA;EAAA;EAAA,UAMI,eAAA;IACR,uBAAA,EAAyB,eAAA;IACzB,qBAAA,EAAuB,eAAA;IACvB,uBAAA,EAAyB,eAAA;IACzB,qBAAA,EAAuB,eAAA;EAAA;AAAA;AAAA,KAYf,uBAAA;EAhCY;;;;;;EAwCtB,gBAAA;EA/BkB;;;;;;EAsClB,cAAA;EA9EiB;;;;EAmFjB,cAAA;EAlFoE;;;;EAuFpE,aAAA,GAAgB,qBAAA;EArFgC;;;EAyFhD,kBAAA,GAAqB,0BAA0B;AAAA"}
1
+ {"version":3,"file":"types.d.mts","names":[],"sources":["../../../../../../../core/src/validation/types.ts"],"mappings":";;;;;;;;;;;;KAmCK,uBAAA,WAAkC,aAAA,IAAiB,eAAA;EACtD,UAAA,EAAY,eAAA,GAAkB,gBAAA;EAC9B,KAAA,EAAO,CAAA;AAAA,KAEP,gBAAA;EACE,UAAA;EACA,KAAA,EAAO,KAAA,CAAM,CAAA;AAAA;AAAA;EAAA,UAME,UAAA;IACf,IAAA,GAAO,YAAA,cAA0B,aAAA,GAAgB,gBAAA,CAAiB,YAAA;IAClE,SAAA,aACY,aAAA,GAAgB,eAAA,GAAkB,gBAAA,6BAE5C,cAAA,GAAiB,CAAA,EACjB,YAAA,cACG,cAAA;MACH,SAAA,EAAW,uBAAA,CAAwB,CAAA;IAAA,IACjC,gBAAA,CACA,KAAA;MACE,UAAA;MACA,KAAA,EAAO,KAAA,CAAM,CAAA;IAAA;EAAA;EAAA,UAKX,eAAA;IAvBM;IAyBd,uBAAA,CACE,KAAA,EAAO,UAAA,CAAW,KAAA,YAClB,WAAA,GAAc,OAAA,CAAQ,kCAAA;MACpB,YAAA;IAAA;IA5BU;IAiCd,qBAAA,CACE,KAAA,EAAO,UAAA,CAAW,KAAA,YAClB,WAAA,GAAc,OAAA,CAAQ,gCAAA;MACpB,YAAA;IAAA;IA3BQ;IAgCZ,uBAAA,CACE,KAAA,EAAO,UAAA,CAAW,KAAA,YAClB,WAAA,GAAc,OAAA,CAAQ,kCAAA;MACpB,YAAA;IAAA;IA/BC;IAoCL,qBAAA,CACE,KAAA,EAAO,UAAA,CAAW,KAAA,YAClB,WAAA,GAAc,OAAA,CAAQ,gCAAA;MACpB,YAAA;IAAA;EAAA;EAAA,UAMI,eAAA;IACR,uBAAA,EAAyB,eAAA;IACzB,qBAAA,EAAuB,eAAA;IACvB,uBAAA,EAAyB,eAAA;IACzB,qBAAA,EAAuB,eAAA;EAAA;AAAA;AAAA,KAYf,uBAAA;EAvCQ;;;;;;EA+ClB,gBAAA;EA/B0B;;;;;;EAsC1B,cAAA;EA3BwC;;;;EAgCxC,cAAA;EAvFmD;;;;EA4FnD,aAAA,GAAgB,qBAAA;EA1Fc;;;EA8F9B,kBAAA,GAAqB,0BAA0B;AAAA"}
package/llms-full.txt CHANGED
@@ -3586,7 +3586,7 @@ The third line is conditional on the parent having actually seen child output. W
3586
3586
 
3587
3587
  That distinction is the point of the change: an unhelpful "see above" printed above an empty terminal used to be the entire diagnostic.
3588
3588
 
3589
- **Port already in use.** The HTTP connector preflights the port immediately before `listen()`, so a collision is named rather than surfacing as a raw `EADDRINUSE` from inside Fastify:
3589
+ **Port already in use.** The port is preflighted twice: once **before the early-phase connectors**, so a collision is reported without waiting for the database to connect, and again in the HTTP connector immediately before `listen()`, because a port can be taken in the seconds between the two. Either way the collision is named rather than surfacing as a raw `EADDRINUSE` from inside Fastify:
3590
3590
 
3591
3591
  ```
3592
3592
  EADDRINUSE: Port 3000 is already in use on 127.0.0.1. Stop the dev server (or whatever
@@ -3594,7 +3594,15 @@ else is listening on port 3000) and run again, or start on a free port — e.g.
3594
3594
  startHttpTestServer({ port: 3001 }).
3595
3595
  ```
3596
3596
 
3597
- The connector logs it fatally and exits `1`; the supervisor forwards that text and then prints the failure summary above it. `EACCES` on the port is treated the same way as `EADDRINUSE` (a privileged port you may not bind is also "not available"); anything else the probe throws is rethrown untouched.
3597
+ **The process exits `78` (`EX_CONFIG`), and `warlock dev`'s supervisor treats that as terminal it prints once and stops rather than restarting.** That code is the counterpart of `75`, which a worker uses to ask for a fresh process. The distinction is the point: a code error is worth restarting, and a *startup precondition* a port held by something else, a port value that is not a port, a boot validator that rejected — cannot change because we tried again six seconds later. Retrying one only reprints the diagnostic and then scrolls it away.
3598
+
3599
+ `EACCES` on the port is treated the same way as `EADDRINUSE` (a privileged port you may not bind is also "not available"); anything else the probe throws is rethrown untouched.
3600
+
3601
+ **A configured port is normalised before anything binds.** `env()` coerces a `.env` value to a number only when it round-trips exactly, so `HTTP_PORT=03999`, `" 3999"`, `+3999` and `1e3` all arrive as strings. They are resolved to a canonical integer first — used for the preflight, for `listen()`, and for the port reported to a supervisor — and a value that cannot become a usable port fails naming it. When the raw value was not already canonical, one line says so:
3602
+
3603
+ ```
3604
+ Configured http.port "03999" normalised to 3999.
3605
+ ```
3598
3606
 
3599
3607
  ### How readiness is reported
3600
3608
 
package/package.json CHANGED
@@ -25,13 +25,13 @@
25
25
  "@mongez/slug": "^1.0.7",
26
26
  "@mongez/supportive-is": "^2.1.4",
27
27
  "@mongez/time-wizard": "^1.0.6",
28
- "@warlock.js/auth": "5.3.1",
29
- "@warlock.js/cache": "5.3.1",
30
- "@warlock.js/cascade": "5.3.1",
31
- "@warlock.js/context": "5.3.1",
32
- "@warlock.js/logger": "5.3.1",
33
- "@warlock.js/seal": "5.3.1",
34
- "@warlock.js/fs": "5.3.1",
28
+ "@warlock.js/auth": "5.4.0",
29
+ "@warlock.js/cache": "5.4.0",
30
+ "@warlock.js/cascade": "5.4.0",
31
+ "@warlock.js/context": "5.4.0",
32
+ "@warlock.js/logger": "5.4.0",
33
+ "@warlock.js/seal": "5.4.0",
34
+ "@warlock.js/fs": "5.4.0",
35
35
  "chokidar": "^5.0.0",
36
36
  "dayjs": "^1.11.19",
37
37
  "es-module-lexer": "^2.0.0",
@@ -57,10 +57,10 @@
57
57
  "react": "^19.2.3",
58
58
  "react-dom": "^19.2.3",
59
59
  "@react-email/render": "^2.0.5",
60
- "@warlock.js/herald": "5.3.1",
61
- "@warlock.js/ai": "5.3.1",
62
- "@warlock.js/access": "5.3.1",
63
- "@warlock.js/notifications": "5.3.1"
60
+ "@warlock.js/herald": "5.4.0",
61
+ "@warlock.js/ai": "5.4.0",
62
+ "@warlock.js/access": "5.4.0",
63
+ "@warlock.js/notifications": "5.4.0"
64
64
  },
65
65
  "peerDependenciesMeta": {
66
66
  "sharp": {
@@ -123,7 +123,7 @@
123
123
  ],
124
124
  "author": "hassanzohdy",
125
125
  "license": "MIT",
126
- "version": "5.3.1",
126
+ "version": "5.4.0",
127
127
  "type": "module",
128
128
  "main": "./esm/index.mjs",
129
129
  "module": "./esm/index.mjs",
@@ -309,7 +309,7 @@ The third line is conditional on the parent having actually seen child output. W
309
309
 
310
310
  That distinction is the point of the change: an unhelpful "see above" printed above an empty terminal used to be the entire diagnostic.
311
311
 
312
- **Port already in use.** The HTTP connector preflights the port immediately before `listen()`, so a collision is named rather than surfacing as a raw `EADDRINUSE` from inside Fastify:
312
+ **Port already in use.** The port is preflighted twice: once **before the early-phase connectors**, so a collision is reported without waiting for the database to connect, and again in the HTTP connector immediately before `listen()`, because a port can be taken in the seconds between the two. Either way the collision is named rather than surfacing as a raw `EADDRINUSE` from inside Fastify:
313
313
 
314
314
  ```
315
315
  EADDRINUSE: Port 3000 is already in use on 127.0.0.1. Stop the dev server (or whatever
@@ -317,7 +317,15 @@ else is listening on port 3000) and run again, or start on a free port — e.g.
317
317
  startHttpTestServer({ port: 3001 }).
318
318
  ```
319
319
 
320
- The connector logs it fatally and exits `1`; the supervisor forwards that text and then prints the failure summary above it. `EACCES` on the port is treated the same way as `EADDRINUSE` (a privileged port you may not bind is also "not available"); anything else the probe throws is rethrown untouched.
320
+ **The process exits `78` (`EX_CONFIG`), and `warlock dev`'s supervisor treats that as terminal it prints once and stops rather than restarting.** That code is the counterpart of `75`, which a worker uses to ask for a fresh process. The distinction is the point: a code error is worth restarting, and a *startup precondition* a port held by something else, a port value that is not a port, a boot validator that rejected — cannot change because we tried again six seconds later. Retrying one only reprints the diagnostic and then scrolls it away.
321
+
322
+ `EACCES` on the port is treated the same way as `EADDRINUSE` (a privileged port you may not bind is also "not available"); anything else the probe throws is rethrown untouched.
323
+
324
+ **A configured port is normalised before anything binds.** `env()` coerces a `.env` value to a number only when it round-trips exactly, so `HTTP_PORT=03999`, `" 3999"`, `+3999` and `1e3` all arrive as strings. They are resolved to a canonical integer first — used for the preflight, for `listen()`, and for the port reported to a supervisor — and a value that cannot become a usable port fails naming it. When the raw value was not already canonical, one line says so:
325
+
326
+ ```
327
+ Configured http.port "03999" normalised to 3999.
328
+ ```
321
329
 
322
330
  ### How readiness is reported
323
331