@warlock.js/core 4.12.0 → 4.14.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 (189) hide show
  1. package/CHANGELOG.md +214 -0
  2. package/esm/cli/cli-commands.manager.mjs.map +1 -1
  3. package/esm/cli/commands/add.command.mjs +1 -1
  4. package/esm/cli/commands/add.command.mjs.map +1 -1
  5. package/esm/cli/commands/build.command.mjs +1 -1
  6. package/esm/cli/commands/build.command.mjs.map +1 -1
  7. package/esm/cli/commands/create-database.command.mjs +1 -1
  8. package/esm/cli/commands/create-database.command.mjs.map +1 -1
  9. package/esm/cli/commands/dev-server.command.mjs +1 -1
  10. package/esm/cli/commands/dev-server.command.mjs.map +1 -1
  11. package/esm/cli/commands/doctor/doctor-command.action.mjs.map +1 -1
  12. package/esm/cli/commands/doctor.command.mjs +1 -1
  13. package/esm/cli/commands/doctor.command.mjs.map +1 -1
  14. package/esm/cli/commands/drop-tables.command.mjs +1 -1
  15. package/esm/cli/commands/drop-tables.command.mjs.map +1 -1
  16. package/esm/cli/commands/generate/generate.command.mjs +1 -1
  17. package/esm/cli/commands/generate/generate.command.mjs.map +1 -1
  18. package/esm/cli/commands/generate/generators/controller.generator.mjs.map +1 -1
  19. package/esm/cli/commands/generate/generators/migration.generator.mjs +1 -1
  20. package/esm/cli/commands/generate/generators/migration.generator.mjs.map +1 -1
  21. package/esm/cli/commands/generate/generators/model.generator.mjs +1 -1
  22. package/esm/cli/commands/generate/generators/model.generator.mjs.map +1 -1
  23. package/esm/cli/commands/generate/generators/module.generator.mjs +1 -1
  24. package/esm/cli/commands/generate/generators/module.generator.mjs.map +1 -1
  25. package/esm/cli/commands/generate/generators/repository.generator.mjs.map +1 -1
  26. package/esm/cli/commands/generate/generators/resource.generator.mjs.map +1 -1
  27. package/esm/cli/commands/generate/generators/service.generator.mjs.map +1 -1
  28. package/esm/cli/commands/generate/utils/path-resolver.mjs +1 -1
  29. package/esm/cli/commands/generate/utils/writer.mjs +1 -1
  30. package/esm/cli/commands/migrate.command.mjs +1 -1
  31. package/esm/cli/commands/migrate.command.mjs.map +1 -1
  32. package/esm/cli/commands/routes/routes-command.action.mjs.map +1 -1
  33. package/esm/cli/commands/routes.command.mjs +1 -1
  34. package/esm/cli/commands/routes.command.mjs.map +1 -1
  35. package/esm/cli/commands/seed.command.mjs +1 -1
  36. package/esm/cli/commands/seed.command.mjs.map +1 -1
  37. package/esm/cli/commands/start-production.command.mjs +1 -1
  38. package/esm/cli/commands/start-production.command.mjs.map +1 -1
  39. package/esm/cli/commands/storage-put.action.mjs.map +1 -1
  40. package/esm/cli/commands/storage-put.command.mjs +1 -1
  41. package/esm/cli/commands/storage-put.command.mjs.map +1 -1
  42. package/esm/cli/commands/typings-generator.command.mjs +2 -2
  43. package/esm/cli/commands/typings-generator.command.mjs.map +1 -1
  44. package/esm/cli/commands/update.command.mjs +1 -1
  45. package/esm/cli/commands/update.command.mjs.map +1 -1
  46. package/esm/cli/commands-loader.mjs +1 -1
  47. package/esm/cli/commands-loader.mjs.map +1 -1
  48. package/esm/{cli → commands}/cli-command.d.mts +1 -1
  49. package/esm/commands/cli-command.d.mts.map +1 -0
  50. package/esm/{cli → commands}/cli-command.mjs +1 -1
  51. package/esm/commands/cli-command.mjs.map +1 -0
  52. package/esm/{cli → commands}/types.d.mts +1 -1
  53. package/esm/commands/types.d.mts.map +1 -0
  54. package/esm/config/load-config-files.mjs +1 -1
  55. package/esm/config/load-config-files.mjs.map +1 -1
  56. package/esm/connectors/base-connector.mjs +1 -1
  57. package/esm/connectors/base-connector.mjs.map +1 -1
  58. package/esm/connectors/connectors-manager.d.mts.map +1 -1
  59. package/esm/connectors/connectors-manager.mjs +5 -3
  60. package/esm/connectors/connectors-manager.mjs.map +1 -1
  61. package/esm/connectors/http-connector.d.mts.map +1 -1
  62. package/esm/connectors/http-connector.mjs +0 -2
  63. package/esm/connectors/http-connector.mjs.map +1 -1
  64. package/esm/database/create-database-action.mjs.map +1 -1
  65. package/esm/database/drop-tables-action.mjs.map +1 -1
  66. package/esm/database/migrate-action.mjs +1 -1
  67. package/esm/database/migrate-action.mjs.map +1 -1
  68. package/esm/database/seed-command-action.mjs +1 -1
  69. package/esm/database/seed-command-action.mjs.map +1 -1
  70. package/esm/dev-server/dev-logger.mjs +1 -1
  71. package/esm/dev-server/dev-logger.mjs.map +1 -1
  72. package/esm/dev-server/development-server.mjs +2 -2
  73. package/esm/dev-server/file-event-handler.mjs +1 -1
  74. package/esm/dev-server/file-event-handler.mjs.map +1 -1
  75. package/esm/dev-server/file-manager.mjs +1 -1
  76. package/esm/dev-server/file-manager.mjs.map +1 -1
  77. package/esm/dev-server/file-operations.mjs +1 -1
  78. package/esm/dev-server/file-operations.mjs.map +1 -1
  79. package/esm/dev-server/files-orchestrator.mjs +3 -18
  80. package/esm/dev-server/files-orchestrator.mjs.map +1 -1
  81. package/esm/dev-server/files-watcher.mjs +1 -1
  82. package/esm/dev-server/files-watcher.mjs.map +1 -1
  83. package/esm/dev-server/health-checker/file-health-checker.contract.d.mts +1 -1
  84. package/esm/dev-server/layer-executor.mjs +1 -1
  85. package/esm/dev-server/loader/register-loader.mjs +1 -1
  86. package/esm/dev-server/package-json-manager.mjs +1 -1
  87. package/esm/dev-server/package-json-manager.mjs.map +1 -1
  88. package/esm/dev-server/parse-imports.mjs +2 -2
  89. package/esm/dev-server/parse-imports.mjs.map +1 -1
  90. package/esm/dev-server/tsconfig-manager.mjs +1 -1
  91. package/esm/dev-server/tsconfig-manager.mjs.map +1 -1
  92. package/esm/dev-server/type-generator.mjs +1 -1
  93. package/esm/dev-server/type-generator.mjs.map +1 -1
  94. package/esm/dev-server/utils.mjs +1 -1
  95. package/esm/dev-server/utils.mjs.map +1 -1
  96. package/esm/generations/add-command.action.mjs +20 -8
  97. package/esm/generations/add-command.action.mjs.map +1 -1
  98. package/esm/http/build-cors-options.mjs +32 -0
  99. package/esm/http/build-cors-options.mjs.map +1 -0
  100. package/esm/http/middleware/max-body-size.middleware.d.mts +13 -5
  101. package/esm/http/middleware/max-body-size.middleware.d.mts.map +1 -1
  102. package/esm/http/middleware/max-body-size.middleware.mjs +13 -5
  103. package/esm/http/middleware/max-body-size.middleware.mjs.map +1 -1
  104. package/esm/http/plugins.d.mts.map +1 -1
  105. package/esm/http/plugins.mjs +2 -9
  106. package/esm/http/plugins.mjs.map +1 -1
  107. package/esm/http/server.d.mts.map +1 -1
  108. package/esm/http/server.mjs +3 -8
  109. package/esm/http/server.mjs.map +1 -1
  110. package/esm/index.d.mts +9 -17
  111. package/esm/index.mjs +4 -15
  112. package/esm/production/production-builder.mjs +51 -3
  113. package/esm/production/production-builder.mjs.map +1 -1
  114. package/esm/production/resolve-build-config.mjs +1 -1
  115. package/esm/production/resolve-build-config.mjs.map +1 -1
  116. package/esm/router/router.d.mts +9 -0
  117. package/esm/router/router.d.mts.map +1 -1
  118. package/esm/router/router.mjs +58 -5
  119. package/esm/router/router.mjs.map +1 -1
  120. package/esm/router/types.d.mts +24 -1
  121. package/esm/router/types.d.mts.map +1 -1
  122. package/esm/tests/index.d.mts +3 -2
  123. package/esm/tests/index.mjs +2 -3
  124. package/esm/tests/start-http-development-server.d.mts.map +1 -1
  125. package/esm/tests/start-http-development-server.mjs +38 -15
  126. package/esm/tests/start-http-development-server.mjs.map +1 -1
  127. package/esm/tests/test-connectors-selection.d.mts +14 -0
  128. package/esm/tests/test-connectors-selection.d.mts.map +1 -0
  129. package/esm/tests/test-connectors-selection.mjs +72 -0
  130. package/esm/tests/test-connectors-selection.mjs.map +1 -0
  131. package/esm/tests/test-helpers.d.mts.map +1 -1
  132. package/esm/tests/test-helpers.mjs +34 -13
  133. package/esm/tests/test-helpers.mjs.map +1 -1
  134. package/esm/tests/test-lifecycle-state.mjs +27 -0
  135. package/esm/tests/test-lifecycle-state.mjs.map +1 -0
  136. package/esm/tests/test-setup-timeout.mjs +53 -0
  137. package/esm/tests/test-setup-timeout.mjs.map +1 -0
  138. package/esm/tests/vitest-setup.d.mts +64 -8
  139. package/esm/tests/vitest-setup.d.mts.map +1 -1
  140. package/esm/tests/vitest-setup.mjs +317 -11
  141. package/esm/tests/vitest-setup.mjs.map +1 -1
  142. package/esm/utils/framework-vesion.mjs +1 -1
  143. package/esm/utils/index.d.mts +1 -0
  144. package/esm/utils/index.mjs +1 -0
  145. package/esm/utils/normalized-path.d.mts +55 -0
  146. package/esm/utils/normalized-path.d.mts.map +1 -0
  147. package/esm/{dev-server/path.mjs → utils/normalized-path.mjs} +15 -2
  148. package/esm/utils/normalized-path.mjs.map +1 -0
  149. package/esm/vite/index.d.mts +2 -0
  150. package/esm/vite/index.mjs +1 -1
  151. package/esm/vite/lower-stage3-decorators.d.mts +1 -1
  152. package/esm/vite/lower-stage3-decorators.mjs +1 -1
  153. package/esm/vite/lower-stage3-decorators.mjs.map +1 -1
  154. package/esm/warlock-config/index.mjs +1 -1
  155. package/esm/warlock-config/types.d.mts +34 -1
  156. package/esm/warlock-config/types.d.mts.map +1 -1
  157. package/esm/warlock-config/warlock-config.manager.d.mts.map +1 -1
  158. package/esm/warlock-config/warlock-config.manager.mjs +1 -2
  159. package/esm/warlock-config/warlock-config.manager.mjs.map +1 -1
  160. package/llms-full.txt +78 -23
  161. package/llms.txt +3 -3
  162. package/package.json +24 -12
  163. package/skills/lower-stage3-decorators/SKILL.md +4 -2
  164. package/skills/run-app/SKILL.md +6 -0
  165. package/skills/test-http/SKILL.md +37 -12
  166. package/skills/test-service/SKILL.md +167 -24
  167. package/skills/use-middleware/SKILL.md +5 -1
  168. package/esm/cli/cli-command.d.mts.map +0 -1
  169. package/esm/cli/cli-command.mjs.map +0 -1
  170. package/esm/cli/types.d.mts.map +0 -1
  171. package/esm/dev-server/files-orchestrator.d.mts +0 -89
  172. package/esm/dev-server/files-orchestrator.d.mts.map +0 -1
  173. package/esm/dev-server/files-watcher.d.mts +0 -69
  174. package/esm/dev-server/files-watcher.d.mts.map +0 -1
  175. package/esm/dev-server/health-checker/checkers/base-health-checker.d.mts +0 -55
  176. package/esm/dev-server/health-checker/checkers/base-health-checker.d.mts.map +0 -1
  177. package/esm/dev-server/health-checker/checkers/eslint-health-checker.d.mts +0 -44
  178. package/esm/dev-server/health-checker/checkers/eslint-health-checker.d.mts.map +0 -1
  179. package/esm/dev-server/health-checker/checkers/typescript-health-checker.d.mts +0 -60
  180. package/esm/dev-server/health-checker/checkers/typescript-health-checker.d.mts.map +0 -1
  181. package/esm/dev-server/health-checker/files-healthcare.manager.d.mts +0 -119
  182. package/esm/dev-server/health-checker/files-healthcare.manager.d.mts.map +0 -1
  183. package/esm/dev-server/health-checker/index.mjs +0 -7
  184. package/esm/dev-server/module-loader.d.mts +0 -63
  185. package/esm/dev-server/module-loader.d.mts.map +0 -1
  186. package/esm/dev-server/path.mjs.map +0 -1
  187. package/esm/tests/test-server-port-channel.d.mts +0 -27
  188. package/esm/tests/test-server-port-channel.d.mts.map +0 -1
  189. /package/esm/{cli → commands}/index.d.mts +0 -0
