ReviewOS

also looking at this

stacks/dtsx

chore(deps): update all non-major dependencies

#2997
Closed renovate[bot] wants to merge renovate/all-minor-patch into main
29 files +1047 -444
packages/dtsx/bin/cli.tsmodified+107-8
Changes to packages/dtsx/bin/cli.ts
@@ -1,18 +1,12 @@
11// Fast path — skip CLI framework for maximum startup speed
22import type { LogLevel } from '../src/logger'
33import type { DtsGenerationConfig, DtsGenerationOption } from '../src/types'
4import { resolve } from 'node:path'
54import process from 'node:process'
6import { CLI } from '@stacksjs/clapp'
7import { version } from '../../../package.json'
8import { getConfig } from '../src/config'
9import { generate, processSource, watch } from '../src/generator'
105
116const _cmd = process.argv[2]
12if (_cmd === 'stdin' || _cmd === 'emit') {
13 const { processSource } = await import('../src/process-source')
14
7if (_cmd === 'stdin' || _cmd === 'emit' || _cmd === '--project' || _cmd === '--project-worker') {
158 if (_cmd === 'stdin') {
9 const { processSource } = await import('../src/process-source')
1610 const chunks: Buffer[] = []
1711 for await (const chunk of process.stdin) {
1812 chunks.push(chunk)
@@ -23,7 +17,105 @@ if (_cmd === 'stdin' || _cmd === 'emit') {
2317 process.stdout.write('\n')
2418 }
2519 }
20 else if (_cmd === '--project-worker') {
21 // Worker subprocess: receives file list on stdin, processes & writes output
22 const { processSourceDirect } = await import('../src/process-source')
23 const { join } = await import('node:path')
24 const { mkdirSync } = await import('node:fs')
25 const wArgs = process.argv.slice(3)
26 let wDir = ''
27 let wOut = ''
28 for (let i = 0; i < wArgs.length; i++) {
29 if (wArgs[i] === '--outdir' && wArgs[i + 1]) { wOut = wArgs[i + 1]; i++ }
30 else if (!wDir) { wDir = wArgs[i] }
31 }
32 mkdirSync(wOut, { recursive: true })
33
34 // Read file list from stdin
35 const wChunks: Buffer[] = []
36 for await (const chunk of process.stdin) { wChunks.push(chunk) }
37 const wFiles = Buffer.concat(wChunks).toString('utf-8').trim().split('\n').filter(Boolean)
38 if (wFiles.length === 0) { process.exit(0) }
39
40 // JIT warmup
41 processSourceDirect('export interface W{a:string}\nexport function f(x:W):void{}\nexport class C{m():void{}}\nexport type T=string\nexport const v:number=1\nexport enum E{A,B}', 'warmup.ts')
42
43 // Pipeline: read → process → write overlapped
44 const wReadPromises = wFiles.map(f => Bun.file(join(wDir, f)).text())
45 const wWritePromises: Promise<number>[] = new Array(wFiles.length)
46 for (let i = 0; i < wFiles.length; i++) {
47 const wSource = await wReadPromises[i]
48 wWritePromises[i] = Bun.write(
49 join(wOut, wFiles[i].replace(/\.ts$/, '.d.ts')),
50 processSourceDirect(wSource, wFiles[i]),
51 )
52 }
53 await Promise.all(wWritePromises)
54 }
55 else if (_cmd === '--project') {
56 // Usage: dtsx --project <dir> --outdir <outdir>
57 const { readdirSync, mkdirSync } = await import('node:fs')
58 const { join } = await import('node:path')
59 const args = process.argv.slice(3)
60 let dir = ''
61 let out = ''
62 for (let i = 0; i < args.length; i++) {
63 if (args[i] === '--outdir' && args[i + 1]) {
64 out = args[i + 1]
65 i++
66 }
67 else if (!dir) {
68 dir = args[i]
69 }
70 }
71 mkdirSync(out, { recursive: true })
72 const files = readdirSync(dir).filter((f: string) => f.endsWith('.ts') && !f.endsWith('.d.ts'))
73
74 // For large file counts, parallelize across CPU cores using worker subprocesses
75 // Use conservative worker count to balance spawn overhead vs parallelism
76 const PARALLEL_THRESHOLD = 200
77 if (files.length >= PARALLEL_THRESHOLD) {
78 const os = await import('node:os')
79 const numCPUs = os.availableParallelism?.() ?? os.cpus().length
80 const numWorkers = Math.min(Math.min(numCPUs, 6), Math.ceil(files.length / 50))
81 const batchSize = Math.ceil(files.length / numWorkers)
82 const procs: Array<ReturnType<typeof Bun.spawn>> = []
83 for (let w = 0; w < numWorkers; w++) {
84 const start = w * batchSize
85 const batch = files.slice(start, start + batchSize)
86 if (batch.length === 0) break
87 const proc = Bun.spawn([process.execPath, '--project-worker', dir, '--outdir', out], {
88 stdin: 'pipe',
89 stdout: 'ignore',
90 stderr: 'inherit',
91 })
92 proc.stdin!.write(batch.join('\n'))
93 proc.stdin!.end()
94 procs.push(proc)
95 }
96
97 const exitCodes = await Promise.all(procs.map(p => p.exited))
98 if (exitCodes.some(c => c !== 0)) { process.exit(1) }
99 }
100 else {
101 // Sequential batch mode for small file counts
102 const { processSourceDirect } = await import('../src/process-source')
103
104 // JIT warmup
105 processSourceDirect('export interface W{a:string}\nexport function f(x:W):void{}\nexport class C{m():void{}}\nexport type T=string\nexport const v:number=1\nexport enum E{A,B}', 'warmup.ts')
106
107 // Read all → Process all → Write all (batch approach avoids per-file await overhead)
108 const sources = await Promise.all(files.map(f => Bun.file(join(dir, f)).text()))
109 const results: string[] = new Array(files.length)
110 for (let i = 0; i < files.length; i++) {
111 results[i] = processSourceDirect(sources[i], files[i])
112 }
113 await Promise.all(files.map((f, i) => Bun.write(join(out, f.replace(/\.ts$/, '.d.ts')), results[i])))
114 }
115 }
26116 else {
117 // emit command
118 const { processSource } = await import('../src/process-source')
27119 const { readFileSync, writeFileSync, mkdirSync } = await import('node:fs')
28120 const filePath = process.argv[3]!
29121 const source = readFileSync(filePath, 'utf-8')
@@ -41,6 +133,13 @@ if (_cmd === 'stdin' || _cmd === 'emit') {
41133 process.exit(0)
42134}
43135
136// Heavy imports — only loaded when CLI framework is needed (not on fast path)
137const { resolve } = await import('node:path')
138const { CLI } = await import('@stacksjs/clapp')
139const { version } = await import('../../../package.json')
140const { getConfig } = await import('../src/config')
141const { generate, processSource, watch } = await import('../src/generator')
142
44143const cli = new CLI('dtsx')
45144
46145const defaultOptions: DtsGenerationConfig = {