@antigenic-oss/paint 0.2.6 → 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 +43 -3
- package/bin/smoke-packed-global.js +106 -0
- package/next.config.mjs +10 -0
- package/package.json +4 -2
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 =
|
|
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(
|
|
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,
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs')
|
|
4
|
+
const os = require('node:os')
|
|
5
|
+
const path = require('node:path')
|
|
6
|
+
const { spawnSync } = require('node:child_process')
|
|
7
|
+
|
|
8
|
+
const APP_ROOT = path.resolve(__dirname, '..')
|
|
9
|
+
const PORT = '4210'
|
|
10
|
+
|
|
11
|
+
function runOrFail(cmd, args, opts = {}) {
|
|
12
|
+
const result = spawnSync(cmd, args, {
|
|
13
|
+
cwd: opts.cwd || APP_ROOT,
|
|
14
|
+
env: opts.env || process.env,
|
|
15
|
+
stdio: 'inherit',
|
|
16
|
+
})
|
|
17
|
+
if (result.status !== 0) {
|
|
18
|
+
process.exit(result.status || 1)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function run(cmd, args, opts = {}) {
|
|
23
|
+
return spawnSync(cmd, args, {
|
|
24
|
+
cwd: opts.cwd || APP_ROOT,
|
|
25
|
+
env: opts.env || process.env,
|
|
26
|
+
stdio: 'inherit',
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function main() {
|
|
31
|
+
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'paint-packed-smoke-'))
|
|
32
|
+
const packDir = path.join(tempRoot, 'pack')
|
|
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
|
+
)
|
|
41
|
+
const fakeHome = path.join(tempRoot, 'home')
|
|
42
|
+
fs.mkdirSync(packDir, { recursive: true })
|
|
43
|
+
fs.mkdirSync(extractDir, { recursive: true })
|
|
44
|
+
fs.mkdirSync(globalNodeModules, { recursive: true })
|
|
45
|
+
fs.mkdirSync(fakeHome, { recursive: true })
|
|
46
|
+
|
|
47
|
+
runOrFail('npm', ['pack', '--silent', '--pack-destination', packDir])
|
|
48
|
+
|
|
49
|
+
const tarball = fs
|
|
50
|
+
.readdirSync(packDir)
|
|
51
|
+
.find((name) => name.endsWith('.tgz'))
|
|
52
|
+
if (!tarball) {
|
|
53
|
+
console.error('Smoke test failed: npm pack produced no tarball.')
|
|
54
|
+
process.exit(1)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
runOrFail('tar', ['-xzf', path.join(packDir, tarball), '-C', extractDir])
|
|
58
|
+
|
|
59
|
+
const packedRoot = path.join(extractDir, 'package')
|
|
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')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const env = {
|
|
83
|
+
...process.env,
|
|
84
|
+
HOME: fakeHome,
|
|
85
|
+
USERPROFILE: fakeHome,
|
|
86
|
+
PAINT_SKIP_POSTINSTALL_BUILD: '1',
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let started = false
|
|
90
|
+
try {
|
|
91
|
+
runOrFail('node', [path.join(scopedPackageRoot, 'bin', 'paint.js'), 'start', '--rebuild', '--port', PORT], {
|
|
92
|
+
cwd: scopedPackageRoot,
|
|
93
|
+
env,
|
|
94
|
+
})
|
|
95
|
+
started = true
|
|
96
|
+
} finally {
|
|
97
|
+
if (started) {
|
|
98
|
+
run('node', [path.join(scopedPackageRoot, 'bin', 'paint.js'), 'stop'], {
|
|
99
|
+
cwd: scopedPackageRoot,
|
|
100
|
+
env,
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
main()
|
package/next.config.mjs
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
|
|
1
3
|
const nextConfig = {
|
|
4
|
+
webpack(config) {
|
|
5
|
+
config.resolve = config.resolve || {}
|
|
6
|
+
config.resolve.alias = config.resolve.alias || {}
|
|
7
|
+
// Force runtime alias resolution even if tsconfig path loading is skipped.
|
|
8
|
+
config.resolve.alias['@'] = path.resolve(process.cwd(), 'src')
|
|
9
|
+
return config
|
|
10
|
+
},
|
|
11
|
+
|
|
2
12
|
async headers() {
|
|
3
13
|
return [
|
|
4
14
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antigenic-oss/paint",
|
|
3
|
-
"version": "0.2.
|
|
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",
|
|
@@ -47,11 +47,13 @@
|
|
|
47
47
|
"dev:all": "node ./bin/terminal-server.js & node ./bin/bridge-server.js & next dev --port 4000 --turbopack",
|
|
48
48
|
"bridge": "node ./bin/bridge-server.js",
|
|
49
49
|
"postinstall": "node ./bin/postinstall.js",
|
|
50
|
-
"build": "next build",
|
|
50
|
+
"build": "next build --webpack",
|
|
51
51
|
"start": "next start --port 4000",
|
|
52
52
|
"lint": "biome lint .",
|
|
53
53
|
"lint:fix": "biome lint --write .",
|
|
54
54
|
"format": "biome format --write .",
|
|
55
|
+
"smoke:packed-global": "node ./bin/smoke-packed-global.js",
|
|
56
|
+
"prepublishOnly": "npm run smoke:packed-global",
|
|
55
57
|
"changeset": "changeset",
|
|
56
58
|
"version-packages": "changeset version",
|
|
57
59
|
"release": "changeset publish"
|