@antigenic-oss/paint 0.2.7 → 0.2.8

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/paint.js CHANGED
@@ -22,7 +22,7 @@ const APP_VERSION = (() => {
22
22
  const RUNNING_FROM_NODE_MODULES = APP_ROOT.includes(
23
23
  `${path.sep}node_modules${path.sep}`,
24
24
  )
25
- const RUNTIME_SCHEMA_VERSION = 2
25
+ const RUNTIME_SCHEMA_VERSION = 4
26
26
  const RUNTIME_ROOT = RUNNING_FROM_NODE_MODULES
27
27
  ? path.join(STATE_DIR, 'runtime', APP_VERSION)
28
28
  : APP_ROOT
@@ -68,11 +68,42 @@ function ensureStateDir() {
68
68
  fs.mkdirSync(STATE_DIR, { recursive: true })
69
69
  }
70
70
 
71
+ function findNodeModulesRootFromResolvedPath(resolvedPath) {
72
+ const needle = `${path.sep}node_modules${path.sep}`
73
+ const idx = resolvedPath.lastIndexOf(needle)
74
+ if (idx === -1) return null
75
+ // Keep ".../node_modules" (without trailing slash)
76
+ return resolvedPath.slice(0, idx + needle.length - 1)
77
+ }
78
+
79
+ function resolveDependencyNodeModulesRoot() {
80
+ const probes = [
81
+ 'zustand/package.json',
82
+ '@xterm/xterm/package.json',
83
+ 'react/package.json',
84
+ 'next/package.json',
85
+ ]
86
+
87
+ for (const probe of probes) {
88
+ try {
89
+ const resolved = require.resolve(probe, { paths: [APP_ROOT] })
90
+ const root = findNodeModulesRootFromResolvedPath(resolved)
91
+ if (root) return root
92
+ } catch {
93
+ // keep probing
94
+ }
95
+ }
96
+
97
+ // Last resort: local node_modules under package root.
98
+ return path.join(APP_ROOT, 'node_modules')
99
+ }
100
+
71
101
  function ensureRuntimeRoot() {
72
102
  if (!RUNNING_FROM_NODE_MODULES) return APP_ROOT
73
103
 
74
104
  const stampFile = path.join(RUNTIME_ROOT, '.paint-runtime-stamp.json')
75
105
  let needsRefresh = true
106
+ const moduleRoot = resolveDependencyNodeModulesRoot()
76
107
 
77
108
  if (fs.existsSync(stampFile)) {
78
109
  try {
@@ -81,10 +112,18 @@ function ensureRuntimeRoot() {
81
112
  const hasLegacyConfigTs = fs.existsSync(
82
113
  path.join(RUNTIME_ROOT, 'next.config.ts'),
83
114
  )
115
+ const runtimeNodeModules = path.join(RUNTIME_ROOT, 'node_modules')
116
+ let linkedToExpectedRoot = false
117
+ try {
118
+ linkedToExpectedRoot = fs.realpathSync(runtimeNodeModules) === moduleRoot
119
+ } catch {
120
+ linkedToExpectedRoot = false
121
+ }
84
122
  needsRefresh =
85
123
  stamp?.schemaVersion !== RUNTIME_SCHEMA_VERSION ||
86
124
  !hasConfigMjs ||
87
- hasLegacyConfigTs
125
+ hasLegacyConfigTs ||
126
+ !linkedToExpectedRoot
88
127
  } catch {
89
128
  needsRefresh = true
90
129
  }
@@ -124,7 +163,7 @@ function ensureRuntimeRoot() {
124
163
  }
125
164
 
126
165
  const runtimeNodeModules = path.join(RUNTIME_ROOT, 'node_modules')
127
- fs.symlinkSync(path.join(APP_ROOT, 'node_modules'), runtimeNodeModules, 'dir')
166
+ fs.symlinkSync(moduleRoot, runtimeNodeModules, 'dir')
128
167
 
129
168
  fs.writeFileSync(
130
169
  stampFile,
@@ -133,6 +172,7 @@ function ensureRuntimeRoot() {
133
172
  schemaVersion: RUNTIME_SCHEMA_VERSION,
134
173
  version: APP_VERSION,
135
174
  sourceRoot: APP_ROOT,
175
+ moduleRoot,
136
176
  preparedAt: now(),
137
177
  },
138
178
  null,
@@ -31,9 +31,17 @@ function main() {
31
31
  const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'paint-packed-smoke-'))
32
32
  const packDir = path.join(tempRoot, 'pack')
33
33
  const extractDir = path.join(tempRoot, 'extract')
34
+ const globalRoot = path.join(tempRoot, 'global')
35
+ const globalNodeModules = path.join(globalRoot, 'node_modules')
36
+ const scopedPackageRoot = path.join(
37
+ globalNodeModules,
38
+ '@antigenic-oss',
39
+ 'paint',
40
+ )
34
41
  const fakeHome = path.join(tempRoot, 'home')
35
42
  fs.mkdirSync(packDir, { recursive: true })
36
43
  fs.mkdirSync(extractDir, { recursive: true })
44
+ fs.mkdirSync(globalNodeModules, { recursive: true })
37
45
  fs.mkdirSync(fakeHome, { recursive: true })
38
46
 
39
47
  runOrFail('npm', ['pack', '--silent', '--pack-destination', packDir])
@@ -49,9 +57,26 @@ function main() {
49
57
  runOrFail('tar', ['-xzf', path.join(packDir, tarball), '-C', extractDir])
50
58
 
51
59
  const packedRoot = path.join(extractDir, 'package')
52
- const packedNodeModules = path.join(packedRoot, 'node_modules')
53
- if (!fs.existsSync(packedNodeModules)) {
54
- fs.symlinkSync(path.join(APP_ROOT, 'node_modules'), packedNodeModules, 'dir')
60
+
61
+ // Emulate global install layout:
62
+ // <global>/node_modules/@antigenic-oss/paint (package)
63
+ // <global>/node_modules/<deps> (shared deps), no package-local node_modules.
64
+ fs.mkdirSync(path.dirname(scopedPackageRoot), { recursive: true })
65
+ fs.cpSync(packedRoot, scopedPackageRoot, { recursive: true, force: true })
66
+ fs.rmSync(path.join(scopedPackageRoot, 'node_modules'), {
67
+ recursive: true,
68
+ force: true,
69
+ })
70
+
71
+ const sourceNodeModules = path.join(APP_ROOT, 'node_modules')
72
+ const entries = fs.readdirSync(sourceNodeModules, { withFileTypes: true })
73
+ for (const entry of entries) {
74
+ if (entry.name === '.bin') continue
75
+ if (entry.name === '@antigenic-oss') continue
76
+ const src = path.join(sourceNodeModules, entry.name)
77
+ const dst = path.join(globalNodeModules, entry.name)
78
+ if (fs.existsSync(dst)) continue
79
+ fs.symlinkSync(src, dst, 'dir')
55
80
  }
56
81
 
57
82
  const env = {
@@ -63,15 +88,15 @@ function main() {
63
88
 
64
89
  let started = false
65
90
  try {
66
- runOrFail('node', [path.join(packedRoot, 'bin', 'paint.js'), 'start', '--rebuild', '--port', PORT], {
67
- cwd: packedRoot,
91
+ runOrFail('node', [path.join(scopedPackageRoot, 'bin', 'paint.js'), 'start', '--rebuild', '--port', PORT], {
92
+ cwd: scopedPackageRoot,
68
93
  env,
69
94
  })
70
95
  started = true
71
96
  } finally {
72
97
  if (started) {
73
- run('node', [path.join(packedRoot, 'bin', 'paint.js'), 'stop'], {
74
- cwd: packedRoot,
98
+ run('node', [path.join(scopedPackageRoot, 'bin', 'paint.js'), 'stop'], {
99
+ cwd: scopedPackageRoot,
75
100
  env,
76
101
  })
77
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antigenic-oss/paint",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "Visual editor for localhost web projects with a global paint CLI",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/Antigenic-OSS/pAInt",