@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.
Files changed (2) hide show
  1. package/bin/visualize.mjs +22 -28
  2. 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, mkdirSync, rmSync } 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,43 +56,37 @@ 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
-
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
- const candidate = resolve(dir, 'node_modules')
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
- 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)
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
- try { rmSync(workDir, { recursive: true, force: true }) } catch { /* best effort */ }
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(workDir, 'node_modules', '.bin', 'vite')
99
+ const viteBin = resolve(nmRoot, 'node_modules', '.bin', 'vite')
106
100
 
107
101
  const child = spawn(viteBin, ['dev', '--port', port, '--host'], {
108
- cwd: workDir,
102
+ cwd: nmRoot,
109
103
  stdio: 'inherit',
110
104
  env: {
111
105
  ...process.env,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prmichaelsen/acp-visualizer",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "description": "Browser-based dashboard for visualizing ACP progress.yaml data",
6
6
  "bin": {