@prmichaelsen/acp-visualizer 0.1.2 → 0.1.4
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.
- package/bin/visualize.mjs +49 -8
- package/package.json +1 -1
package/bin/visualize.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { resolve, dirname } from 'path'
|
|
4
|
-
import { existsSync } from 'fs'
|
|
4
|
+
import { existsSync, cpSync, mkdirSync, rmSync } from 'fs'
|
|
5
5
|
import { fileURLToPath } from 'url'
|
|
6
6
|
import { spawn } from 'child_process'
|
|
7
7
|
|
|
@@ -56,13 +56,56 @@ if (!existsSync(progressPath)) {
|
|
|
56
56
|
process.exit(1)
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
// Strategy: copy source files into the node_modules root where deps
|
|
60
|
+
// are hoisted. This gives vite a project root with node_modules as a
|
|
61
|
+
// direct child, so ESM resolution works correctly for TanStack Start's
|
|
62
|
+
// virtual modules.
|
|
63
|
+
|
|
64
|
+
function findNodeModulesRoot() {
|
|
65
|
+
let dir = packageRoot
|
|
66
|
+
while (dir !== '/') {
|
|
67
|
+
const candidate = resolve(dir, 'node_modules')
|
|
68
|
+
if (existsSync(resolve(candidate, '.bin', 'vite'))) return dir
|
|
69
|
+
dir = resolve(dir, '..')
|
|
70
|
+
}
|
|
71
|
+
return packageRoot
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const nmRoot = findNodeModulesRoot()
|
|
75
|
+
const workDir = resolve(nmRoot, '.acp-visualizer-app')
|
|
76
|
+
|
|
77
|
+
// Copy source files into workDir (small — ~60KB)
|
|
78
|
+
rmSync(workDir, { recursive: true, force: true })
|
|
79
|
+
mkdirSync(workDir, { recursive: true })
|
|
80
|
+
cpSync(resolve(packageRoot, 'src'), resolve(workDir, 'src'), { recursive: true })
|
|
81
|
+
cpSync(resolve(packageRoot, 'vite.config.ts'), resolve(workDir, 'vite.config.ts'))
|
|
82
|
+
cpSync(resolve(packageRoot, 'tsconfig.json'), resolve(workDir, 'tsconfig.json'))
|
|
83
|
+
cpSync(resolve(packageRoot, 'package.json'), resolve(workDir, 'package.json'))
|
|
84
|
+
|
|
85
|
+
// Symlink the existing node_modules into the workdir
|
|
86
|
+
// (they're one level up, so ../node_modules)
|
|
87
|
+
const existingNM = resolve(nmRoot, 'node_modules')
|
|
88
|
+
const targetNM = resolve(workDir, 'node_modules')
|
|
89
|
+
if (!existsSync(targetNM)) {
|
|
90
|
+
const { symlinkSync } = await import('fs')
|
|
91
|
+
symlinkSync(existingNM, targetNM)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function cleanup() {
|
|
95
|
+
try { rmSync(workDir, { recursive: true, force: true }) } catch { /* best effort */ }
|
|
96
|
+
}
|
|
97
|
+
process.on('exit', cleanup)
|
|
98
|
+
process.on('SIGINT', () => { cleanup(); process.exit(130) })
|
|
99
|
+
process.on('SIGTERM', () => { cleanup(); process.exit(143) })
|
|
100
|
+
|
|
59
101
|
console.log(`\n ACP Progress Visualizer`)
|
|
60
102
|
console.log(` Loading: ${progressPath}`)
|
|
61
103
|
console.log(` Port: ${port}\n`)
|
|
62
104
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
105
|
+
const viteBin = resolve(workDir, 'node_modules', '.bin', 'vite')
|
|
106
|
+
|
|
107
|
+
const child = spawn(viteBin, ['dev', '--port', port, '--host'], {
|
|
108
|
+
cwd: workDir,
|
|
66
109
|
stdio: 'inherit',
|
|
67
110
|
env: {
|
|
68
111
|
...process.env,
|
|
@@ -72,13 +115,11 @@ const child = spawn('npx', ['vite', 'dev', '--port', port, '--host'], {
|
|
|
72
115
|
|
|
73
116
|
child.on('error', (err) => {
|
|
74
117
|
console.error('Failed to start dev server:', err.message)
|
|
118
|
+
cleanup()
|
|
75
119
|
process.exit(1)
|
|
76
120
|
})
|
|
77
121
|
|
|
78
122
|
child.on('exit', (code) => {
|
|
123
|
+
cleanup()
|
|
79
124
|
process.exit(code ?? 0)
|
|
80
125
|
})
|
|
81
|
-
|
|
82
|
-
// Forward signals for clean shutdown
|
|
83
|
-
process.on('SIGINT', () => child.kill('SIGINT'))
|
|
84
|
-
process.on('SIGTERM', () => child.kill('SIGTERM'))
|