@prmichaelsen/acp-visualizer 0.1.3 → 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 +43 -23
- 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,34 +56,56 @@ if (!existsSync(progressPath)) {
|
|
|
56
56
|
process.exit(1)
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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.
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
// then walk up (npx hoists deps to a shared node_modules)
|
|
65
|
-
function findViteBin() {
|
|
66
|
-
// Local development: package has its own node_modules
|
|
67
|
-
const local = resolve(packageRoot, 'node_modules', '.bin', 'vite')
|
|
68
|
-
if (existsSync(local)) return local
|
|
69
|
-
|
|
70
|
-
// npx: deps hoisted — walk up from package root to find node_modules/.bin
|
|
64
|
+
function findNodeModulesRoot() {
|
|
71
65
|
let dir = packageRoot
|
|
72
66
|
while (dir !== '/') {
|
|
73
|
-
const candidate = resolve(dir, 'node_modules'
|
|
74
|
-
if (existsSync(candidate)) return
|
|
67
|
+
const candidate = resolve(dir, 'node_modules')
|
|
68
|
+
if (existsSync(resolve(candidate, '.bin', 'vite'))) return dir
|
|
75
69
|
dir = resolve(dir, '..')
|
|
76
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
|
+
}
|
|
77
93
|
|
|
78
|
-
|
|
79
|
-
|
|
94
|
+
function cleanup() {
|
|
95
|
+
try { rmSync(workDir, { recursive: true, force: true }) } catch { /* best effort */ }
|
|
80
96
|
}
|
|
97
|
+
process.on('exit', cleanup)
|
|
98
|
+
process.on('SIGINT', () => { cleanup(); process.exit(130) })
|
|
99
|
+
process.on('SIGTERM', () => { cleanup(); process.exit(143) })
|
|
100
|
+
|
|
101
|
+
console.log(`\n ACP Progress Visualizer`)
|
|
102
|
+
console.log(` Loading: ${progressPath}`)
|
|
103
|
+
console.log(` Port: ${port}\n`)
|
|
81
104
|
|
|
82
|
-
const viteBin =
|
|
105
|
+
const viteBin = resolve(workDir, 'node_modules', '.bin', 'vite')
|
|
83
106
|
|
|
84
|
-
// Start vite dev server from the package directory
|
|
85
107
|
const child = spawn(viteBin, ['dev', '--port', port, '--host'], {
|
|
86
|
-
cwd:
|
|
108
|
+
cwd: workDir,
|
|
87
109
|
stdio: 'inherit',
|
|
88
110
|
env: {
|
|
89
111
|
...process.env,
|
|
@@ -93,13 +115,11 @@ const child = spawn(viteBin, ['dev', '--port', port, '--host'], {
|
|
|
93
115
|
|
|
94
116
|
child.on('error', (err) => {
|
|
95
117
|
console.error('Failed to start dev server:', err.message)
|
|
118
|
+
cleanup()
|
|
96
119
|
process.exit(1)
|
|
97
120
|
})
|
|
98
121
|
|
|
99
122
|
child.on('exit', (code) => {
|
|
123
|
+
cleanup()
|
|
100
124
|
process.exit(code ?? 0)
|
|
101
125
|
})
|
|
102
|
-
|
|
103
|
-
// Forward signals for clean shutdown
|
|
104
|
-
process.on('SIGINT', () => child.kill('SIGINT'))
|
|
105
|
-
process.on('SIGTERM', () => child.kill('SIGTERM'))
|