orez 0.2.26 → 0.2.29

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 (172) hide show
  1. package/dist/cf-do/worker.d.ts.map +1 -1
  2. package/dist/cf-do/worker.js +9 -1
  3. package/dist/cf-do/worker.js.map +1 -1
  4. package/dist/pg-proxy-do-backend.d.ts +2 -0
  5. package/dist/pg-proxy-do-backend.d.ts.map +1 -1
  6. package/dist/pg-proxy-do-backend.js +49 -7
  7. package/dist/pg-proxy-do-backend.js.map +1 -1
  8. package/dist/pg-sqlite-compiler/catalog/seed.d.ts +67 -0
  9. package/dist/pg-sqlite-compiler/catalog/seed.d.ts.map +1 -0
  10. package/dist/pg-sqlite-compiler/catalog/seed.js +436 -0
  11. package/dist/pg-sqlite-compiler/catalog/seed.js.map +1 -0
  12. package/dist/pg-sqlite-compiler/index.d.ts +12 -0
  13. package/dist/pg-sqlite-compiler/index.d.ts.map +1 -0
  14. package/dist/pg-sqlite-compiler/index.js +59 -0
  15. package/dist/pg-sqlite-compiler/index.js.map +1 -0
  16. package/dist/pg-sqlite-compiler/passes/ast-utils.d.ts +48 -0
  17. package/dist/pg-sqlite-compiler/passes/ast-utils.d.ts.map +1 -0
  18. package/dist/pg-sqlite-compiler/passes/ast-utils.js +93 -0
  19. package/dist/pg-sqlite-compiler/passes/ast-utils.js.map +1 -0
  20. package/dist/pg-sqlite-compiler/passes/catalog.d.ts +34 -0
  21. package/dist/pg-sqlite-compiler/passes/catalog.d.ts.map +1 -0
  22. package/dist/pg-sqlite-compiler/passes/catalog.js +30 -0
  23. package/dist/pg-sqlite-compiler/passes/catalog.js.map +1 -0
  24. package/dist/pg-sqlite-compiler/passes/datetime.d.ts +21 -0
  25. package/dist/pg-sqlite-compiler/passes/datetime.d.ts.map +1 -0
  26. package/dist/pg-sqlite-compiler/passes/datetime.js +53 -0
  27. package/dist/pg-sqlite-compiler/passes/datetime.js.map +1 -0
  28. package/dist/pg-sqlite-compiler/passes/index.d.ts +21 -0
  29. package/dist/pg-sqlite-compiler/passes/index.d.ts.map +1 -0
  30. package/dist/pg-sqlite-compiler/passes/index.js +39 -0
  31. package/dist/pg-sqlite-compiler/passes/index.js.map +1 -0
  32. package/dist/pg-sqlite-compiler/passes/types.d.ts +41 -0
  33. package/dist/pg-sqlite-compiler/passes/types.d.ts.map +1 -0
  34. package/dist/pg-sqlite-compiler/passes/types.js +103 -0
  35. package/dist/pg-sqlite-compiler/passes/types.js.map +1 -0
  36. package/dist/pg-sqlite-compiler/test/oracle.d.ts +34 -0
  37. package/dist/pg-sqlite-compiler/test/oracle.d.ts.map +1 -0
  38. package/dist/pg-sqlite-compiler/test/oracle.js +204 -0
  39. package/dist/pg-sqlite-compiler/test/oracle.js.map +1 -0
  40. package/dist/pg-sqlite-compiler/types.d.ts +55 -0
  41. package/dist/pg-sqlite-compiler/types.d.ts.map +1 -0
  42. package/dist/pg-sqlite-compiler/types.js +2 -0
  43. package/dist/pg-sqlite-compiler/types.js.map +1 -0
  44. package/package.json +8 -4
  45. package/src/admin/admin-data.test.ts +0 -348
  46. package/src/admin/http-proxy.ts +0 -252
  47. package/src/admin/log-store.ts +0 -192
  48. package/src/admin/server.ts +0 -471
  49. package/src/admin/ui.ts +0 -1322
  50. package/src/bench/proxy-throughput.bench.ts +0 -343
  51. package/src/bench/serial-mutations.bench.ts +0 -270
  52. package/src/browser.ts +0 -203
  53. package/src/cf-do/.wrangler/cache/cf.json +0 -1
  54. package/src/cf-do/.wrangler/state/v3/cache/miniflare-CacheObject/metadata.sqlite +0 -0
  55. package/src/cf-do/.wrangler/state/v3/cache/miniflare-CacheObject/metadata.sqlite-shm +0 -0
  56. package/src/cf-do/.wrangler/state/v3/cache/miniflare-CacheObject/metadata.sqlite-wal +0 -0
  57. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/0f0f3bdf0abda097eb6f1246db4657d9fc622081362d894d82c1a1ce067b05b6.sqlite +0 -0
  58. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/1ddd3a4a48a11b51658444f5458a1fb175194b1d5b6a5bda20ef3fe3205b900c.sqlite +0 -0
  59. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/204a39120310d37e972c5914cfd71ad55c151bdb9e8ed289a5f8c5b052dd60e4.sqlite +0 -0
  60. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/3835f242df9728adba3d127a238793fd054ed3e51df3f60749ee744c469bf2a2.sqlite +0 -0
  61. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/4aa9c80eb716cf55b8995ccf7afab0b36c683e6da07d7c37a3f9c570136036df.sqlite +0 -0
  62. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/533e2fd1d6ea46e7a9a0017916ef341802d438d72583462755f2c1f8225e9bf2.sqlite +0 -0
  63. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/5ffa1aced1225ecaeac6366f7586aa3de92761cdff8711d81fbd81f248076abd.sqlite +0 -0
  64. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/686c3a9f0d7e59ed2ab607efd4b76d779c97cafeb3818380033bf7c7eb86c819.sqlite +0 -0
  65. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/6e8214e8dcfadd0deb52d64e5e9ca85c6b329ace11193909845995396914c473.sqlite +0 -0
  66. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/78d9ec9ff873d3fe3507ff53c2a6f6dfc408b4268eb0db3f2a146c0678965366.sqlite +0 -0
  67. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/7eff9f0ed7e27ad0d3f9d923de0682fab1928591172c1ba336c5f79a134a5d85.sqlite +0 -0
  68. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/836cda5b995b25867d722ed4f4c2292167e80351a3c6038db626648eb247dd8b.sqlite +0 -0
  69. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/91ef63b112209ab30172763acd8a0935106c248f7f1bcae5545ce37a9f201551.sqlite +0 -0
  70. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/a66ea4293a5f5938bc6d116edfa2522bb85bc37aea3541fbc09c3b613b9b32c0.sqlite +0 -0
  71. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/ceb2ab26b80590840b65651deb6e948d3bf81565c6751f3a58752cf4bf4aecae.sqlite +0 -0
  72. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/metadata.sqlite +0 -0
  73. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/metadata.sqlite-shm +0 -0
  74. package/src/cf-do/.wrangler/state/v3/do/zero-do-ZeroDO/metadata.sqlite-wal +0 -0
  75. package/src/cf-do/ARCHITECTURE.md +0 -83
  76. package/src/cf-do/watermark.test.ts +0 -103
  77. package/src/cf-do/watermark.ts +0 -118
  78. package/src/cf-do/worker.ts +0 -1033
  79. package/src/cf-do/wrangler.toml +0 -11
  80. package/src/cf-pglite/README.md +0 -19
  81. package/src/change-tracking.ts +0 -25
  82. package/src/child-process.test.ts +0 -147
  83. package/src/child-process.ts +0 -90
  84. package/src/cli-entry.ts +0 -72
  85. package/src/cli.test.ts +0 -38
  86. package/src/cli.ts +0 -1214
  87. package/src/config.ts +0 -150
  88. package/src/do-sql-tracking.test.ts +0 -19
  89. package/src/do-sql-tracking.ts +0 -19
  90. package/src/index.ts +0 -1215
  91. package/src/integration/integration.test.ts +0 -517
  92. package/src/integration/native-binary.guard.test.ts +0 -13
  93. package/src/integration/native-startup.test.ts +0 -44
  94. package/src/integration/replication-latency.test.ts +0 -428
  95. package/src/integration/restore-live-stress.test.ts +0 -433
  96. package/src/integration/restore-reset.test.ts +0 -400
  97. package/src/integration/restore.test.ts +0 -274
  98. package/src/integration/test-permissions.ts +0 -147
  99. package/src/load-config.ts +0 -46
  100. package/src/log.ts +0 -96
  101. package/src/mutex.ts +0 -47
  102. package/src/pg-proxy-browser.singledb.test.ts +0 -233
  103. package/src/pg-proxy-browser.ts +0 -2022
  104. package/src/pg-proxy-do-backend.test.ts +0 -3890
  105. package/src/pg-proxy-do-backend.ts +0 -7157
  106. package/src/pg-proxy.ts +0 -1087
  107. package/src/pglite-ipc.test.ts +0 -116
  108. package/src/pglite-ipc.ts +0 -266
  109. package/src/pglite-manager.ts +0 -557
  110. package/src/pglite-web-proxy.test.ts +0 -57
  111. package/src/pglite-web-proxy.ts +0 -221
  112. package/src/pglite-web-worker.ts +0 -152
  113. package/src/pglite-worker-thread.ts +0 -253
  114. package/src/port.ts +0 -25
  115. package/src/process-title.ts +0 -9
  116. package/src/recovery.ts +0 -155
  117. package/src/replication/change-tracker.test.ts +0 -357
  118. package/src/replication/change-tracker.ts +0 -279
  119. package/src/replication/handler.test.ts +0 -511
  120. package/src/replication/handler.ts +0 -1190
  121. package/src/replication/pgoutput-encoder.test.ts +0 -697
  122. package/src/replication/pgoutput-encoder.ts +0 -373
  123. package/src/replication/tcp-replication.test.ts +0 -876
  124. package/src/replication/zero-compat.test.ts +0 -1150
  125. package/src/restore-stress.test.ts +0 -188
  126. package/src/s3-local.ts +0 -203
  127. package/src/shim/hooks.mjs +0 -120
  128. package/src/shim/register.mjs +0 -4
  129. package/src/sqlite-mode/apply-mode.ts +0 -224
  130. package/src/sqlite-mode/index.ts +0 -15
  131. package/src/sqlite-mode/native-binary.ts +0 -89
  132. package/src/sqlite-mode/package-resolve.ts +0 -17
  133. package/src/sqlite-mode/resolve-mode.ts +0 -80
  134. package/src/sqlite-mode/shim-template.ts +0 -159
  135. package/src/sqlite-mode/sqlite-mode.test.ts +0 -427
  136. package/src/sqlite-mode/types.ts +0 -30
  137. package/src/vite-plugin.ts +0 -67
  138. package/src/wasm-sqlite.test.ts +0 -537
  139. package/src/worker/browser-admin.ts +0 -52
  140. package/src/worker/browser-build-config.test.ts +0 -71
  141. package/src/worker/browser-build-config.ts +0 -109
  142. package/src/worker/browser-embed-admin.test.ts +0 -75
  143. package/src/worker/browser-embed.ts +0 -345
  144. package/src/worker/cf-patches.ts +0 -384
  145. package/src/worker/embed-integration.test.ts +0 -321
  146. package/src/worker/index.ts +0 -138
  147. package/src/worker/shims/fastify.test.ts +0 -255
  148. package/src/worker/shims/fastify.ts +0 -306
  149. package/src/worker/shims/http-service.test.ts +0 -355
  150. package/src/worker/shims/http-service.ts +0 -293
  151. package/src/worker/shims/node-stub.ts +0 -290
  152. package/src/worker/shims/oxfmt.ts +0 -3
  153. package/src/worker/shims/postgres-browser.ts +0 -59
  154. package/src/worker/shims/postgres-socket.test.ts +0 -576
  155. package/src/worker/shims/postgres-socket.ts +0 -310
  156. package/src/worker/shims/postgres.test.ts +0 -364
  157. package/src/worker/shims/postgres.ts +0 -1454
  158. package/src/worker/shims/sqlite-browser.test.ts +0 -233
  159. package/src/worker/shims/sqlite-browser.ts +0 -175
  160. package/src/worker/shims/sqlite.test.ts +0 -786
  161. package/src/worker/shims/sqlite.ts +0 -978
  162. package/src/worker/shims/stream-browser.ts +0 -15
  163. package/src/worker/shims/ws-browser.test.ts +0 -205
  164. package/src/worker/shims/ws-browser.ts +0 -248
  165. package/src/worker/shims/ws.test.ts +0 -288
  166. package/src/worker/shims/ws.ts +0 -467
  167. package/src/worker/shims/zero-process-env.ts +0 -11
  168. package/src/worker/types.ts +0 -75
  169. package/src/worker/worker-integration.test.ts +0 -223
  170. package/src/worker/worker.test.ts +0 -136
  171. package/src/worker/zero-cache-embed-cf.ts +0 -463
  172. package/src/worker/zero-cache-embed.ts +0 -277
