@prmichaelsen/acp-visualizer 0.1.3 → 0.1.5
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 +38 -24
- 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, rmSync } from 'fs'
|
|
5
5
|
import { fileURLToPath } from 'url'
|
|
6
6
|
import { spawn } from 'child_process'
|
|
7
7
|
|
|
@@ -56,34 +56,50 @@ if (!existsSync(progressPath)) {
|
|
|
56
56
|
process.exit(1)
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// Resolve vite binary — check package's own node_modules first,
|
|
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
|
|
59
|
+
// Find the directory that contains node_modules with vite installed.
|
|
60
|
+
// When run via npx, deps are hoisted to ~/.npm/_npx/xxx/node_modules/
|
|
61
|
+
function findNodeModulesRoot() {
|
|
71
62
|
let dir = packageRoot
|
|
72
63
|
while (dir !== '/') {
|
|
73
|
-
|
|
74
|
-
if (existsSync(candidate)) return candidate
|
|
64
|
+
if (existsSync(resolve(dir, 'node_modules', '.bin', 'vite'))) return dir
|
|
75
65
|
dir = resolve(dir, '..')
|
|
76
66
|
}
|
|
67
|
+
return packageRoot
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const nmRoot = findNodeModulesRoot()
|
|
71
|
+
|
|
72
|
+
// Copy source files directly into nmRoot (the dir that already has
|
|
73
|
+
// node_modules/ as a direct child). No symlinks — vite gets a real
|
|
74
|
+
// project root with real node_modules, so ESM resolution works.
|
|
75
|
+
const filesToCopy = ['src', 'vite.config.ts', 'tsconfig.json', 'package.json']
|
|
76
|
+
const copied = []
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
for (const f of filesToCopy) {
|
|
79
|
+
const src = resolve(packageRoot, f)
|
|
80
|
+
const dest = resolve(nmRoot, f)
|
|
81
|
+
if (src === dest) continue // already in the right place (local dev)
|
|
82
|
+
cpSync(src, dest, { recursive: true })
|
|
83
|
+
copied.push(dest)
|
|
80
84
|
}
|
|
81
85
|
|
|
82
|
-
|
|
86
|
+
function cleanup() {
|
|
87
|
+
for (const f of copied) {
|
|
88
|
+
try { rmSync(f, { recursive: true, force: true }) } catch { /* best effort */ }
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
process.on('exit', cleanup)
|
|
92
|
+
process.on('SIGINT', () => { cleanup(); process.exit(130) })
|
|
93
|
+
process.on('SIGTERM', () => { cleanup(); process.exit(143) })
|
|
94
|
+
|
|
95
|
+
console.log(`\n ACP Progress Visualizer`)
|
|
96
|
+
console.log(` Loading: ${progressPath}`)
|
|
97
|
+
console.log(` Port: ${port}\n`)
|
|
98
|
+
|
|
99
|
+
const viteBin = resolve(nmRoot, 'node_modules', '.bin', 'vite')
|
|
83
100
|
|
|
84
|
-
// Start vite dev server from the package directory
|
|
85
101
|
const child = spawn(viteBin, ['dev', '--port', port, '--host'], {
|
|
86
|
-
cwd:
|
|
102
|
+
cwd: nmRoot,
|
|
87
103
|
stdio: 'inherit',
|
|
88
104
|
env: {
|
|
89
105
|
...process.env,
|
|
@@ -93,13 +109,11 @@ const child = spawn(viteBin, ['dev', '--port', port, '--host'], {
|
|
|
93
109
|
|
|
94
110
|
child.on('error', (err) => {
|
|
95
111
|
console.error('Failed to start dev server:', err.message)
|
|
112
|
+
cleanup()
|
|
96
113
|
process.exit(1)
|
|
97
114
|
})
|
|
98
115
|
|
|
99
116
|
child.on('exit', (code) => {
|
|
117
|
+
cleanup()
|
|
100
118
|
process.exit(code ?? 0)
|
|
101
119
|
})
|
|
102
|
-
|
|
103
|
-
// Forward signals for clean shutdown
|
|
104
|
-
process.on('SIGINT', () => child.kill('SIGINT'))
|
|
105
|
-
process.on('SIGTERM', () => child.kill('SIGTERM'))
|