@@ -1,13 +1,23 @@
1
1
  ---
2
2
  name: test-service
3
- description: 'Pure unit tests against services, repositories, models, and use-cases — `setupTest({ connectors })` bootstraps each Vitest worker with its own DB/cache connections so you can call your code directly. Triggers: `setupTest`, `src/test-setup.ts`, `tests.connectors`, `Application.setEnvironment`; "unit-test a service", "test a repository query", "vitest setupFiles", "skip connectors for pure-logic tests"; typical import `import { setupTest } from "@warlock.js/core"`. Skip: HTTP integration — `@warlock.js/core/test-http/SKILL.md`; warlock add test scaffold — `@warlock.js/core/write-cli-command/SKILL.md`; competing tooling: jest direct, `supertest`, `nock`.'
3
+ description: 'Pure unit tests against services, repositories, models, and use-cases — `setupTest({ connectors })` bootstraps the framework with its own DB/cache connections so you can call your code directly, and `teardownTest()` closes it. Triggers: `setupTest`, `teardownTest`, `src/test-setup.ts`, `tests.connectors`, `tests.setupTimeout`, `Application.setEnvironment`; "unit-test a service", "test a repository query", "vitest setupFiles", "skip connectors for pure-logic tests"; typical import `import { setupTest, teardownTest } from "@warlock.js/core/tests"`. Skip: HTTP integration — `@warlock.js/core/test-http/SKILL.md`; warlock add test scaffold — `@warlock.js/core/write-cli-command/SKILL.md`; competing tooling: jest direct, `supertest`, `nock`.'
4
4
  ---
5
5
 
6
6
  # Warlock — test a service
7
7
 
8
- For unit tests, you import the thing under test and call it directly. No HTTP, no fetch, no controllers. Framework testing in Warlock is about getting your **service layer** under test efficiently — and that means each Vitest worker needs its own bootstrapped framework with a DB connection.
8
+ For unit tests, you import the thing under test and call it directly. No HTTP, no fetch, no controllers. Framework testing in Warlock is about getting your **service layer** under test efficiently — and that means your tests need a bootstrapped framework with a DB connection.
9
9
 
10
- `setupTest()` is the one-call bootstrap that gives each worker that environment.
10
+ `setupTest()` is the one-call bootstrap that provides that environment; `teardownTest()` closes it.
11
+
12
+ ⚠ **Corrected in 4.14.0 — `setupTest` is CALLED once per TEST FILE, not once per worker.** Every version of this skill through 4.13.0 said "per worker", the generated `src/test-setup.ts` carries a `Per-Worker Test Setup` comment saying the same thing, and **both were wrong.** Vitest runs `setupFiles` before **each test file**, and the setup module's registry is rebuilt every time — measured across all four `pool` × `isolate` combinations.
13
+
14
+ ⛔ **If your project was generated before 4.14.0, fix BOTH the comment and the call.** The comment is false, **and** the generated `setupTest({ connectors: true })` is now an *explicit* value that overrides your `src/config/tests.ts`. **Bare `setupTest()` is the correct call.**
15
+
16
+ **The lifetime is FILE-SCOPED, on purpose.** Your setup file bootstraps the framework and its `afterAll(teardownTest)` closes it, once per test file. **One owner, one pairing — correct under every pool, every isolation setting, and watch mode.**
17
+
18
+ ⚠ **A worker-scoped lifetime is possible and is deliberately not shipped yet.** Lifecycle state now lives in the worker runtime, so leaving the framework running would let every file in a worker share one bootstrap. Two things block claiming it: under `pool: "threads"` we cannot observe whether Node reclaims a torn-down thread's sockets and pools, and **in watch mode Vitest reuses workers between reruns, so there is no recycle and no cleanup owner.** It gets taken when the real cost is measured and the integration is chosen, not inherited. See *Lifecycle and repeated calls* below.
19
+
20
+ ⚠ **Changed in 4.13.0 — the import is a subpath now.** `setupTest` used to be re-exported from the package root; it is not any more, because that put the test helpers into every application's production module graph. `import { setupTest } from "@warlock.js/core"` now fails with *"has no exported member"* — **add `/tests` to the specifier and nothing else changes.**
11
21
 
12
22
  ## The shape
13
23
 
@@ -32,12 +42,12 @@ describe("registerUserService", () => {
32
42
  });
