|
1 | 1 | /** |
2 | 2 | * What runs once, when the server starts. |
3 | 3 | * |
4 | | - * Next calls `register()` a single time per server process, which is the only |
5 | | - * hook that fits work that must not run per request: opening the database, |
6 | | - * migrating it, and recovering reviews that a previous process left marked as |
7 | | - * running. A review in that state cannot be running, because nothing survived |
8 | | - * the restart that could be running it, and until it is recovered it can |
9 | | - * neither be started nor cancelled. |
| 4 | + * Next compiles this file for its edge runtime as well as for Node, and the |
| 5 | + * edge compiler statically flags any node: import it can see, including one |
| 6 | + * inside an unreached branch. So this file imports nothing at all: the guard |
| 7 | + * decides the runtime, and the Node-only work lives in `instrumentation-node`, |
| 8 | + * reached through a dynamic import the edge build does not follow. |
10 | 9 | * |
11 | | - * Every import is inside the function and behind the runtime check. Next builds |
12 | | - * this file for its edge runtime as well, where none of it can load, and a |
13 | | - * top-level import of anything touching node:path fails that build. |
| 10 | + * The work itself is opening the database, migrating it, and recovering |
| 11 | + * reviews a previous process left marked as running. A review in that state |
| 12 | + * cannot be running, because nothing survived the restart that could be |
| 13 | + * running it, and until it is recovered it can neither be started nor |
| 14 | + * cancelled. |
14 | 15 | */ |
15 | 16 |
|
16 | 17 | export async function register(): Promise<void> { |
17 | 18 | if (process.env.NEXT_RUNTIME !== "nodejs") return; |
18 | | - |
19 | | - const { homedir } = await import("node:os"); |
20 | | - const { dbPath, resolveDataDir } = await import("@/lib/paths"); |
21 | | - const { createDb } = await import("@/server/db/client"); |
22 | | - const { runMigrations } = await import("@/server/db/migrate"); |
23 | | - const { jobManager } = await import("@/server/jobs/manager"); |
24 | | - |
25 | | - const dataDir = resolveDataDir(process.env, homedir()); |
26 | | - const db = createDb(dbPath(dataDir)); |
27 | | - runMigrations(db); |
28 | | - jobManager().init({ db, dataDir }); |
| 19 | + await import("./instrumentation-node"); |
29 | 20 | } |
0 commit comments