@aiwayds/dsh-opentui 0.4.2 → 0.5.0

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.
@@ -0,0 +1,286 @@
1
+ /**
2
+ * Shared solid-js client-build pin for the dsh profile.
3
+ *
4
+ * solid-js's "node" export condition resolves to dist/server.js (SSR, no
5
+ * reactive scheduling): under the dsh host's node runtime the TUI renders one
6
+ * frame and then goes dead. Under bun dev the @opentui/solid preload remaps
7
+ * this; the host has no such preload, so the installed package itself must
8
+ * resolve to the client build. Two layers, both managed here:
9
+ *
10
+ * 1. a pnpm patchedDependencies patch — the primary fix, survives any
11
+ * `pnpm install` in the profile
12
+ * 2. an idempotent direct rewrite of the installed package.json exports —
13
+ * belt-and-braces for right after an install or a dist-host deploy
14
+ *
15
+ * Used by scripts/install-profile.mjs (before its pnpm install steps) and
16
+ * scripts/sync-profile.mjs (the local-dev deploy loop).
17
+ */
18
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
19
+ import { join } from 'node:path'
20
+
21
+ export const SOLID_JS_VERSION = '1.9.12'
22
+ export const SOLID_PATCH_RELPATH = `patches/solid-js@${SOLID_JS_VERSION}.patch`
23
+
24
+ // pristine solid-js@1.9.12 package.json -> client-pinned variant:
25
+ // - "module" points at dist/solid.js instead of dist/server.js
26
+ // - exports["."] drops the worker/deno/node conditions (node used to win and
27
+ // select the SSR build) and resolves straight to dist/solid.js
28
+ // - the SSR-flavored subpath exports (./store, ./web, ./h, ...) go away; the
29
+ // host bundle imports bare "solid-js" only
30
+ export const SOLID_JS_PATCH = `diff --git a/package.json b/package.json
31
+ index ad27a1f..f3aa43a 100644
32
+ --- a/package.json
33
+ +++ b/package.json
34
+ @@ -10,7 +10,7 @@
35
+ "url": "https://github.com/solidjs/solid"
36
+ },
37
+ "main": "./dist/server.cjs",
38
+ - "module": "./dist/server.js",
39
+ + "module": "./dist/solid.js",
40
+ "unpkg": "./dist/solid.cjs",
41
+ "types": "types/index.d.ts",
42
+ "sideEffects": false,
43
+ @@ -44,164 +44,12 @@
44
+ ],
45
+ "exports": {
46
+ ".": {
47
+ - "worker": {
48
+ - "types": "./types/index.d.ts",
49
+ - "import": "./dist/server.js",
50
+ - "require": "./dist/server.cjs"
51
+ - },
52
+ - "browser": {
53
+ - "development": {
54
+ - "types": "./types/index.d.ts",
55
+ - "import": "./dist/dev.js",
56
+ - "require": "./dist/dev.cjs"
57
+ - },
58
+ - "types": "./types/index.d.ts",
59
+ - "import": "./dist/solid.js",
60
+ - "require": "./dist/solid.cjs"
61
+ - },
62
+ - "deno": {
63
+ - "types": "./types/index.d.ts",
64
+ - "import": "./dist/server.js",
65
+ - "require": "./dist/server.cjs"
66
+ - },
67
+ - "node": {
68
+ - "types": "./types/index.d.ts",
69
+ - "import": "./dist/server.js",
70
+ - "require": "./dist/server.cjs"
71
+ - },
72
+ - "development": {
73
+ - "types": "./types/index.d.ts",
74
+ - "import": "./dist/dev.js",
75
+ - "require": "./dist/dev.cjs"
76
+ - },
77
+ "types": "./types/index.d.ts",
78
+ "import": "./dist/solid.js",
79
+ "require": "./dist/solid.cjs"
80
+ },
81
+ - "./dist/*": "./dist/*",
82
+ - "./types/*": "./types/*",
83
+ - "./jsx-runtime": {
84
+ - "types": "./types/jsx.d.ts",
85
+ - "default": "./dist/solid.js"
86
+ - },
87
+ - "./jsx-dev-runtime": {
88
+ - "types": "./types/jsx.d.ts",
89
+ - "default": "./dist/solid.js"
90
+ - },
91
+ - "./store": {
92
+ - "worker": {
93
+ - "types": "./store/types/index.d.ts",
94
+ - "import": "./store/dist/server.js",
95
+ - "require": "./store/dist/server.cjs"
96
+ - },
97
+ - "browser": {
98
+ - "development": {
99
+ - "types": "./store/types/index.d.ts",
100
+ - "import": "./store/dist/dev.js",
101
+ - "require": "./store/dist/dev.cjs"
102
+ - },
103
+ - "types": "./store/types/index.d.ts",
104
+ - "import": "./store/dist/store.js",
105
+ - "require": "./store/dist/store.cjs"
106
+ - },
107
+ - "deno": {
108
+ - "types": "./store/types/index.d.ts",
109
+ - "import": "./store/dist/server.js",
110
+ - "require": "./store/dist/server.cjs"
111
+ - },
112
+ - "node": {
113
+ - "types": "./store/types/index.d.ts",
114
+ - "import": "./store/dist/server.js",
115
+ - "require": "./store/dist/server.cjs"
116
+ - },
117
+ - "development": {
118
+ - "types": "./store/types/index.d.ts",
119
+ - "import": "./store/dist/dev.js",
120
+ - "require": "./store/dist/dev.cjs"
121
+ - },
122
+ - "types": "./store/types/index.d.ts",
123
+ - "import": "./store/dist/store.js",
124
+ - "require": "./store/dist/store.cjs"
125
+ - },
126
+ - "./store/dist/*": "./store/dist/*",
127
+ - "./store/types/*": "./store/types/*",
128
+ - "./web": {
129
+ - "worker": {
130
+ - "types": "./web/types/index.d.ts",
131
+ - "import": "./web/dist/server.js",
132
+ - "require": "./web/dist/server.cjs"
133
+ - },
134
+ - "browser": {
135
+ - "development": {
136
+ - "types": "./web/types/index.d.ts",
137
+ - "import": "./web/dist/dev.js",
138
+ - "require": "./web/dist/dev.cjs"
139
+ - },
140
+ - "types": "./web/types/index.d.ts",
141
+ - "import": "./web/dist/web.js",
142
+ - "require": "./web/dist/web.cjs"
143
+ - },
144
+ - "deno": {
145
+ - "types": "./web/types/index.d.ts",
146
+ - "import": "./web/dist/server.js",
147
+ - "require": "./web/dist/server.cjs"
148
+ - },
149
+ - "node": {
150
+ - "types": "./web/types/index.d.ts",
151
+ - "import": "./web/dist/server.js",
152
+ - "require": "./web/dist/server.cjs"
153
+ - },
154
+ - "development": {
155
+ - "types": "./web/types/index.d.ts",
156
+ - "import": "./web/dist/dev.js",
157
+ - "require": "./web/dist/dev.cjs"
158
+ - },
159
+ - "types": "./web/types/index.d.ts",
160
+ - "import": "./web/dist/web.js",
161
+ - "require": "./web/dist/web.cjs"
162
+ - },
163
+ - "./web/storage": {
164
+ - "types": "./web/storage/types/index.d.ts",
165
+ - "import": "./web/storage/dist/storage.js",
166
+ - "require": "./web/storage/dist/storage.cjs"
167
+ - },
168
+ - "./web/dist/*": "./web/dist/*",
169
+ - "./web/types/*": "./web/types/*",
170
+ - "./universal": {
171
+ - "development": {
172
+ - "types": "./universal/types/index.d.ts",
173
+ - "import": "./universal/dist/dev.js",
174
+ - "require": "./universal/dist/dev.cjs"
175
+ - },
176
+ - "types": "./universal/types/index.d.ts",
177
+ - "import": "./universal/dist/universal.js",
178
+ - "require": "./universal/dist/universal.cjs"
179
+ - },
180
+ - "./universal/dist/*": "./universal/dist/*",
181
+ - "./universal/types/*": "./universal/types/*",
182
+ - "./h": {
183
+ - "types": "./h/types/index.d.ts",
184
+ - "import": "./h/dist/h.js",
185
+ - "require": "./h/dist/h.cjs"
186
+ - },
187
+ - "./h/jsx-runtime": {
188
+ - "types": "./h/jsx-runtime/types/index.d.ts",
189
+ - "import": "./h/jsx-runtime/dist/jsx.js",
190
+ - "require": "./h/jsx-runtime/dist/jsx.cjs"
191
+ - },
192
+ - "./h/jsx-dev-runtime": {
193
+ - "types": "./h/jsx-runtime/types/index.d.ts",
194
+ - "import": "./h/jsx-runtime/dist/jsx.js",
195
+ - "require": "./h/jsx-runtime/dist/jsx.cjs"
196
+ - },
197
+ - "./h/dist/*": "./h/dist/*",
198
+ - "./h/types/*": "./h/types/*",
199
+ - "./html": {
200
+ - "types": "./html/types/index.d.ts",
201
+ - "import": "./html/dist/html.js",
202
+ - "require": "./html/dist/html.cjs"
203
+ - },
204
+ - "./html/dist/*": "./html/dist/*",
205
+ + "./dist/solid.js": "./dist/solid.js",
206
+ + "./dist/solid.cjs": "./dist/solid.cjs",
207
+ "./package.json": "./package.json"
208
+ },
209
+ "keywords": [
210
+ `
211
+
212
+ // The exports object the pinned package.json must carry (also the target of
213
+ // the direct re-pin below).
214
+ export const SOLID_JS_EXPORTS = {
215
+ '.': { types: './types/index.d.ts', import: './dist/solid.js', require: './dist/solid.cjs' },
216
+ './dist/solid.js': './dist/solid.js',
217
+ './dist/solid.cjs': './dist/solid.cjs',
218
+ './package.json': './package.json',
219
+ }
220
+
221
+ const WORKSPACE_DEFAULT = `packages:
222
+ - .
223
+ nodeLinker: hoisted
224
+ autoInstallPeers: false
225
+ `
226
+
227
+ const PATCHED_DEPS_BLOCK = `patchedDependencies:
228
+ solid-js@${SOLID_JS_VERSION}: ${SOLID_PATCH_RELPATH}
229
+ `
230
+
231
+ /**
232
+ * Make sure the profile carries the solid-js patch and registers it with
233
+ * pnpm. Call BEFORE any `pnpm install` in the profile — patchedDependencies
234
+ * must be in pnpm-workspace.yaml when install runs for the pin to survive.
235
+ *
236
+ * Creates pnpm-workspace.yaml with the default hoisted layout when missing;
237
+ * otherwise appends the patchedDependencies key only when not yet present
238
+ * (user edits to the yaml are preserved). Returns what it did.
239
+ */
240
+ export function ensureSolidPatch(profileDir) {
241
+ mkdirSync(join(profileDir, 'patches'), { recursive: true })
242
+ const patchPath = join(profileDir, SOLID_PATCH_RELPATH)
243
+ let patchWrote = false
244
+ if (!existsSync(patchPath) || readFileSync(patchPath, 'utf8') !== SOLID_JS_PATCH) {
245
+ writeFileSync(patchPath, SOLID_JS_PATCH)
246
+ patchWrote = true
247
+ }
248
+
249
+ const wsPath = join(profileDir, 'pnpm-workspace.yaml')
250
+ let workspaceNote
251
+ if (!existsSync(wsPath)) {
252
+ writeFileSync(wsPath, WORKSPACE_DEFAULT + PATCHED_DEPS_BLOCK)
253
+ workspaceNote = 'workspace created'
254
+ } else {
255
+ const ws = readFileSync(wsPath, 'utf8')
256
+ if (ws.includes(`solid-js@${SOLID_JS_VERSION}:`)) {
257
+ workspaceNote = 'patch already registered'
258
+ } else {
259
+ writeFileSync(wsPath, ws.replace(/\n*$/, '\n') + PATCHED_DEPS_BLOCK)
260
+ workspaceNote = 'patch registered in existing workspace'
261
+ }
262
+ }
263
+ return { patchWrote, workspaceNote }
264
+ }
265
+
266
+ /**
267
+ * Directly re-pin node_modules/solid-js/package.json to the client build.
268
+ * Idempotent: returns 'already' when the installed file already matches,
269
+ * 'pinned' after a rewrite, 'missing' when solid-js is not installed.
270
+ */
271
+ export function pinSolidJsExports(profileDir) {
272
+ const solidPkg = join(profileDir, 'node_modules', 'solid-js', 'package.json')
273
+ let pkgJson
274
+ try {
275
+ pkgJson = JSON.parse(readFileSync(solidPkg, 'utf8'))
276
+ } catch {
277
+ return 'missing'
278
+ }
279
+ if (pkgJson.module === './dist/solid.js' && JSON.stringify(pkgJson.exports) === JSON.stringify(SOLID_JS_EXPORTS)) {
280
+ return 'already'
281
+ }
282
+ pkgJson.module = './dist/solid.js'
283
+ pkgJson.exports = SOLID_JS_EXPORTS
284
+ writeFileSync(solidPkg, JSON.stringify(pkgJson, null, 2))
285
+ return 'pinned'
286
+ }
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Deploy the local build into the dsh profile — the manual dev loop, codified:
4
+ *
5
+ * 1. bun build-host.ts — rebuild packages/shell/dist-host
6
+ * 2. rsync dist-host contents — overlay the profile's installed
7
+ * @aiwayds/dsh-opentui copy
8
+ * 3. solid-js patch + patchedDependencies — keep the client-build pin
9
+ * pnpm-install-proof
10
+ * 4. direct re-pin of solid-js exports — idempotent belt-and-braces
11
+ *
12
+ * Safe to re-run at any time; prints a summary of what was done.
13
+ * Run from anywhere (paths resolve from this file); `npm run sync` works too.
14
+ */
15
+ import { spawnSync } from 'node:child_process'
16
+ import { existsSync, mkdirSync } from 'node:fs'
17
+ import { homedir } from 'node:os'
18
+ import { dirname, join } from 'node:path'
19
+ import { fileURLToPath } from 'node:url'
20
+ import { ensureSolidPatch, pinSolidJsExports } from './solid-js-pin.mjs'
21
+
22
+ const shellDir = dirname(dirname(fileURLToPath(import.meta.url))) // packages/shell
23
+ const DSH_HOME = process.env.DSH_HOME || join(homedir(), '.dsh')
24
+ const profileDir = join(DSH_HOME, 'profiles', 'dsh-opentui')
25
+ const dstPkg = join(profileDir, 'node_modules', '@aiwayds', 'dsh-opentui')
26
+
27
+ const done = []
28
+ const fail = (msg) => {
29
+ console.error(`[sync-profile] ${msg}`)
30
+ process.exit(1)
31
+ }
32
+
33
+ if (!existsSync(dstPkg)) fail(`profile package ${dstPkg} not installed — run the dsh installer or pnpm install in the profile first`)
34
+
35
+ // 1. rebuild the host bundle. The bunfig preload that remaps solid-js to the
36
+ // client build lives in packages/shell, so bun MUST run with that cwd.
37
+ const build = spawnSync('bun', ['build-host.ts'], { cwd: shellDir, stdio: 'inherit' })
38
+ if (build.status !== 0) fail('bun build-host.ts failed')
39
+
40
+ // 2. overlay the fresh dist-host into the profile's installed package.
41
+ // Plain `rsync -a` of the contents (no --delete): dist-host is fully owned
42
+ // by the build, and it ships its own node_modules — copy those too.
43
+ const srcDist = join(shellDir, 'dist-host')
44
+ const dstDist = join(dstPkg, 'dist-host')
45
+ if (!existsSync(srcDist)) fail(`no dist-host at ${srcDist} — build produced nothing?`)
46
+ mkdirSync(dstDist, { recursive: true })
47
+ const rsync = spawnSync('rsync', ['-a', `${srcDist}/`, `${dstDist}/`])
48
+ if (rsync.status !== 0) fail(`rsync failed: ${(rsync.stderr || '').toString().trim()}`)
49
+ done.push(`rsync dist-host -> ${dstDist}`)
50
+
51
+ // 3. keep the solid-js client pin pnpm-install-proof
52
+ const { patchWrote, workspaceNote } = ensureSolidPatch(profileDir)
53
+ done.push(`solid-js patch ${patchWrote ? 'written' : 'already current'} (${workspaceNote})`)
54
+
55
+ // 4. idempotent direct re-pin of the installed solid-js exports
56
+ const pinState = pinSolidJsExports(profileDir)
57
+ if (pinState === 'missing') fail('solid-js not installed in the profile — pnpm install in the profile first')
58
+ done.push(`solid-js exports ${pinState === 'pinned' ? 're-pinned to' : 'already pinned to'} client build (dist/solid.js)`)
59
+
60
+ console.log('[sync-profile] done:')
61
+ for (const step of done) console.log(` - ${step}`)
62
+ console.log(`[sync-profile] profile: ${profileDir}`)