@@ -1,11 +0,0 @@
1
- name = "zero-do"
2
- main = "worker.ts"
3
- compatibility_date = "2025-04-01"
4
-
5
- [[durable_objects.bindings]]
6
- name = "ZERO_DO"
7
- class_name = "ZeroDO"
8
-
9
- [[migrations]]
10
- tag = "v1"
11
- new_sqlite_classes = ["ZeroDO"]
@@ -1,19 +0,0 @@
1
- # CF-Compatible PGlite Build
2
-
3
- PGlite compiled without `-sMAIN_MODULE=2` and `-sALLOW_TABLE_GROWTH`
4
- for Cloudflare Workers compatibility.
5
-
6
- Key differences from standard PGlite:
7
-
8
- - No dynamic linking (extensions must be statically linked)
9
- - No `addFunction`/`removeFunction` (no runtime WASM compilation)
10
- - `ENVIRONMENT=web,worker` only (no node — avoids require("fs"))
11
- - No side modules (no dlopen/dlsym)
12
-
13
- Files:
14
-
15
- - `pglite.wasm` — CF-compatible postgres WASM binary
16
- - `pglite.data` — filesystem bundle (postgres data directory)
17
- - `pglite.js` — Emscripten JS glue
18
-
19
- Build: `cd postgres-pglite && docker run ... ./build-pglite-cf.sh`
@@ -1,25 +0,0 @@
1
- /**
2
- * orez/change-tracking — standalone entrypoint for installing and reading
3
- * the `_orez` change tracking schema against a postgres-compatible database.
4
- *
5
- * this module intentionally has no transitive dependency on pglite-manager
6
- * or any other server-only orez module. it talks to the database through
7
- * the minimal `ChangeTrackingDb` structural interface (`exec` + `query`),
8
- * so it can be imported anywhere a sql executor exists — embedded PGlite,
9
- * a worker proxy, tests, or an external host.
10
- *
11
- * usage:
12
- * import { installChangeTracking } from 'orez/change-tracking'
13
- * await installChangeTracking(db)
14
- */
15
-
16
- export {
17
- installChangeTracking,
18
- installTriggersOnShardTables,
19
- resetShardSchemaCache,
20
- getChangesSince,
21
- getCurrentWatermark,
22
- purgeConsumedChanges,
23
- } from './replication/change-tracker.js'
24
-
25
- export type { ChangeRecord, ChangeTrackingDb } from './replication/change-tracker.js'
@@ -1,147 +0,0 @@
1
- import { spawn, type ChildProcess } from 'node:child_process'
2
-
3
- import { afterEach, describe, expect, it } from 'vitest'
4
-
5
- import {
6
- isChildProcessRunning,
7
- isPidRunning,
8
- killProcessTree,
9
- waitForChildProcessExit,
10
- } from './child-process.js'
11
-
12
- const spawned = new Set<ChildProcess>()
13
-
14
- function track(child: ChildProcess): ChildProcess {
15
- spawned.add(child)
16
- child.once('close', () => spawned.delete(child))
17
- return child
18
- }
19
-
20
- function pidExists(pid: number): boolean {
21
- try {
22
- process.kill(pid, 0)
23
- return true
24
- } catch (err: any) {
25
- if (err?.code === 'ESRCH') return false
26
- throw err
27
- }
28
- }
29
-
30
- async function waitForPidExit(pid: number, timeoutMs: number): Promise<boolean> {
31
- const start = Date.now()
32
- while (Date.now() - start < timeoutMs) {
33
- if (!pidExists(pid)) return true
34
- await new Promise((resolve) => setTimeout(resolve, 25))
35
- }
36
- return !pidExists(pid)
37
- }
38
-
39
- afterEach(async () => {
40
- for (const child of spawned) {
41
- if (!isChildProcessRunning(child)) continue
42
- if (child.pid) killProcessTree(child.pid, 'SIGKILL')
43
- else child.kill('SIGKILL')
44
- await waitForChildProcessExit(child, 1000)
45
- }
46
- spawned.clear()
47
- })
48
-
49
- describe('child process helpers', () => {
50
- it('tracks whether a pid is still alive', async () => {
51
- const child = track(
52
- spawn(process.execPath, ['-e', 'setInterval(() => {}, 1000)'], {
53
- stdio: 'ignore',
54
- })
55
- )
56
-
57
- expect(isPidRunning(child.pid)).toBe(true)
58
-
59
- child.kill('SIGKILL')
60
- await expect(waitForChildProcessExit(child, 2000)).resolves.toBe(true)
61
- expect(isPidRunning(child.pid)).toBe(false)
62
- })
63
-
64
- it('does not confuse "signal sent" with "process exited"', async () => {
65
- const child = track(
66
- spawn(
67
- process.execPath,
68
- [
69
- '-e',
70
- "process.on('SIGTERM', () => {}); console.log('ready'); setInterval(() => {}, 1000)",
71
- ],
72
- { stdio: ['ignore', 'pipe', 'ignore'] }
73
- )
74
- )
75
-
76
- await new Promise<void>((resolve, reject) => {
77
- let output = ''
78
-
79
- const onData = (chunk: Buffer) => {
80
- output += chunk.toString()
81
- if (!output.includes('ready')) return
82
- child.stdout?.off('data', onData)
83
- resolve()
84
- }
85
-
86
- child.stdout?.on('data', onData)
87
- child.once('error', reject)
88
- child.once('close', () =>
89
- reject(new Error('child exited before signaling readiness'))
90
- )
91
- })
92
-
93
- child.kill('SIGTERM')
94
-
95
- expect(child.killed).toBe(true)
96
- expect(isChildProcessRunning(child)).toBe(true)
97
- await expect(waitForChildProcessExit(child, 100)).resolves.toBe(false)
98
-
99
- child.kill('SIGKILL')
100
- await expect(waitForChildProcessExit(child, 2000)).resolves.toBe(true)
101
- expect(isChildProcessRunning(child)).toBe(false)
102
- })
103
-
104
- it('kills a parent process and its descendants', async () => {
105
- const parent = track(
106
- spawn(
107
- process.execPath,
108
- [
109
- '-e',
110
- [
111
- "const { spawn } = require('node:child_process')",
112
- "const child = spawn(process.execPath, ['-e', 'setInterval(() => {}, 1000)'], { stdio: 'ignore' })",
113
- 'console.log(child.pid)',
114
- 'setInterval(() => {}, 1000)',
115
- ].join('; '),
116
- ],
117
- { stdio: ['ignore', 'pipe', 'ignore'] }
118
- )
119
- )
120
-
121
- const childPid = await new Promise<number>((resolve, reject) => {
122
- let output = ''
123
-
124
- const onData = (chunk: Buffer) => {
125
- output += chunk.toString()
126
- if (!output.includes('\n')) return
127
-
128
- const value = Number.parseInt(output.split(/\r?\n/, 1)[0]!.trim(), 10)
129
- if (Number.isInteger(value) && value > 0) {
130
- parent.stdout?.off('data', onData)
131
- resolve(value)
132
- }
133
- }
134
-
135
- parent.stdout?.on('data', onData)
136
- parent.once('error', reject)
137
- parent.once('close', () =>
138
- reject(new Error('parent exited before reporting child pid'))
139
- )
140
- })
141
-
142
- killProcessTree(parent.pid!, 'SIGKILL')
143
-
144
- await expect(waitForChildProcessExit(parent, 2000)).resolves.toBe(true)
145
- await expect(waitForPidExit(childPid, 2000)).resolves.toBe(true)
146
- })
147
- })
@@ -1,90 +0,0 @@
1
- import { spawnSync, type ChildProcess } from 'node:child_process'
2
-
3
- export function isPidRunning(pid: number | null | undefined): pid is number {
4
- if (!Number.isInteger(pid) || (pid as number) <= 0) return false
5
-
6
- try {
7
- process.kill(pid as number, 0)
8
- return true
9
- } catch (err: any) {
10
- if (err?.code === 'ESRCH') return false
11
- if (err?.code === 'EPERM') return true
12
- throw err
13
- }
14
- }
15
-
16
- export function isChildProcessRunning(
17
- child: ChildProcess | null | undefined
18
- ): child is ChildProcess {
19
- if (!child) return false
20
- return child.exitCode === null && child.signalCode === null
21
- }
22
-
23
- export async function waitForChildProcessExit(
24
- child: ChildProcess,
25
- timeoutMs: number
26
- ): Promise<boolean> {
27
- if (!isChildProcessRunning(child)) return true
28
-
29
- return await new Promise<boolean>((resolve) => {
30
- let settled = false
31
-
32
- const finish = (exited: boolean) => {
33
- if (settled) return
34
- settled = true
35
- clearTimeout(timer)
36
- child.off('exit', onExit)
37
- child.off('close', onClose)
38
- resolve(exited || !isChildProcessRunning(child))
39
- }
40
-
41
- const onExit = () => finish(true)
42
- const onClose = () => finish(true)
43
-
44
- const timer = setTimeout(() => finish(false), timeoutMs)
45
-
46
- child.once('exit', onExit)
47
- child.once('close', onClose)
48
- })
49
- }
50
-
51
- function listChildPids(pid: number): number[] {
52
- if (process.platform === 'win32') return []
53
-
54
- const result = spawnSync('pgrep', ['-P', String(pid)], {
55
- encoding: 'utf8',
56
- env: process.env,
57
- })
58
-
59
- if (result.status !== 0 || !result.stdout) return []
60
-
61
- return result.stdout
62
- .split(/\s+/)
63
- .map((value) => Number(value.trim()))
64
- .filter((value) => Number.isInteger(value) && value > 0)
65
- }
66
-
67
- export function killProcessTree(pid: number, signal: NodeJS.Signals | number): void {
68
- const seen = new Set<number>()
69
- const stack = [pid]
70
- const order: number[] = []
71
-
72
- while (stack.length > 0) {
73
- const current = stack.pop()!
74
- if (seen.has(current)) continue
75
- seen.add(current)
76
- order.push(current)
77
-
78
- for (const childPid of listChildPids(current)) {
79
- if (!seen.has(childPid)) stack.push(childPid)
80
- }
81
- }
82
-
83
- for (const current of order.reverse()) {
84
- try {
85
- process.kill(current, signal)
86
- } catch (err: any) {
87
- if (err?.code !== 'ESRCH') throw err
88
- }
89
- }
90
- }
package/src/cli-entry.ts DELETED
@@ -1,72 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // by default runs cli.js in-process. when --bump-heap (or OREZ_BUMP_HEAP=1)
4
- // is set, re-execs with --max-old-space-size at ~50% of system memory —
5
- // needed for pglite wasm workloads. default off since memory usage was reduced.
6
-
7
- import { spawn } from 'node:child_process'
8
- import { totalmem } from 'node:os'
9
- import { resolve, dirname } from 'node:path'
10
- import { fileURLToPath } from 'node:url'
11
-
12
- import { orezTitle } from './process-title.js'
13
-
14
- const currentOpts = process.env.NODE_OPTIONS || ''
15
- const bumpHeapRequested =
16
- process.argv.includes('--bump-heap') ||
17
- process.env.OREZ_BUMP_HEAP === '1' ||
18
- process.env.OREZ_BUMP_HEAP === 'true'
19
-
20
- const willRespawn =
21
- bumpHeapRequested &&
22
- !currentOpts.includes('--max-old-space-size') &&
23
- !process.env.__OREZ_SPAWNED
24
-
25
- // label the wrapper distinctly so it's not confused with the real orez process
26
- process.title = willRespawn ? orezTitle('orez [wrapper]') : orezTitle()
27
-
28
- if (willRespawn) {
29
- const memMB = Math.round(totalmem() / 1024 / 1024)
30
- const heapMB = Math.max(4096, Math.round(memMB * 0.5))
31
- const cliPath = resolve(dirname(fileURLToPath(import.meta.url)), 'cli.js')
32
-
33
- // enable --experimental-strip-types so orez.config.ts works on Node 22.6+
34
- // (Node 23.6+ has it by default; harmless if already enabled)
35
- let nodeOpts = `--max-old-space-size=${heapMB} ${currentOpts}`.trim()
36
- if (!nodeOpts.includes('--experimental-strip-types')) {
37
- const [major, minor] = process.versions.node.split('.').map(Number)
38
- if (major > 22 || (major === 22 && minor >= 6)) {
39
- nodeOpts = `--experimental-strip-types ${nodeOpts}`
40
- }
41
- }
42
-
43
- // strip --bump-heap from argv so cli.ts doesn't see it as an unknown flag
44
- const childArgs = process.argv.slice(2).filter((a) => a !== '--bump-heap')
45
-
46
- const child = spawn(process.execPath, [cliPath, ...childArgs], {
47
- env: {
48
- ...process.env,
49
- NODE_OPTIONS: nodeOpts,
50
- __OREZ_SPAWNED: '1',
51
- },
52
- stdio: 'inherit',
53
- })
54
-
55
- // forward signals to child
56
- for (const sig of ['SIGINT', 'SIGTERM'] as const) {
57
- process.on(sig, () => child.kill(sig))
58
- }
59
-
60
- child.on('exit', (code, signal) => {
61
- if (signal) process.kill(process.pid, signal)
62
- else process.exit(code ?? 1)
63
- })
64
- } else {
65
- // run cli directly — no heap bump, no wrapper process
66
- // strip --bump-heap in case it was passed but we're already the spawned child
67
- if (process.argv.includes('--bump-heap')) {
68
- process.argv = process.argv.filter((a) => a !== '--bump-heap')
69
- }
70
- const [{ runMain }, { main }] = await Promise.all([import('citty'), import('./cli.js')])
71
- runMain(main)
72
- }
package/src/cli.test.ts DELETED
@@ -1,38 +0,0 @@
1
- import { spawn } from 'node:child_process'
2
- import { resolve } from 'node:path'
3
-
4
- import { describe, it, expect } from 'vitest'
5
-
6
- function runCli(
7
- args: string[]
8
- ): Promise<{ stdout: string; stderr: string; code: number }> {
9
- return new Promise((res) => {
10
- const child = spawn('bun', [resolve('dist/cli.js'), ...args], {
11
- timeout: 10_000,
12
- env: { ...process.env, NODE_ENV: 'test' },
13
- })
14
- let stdout = ''
15
- let stderr = ''
16
- child.stdout?.on('data', (d: Buffer) => (stdout += d.toString()))
17
- child.stderr?.on('data', (d: Buffer) => (stderr += d.toString()))
18
- child.on('close', (code) => res({ stdout, stderr, code: code ?? 1 }))
19
- })
20
- }
21
-
22
- describe('cli', () => {
23
- it('shows help with --help', async () => {
24
- const { stdout, stderr } = await runCli(['--help'])
25
- const output = stdout + stderr
26
- expect(output).toContain('orez')
27
- expect(output).toContain('--pg-port')
28
- expect(output).toContain('--zero-port')
29
- expect(output).toContain('--skip-zero-cache')
30
- })
31
-
32
- it('s3 subcommand shows help', async () => {
33
- const { stdout, stderr } = await runCli(['s3', '--help'])
34
- const output = stdout + stderr
35
- expect(output).toContain('--port')
36
- expect(output).toContain('--data-dir')
37
- })
38
- })