33
43
  ```
34
44
 
35
- No `beforeAll(setupTest)` in this file — the project's `src/test-setup.ts` (registered as `setupFiles` in `vite.config.ts`) already ran it once per worker before any test executed.
45
+ No `beforeAll(setupTest)` in this file — the project's `src/test-setup.ts` (registered as `setupFiles` in `vite.config.ts`) already ran it **before this file's tests executed**, as it does before every test file.
36
46
 
37
- ## `setupTest({ connectors })` — the worker bootstrap
47
+ ## `setupTest({ connectors })` — the bootstrap
38
48
 
39
49
  ```ts
40
- import { setupTest } from "@warlock.js/core";
50
+ import { setupTest } from "@warlock.js/core/tests";
41
51
 
42
52
  await setupTest({ connectors: true });
43
53
  ```
@@ -49,10 +59,10 @@ What it does (in order):
49
59
  3. Runs `bootstrap()` — env, app, prestart hooks.
50
60
  4. Initializes the `filesOrchestrator` (module/route/config discovery, no file watching).
51
61
  5. Loads all `src/config/*.ts` files.
52
- 6. Reads `tests.connectors` from config (overrides the parameter if set).
62
+ 6. Resolves the connector selection — **an explicit parameter wins, then `tests.connectors` from config, then the `true` default.** See *Selecting connectors* below.
53
63
  7. Starts the chosen connectors — but **never `http`** when you pass a boolean. HTTP is the global-setup's job.
54
64
 
55
- The result: each worker has its own DB/cache/logger/storage connections. Models save, repositories query, services run. Same code as production, just isolated to the test process.
65
+ The result: DB/cache/logger/storage connections your code can use. Models save, repositories query, services run. Same code as production, just isolated to the test process.
56
66
 
57
67
  ### The `connectors` parameter
58
68
 
@@ -62,9 +72,9 @@ The result: each worker has its own DB/cache/logger/storage connections. Models
62
72
  | `false` | None | Pure logic tests with no DB / cache touches (parsers, validators, util functions). |
63
73
  | `["database", "cache"]` | Just those, in that order | A test that only needs DB but not, say, the storage driver. |
64
74
 
65
- The default `true` is the sane choice. Reach for `false` when the unit you're testing genuinely doesn't talk to any framework subsystem — pulling up a DB connection per worker just to test a string parser is wasted setup time.
75
+ The default `true` is the sane choice. Reach for `false` when the unit you're testing genuinely doesn't talk to any framework subsystem — pulling up a DB connection **for every file** just to test a string parser is wasted setup time.
66
76
 
67
- ### Override via config — `src/config/tests.ts`
77
+ ### Selecting connectors — `src/config/tests.ts`
68
78
 
69
79
  ```ts title="src/config/tests.ts"
70
80
  const testsConfigurations = {
@@ -74,7 +84,33 @@ const testsConfigurations = {
74
84
  export default testsConfigurations;
75
85
  ```
76
86
 
77
- If `tests.connectors` is set, **it wins over the `setupTest({ connectors })` parameter**. Use this when every test file in the project agrees on the same minimal connector list saves repeating the explicit array in `test-setup.ts`.
87
+ **BREAKING in 4.14.0 — the precedence flipped.**
88
+
89
+ | | Order |
90
+ |---|---|
91
+ | **4.13.0 and earlier** | `tests.connectors` config **>** `setupTest({ connectors })` parameter **>** `true` |
92
+ | **4.14.0 onward** | **explicit `setupTest({ connectors })` parameter** **>** `tests.connectors` config **>** `true` |
93
+
94
+ **An explicit call-site value now beats project config.** If your project sets `tests.connectors` *and* some test file passes `connectors` explicitly, **that file will start a different connector set after upgrading.** Search for `setupTest({` across your tests before you upgrade — a call passing `connectors` was previously ignored and is now honoured.
95
+
96
+ **"Explicit" means you supplied a non-`undefined` value.** Both of these fall through to config:
97
+
98
+ ```ts
99
+ await setupTest(); // → tests.connectors, else true
100
+ await setupTest({}); // → tests.connectors, else true
101
+ await setupTest({ connectors: undefined }); // → tests.connectors, else true — NOT "start none"
102
+ ```
103
+
104
+ The `undefined` rule is deliberate: an optional variable that happens to be `undefined` must not silently erase your project config.
105
+
106
+ ```ts
107
+ await setupTest({ connectors: false }); // → none, even if config says otherwise
108
+ await setupTest({ connectors: ["database"] }); // → exactly that, even if config differs
109
+ ```
110
+
111
+ ⚠ **The generated `src/test-setup.ts` calls `setupTest()` with no argument, on purpose.** If you "helpfully" change it to `setupTest({ connectors: true })`, you have made it explicit and **erased the `tests.connectors` layer for the whole project.**
112
+
113
+ Use `tests.connectors` when every test file agrees on the same minimal list — it saves repeating the array, and individual files can still override it.
78
114
 
79
115
  ## Project wiring — `src/test-setup.ts` + `vite.config.ts`
80
116
 
@@ -82,16 +118,24 @@ The `warlock add test` feature creates both files. The standard wiring:
82
118
 
83
119
  ```ts title="src/test-setup.ts"
84
120
  /**
85
- * Per-Worker Test Setup
86
- * Runs in EACH Vitest worker thread before tests execute.
121
+ * Test Setup
122
+ * Runs before EACH test file not once per worker.
87
123
  */
88
- import { setupTest } from "@warlock.js/core";
124
+ import { afterAll } from "vitest";
125
+ import { setupTest, teardownTest } from "@warlock.js/core/tests";
89
126
 
90
- await setupTest({ connectors: true });
127
+ await setupTest();
128
+ afterAll(teardownTest);
91
129
  ```
92
130
 
131
+ ⛔ **Three things changed here in 4.14.0. If you generated this file earlier, replace all three — it is not a comment fix.**
132
+
133
+ 1. **`afterAll(teardownTest)` is new and mandatory.** Nothing else closes the framework your tests started. This is what makes the lifetime file-scoped and owned rather than left running.
134
+ 2. **The call is now bare `setupTest()`, not `setupTest({ connectors: true })`.** Under the flipped precedence, passing `true` is an *explicit* value and would override `tests.connectors` for **every file in the project.** Bare means "whatever this project configured, else the default".
135
+ 3. **The comment used to say `Per-Worker Test Setup` / "Runs in EACH Vitest worker thread".** False — see the top of this skill.
136
+
93
137
  ```ts title="vite.config.ts"
94
- import { lowerStage3Decorators } from "@warlock.js/core";
138
+ import { lowerStage3Decorators } from "@warlock.js/core/vite";
95
139
  import mongezVite from "@mongez/vite";
96
140
  import { defineConfig } from "vitest/config";
97
141
 
