@prmichaelsen/acp-visualizer 0.1.4 → 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 +22 -28
- 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, cpSync,
|
|
4
|
+
import { existsSync, cpSync, rmSync } from 'fs'
|
|
5
5
|
import { fileURLToPath } from 'url'
|
|
6
6
|
import { spawn } from 'child_process'
|
|
7
7
|
|
|
@@ -56,43 +56,37 @@ if (!existsSync(progressPath)) {
|
|
|
56
56
|
process.exit(1)
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
// direct child, so ESM resolution works correctly for TanStack Start's
|
|
62
|
-
// virtual modules.
|
|
63
|
-
|
|
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/
|
|
64
61
|
function findNodeModulesRoot() {
|
|
65
62
|
let dir = packageRoot
|
|
66
63
|
while (dir !== '/') {
|
|
67
|
-
|
|
68
|
-
if (existsSync(resolve(candidate, '.bin', 'vite'))) return dir
|
|
64
|
+
if (existsSync(resolve(dir, 'node_modules', '.bin', 'vite'))) return dir
|
|
69
65
|
dir = resolve(dir, '..')
|
|
70
66
|
}
|
|
71
67
|
return packageRoot
|
|
72
68
|
}
|
|
73
69
|
|
|
74
70
|
const nmRoot = findNodeModulesRoot()
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const targetNM = resolve(workDir, 'node_modules')
|
|
89
|
-
if (!existsSync(targetNM)) {
|
|
90
|
-
const { symlinkSync } = await import('fs')
|
|
91
|
-
symlinkSync(existingNM, targetNM)
|
|
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
|
+
|
|
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)
|
|
92
84
|
}
|
|
93
85
|
|
|
94
86
|
function cleanup() {
|
|
95
|
-
|
|
87
|
+
for (const f of copied) {
|
|
88
|
+
try { rmSync(f, { recursive: true, force: true }) } catch { /* best effort */ }
|
|
89
|
+
}
|
|
96
90
|
}
|
|
97
91
|
process.on('exit', cleanup)
|
|
98
92
|
process.on('SIGINT', () => { cleanup(); process.exit(130) })
|
|
@@ -102,10 +96,10 @@ console.log(`\n ACP Progress Visualizer`)
|
|
|
102
96
|
console.log(` Loading: ${progressPath}`)
|
|
103
97
|
console.log(` Port: ${port}\n`)
|
|
104
98
|
|
|
105
|
-
const viteBin = resolve(
|
|
99
|
+
const viteBin = resolve(nmRoot, 'node_modules', '.bin', 'vite')
|
|
106
100
|
|
|
107
101
|
const child = spawn(viteBin, ['dev', '--port', port, '--host'], {
|
|
108
|
-
cwd:
|
|
102
|
+
cwd: nmRoot,
|
|
109
103
|
stdio: 'inherit',
|
|
110
104
|
env: {
|
|
111
105
|
...process.env,
|