@@ -99,7 +143,7 @@ export default defineConfig({
99
143
  plugins: [lowerStage3Decorators(), mongezVite()],
100
144
  test: {
101
145
  globalSetup: "./src/test-global-setup.ts", // ← HTTP server (see test-http skill)
102
- setupFiles: ["./src/test-setup.ts"], // ← runs setupTest per worker
146
+ setupFiles: ["./src/test-setup.ts"], // ← runs setupTest before EACH test file
103
147
  environment: "node",
104
148
  globals: false,
105
149
  include: ["src/app/**/*.test.ts"],
@@ -204,17 +248,19 @@ afterEach(async () => {
204
248
  });
205
249
  ```
206
250
 
207
- Vitest runs tests in a single worker file sequentially, so an `afterEach` truncate gives each test a clean slate. For cross-file isolation, run the suite with `vitest --pool=forks --maxWorkers=N` and rely on the per-worker connection — each file's data stays within its worker until the run ends.
251
+ Vitest runs the tests within one file sequentially, so an `afterEach` truncate gives each test a clean slate.
252
+
253
+ ⚠ **Cross-*file* isolation is not solved by this.** Separate workers get separate **connections**, not separate **rows** — two files pointed at the same database see each other's committed data regardless of pool or worker count. **Truncate what your file wrote; don't assume the worker boundary did it for you.** Real data isolation (DB-per-worker, transaction-per-test) is a separate piece of work and is not in this release.
208
254
 
209
255
  ### Skipping connectors for pure logic tests
210
256
 
211
257
  ```ts title="src/app/utils/tests/slugify.test.ts"
212
258
  import { beforeAll, describe, expect, it } from "vitest";
213
- import { setupTest } from "@warlock.js/core";
259
+ import { setupTest } from "@warlock.js/core/tests";
214
260
  import { slugify } from "../utils/slugify";
215
261
 
216
262
  beforeAll(async () => {
217
- await setupTest({ connectors: false }); // override the project default
263
+ await setupTest({ connectors: false }); // starts no connectors at all
218
264
  });
219
265
 
220
266
  describe("slugify", () => {
@@ -224,15 +270,112 @@ describe("slugify", () => {
224
270
  });
225
271
  ```
226
272
 
227
- `setupTest` is idempotent per worker (`isSetupComplete` flag) — calling it again with different options after `src/test-setup.ts` already ran is a no-op. To genuinely skip connectors, either set `tests.connectors: false` in config (project-wide) or rely on the default in `src/test-setup.ts` being what you want most of the time.
273
+ **BREAKING in 4.14.0 the example above now REJECTS if your project has a `src/test-setup.ts`.**
274
+
275
+ Through 4.13.0 a second `setupTest` call with different options was a **silent no-op** — you asked for no connectors, got all of them, and nothing told you. In 4.14.0 a conflicting call **rejects with an error naming both the active and the requested selection**, because silently ignoring what you asked for is worse than failing.
276
+
277
+ **If `src/test-setup.ts` already ran `setupTest()` in this file, use one of these instead:**
278
+
279
+ ```ts
280
+ // 1. Tear down first, then set up differently — and PUT IT BACK when the file ends.
281
+ import { afterAll, beforeAll } from "vitest";
282
+ import { setupTest, teardownTest } from "@warlock.js/core/tests";
283
+
284
+ beforeAll(async () => {
285
+ await teardownTest();
286
+ await setupTest({ connectors: false });
287
+ });
288
+
289
+ afterAll(async () => {
290
+ await teardownTest(); // ← REQUIRED, see below
291
+ });
292
+ ```
293
+
294
+ ⛔ **The `afterAll` is not optional** — without it you leave a `connectors: false` runtime ready when the file ends.
295
+
296
+ ⚠ **This pattern interacts with the `afterAll(teardownTest)` in your setup file, and the relative ordering of the two has not been verified.** `teardownTest` is idempotent, so whichever runs second finds an idle lifecycle and no-ops — but **do not build anything on a particular order until someone has measured it.** This is the strongest argument for option 2 below.
297
+
298
+ ```ts
299
+ // 2. Or don't call setupTest at all — a pure-logic test needs nothing from it.
300
+ // The connectors your setup file started are already running; you simply don't use them.
301
+ ```
302
+
303
+ **3. Or set `tests.connectors: false` in `src/config/tests.ts`** if no test file in the project needs connectors.
304
+
305
+ **Option 2 is usually right, and option 1 is easy to get wrong.** Tearing down and re-bootstrapping costs a full framework startup — twice, once for your file and once for the next — to avoid a DB connection you were never going to use. **Reach for option 1 only when a connector's mere presence breaks the thing you're testing**, not to save setup time.
306
+
307
+ ## Lifecycle and repeated calls
308
+
309
+ `setupTest` / `teardownTest` are a pair. **The harness that calls one owns calling the other in the same context.**
310
+
311
+ | Call | Behaviour |
312
+ |---|---|
313
+ | `setupTest(x)` while idle | bootstraps |
314
+ | `setupTest(x)` while already ready with the **same** effective options | no-op |
315
+ | `setupTest(y)` while ready or starting with **different** effective options | ⛔ **rejects**, naming active vs requested |
316
+ | two concurrent `setupTest(x)` calls | share one startup |
317
+ | `setupTest` after a failed setup | allowed — a failed setup unwinds and returns to idle |
318
+ | `teardownTest()` while idle | no-op |
319
+ | two concurrent `teardownTest()` calls | share one shutdown |
320
+ | `setupTest(y)` after a **successful** teardown | allowed, different options fine |
321
+
322
+ **"Same options" is compared by meaning, not by literal value** — connector arrays are deduplicated and compared as sets, so `["cache", "database"]` and `["database", "cache", "cache"]` are the same selection.
323
+
324
+ ⚠ **A failed shutdown poisons the lifecycle.** If `teardownTest()` rejects because the shutdown layer reported a failure, later `setupTest` calls **refuse until the Vitest worker is recycled** or a retried teardown fully succeeds. This is deliberate: a cleared flag does not prove that ports, sockets, pools or timers actually closed, and pretending otherwise hands you a "clean" run built on a leaked runtime.
325
+
326
+ ⚠ **What it cannot detect:** `connectorsManager.shutdown()` catches and logs individual connector failures internally. Those never reach this lifecycle, so they never poison it. It surfaces what that layer reports — no more.
327
+
328
+ ### `tests.setupTimeout` — the setup attempt is bounded
329
+
330
+ **New in 4.14.0.** A setup attempt that never settles used to leave the lifecycle stuck in `starting` and take the worker down with an out-of-memory crash. It is now bounded.
331
+
332
+ ```ts title="src/config/tests.ts"
333
+ const testsConfigurations = {
334
+ connectors: ["database", "logger"],
335
+ setupTimeout: 120000, // milliseconds — this is the default
336
+ };
337
+
338
+ export default testsConfigurations;
339
+ ```
340
+
341
+ **Default: `120000` (two minutes)** — far above a healthy cold start, below the point where you'd stop watching the terminal. When it expires:
342
+
343
+ ```
344
+ setupTest() did not finish within 120000ms and is stuck in the "starting" state. The
345
+ lifecycle is now poisoned: whatever that attempt had already started is not known to be
346
+ closed, so later setupTest() calls refuse until the Vitest worker is recycled. If your
347
+ cold start is legitimately slower than this, raise the bound with `tests.setupTimeout`
348
+ in `src/config/tests.ts` — milliseconds, default 120000.
349
+ ```
350
+
351
+ 1. **It bounds the setup ATTEMPT, not teardown separately.** `teardownTest()` awaits the same attempt, so it inherits the bound — **one timer, not two.** A second teardown-side deadline was tried and rejected: it re-introduced the unbounded re-entry this whole guard exists to remove.
352
+ 2. **Expiry poisons the lifecycle**, it does not return to `idle`. The attempt may have started connectors nobody can now account for, so pretending the runtime is clean would be worse than refusing.
353
+ 3. **⛔ An invalid `setupTimeout` throws, naming the bad value.** Zero, negative and non-numeric all fail loudly rather than falling back to the default — a silent fallback would hide a typo behind a working suite.
354
+ 4. **The bound is measured from when the attempt started**, not from when config was read. `tests.setupTimeout` is only readable after `loadConfigFiles()`, which happens *inside* the window being bounded; re-arming naively would give you the default plus your configured value.
355
+
356
+ ⚠ **What is proven and what is not.** The nine guards above were each seen to fail under their own mutation. **But every spec injects its scheduler**, so the default *value* is tested while the production timer — and whether its `unref` actually releases the worker — is not. **And no spec observes a real hang**: the stuck attempt is a mock gate, not a socket that never returns. These prove what the lifecycle *decides*, not what a genuinely wedged connector does.
357
+
358
+ ### State is per worker runtime, not per module
359
+
360
+ The lifecycle state lives in the worker runtime, not in a module variable. That matters because **Vitest rebuilds the module registry between test files while the worker itself keeps running** — so a module-level flag resets exactly where live DB connections and pools survive. Scope:
361
+
362
+ - **`pool: "forks"`** — state is per worker **process**.
363
+ - **`pool: "threads"`** — state is per worker **thread**. It does **not** cross threads; `globalThis` is per realm, not per process.
364
+
365
+ In both cases the guard's scope matches the resource's scope, which is the point.
366
+
367
+ ⚠ **Not guaranteed:** under `threads` with `isolate: true`, Vitest tears the thread down while the process lives on. **Whether Node reclaims that thread's sockets and pools is unmeasured**, and nothing in this lifecycle can observe it.
228
368
 
229
369
  ## Gotchas
230
370
 
231
- - **`setupTest` is idempotent per worker.** Second + later calls early-return. You can't "swap" the connector set mid-run the first call wins, including the one in `src/test-setup.ts`. Choose your worker default carefully.
232
- - **Per-worker connections are separate from the HTTP server's connections.** A row inserted by a service-level test is on the worker's connection; the HTTP test server has its own. They don't see each other unless they're both pointing at the same physical DB and the inserting test has already committed.
371
+ - **`setupTest` runs per test file, not per worker** every version of this skill through 4.13.0 said otherwise. **You pay one framework bootstrap per test file**, which is what 4.13.0 already cost; the difference is that it is now a chosen lifetime rather than a side effect of a module flag resetting.
372
+ - **Never delete the `afterAll(teardownTest)` from your setup file.** Without it nothing closes what `setupTest` opened, and the connectors outlive the file that started them.
373
+ - ⛔ **You can't swap the connector set by calling `setupTest` again — it rejects now.** Through 4.13.0 the second call was silently ignored. Tear down first, or don't call it.
374
+ - **These connections are separate from the HTTP test server's.** A row inserted by a service-level test is on this connection; the HTTP test server has its own. They only see each other if both point at the same physical DB **and** the inserting test has committed.
375
+ - **`setupTest` takes over the process's `connectorsManager` for its lifetime.** Teardown is manager-wide, so **mixing `setupTest` with manually started connectors is unsupported** — teardown may close yours too.
233
376
  - **`NODE_ENV` is set to `"test"`** by `setupTest`. Code that branches on `Application.isProduction` / `Application.isDevelopment` sees `false` for both. If your tests need production-like config (cookies, CORS), set those values in `src/config/*.ts` explicitly under the test branch — don't rely on the env flag.
234
377
  - **No HTTP from this layer.** `setupTest({ connectors: true })` never starts the HTTP connector by design. Don't try to `request.app.http` your way to a fetch test — use the `test-http` skill instead.
235
- - **Don't import `vitest-setup` from `@warlock.js/core/src/...`.** The public surface is `import { setupTest } from "@warlock.js/core"`. Reaching into source paths breaks when the package layout shifts.
378
+ - **Don't import `vitest-setup` from `@warlock.js/core/src/...`.** The public surface is `import { setupTest } from "@warlock.js/core/tests"`. Reaching into source paths breaks when the package layout shifts.
236
379
  - **Test files need the `.test.ts` suffix.** `include: ["src/app/**/*.test.ts"]` is what vitest scans. A file named `service.tests.ts` (plural) silently doesn't run.
237
380
 
238
381
  ## See also
@@ -81,6 +81,8 @@ Server errors (5xx) are not cached — clients can retry past a 5xx. 4xx respons
81
81
 
82
82
  `http.bodyLimit` in config is read by Fastify at server-start and applies to every body. `middleware.maxBodySize()` is a per-route middleware on top — it checks `Content-Length` after route match and rejects with 413 before body parsing runs. Use both: global as a safety net, per-route for tight caps on small-payload endpoints.
83
83
 
84
+ ⚠ **Since 4.13.0, configuring nothing gives you Fastify's own 1 MB limit.** Earlier versions defaulted to 200 GB, which **replaced** Fastify's protection rather than adding to it — so an app that set nothing had effectively no cap. **Set `bodyLimit` explicitly if you need more than 1 MB.**
85
+
84
86
  ```ts
85
87
  // src/config/http.ts
86
88
  export default { bodyLimit: 10 * 1024 * 1024 }; // 10MB globally
@@ -111,7 +113,9 @@ export default {
111
113
 
112
114
  ## `ipFilter` — fail-closed
113
115
 
114
- `deny` wins over `allow`. If the IP can't be read (empty / unparseable), the request is rejected with 403. Reads via `request.detectIp()` which honors `X-Real-IP` and `X-Forwarded-For` (Fastify starts with `trustProxy: true`).
116
+ `deny` wins over `allow`. If the IP can't be read (empty / unparseable), the request is rejected with 403. Reads via `request.detectIp()`.
117
+
118
+ ⚠ **Since 4.13.0 `http.trustProxy` defaults to `false`**, so `request.detectIp()` returns the socket address and **`X-Real-IP` / `X-Forwarded-For` are ignored unless you opt in.** Set `trustProxy: true` **only when you are genuinely behind a proxy that overwrites those headers** — before 4.13.0 the default was `true`, which meant any client could set its own forwarding header and be believed.
115
119
 
116
120
  ```ts
117
121
  import { middleware } from "@warlock.js/core";
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli-command.d.mts","names":[],"sources":["../../../../../../../core/src/cli/cli-command.ts"],"mappings":";;;cAUa,UAAA;EAqDF,IAAA;EArDE;;;EAIJ,aAAA,GAAgB,gBAAA;EAKA;;;EAAhB,aAAA,GAAgB,gBAAA;EAyDD;;;;EAnDf,gBAAA,GAAmB,gBAAA;EAuHuC;;;EAlH1D,cAAA,GAAiB,iBAAA;EAoNA;;;EA/MjB,kBAAA;EAuNqC;;;EAlNrC,cAAA,EAAgB,wBAAA;EArBhB;;;;;EA4BA,mBAAA;EAZA;;;EAiBA,YAAA;EAAA;;;EAKA,YAAA;EAOL;;;cADO,IAAA,UACP,WAAA;EAoBK;;;EARA,MAAA,CAAO,MAAA,EAAQ,gBAAA;EAyBf;;;EAjBA,WAAA,CAAY,WAAA;EAyBL;;;EAjBP,UAAA,CAAW,YAAA;EAkCX;;;;EAzBA,KAAA,CAAM,KAAA;EA0CN;;;EAlCA,MAAA,CAAO,MAAA,EAAQ,gBAAA;EAmCR;;;;EA1BP,SAAA,CAAU,MAAA,EAAQ,gBAAA;EAwDf;;;EAhDH,OAAA,CAAQ,OAAA,EAAS,gBAAA;EA8FhB;;;EArFD,aAAA,CAAc,YAAA;EAmHR;;;EA3GN,MAAA,CAAO,MAAA,EAAQ,gBAAA;EACf,MAAA,CAAO,IAAA,UAAc,WAAA,WAAsB,OAAA,GAAU,IAAA,CAAK,gBAAA;EA0GrB;AAS9C;;;;;;;;EAT8C,UA5ElC,WAAA,CAAY,MAAA,EAAQ,gBAAA,GAAmB,wBAAA;;;;;;;;;UA8CzC,iBAAA;;;;EAsBD,OAAA,CAAQ,OAAA,EAAS,iBAAA;;;;EAQX,OAAA,CAAQ,IAAA,EAAM,iBAAA,GAAiB,OAAA;AAAA;AAAA,iBAS9B,OAAA,CAAQ,OAAA,EAAS,iBAAA,GAAiB,UAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli-command.mjs","names":[],"sources":["../../../../../../../core/src/cli/cli-command.ts"],"sourcesContent":["import type {\n CLICommandAction,\n CLICommandOption,\n CLICommandOptions,\n CLICommandPreload,\n CLICommandSource,\n CommandActionData,\n ResolvedCLICommandOption,\n} from \"./types\";\n\nexport class CLICommand {\n /**\n * Command source\n */\n public commandSource?: CLICommandSource;\n\n /**\n * Command action\n */\n public commandAction?: CLICommandAction;\n\n /**\n * Command pre action\n * This will be executed before loading preloaders\n */\n public commandPreAction?: CLICommandAction;\n\n /**\n * Command preload\n */\n public commandPreload?: CLICommandPreload;\n\n /**\n * Command description\n */\n public commandDescription?: string;\n\n /**\n * Command options\n */\n public commandOptions: ResolvedCLICommandOption[] = [];\n\n /**\n * Command relative path\n * Available only for project commands\n * Auto injected by the framework itself\n */\n public commandRelativePath?: string;\n\n /**\n * Determine if the command is persistent\n */\n public isPersistent: boolean = false;\n\n /**\n * Command alias (short name)\n */\n public commandAlias?: string;\n\n /**\n * Constructor\n */\n public constructor(\n public name: string,\n description?: string,\n ) {\n if (description) {\n this.commandDescription = description;\n }\n\n return this;\n }\n\n /**\n * Add command source\n */\n public source(source: CLICommandSource): this {\n this.commandSource = source;\n return this;\n }\n\n /**\n * Set command description\n */\n public description(description: string): this {\n this.commandDescription = description;\n return this;\n }\n\n /**\n * Determine if the command is persistent\n */\n public persistent(isPersistent = true): this {\n this.isPersistent = isPersistent;\n return this;\n }\n\n /**\n * Set command alias (short name)\n * @example .alias(\"m\") for \"migrate\"\n */\n public alias(alias: string): this {\n this.commandAlias = alias;\n return this;\n }\n\n /**\n * Command action\n */\n public action(action: CLICommandAction): this {\n this.commandAction = action;\n return this;\n }\n\n /**\n * Command pre action\n * This will be executed before loading preloaders\n */\n public preAction(action: CLICommandAction): this {\n this.commandPreAction = action;\n return this;\n }\n\n /**\n * Add command options\n */\n public options(options: CLICommandOption[]): this {\n options.map((option) => this.option(option));\n\n return this;\n }\n\n /**\n * Add command relative path\n */\n public $relativePath(relativePath: string) {\n this.commandRelativePath = relativePath;\n return this;\n }\n\n /**\n * Add command option\n */\n public option(option: CLICommandOption): this;\n public option(name: string, description?: string, options?: Omit<CLICommandOption, \"name\">): this;\n public option(\n ...args: [CLICommandOption] | [string, string?, Omit<CLICommandOption, \"name\">?]\n ): this {\n let option: CLICommandOption;\n if (args.length === 1) {\n option = args[0] as CLICommandOption;\n } else {\n option = {\n text: args[0],\n description: args[1],\n ...args[2],\n name: \"\",\n };\n }\n\n this.commandOptions.push(this.parseOption(option));\n\n return this;\n }\n\n /**\n * Parse option name and alias if exists\n *\n * Supports formats:\n * - \"--port, -p\" → name: \"port\", alias: \"p\"\n * - \"-p, --port\" → name: \"port\", alias: \"p\"\n * - \"--port\" → name: \"port\", alias: undefined\n * - \"-p\" → name: \"p\", alias: undefined\n */\n protected parseOption(option: CLICommandOption): ResolvedCLICommandOption {\n const text = option.text.trim();\n\n // Split by comma to check for alias\n const parts = text.split(\",\").map((part) => part.trim());\n\n let name = \"\";\n let alias = \"\";\n\n if (parts.length === 1) {\n // Single option: \"--port\" or \"-p\"\n name = this.extractOptionName(parts[0]);\n } else if (parts.length === 2) {\n // Two options: \"--port, -p\" or \"-p, --port\"\n const first = parts[0];\n const second = parts[1];\n\n // Determine which is the long form (name) and which is short (alias)\n if (first.startsWith(\"--\")) {\n name = this.extractOptionName(first);\n alias = this.extractOptionName(second);\n } else {\n name = this.extractOptionName(second);\n alias = this.extractOptionName(first);\n }\n }\n\n if (alias === \"h\" || name === \"help\") {\n throw new Error(\"Help option is not allowed, it's reserved for displaying command help\");\n }\n\n return {\n ...option,\n name,\n alias,\n };\n }\n\n /**\n * Extract option name from text (removes -- or -)\n *\n * @example\n * extractOptionName(\"--port\") → \"port\"\n * extractOptionName(\"-p\") → \"p\"\n * extractOptionName(\"--port=3000\") → \"port\"\n */\n private extractOptionName(text: string): string {\n // Remove leading dashes\n let name = text.replace(/^-+/, \"\");\n\n // Remove value assignment if exists (e.g., \"--port=3000\" → \"port\")\n const equalIndex = name.indexOf(\"=\");\n if (equalIndex !== -1) {\n name = name.slice(0, equalIndex);\n }\n\n // Remove angle brackets if exists (e.g., \"--port <number>\" → \"port\")\n const spaceIndex = name.indexOf(\" \");\n if (spaceIndex !== -1) {\n name = name.slice(0, spaceIndex);\n }\n\n return name.trim();\n }\n\n /**\n * Command preload\n */\n public preload(options: CLICommandPreload) {\n this.commandPreload = options;\n return this;\n }\n\n /**\n * Execute the command\n */\n public async execute(data: CommandActionData) {\n if (!this.commandAction) {\n throw new Error(`Command \"${this.name}\" has no action defined`);\n }\n\n await this.commandAction(data);\n }\n}\n\nexport function command(options: CLICommandOptions) {\n const commandInstnace = new CLICommand(options.name, options.description);\n\n if (options.preload) {\n commandInstnace.preload(options.preload);\n }\n\n if (options.persistent) {\n commandInstnace.persistent(options.persistent);\n }\n\n if (options.alias) {\n commandInstnace.alias(options.alias);\n }\n\n commandInstnace.action(options.action);\n\n if (options.options) {\n commandInstnace.options(options.options);\n }\n\n if (options.preAction) {\n commandInstnace.preAction(options.preAction);\n }\n\n return commandInstnace;\n}\n"],"mappings":";AAUA,IAAa,aAAb,MAAwB;;;;CAoDtB,AAAO,YACL,AAAO,MACP,aACA;EAFO;wBAvB2C,CAAC;sBAYtB;EAc7B,IAAI,aACF,KAAK,qBAAqB;EAG5B,OAAO;CACT;;;;CAKA,AAAO,OAAO,QAAgC;EAC5C,KAAK,gBAAgB;EACrB,OAAO;CACT;;;;CAKA,AAAO,YAAY,aAA2B;EAC5C,KAAK,qBAAqB;EAC1B,OAAO;CACT;;;;CAKA,AAAO,WAAW,eAAe,MAAY;EAC3C,KAAK,eAAe;EACpB,OAAO;CACT;;;;;CAMA,AAAO,MAAM,OAAqB;EAChC,KAAK,eAAe;EACpB,OAAO;CACT;;;;CAKA,AAAO,OAAO,QAAgC;EAC5C,KAAK,gBAAgB;EACrB,OAAO;CACT;;;;;CAMA,AAAO,UAAU,QAAgC;EAC/C,KAAK,mBAAmB;EACxB,OAAO;CACT;;;;CAKA,AAAO,QAAQ,SAAmC;EAChD,QAAQ,KAAK,WAAW,KAAK,OAAO,MAAM,CAAC;EAE3C,OAAO;CACT;;;;CAKA,AAAO,cAAc,cAAsB;EACzC,KAAK,sBAAsB;EAC3B,OAAO;CACT;CAOA,AAAO,OACL,GAAG,MACG;EACN,IAAI;EACJ,IAAI,KAAK,WAAW,GAClB,SAAS,KAAK;OAEd,SAAS;GACP,MAAM,KAAK;GACX,aAAa,KAAK;GAClB,GAAG,KAAK;GACR,MAAM;EACR;EAGF,KAAK,eAAe,KAAK,KAAK,YAAY,MAAM,CAAC;EAEjD,OAAO;CACT;;;;;;;;;;CAWA,AAAU,YAAY,QAAoD;EAIxE,MAAM,QAHO,OAAO,KAAK,KAGR,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,SAAS,KAAK,KAAK,CAAC;EAEvD,IAAI,OAAO;EACX,IAAI,QAAQ;EAEZ,IAAI,MAAM,WAAW,GAEnB,OAAO,KAAK,kBAAkB,MAAM,EAAE;OACjC,IAAI,MAAM,WAAW,GAAG;GAE7B,MAAM,QAAQ,MAAM;GACpB,MAAM,SAAS,MAAM;GAGrB,IAAI,MAAM,WAAW,IAAI,GAAG;IAC1B,OAAO,KAAK,kBAAkB,KAAK;IACnC,QAAQ,KAAK,kBAAkB,MAAM;GACvC,OAAO;IACL,OAAO,KAAK,kBAAkB,MAAM;IACpC,QAAQ,KAAK,kBAAkB,KAAK;GACtC;EACF;EAEA,IAAI,UAAU,OAAO,SAAS,QAC5B,MAAM,IAAI,MAAM,uEAAuE;EAGzF,OAAO;GACL,GAAG;GACH;GACA;EACF;CACF;;;;;;;;;CAUA,AAAQ,kBAAkB,MAAsB;EAE9C,IAAI,OAAO,KAAK,QAAQ,OAAO,EAAE;EAGjC,MAAM,aAAa,KAAK,QAAQ,GAAG;EACnC,IAAI,eAAe,IACjB,OAAO,KAAK,MAAM,GAAG,UAAU;EAIjC,MAAM,aAAa,KAAK,QAAQ,GAAG;EACnC,IAAI,eAAe,IACjB,OAAO,KAAK,MAAM,GAAG,UAAU;EAGjC,OAAO,KAAK,KAAK;CACnB;;;;CAKA,AAAO,QAAQ,SAA4B;EACzC,KAAK,iBAAiB;EACtB,OAAO;CACT;;;;CAKA,MAAa,QAAQ,MAAyB;EAC5C,IAAI,CAAC,KAAK,eACR,MAAM,IAAI,MAAM,YAAY,KAAK,KAAK,wBAAwB;EAGhE,MAAM,KAAK,cAAc,IAAI;CAC/B;AACF;AAEA,SAAgB,QAAQ,SAA4B;CAClD,MAAM,kBAAkB,IAAI,WAAW,QAAQ,MAAM,QAAQ,WAAW;CAExE,IAAI,QAAQ,SACV,gBAAgB,QAAQ,QAAQ,OAAO;CAGzC,IAAI,QAAQ,YACV,gBAAgB,WAAW,QAAQ,UAAU;CAG/C,IAAI,QAAQ,OACV,gBAAgB,MAAM,QAAQ,KAAK;CAGrC,gBAAgB,OAAO,QAAQ,MAAM;CAErC,IAAI,QAAQ,SACV,gBAAgB,QAAQ,QAAQ,OAAO;CAGzC,IAAI,QAAQ,WACV,gBAAgB,UAAU,QAAQ,SAAS;CAG7C,OAAO;AACT"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../../../../../../../core/src/cli/types.ts"],"mappings":";;;;;AAgB4B;AAY5B;;;;KAZY,gBAAA;;;;AAwBK;AAsBjB;;;;;;KAlCY,iBAAA;EAuDV;;;;EAlDA,IAAA;EAiFA;;;AAA0B;AAgB5B;EA1FE,OAAA,EAAS,MAAM;AAAA;;;;;;;;;;AAiIP;AAGV;;;;;;;;;KA9GY,iBAAA;EAuHA;;;;;EAjHV,MAAA;EAiHiE;;AAAO;EA5GxE,QAAA;EAkI2B;;;EA7H3B,aAAA;EAsKQ;;;EAjKR,eAAA,GAAkB,eAAA;EA6HlB;;;EAxHA,WAAA;EAyIU;;;;;;;;;EA9HV,GAAA;;;;;EAMA,SAAA;;;;;;;;EASA,UAAA,GAAa,aAAa;AAAA;;;;;;;;;;;;;;KAgBhB,gBAAA;;;;;EAKV,IAAA;;;;;EAMA,IAAA;;;;;EAMA,KAAA;;;;EAKA,WAAA;;;;;EAMA,IAAA;;;;EAKA,YAAA;;;;;EAMA,QAAA;AAAA;AAAA,KAGU,wBAAA,GAA2B,IAAI,CAAC,gBAAA;EAC1C,IAAA;EACA,KAAA;AAAA;;;;;KAOU,gBAAA,IAAoB,IAAA,EAAM,iBAAA,YAA6B,OAAO;;;;;;;;;;;;;;;;;;;;;KAsB9D,iBAAA;;;;;EAKV,IAAA;;;;;EAMA,KAAA;;;;EAKA,WAAA;;;;;EAMA,OAAA,GAAU,iBAAA;;;;;;EAOV,UAAA;;;;;EAMA,SAAA,GAAY,gBAAA;;;;;EAMZ,MAAA,EAAQ,gBAAA;;;;;EAMR,OAAA,GAAU,gBAAA;AAAA"}
@@ -1,89 +0,0 @@
1
- import { DependencyGraph } from "./dependency-graph.mjs";
2
- import { SpecialFilesCollector } from "./special-files-collector.mjs";
3
- import { FileOperations } from "./file-operations.mjs";
4
- import { FileManager } from "./file-manager.mjs";
5
- import { FilesWatcher } from "./files-watcher.mjs";
6
- import { FileHealthCheckerContract } from "./health-checker/file-health-checker.contract.mjs";
7
- import { FilesHealthcareManager } from "./health-checker/files-healthcare.manager.mjs";
8
- import { ModuleLoader } from "./module-loader.mjs";
9
-
10
- //#region ../core/src/dev-server/files-orchestrator.d.ts
11
- /**
12
- * Register a cleanup callback that fires before the current module is
13
- * unloaded by HMR. Stack-inspects the caller so user code doesn't need to
14
- * thread the FileManager through.
15
- */
16
- declare function onCleanup(callback: () => any): void;
17
- /**
18
- * Top-level coordinator for the dev server's file system.
19
- *
20
- * Owns: file discovery, the dependency graph, the manifest, the special-files
21
- * index, the file watcher, and the lifecycle of the ESM loader hook (which
22
- * provides cache-busting via `?v=N` version tokens).
23
- */
24
- declare class FilesOrchestrator {
25
- readonly filesWatcher: FilesWatcher;
26
- readonly files: Map<string, FileManager>;
27
- private readonly manifest;
28
- private readonly dependencyGraph;
29
- private readonly healthCheckerManager;
30
- readonly specialFilesCollector: SpecialFilesCollector;
31
- readonly moduleLoader: ModuleLoader;
32
- readonly fileOperations: FileOperations;
33
- private readonly eventHandler;
34
- /** Main-thread end of the MessageChannel to the loader hook worker. */
35
- private loaderPort;
36
- /** Resolve callbacks for pending `flushVersionBumps()` calls. */
37
- private readonly pendingFlushes;
38
- isInitialized: boolean;
39
- constructor();
40
- add(relativePath: string): Promise<FileManager>;
41
- load<T>(relativePath: string, type?: string): Promise<T | undefined>;
42
- getDependencyGraph(): DependencyGraph;
43
- getInvalidationChain(file: string): string[];
44
- getFiles(): Map<string, FileManager>;
45
- getHealthCheckerManager(): FilesHealthcareManager;
46
- /**
47
- * Initialise managers and register the ESM loader hook. Must be called
48
- * before any user `src/` module is dynamically imported.
49
- */
50
- init(): Promise<void>;
51
- /**
52
- * Tell the hook worker a file changed. The next `import()` of it will get
53
- * a fresh `?v=N` URL → Node cache miss → fresh content.
54
- */
55
- bumpVersion(absolutePath: string): void;
56
- /**
57
- * Wait until the hook worker has processed every pending bump.
58
- *
59
- * `postMessage` is async — without this, a follow-up `import()` may
60
- * resolve before the worker increments the counter and Node will return
61
- * the cached old module.
62
- */
63
- flushVersionBumps(): Promise<void>;
64
- /**
65
- * Discover files on disk, reconcile against the manifest, build the dep
66
- * graph, and persist the new manifest. Idempotent.
67
- */
68
- initializeAll(): Promise<void>;
69
- checkHealth(files: {
70
- added: string[];
71
- changed: string[];
72
- deleted: string[];
73
- }): Promise<void>;
74
- startCheckingHealth(healthCheckers?: FileHealthCheckerContract[]): Promise<void>;
75
- /**
76
- * Glob the src directory, returning relative paths.
77
- */
78
- getAllFilesFromFilesystem(): Promise<string[]>;
79
- /**
80
- * Process every file from scratch — used when no manifest exists.
81
- */
82
- private processFiles;
83
- private reconcileFiles;
84
- watchFiles(): Promise<void>;
85
- }
86
- declare const filesOrchestrator: FilesOrchestrator;
87
- //#endregion
88
- export { FilesOrchestrator, filesOrchestrator, onCleanup };
89
- //# sourceMappingURL=files-orchestrator.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"files-orchestrator.d.mts","names":[],"sources":["../../../../../../../core/src/dev-server/files-orchestrator.ts"],"mappings":";;;;;;;;;;;;AA8BA;;;iBAAgB,SAAA,CAAU,QAAmB;AAAA;AAuB7C;;;;;;AAvB6C,cAuBhC,iBAAA;EAAA,SACK,YAAA,EAAY,YAAA;EAAA,SACZ,KAAA,EAAK,GAAA,SAAA,WAAA;EAAA,iBACJ,QAAA;EAAA,iBACA,eAAA;EAAA,iBACA,oBAAA;EAAA,SACD,qBAAA,EAAqB,qBAAA;EAAA,SACrB,YAAA,EAAY,YAAA;EAAA,SACZ,cAAA,EAAgB,cAAA;EAAA,iBACf,YAAA;EA+CiB;EAAA,QA5C1B,UAAA;EA4FoB;EAAA,iBAzFX,cAAA;EAEV,aAAA;;EAkBM,GAAA,CAAI,YAAA,WAAuB,OAAA,CAAQ,WAAA;EAInC,IAAA,IAAQ,YAAA,UAAsB,IAAA,YAAc,OAAA,CAAA,CAAA;EAKlD,kBAAA,IAAsB,eAAA;EAItB,oBAAA,CAAqB,IAAA;EAIrB,QAAA,IAAY,GAAA,SAAY,WAAA;EAIxB,uBAAA,IAA2B,sBAAA;EAvDN;;;;EA+Df,IAAA,IAAI,OAAA;EA5DA;;;;EAyFV,WAAA,CAAY,YAAA;EAtFS;;;;;;;EAiGrB,iBAAA,IAAqB,OAAA;EArEf;;;;EAkFA,aAAA,IAAa,OAAA;EAkBb,WAAA,CAAY,KAAA;IAAS,KAAA;IAAiB,OAAA;IAAmB,OAAA;EAAA,IAAmB,OAAA;EAc5E,mBAAA,CAAoB,cAAA,GAAiB,yBAAA,KAA8B,OAAA;EAzGnD;;;EAmHhB,yBAAA,IAA6B,OAAA;EA3GvB;;;EAAA,QAmHL,YAAA;EAAA,QAcA,cAAA;EAgCD,UAAA,IAAU,OAAA;AAAA;AAAA,cAuBZ,iBAAA,EAAiB,iBAA0B"}
@@ -1,69 +0,0 @@
1
- //#region ../core/src/dev-server/files-watcher.d.ts
2
- type FileWatcherEvent = "change" | "delete" | "add" | "error" | "addDir" | "unlinkDir";
3
- type FileChangeCallback = (filePath: string) => void;
4
- type FileDeleteCallback = (filePath: string) => void;
5
- type FileAddCallback = (filePath: string) => void;
6
- type FileErrorCallback = (filePath: string, error: Error) => void;
7
- type FileAddDirCallback = (filePath: string) => void;
8
- type FileUnlinkDirCallback = (filePath: string) => void;
9
- type OnFileEventCallback = FileChangeCallback | FileDeleteCallback | FileAddCallback | FileErrorCallback | FileAddDirCallback | FileUnlinkDirCallback;
10
- /**
11
- * Watch configuration options
12
- */
13
- type WatchConfig = {
14
- /**
15
- * Glob patterns to include
16
- */
17
- include?: string[];
18
- /**
19
- * Glob patterns to exclude
20
- */
21
- exclude?: string[];
22
- };
23
- declare class FilesWatcher {
24
- /**
25
- * File watcher id
26
- */
27
- private id;
28
- /**
29
- * Watch for files changes
30
- * @param config Optional watch configuration
31
- */
32
- watch(config?: WatchConfig): Promise<void>;
33
- /**
34
- * Trigger event immediately (no debouncing here)
35
- * Debouncing is handled at the orchestrator level for batch processing
36
- */
37
- private triggerEvent;
38
- /**
39
- * On file change event
40
- */
41
- onFileChange(callback: FileChangeCallback): import("@mongez/events").EventSubscription;
42
- /**
43
- * On file delete event
44
- */
45
- onFileDelete(callback: FileDeleteCallback): import("@mongez/events").EventSubscription;
46
- /**
47
- * On file add event
48
- */
49
- onFileAdd(callback: FileAddCallback): import("@mongez/events").EventSubscription;
50
- /**
51
- * On file error event
52
- */
53
- onFileError(callback: FileErrorCallback): import("@mongez/events").EventSubscription;
54
- /**
55
- * On file add dir event
56
- */
57
- onDirectoryAdd(callback: FileAddDirCallback): import("@mongez/events").EventSubscription;
58
- /**
59
- * On file unlink dir event
60
- */
61
- onDirectoryRemove(callback: FileUnlinkDirCallback): import("@mongez/events").EventSubscription;
62
- /**
63
- * On file event
64
- */
65
- on(event: FileWatcherEvent, callback: OnFileEventCallback): import("@mongez/events").EventSubscription;
66
- }
67
- //#endregion
68
- export { FilesWatcher };
69
- //# sourceMappingURL=files-watcher.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"files-watcher.d.mts","names":[],"sources":["../../../../../../../core/src/dev-server/files-watcher.ts"],"mappings":";KAOK,gBAAA;AAAA,KAEA,kBAAA,IAAsB,QAAgB;AAAA,KACtC,kBAAA,IAAsB,QAAgB;AAAA,KACtC,eAAA,IAAmB,QAAgB;AAAA,KACnC,iBAAA,IAAqB,QAAA,UAAkB,KAAA,EAAO,KAAK;AAAA,KACnD,kBAAA,IAAsB,QAAgB;AAAA,KACtC,qBAAA,IAAyB,QAAgB;AAAA,KACzC,mBAAA,GACD,kBAAA,GACA,kBAAA,GACA,eAAA,GACA,iBAAA,GACA,kBAAA,GACA,qBAAA;;;AAZuC;KAiB/B,WAAA;EAhBW;;;EAoBrB,OAAA;EAnBG;;;EAuBH,OAAO;AAAA;AAAA,cAsBI,YAAA;EA5CS;;;EAAA,QAgDZ,EAAA;EAhDyC;;;AAAK;EAsDzC,KAAA,CAAM,MAAA,GAAS,WAAA,GAAW,OAAA;EArDlB;;;AAAoB;EAApB,QA8Gb,YAAA;EA7GgB;;;EAoHjB,YAAA,CAAa,QAAA,EAAU,kBAAA,4BAAkB,iBAAA;EAnH7C;;;EA0HI,YAAA,CAAa,QAAA,EAAU,kBAAA,4BAAkB,iBAAA;EAxH9C;;;EA+HK,SAAA,CAAU,QAAA,EAAU,eAAA,4BAAe,iBAAA;EA3HxC;;;EAkIK,WAAA,CAAY,QAAA,EAAU,iBAAA,4BAAiB,iBAAA;EAtI5C;;;EA6IK,cAAA,CAAe,QAAA,EAAU,kBAAA,4BAAkB,iBAAA;EAzIhD;;AAAqB;EAgJhB,iBAAA,CAAkB,QAAA,EAAU,qBAAA,4BAAqB,iBAAA;EA3InC;;;EAkJd,EAAA,CAAG,KAAA,EAAO,gBAAA,EAAkB,QAAA,EAAU,mBAAA,4BAAmB,iBAAA;AAAA"}
@@ -1,55 +0,0 @@
1
- import { FileManager } from "../../file-manager.mjs";
2
- import { FileHealthResult } from "../file-health-result.mjs";
3
- import { FileHealthCheckerContract, HealthCheckerFilesStats } from "../file-health-checker.contract.mjs";
4
-
5
- //#region ../core/src/dev-server/health-checker/checkers/base-health-checker.d.ts
6
- type CheckerFile = {
7
- file: FileManager;
8
- healthResult: FileHealthResult;
9
- };
10
- declare abstract class BaseHealthChecker implements FileHealthCheckerContract {
11
- /**
12
- * List of checked files
13
- */
14
- protected files: Map<string, CheckerFile>;
15
- /**
16
- * Health checker name (unique identifier)
17
- */
18
- abstract name: string;
19
- /**
20
- * Path to worker file (without extension)
21
- *
22
- * If provided, the checker runs in a dedicated worker thread.
23
- * If undefined, the checker runs in the main thread.
24
- *
25
- * @see FileHealthCheckerContract.workerPath
26
- */
27
- workerPath?: string;
28
- /**
29
- * Initialize the health checker
30
- */
31
- abstract initialize(): void;
32
- /**
33
- * Detect when files are changed
34
- */
35
- onFileChanges(files: FileManager[]): Promise<void>;
36
- /**
37
- * Remove the given file from the checker
38
- */
39
- removeFile(file: FileManager): BaseHealthChecker;
40
- /**
41
- * Validate the health of the file
42
- */
43
- check(file: FileManager): Promise<FileHealthResult>;
44
- /**
45
- * Validate the health of the file
46
- */
47
- abstract validate(file: FileManager, result: FileHealthResult): Promise<FileHealthResult>;
48
- /**
49
- * Get the stats of the health checker
50
- */
51
- stats(): Promise<HealthCheckerFilesStats>;
52
- }
53
- //#endregion
54
- export { BaseHealthChecker };
55
- //# sourceMappingURL=base-health-checker.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base-health-checker.d.mts","names":[],"sources":["../../../../../../../../../core/src/dev-server/health-checker/checkers/base-health-checker.ts"],"mappings":";;;;;KAOK,WAAA;EACH,IAAA,EAAM,WAAA;EACN,YAAA,EAAc,gBAAgB;AAAA;AAAA,uBAGV,iBAAA,YAA6B,yBAAA;EAHnB;;;EAAA,UAOpB,KAAA,EAAO,GAAA,SAAY,WAAA;EAPf;;AAAgB;EAAhB,SAYE,IAAA;EATsB;;;;;;;;EAmB/B,UAAA;EAyBwC;;;EAAA,SApB/B,UAAA;EAkC+D;;;EA7BlE,aAAA,CAAc,KAAA,EAAO,WAAA,KAAgB,OAAA;EA7BD;;;EAoC1C,UAAA,CAAW,IAAA,EAAM,WAAA,GAAc,iBAAA;EAhC5B;;;EAwCG,KAAA,CAAM,IAAA,EAAM,WAAA,GAAc,OAAA,CAAQ,gBAAA;EAzBxC;;;EAAA,SAuCS,QAAA,CAAS,IAAA,EAAM,WAAA,EAAa,MAAA,EAAQ,gBAAA,GAAmB,OAAA,CAAQ,gBAAA;EA7BpD;;;EAkCd,KAAA,IAAS,OAAA,CAAQ,uBAAA;AAAA"}
@@ -1,44 +0,0 @@
1
- import { FileManager } from "../../file-manager.mjs";
2
- import { FileHealthResult } from "../file-health-result.mjs";
3
- import { FileHealthCheckerContract } from "../file-health-checker.contract.mjs";
4
- import { BaseHealthChecker } from "./base-health-checker.mjs";
5
-
6
- //#region ../core/src/dev-server/health-checker/checkers/eslint-health-checker.d.ts
7
- declare class EslintHealthChecker extends BaseHealthChecker implements FileHealthCheckerContract {
8
- /**
9
- * ESLint instance (using new ESLint v9 API with flat config)
10
- */
11
- private eslint;
12
- /**
13
- * Health checker name
14
- */
15
- name: string;
16
- /**
17
- * Path to dedicated worker file for ESLint checking
18
- * Runs in a separate thread to avoid blocking the main dev server
19
- */
20
- workerPath: string;
21
- /**
22
- * Whether checker is initialized
23
- */
24
- private initialized;
25
- /**
26
- * Check if file is a lintable file
27
- */
28
- private isLintableFile;
29
- /**
30
- * Initialize the health checker
31
- */
32
- initialize(): EslintHealthChecker;
33
- /**
34
- * Display health check results in a pretty format
35
- */
36
- private displayResults;
37
- /**
38
- * Validate the health of the file
39
- */
40
- validate(file: FileManager, result: FileHealthResult): Promise<FileHealthResult>;
41
- }
42
- //#endregion
43
- export { EslintHealthChecker };
44
- //# sourceMappingURL=eslint-health-checker.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"eslint-health-checker.d.mts","names":[],"sources":["../../../../../../../../../core/src/dev-server/health-checker/checkers/eslint-health-checker.ts"],"mappings":";;;;;;cASa,mBAAA,SAA4B,iBAAA,YAA6B,yBAAA;;AAAtE;;UAIU,MAAA;EA+Ba;;;EA1Bd,IAAA;EA2K6D;;;;EArK7D,UAAA;EAfgC;;;EAAA,QAoB/B,WAAA;EALD;;;EAAA,QAUC,cAAA;EAUa;;;EAAd,UAAA,IAAc,mBAAA;EAiJC;;;EAAA,QA5Gd,cAAA;EA4GoE;;AAAgB;EAA/E,QAAA,CAAS,IAAA,EAAM,WAAA,EAAa,MAAA,EAAQ,gBAAA,GAAmB,OAAA,CAAQ,gBAAA;AAAA"}