@abide/abide 0.101.0 → 0.103.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.
- package/CHANGELOG.md +26 -0
- package/bin/abide.ts +226 -164
- package/docs/REGISTRY.md +730 -0
- package/docs/RULEBOOK.md +2768 -0
- package/docs/abide.md +13127 -0
- package/package.json +6 -3
- package/scaffold/AGENTS.md +38 -0
- package/scaffold/CLAUDE.md +1 -0
- package/scaffold/src/layout.abide +18 -0
- package/src/compiler/Lowering.ts +78 -9
- package/src/compiler/ShadowMap.ts +2 -2
- package/src/compiler/TypeSession.ts +341 -71
- package/src/compiler/appMap.ts +96 -0
- package/src/compiler/argsSchemaOf.ts +1 -1
- package/src/compiler/checkApp.ts +53 -8
- package/src/compiler/checkedShadow.ts +73 -6
- package/src/compiler/classifyRead.ts +6 -4
- package/src/compiler/classifyTemplate.ts +1 -1
- package/src/compiler/compileApp.ts +598 -200
- package/src/compiler/compiledEntry.ts +48 -40
- package/src/compiler/componentGraph.ts +57 -71
- package/src/compiler/declaredExports.ts +26 -9
- package/src/compiler/emitClient.ts +142 -72
- package/src/compiler/emitComponent.ts +41 -12
- package/src/compiler/emitSource.ts +102 -13
- package/src/compiler/handlersUnder.ts +164 -76
- package/src/compiler/hooksCalled.ts +35 -0
- package/src/compiler/index.ts +7 -0
- package/src/compiler/mountsOf.ts +150 -0
- package/src/compiler/nearest.ts +14 -0
- package/src/compiler/parseAbide.ts +157 -20
- package/src/compiler/projectShadow.ts +250 -19
- package/src/compiler/reactiveTypes.ts +20 -7
- package/src/compiler/readSources.ts +15 -2
- package/src/compiler/readsIn.ts +62 -8
- package/src/compiler/renderMarkup.ts +3 -3
- package/src/compiler/scaffold.ts +37 -15
- package/src/compiler/serveLanguage.ts +101 -34
- package/src/compiler/sharedModuleWrites.ts +2 -2
- package/src/compiler/sourceMapOf.ts +193 -0
- package/src/compiler/splitImports.ts +205 -83
- package/src/compiler/tokenize.ts +14 -0
- package/src/compiler/writeDefaultProject.ts +29 -2
- package/src/server/CLIENT_BUILD.ts +11 -13
- package/src/server/DEFAULT_PORT.ts +1 -1
- package/src/server/MODULE_QUERIES.ts +27 -0
- package/src/server/TABLES.ts +7 -0
- package/src/server/VIRTUAL_DIRECTORY.ts +4 -5
- package/src/server/abideModules.ts +457 -0
- package/src/server/answerFailure.ts +16 -6
- package/src/server/answerRequest.ts +241 -107
- package/src/server/answerRpc.ts +107 -33
- package/src/server/answerSocket.ts +65 -20
- package/src/server/answerValue.ts +22 -9
- package/src/server/appDirectories.ts +1 -1
- package/src/server/appPlugins.ts +1 -1
- package/src/server/appTree.ts +238 -0
- package/src/server/argsFor.ts +2 -2
- package/src/server/assistant.ts +2 -2
- package/src/server/bridgeRelay.ts +6 -8
- package/src/server/claudeCode.ts +0 -6
- package/src/server/clientBuildOptions.ts +8 -3
- package/src/server/coerceArgs.ts +1 -1
- package/src/server/commands.ts +38 -37
- package/src/server/componentModules.d.ts +2 -1
- package/src/server/compressAnswer.ts +4 -4
- package/src/server/config.ts +25 -29
- package/src/server/configFields.ts +31 -25
- package/src/server/createApp.ts +77 -79
- package/src/server/devWorker.ts +118 -181
- package/src/server/executableName.ts +4 -0
- package/src/server/fenceServer.ts +57 -32
- package/src/server/generatedSurfaces.ts +99 -66
- package/src/server/hooks.ts +137 -52
- package/src/server/iconAccent.ts +191 -0
- package/src/server/index.ts +12 -7
- package/src/server/installSourceMaps.ts +93 -0
- package/src/server/launcherOptions.ts +33 -31
- package/src/server/launcherPage.ts +107 -64
- package/src/server/manifestOf.ts +16 -13
- package/src/server/namesUnder.ts +2 -2
- package/src/server/nativeMenu.ts +6 -6
- package/src/server/negotiateEncoding.ts +1 -1
- package/src/server/preload.ts +13 -0
- package/src/server/principal.ts +10 -5
- package/src/server/realOrAsGiven.ts +10 -0
- package/src/server/refuseAddressCollision.ts +21 -14
- package/src/server/remote.ts +49 -52
- package/src/server/render.ts +65 -94
- package/src/server/renderComponent.ts +5 -0
- package/src/server/reportHealth.ts +2 -2
- package/src/server/requestScope.ts +12 -1
- package/src/server/runBuild.ts +24 -0
- package/src/server/runCompiled.ts +5 -5
- package/src/server/runDesktop.ts +48 -28
- package/src/server/serveBuild.ts +43 -52
- package/src/server/serveDev.ts +79 -37
- package/src/server/shell.ts +7 -22
- package/src/server/sourceMappings.ts +139 -0
- package/src/server/surfaceOf.ts +20 -3
- package/src/server/testBuild.ts +1 -19
- package/src/server/withAbideSources.ts +117 -0
- package/src/shared/ADDRESSES.ts +10 -18
- package/src/shared/APP_META.ts +7 -0
- package/src/shared/CopyOptions.ts +1 -1
- package/src/shared/DEBUG_META.ts +1 -1
- package/src/shared/LAUNCHER_FILES.ts +9 -0
- package/src/shared/RESERVED_DIRECTORIES.ts +24 -0
- package/src/shared/cookies.ts +2 -2
- package/src/shared/csp.ts +1 -1
- package/src/shared/escapeText.ts +1 -1
- package/src/shared/filledPath.ts +85 -0
- package/src/shared/framing.ts +79 -6
- package/src/shared/headKeyOf.ts +2 -0
- package/src/shared/index.ts +2 -1
- package/src/shared/log.ts +27 -13
- package/src/shared/matchRoute.ts +23 -4
- package/src/{ui → shared}/menuBridge.ts +2 -2
- package/src/shared/menuItem.ts +4 -4
- package/src/shared/onMenu.ts +58 -0
- package/src/shared/reactive/Keyed.ts +2 -2
- package/src/shared/reactive/NotLanded.ts +1 -1
- package/src/shared/reactive/Reactive.ts +43 -43
- package/src/shared/reactive/argsContract.ts +4 -4
- package/src/shared/reactive/canonicalKey.ts +4 -4
- package/src/shared/reactive/chunksOfStream.ts +6 -0
- package/src/shared/reactive/index.ts +1 -1
- package/src/shared/reactive/recordWrites.ts +103 -5
- package/src/shared/reactive/structural.ts +1 -1
- package/src/shared/reactive/tracking.ts +1 -1
- package/src/shared/reactive/watch.ts +3 -3
- package/src/shared/refuse.ts +1 -1
- package/src/{ui → shared}/reportMenu.ts +8 -10
- package/src/shared/routePattern.ts +122 -48
- package/src/shared/rpc.ts +37 -8
- package/src/shared/rpcRequest.ts +27 -3
- package/src/shared/url.ts +4 -44
- package/src/shared/writePath.ts +1 -1
- package/src/ui/LAYER_NAMES.ts +1 -1
- package/src/ui/List.ts +3 -3
- package/src/ui/MOUNTING_LEVEL.ts +18 -0
- package/src/ui/Mismatch.ts +1 -1
- package/src/ui/RawRun.ts +1 -1
- package/src/ui/Router.ts +37 -36
- package/src/ui/Scope.ts +1 -1
- package/src/ui/TryRegion.ts +2 -2
- package/src/ui/applyHead.ts +33 -0
- package/src/ui/index.ts +1 -1
- package/src/ui/moveNode.ts +1 -1
- package/src/ui/reconcile.ts +2 -2
- package/src/ui/routing.ts +2 -2
- package/src/ui/setAttribute.ts +1 -1
- package/src/ui/setText.ts +1 -1
- package/src/ui/socketWire.ts +9 -7
- package/src/ui/wire.ts +1 -1
- package/scaffold/src/server/app.ts +0 -6
- package/scaffold/src/shared/.gitkeep +0 -0
- package/scaffold/src/ui/app.html +0 -8
- package/src/server/componentImports.ts +0 -56
- /package/scaffold/src/{ui/pages/page.abide → index.abide} +0 -0
- /package/src/{compiler → shared}/SPECIFIERS.ts +0 -0
package/src/server/serveDev.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// 38.4 — `abide dev`: the project, watched, with the app kept up across every save. What is here
|
|
2
|
-
// is the LISTENER and nothing else (38.
|
|
2
|
+
// is the LISTENER and nothing else (38.14): the socket is bound once in this process and survives
|
|
3
3
|
// every reload, so a browser holding a connection open meets a server that is still there when
|
|
4
4
|
// the app behind it has been thrown away and rebuilt.
|
|
5
5
|
//
|
|
@@ -12,37 +12,43 @@
|
|
|
12
12
|
// reload, where a compiler imported into each new app cost 4.5 s a save against the 80 ms the
|
|
13
13
|
// compile takes — and the clause asks for the APP to be in the child, which the compiler is not.
|
|
14
14
|
//
|
|
15
|
-
// 38.
|
|
15
|
+
// 38.15 — A RELOAD IS A NEW PROCESS, not a module cache to invalidate. An app leaves things behind
|
|
16
16
|
// that no invalidation reaches — a timer, a `share`, a module that ran once, and bun's own memory of
|
|
17
17
|
// a file it failed to find — and a process is the one boundary that takes all of them with it. Every live socket is force-closed with it, which
|
|
18
18
|
// is also the whole of the reload protocol: the reload client reconnects and reloads, so nothing
|
|
19
19
|
// here has a message to send.
|
|
20
20
|
|
|
21
21
|
import { watch } from 'node:fs' // bun exposes no file watcher of its own
|
|
22
|
+
import { dirname, resolve } from 'node:path' // bun exposes no path helpers of its own
|
|
22
23
|
import {
|
|
23
24
|
type AppChecker,
|
|
25
|
+
compilationOf,
|
|
24
26
|
compileApp,
|
|
25
27
|
openChecker,
|
|
26
28
|
} from '#compiler/compileApp.ts'
|
|
27
29
|
import { formatDiagnosis } from '#compiler/formatDiagnosis.ts'
|
|
28
30
|
import { DEV_ADDRESS } from '#shared/ADDRESSES.ts'
|
|
31
|
+
import { placeOf } from '#shared/routePattern.ts'
|
|
32
|
+
import type { Compilation } from './abideModules.ts'
|
|
29
33
|
import { DEFAULT_PORT } from './DEFAULT_PORT.ts'
|
|
30
34
|
import type { Ask, FromWorker, ToWorker } from './devWorker.ts'
|
|
31
35
|
import { upgraded } from './muxUpgrade.ts'
|
|
32
36
|
import { plainAnswer } from './plainAnswer.ts'
|
|
33
37
|
import { SETTLE_MILLISECONDS } from './SETTLE_MILLISECONDS.ts'
|
|
34
|
-
import { VIRTUAL_DIRECTORY } from './VIRTUAL_DIRECTORY.ts'
|
|
35
38
|
|
|
36
39
|
/** What `abide dev` serves, and where. */
|
|
37
40
|
export type DevOptions = {
|
|
38
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* The app's source root — where its pages sit, and the tree that is watched — as its real path
|
|
43
|
+
* (`appRoot`), which is how the bundler names what it built.
|
|
44
|
+
*/
|
|
39
45
|
root: string
|
|
40
46
|
port?: number | undefined
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
// A request in flight: the request itself — because a worker replaced before it answered answers
|
|
44
|
-
// nothing, and the ask has to be put to the app that exists (38.
|
|
45
|
-
// back, the stream the body is fed into and the pull waiting on the worker's next chunk (38.
|
|
50
|
+
// nothing, and the ask has to be put to the app that exists (38.24) — and, once its head has come
|
|
51
|
+
// back, the stream the body is fed into and the pull waiting on the worker's next chunk (38.35).
|
|
46
52
|
type InFlight = Omit<Ask, 'id' | 'method' | 'url'> & {
|
|
47
53
|
// 16.22 — the request bun handed the listener, which is the one its idle timeout is raised on.
|
|
48
54
|
request: Request
|
|
@@ -60,7 +66,12 @@ type DevWorker = {
|
|
|
60
66
|
terminate(): void
|
|
61
67
|
}
|
|
62
68
|
|
|
63
|
-
type Compiled = {
|
|
69
|
+
type Compiled = {
|
|
70
|
+
compilation: Compilation
|
|
71
|
+
/** The public files the compile's walk found (`appFiles`), which the worker answers. */
|
|
72
|
+
published: Map<string, string>
|
|
73
|
+
failure: string
|
|
74
|
+
}
|
|
64
75
|
|
|
65
76
|
const LAST_DEV_PORT = 3099
|
|
66
77
|
|
|
@@ -128,21 +139,31 @@ export async function serveDev(
|
|
|
128
139
|
if (checker !== undefined && !checker.current())
|
|
129
140
|
await closeChecker()
|
|
130
141
|
checker ??= await openChecker(options.root)
|
|
131
|
-
const compiled = await compileApp(
|
|
132
|
-
options.root,
|
|
133
|
-
`${options.root}/${VIRTUAL_DIRECTORY}`,
|
|
134
|
-
checker,
|
|
135
|
-
)
|
|
142
|
+
const compiled = await compileApp(options.root, checker)
|
|
136
143
|
// 14 and 32.14 — what the compiler has to say, on every compile.
|
|
137
144
|
for (const warning of compiled.warnings)
|
|
138
145
|
console.warn(formatDiagnosis(warning, process.cwd()))
|
|
139
|
-
|
|
146
|
+
watchDependencies(compiled.files)
|
|
147
|
+
return {
|
|
148
|
+
compilation: compilationOf(compiled),
|
|
149
|
+
published: compiled.published,
|
|
150
|
+
failure: '',
|
|
151
|
+
}
|
|
140
152
|
} catch (thrown) {
|
|
141
153
|
await closeChecker()
|
|
142
154
|
const failure =
|
|
143
155
|
thrown instanceof Error ? thrown.message : String(thrown)
|
|
144
156
|
console.error(`abide dev: ${failure}`)
|
|
145
|
-
return {
|
|
157
|
+
return {
|
|
158
|
+
compilation: {
|
|
159
|
+
files: {},
|
|
160
|
+
handlers: {},
|
|
161
|
+
tables: {},
|
|
162
|
+
mounted: {},
|
|
163
|
+
},
|
|
164
|
+
published: new Map(),
|
|
165
|
+
failure,
|
|
166
|
+
}
|
|
146
167
|
}
|
|
147
168
|
}
|
|
148
169
|
|
|
@@ -156,9 +177,34 @@ export async function serveDev(
|
|
|
156
177
|
}
|
|
157
178
|
}
|
|
158
179
|
|
|
180
|
+
// A path a watcher saw move — or a move nobody could name — and the replacement it schedules.
|
|
181
|
+
let settling: ReturnType<typeof setTimeout> | undefined
|
|
182
|
+
function moved(path: string | undefined): void {
|
|
183
|
+
checker?.saw(path)
|
|
184
|
+
if (settling !== undefined) clearTimeout(settling)
|
|
185
|
+
settling = setTimeout(replace, SETTLE_MILLISECONDS)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// 38.99 — A DEPENDENCY'S `.abide` IS THE APP'S TOO, and a linked package's lies outside the root's
|
|
189
|
+
// watcher: each directory one was compiled from is watched once, for the session.
|
|
190
|
+
const watchedDependencies = new Set<string>()
|
|
191
|
+
function watchDependencies(files: Compilation['files']): void {
|
|
192
|
+
for (const relative of Object.keys(files)) {
|
|
193
|
+
if (placeOf(relative) !== 'dependency') continue
|
|
194
|
+
const directory = dirname(resolve(options.root, relative))
|
|
195
|
+
if (watchedDependencies.has(directory)) continue
|
|
196
|
+
watchedDependencies.add(directory)
|
|
197
|
+
watch(directory, (_event, filename) =>
|
|
198
|
+
moved(
|
|
199
|
+
filename === null ? undefined : `${directory}/${filename}`,
|
|
200
|
+
),
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
159
205
|
// The worker, compiled and answering.
|
|
160
|
-
function open({
|
|
161
|
-
// 38.
|
|
206
|
+
function open({ compilation, published, failure }: Compiled): void {
|
|
207
|
+
// 38.14 — A PROCESS, NOT A THREAD, for the header's reason: bun remembers a file it failed
|
|
162
208
|
// to find for the life of the process, and a thread inherits the miss.
|
|
163
209
|
//
|
|
164
210
|
// THE ENVIRONMENT AS IT STANDS, `NODE_ENV` included (36.3): the child is handed what this
|
|
@@ -182,7 +228,7 @@ export async function serveDev(
|
|
|
182
228
|
server.timeout(asked, message.seconds)
|
|
183
229
|
} else answer(started, message)
|
|
184
230
|
},
|
|
185
|
-
// 38.
|
|
231
|
+
// 38.41 — AN APP THAT EXITS ON ITS OWN is replaced, and says so: a listener still
|
|
186
232
|
// forwarding to it leaves every tab hanging.
|
|
187
233
|
onExit() {
|
|
188
234
|
if (worker !== started) return
|
|
@@ -200,7 +246,7 @@ export async function serveDev(
|
|
|
200
246
|
if (!child.killed && child.exitCode === null)
|
|
201
247
|
child.send(message)
|
|
202
248
|
},
|
|
203
|
-
// 38.
|
|
249
|
+
// 38.96 — SIGTERM, which the worker answers by hanging up what it is answering; a worker
|
|
204
250
|
// wedged in a loop never reads it, so a second later it is killed outright.
|
|
205
251
|
terminate() {
|
|
206
252
|
child.kill()
|
|
@@ -211,7 +257,8 @@ export async function serveDev(
|
|
|
211
257
|
started.postMessage({
|
|
212
258
|
kind: 'start',
|
|
213
259
|
root: options.root,
|
|
214
|
-
|
|
260
|
+
compilation,
|
|
261
|
+
published,
|
|
215
262
|
failure,
|
|
216
263
|
})
|
|
217
264
|
// The worker holds every request behind its own compile, so what waited here only had
|
|
@@ -221,8 +268,8 @@ export async function serveDev(
|
|
|
221
268
|
}
|
|
222
269
|
|
|
223
270
|
// WHAT AN APP THAT IS GONE WAS HOLDING. A request whose head has not gone out is re-asked of the
|
|
224
|
-
// replacement (38.
|
|
225
|
-
// ended it (38.
|
|
271
|
+
// replacement (38.24), or answered where the app ended itself — the request in hand may be what
|
|
272
|
+
// ended it (38.41). 38.37 — one whose head has gone out cannot be answered again, and ends as
|
|
226
273
|
// `abide start`'s does.
|
|
227
274
|
function endInFlight(reask: boolean, why: string): void {
|
|
228
275
|
for (const held of inFlight.values()) {
|
|
@@ -235,11 +282,11 @@ export async function serveDev(
|
|
|
235
282
|
inFlight.clear()
|
|
236
283
|
}
|
|
237
284
|
|
|
238
|
-
// 38.
|
|
285
|
+
// 38.15 — THE REPLACEMENT. The old worker is terminated, every socket it could still be
|
|
239
286
|
// answering is force-closed, and the new one is opened. The order matters: a socket closed
|
|
240
287
|
// after the new worker is up is a reload client that reconnects to a server still compiling.
|
|
241
288
|
//
|
|
242
|
-
// 38.
|
|
289
|
+
// 38.24 — A REQUEST IN FLIGHT IS RE-ASKED rather than failed. Failing it serves a reader a
|
|
243
290
|
// network error for asking while somebody saved, and during a regeneration of a whole docs
|
|
244
291
|
// tree that is every request; re-asked, they wait and get the app the source now says.
|
|
245
292
|
function replace(): void {
|
|
@@ -258,24 +305,19 @@ export async function serveDev(
|
|
|
258
305
|
await compiling
|
|
259
306
|
|
|
260
307
|
// 38.4 — THE PROJECT, WATCHED. One recursive watcher over the source root: the pages, the
|
|
261
|
-
//
|
|
308
|
+
// layouts, the stylesheets and every `public` directory are all under it, and every one of them is something
|
|
262
309
|
// the worker read at boot.
|
|
263
310
|
//
|
|
264
311
|
// IT IS NOT UNREFFED. It holds the process open, which is what a command that IS a server
|
|
265
312
|
// wants: the only ways out of `abide dev` are a signal and a throw, exactly as for
|
|
266
313
|
// `abide start`.
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
filename === null ? undefined : `${options.root}/${filename}`,
|
|
271
|
-
)
|
|
272
|
-
if (settling !== undefined) clearTimeout(settling)
|
|
273
|
-
settling = setTimeout(replace, SETTLE_MILLISECONDS)
|
|
274
|
-
})
|
|
314
|
+
watch(options.root, { recursive: true }, (_event, filename) =>
|
|
315
|
+
moved(filename === null ? undefined : `${options.root}/${filename}`),
|
|
316
|
+
)
|
|
275
317
|
|
|
276
318
|
// A REQUEST AS A MESSAGE. `Request` does not survive a structured clone, so what crosses is
|
|
277
319
|
// the four things the worker rebuilds one from — and the request's body is collected here, which
|
|
278
|
-
// is what lets it be asked again of a replacement (38.
|
|
320
|
+
// is what lets it be asked again of a replacement (38.24). The answer's body streams (38.35).
|
|
279
321
|
//
|
|
280
322
|
// COLLECTED ONCE, HERE, rather than inside `forward`: a body can only be read off a
|
|
281
323
|
// `Request` once, and a re-asked request is the second read that is not there.
|
|
@@ -294,7 +336,7 @@ export async function serveDev(
|
|
|
294
336
|
})
|
|
295
337
|
}
|
|
296
338
|
|
|
297
|
-
// 38.
|
|
339
|
+
// 38.38 — ASKED WITHOUT `accept-encoding`, so the app answers uncompressed. A failure after the
|
|
298
340
|
// head is shown as markup appended to the stream (`pull` in the worker), and markup appended to a
|
|
299
341
|
// compressed stream is a stream no browser can decode. Localhost buys nothing from the bytes saved.
|
|
300
342
|
function identityOnly(headers: Headers): [string, string][] {
|
|
@@ -304,7 +346,7 @@ export async function serveDev(
|
|
|
304
346
|
return kept
|
|
305
347
|
}
|
|
306
348
|
|
|
307
|
-
// 38.
|
|
349
|
+
// 38.35, 38.36 — THE HEAD SETTLES THE RESPONSE, and its body pulls one chunk from the worker per
|
|
308
350
|
// read the connection makes: a high-water mark of 0 asks for nothing ahead of the reader.
|
|
309
351
|
function answer(
|
|
310
352
|
from: DevWorker,
|
|
@@ -478,7 +520,7 @@ export async function serveDev(
|
|
|
478
520
|
},
|
|
479
521
|
})
|
|
480
522
|
|
|
481
|
-
// 38.
|
|
523
|
+
// 38.64 — A PORT SOMEONE NAMED IS THE PORT, and one taken is the failure. `Bun.serve` given
|
|
482
524
|
// none reads `PORT` itself.
|
|
483
525
|
const server =
|
|
484
526
|
options.port !== undefined || process.env.PORT
|
|
@@ -487,7 +529,7 @@ export async function serveDev(
|
|
|
487
529
|
return server as unknown as Bun.Server<undefined>
|
|
488
530
|
}
|
|
489
531
|
|
|
490
|
-
// 38.
|
|
532
|
+
// 38.63 — NAMED BY NOBODY, the first free port from 3000. A port taken is the next one tried, and
|
|
491
533
|
// any other failure is the failure.
|
|
492
534
|
function listenOnFirstFree<Listener>(
|
|
493
535
|
listen: (port: number) => Listener,
|
package/src/server/shell.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { useColor } from '#shared/log.ts'
|
|
|
9
9
|
import { paint as painted } from '#shared/paint.ts'
|
|
10
10
|
import type { Mount } from './answerRpc.ts'
|
|
11
11
|
import { LogPanel } from './LogPanel.ts'
|
|
12
|
-
import { callHandler,
|
|
12
|
+
import { callHandler, watch } from './remote.ts'
|
|
13
13
|
import { type Listed, surfaceOf } from './surfaceOf.ts'
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -48,8 +48,7 @@ function wordsOf(text: string): string[] {
|
|
|
48
48
|
* is in argv (38.8). Answers `exit` where the line said so and `ended` where the input did, so a
|
|
49
49
|
* host that owns the app can stop it on the one and keep serving on the other.
|
|
50
50
|
*
|
|
51
|
-
* `local` is the app in this process — the one `abide` alone serves — whose
|
|
52
|
-
* `logs` has nothing to add, and whose `exit` stops it.
|
|
51
|
+
* `local` is the app in this process — the one `abide` alone serves — whose `exit` stops it.
|
|
53
52
|
*/
|
|
54
53
|
export async function shell(options: {
|
|
55
54
|
url: string
|
|
@@ -78,7 +77,7 @@ export async function shell(options: {
|
|
|
78
77
|
),
|
|
79
78
|
})
|
|
80
79
|
// CTRL-C AS A SHELL TAKES IT — raw mode takes the key from the terminal, so no signal is sent for
|
|
81
|
-
// it: a call running is
|
|
80
|
+
// it: a call running is canceled, then every watch standing, a line typed is dropped, and on
|
|
82
81
|
// an empty line it asks once and leaves on the second, as `node`'s REPL does.
|
|
83
82
|
let exited = false
|
|
84
83
|
let closed = false
|
|
@@ -169,7 +168,6 @@ export async function shell(options: {
|
|
|
169
168
|
)
|
|
170
169
|
: undefined
|
|
171
170
|
if (panel === undefined) console.log(options.heading)
|
|
172
|
-
let tailing = false
|
|
173
171
|
try {
|
|
174
172
|
for await (const line of lines) {
|
|
175
173
|
const [word, address] = line.trim().split(/\s+/)
|
|
@@ -199,7 +197,7 @@ export async function shell(options: {
|
|
|
199
197
|
).catch((thrown: Error) => ({
|
|
200
198
|
code: 1,
|
|
201
199
|
text: running?.signal.aborted
|
|
202
|
-
? '(
|
|
200
|
+
? '(canceled)'
|
|
203
201
|
: thrown.message,
|
|
204
202
|
}))
|
|
205
203
|
running = undefined
|
|
@@ -210,14 +208,8 @@ export async function shell(options: {
|
|
|
210
208
|
)
|
|
211
209
|
} else if (word === 'call')
|
|
212
210
|
console.log('call: name the handler — call <address> [args]')
|
|
213
|
-
//
|
|
214
|
-
else if (word === '
|
|
215
|
-
tailing = true
|
|
216
|
-
void followLogs(url).then(() => {
|
|
217
|
-
tailing = false
|
|
218
|
-
})
|
|
219
|
-
} else if (word === 'watch' && address !== undefined) {
|
|
220
|
-
// Followed alongside the prompt, as `logs` is.
|
|
211
|
+
// FOLLOWED ALONGSIDE THE PROMPT rather than in place of it, so the shell still answers.
|
|
212
|
+
else if (word === 'watch' && address !== undefined) {
|
|
221
213
|
const following = new AbortController()
|
|
222
214
|
watching.add(following)
|
|
223
215
|
void watch(
|
|
@@ -235,12 +227,6 @@ export async function shell(options: {
|
|
|
235
227
|
.finally(() => watching.delete(following))
|
|
236
228
|
} else if (word === 'watch')
|
|
237
229
|
console.log('watch: name a GET — watch <address> [args]')
|
|
238
|
-
else if (word === 'logs')
|
|
239
|
-
console.log(
|
|
240
|
-
local
|
|
241
|
-
? "logs: the app's log already tails here."
|
|
242
|
-
: 'logs: already tailing.',
|
|
243
|
-
)
|
|
244
230
|
else
|
|
245
231
|
console.log(
|
|
246
232
|
`unknown: ${word} — help lists what the shell takes`,
|
|
@@ -456,7 +442,6 @@ export function shellWords(local: boolean): [usage: string, meaning: string][] {
|
|
|
456
442
|
['handlers', 'every handler call can reach, with its args'],
|
|
457
443
|
['watch <address> [args]', 'follow a GET — watch chat/room room=lobby'],
|
|
458
444
|
]
|
|
459
|
-
if (!local) words.push(['logs', "tail the app's log.records here"])
|
|
460
445
|
words.push(
|
|
461
446
|
['help', 'this list — Ctrl+C clears the line, Ctrl+L the panel'],
|
|
462
447
|
['exit', local ? 'stop the app and leave' : 'leave the shell'],
|
|
@@ -488,7 +473,7 @@ export function cliListing(handlers: Mount[]): Listed[] {
|
|
|
488
473
|
|
|
489
474
|
/**
|
|
490
475
|
* The handlers the shell lists: each address with the args it is typed with, and its description on
|
|
491
|
-
* the line under it where it declares one. 38.
|
|
476
|
+
* the line under it where it declares one. 38.62.
|
|
492
477
|
*/
|
|
493
478
|
export function handlersText(
|
|
494
479
|
listed: Listed[],
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// THE `mappings` FIELD OF A SOURCE MAP (revision 3), read and written. The compiler writes one per
|
|
2
|
+
// module it emits from a `.abide` (`sourceMapOf`), the server reads them to place a stack frame in
|
|
3
|
+
// the `.abide` (`installSourceMaps`), and the client build reads bun's to put the two together —
|
|
4
|
+
// bun reads no map it is handed, at run time or in the bundler, so every one of those is ours.
|
|
5
|
+
|
|
6
|
+
/** Where one generated column came from: `[column, source, line, sourceColumn]`, all from 0. */
|
|
7
|
+
export type Segment = [number, number, number, number]
|
|
8
|
+
|
|
9
|
+
const DIGITS =
|
|
10
|
+
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
|
11
|
+
const VALUES = new Map<string, number>()
|
|
12
|
+
for (let index = 0; index < DIGITS.length; index += 1)
|
|
13
|
+
VALUES.set(DIGITS[index] as string, index)
|
|
14
|
+
|
|
15
|
+
function vlq(value: number): string {
|
|
16
|
+
let rest = value < 0 ? (-value << 1) | 1 : value << 1
|
|
17
|
+
let out = ''
|
|
18
|
+
do {
|
|
19
|
+
let digit = rest & 31
|
|
20
|
+
rest >>>= 5
|
|
21
|
+
if (rest > 0) digit |= 32
|
|
22
|
+
out += DIGITS[digit]
|
|
23
|
+
} while (rest > 0)
|
|
24
|
+
return out
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Each generated line's segments, ascending by column, as the `mappings` string. */
|
|
28
|
+
export function encodeMappings(lines: readonly (readonly Segment[])[]): string {
|
|
29
|
+
let out = ''
|
|
30
|
+
let source = 0
|
|
31
|
+
let line = 0
|
|
32
|
+
let sourceColumn = 0
|
|
33
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
34
|
+
if (index > 0) out += ';'
|
|
35
|
+
let column = 0
|
|
36
|
+
const segments = lines[index] as readonly Segment[]
|
|
37
|
+
for (let at = 0; at < segments.length; at += 1) {
|
|
38
|
+
const segment = segments[at] as Segment
|
|
39
|
+
if (at > 0) out += ','
|
|
40
|
+
out +=
|
|
41
|
+
vlq(segment[0] - column) +
|
|
42
|
+
vlq(segment[1] - source) +
|
|
43
|
+
vlq(segment[2] - line) +
|
|
44
|
+
vlq(segment[3] - sourceColumn)
|
|
45
|
+
column = segment[0]
|
|
46
|
+
source = segment[1]
|
|
47
|
+
line = segment[2]
|
|
48
|
+
sourceColumn = segment[3]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return out
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A `mappings` string as each generated line's segments. A segment naming no source — one field
|
|
56
|
+
* long — places nothing, and is dropped.
|
|
57
|
+
*/
|
|
58
|
+
export function decodeMappings(mappings: string): Segment[][] {
|
|
59
|
+
const lines: Segment[][] = [[]]
|
|
60
|
+
const fields: number[] = []
|
|
61
|
+
let source = 0
|
|
62
|
+
let line = 0
|
|
63
|
+
let sourceColumn = 0
|
|
64
|
+
let column = 0
|
|
65
|
+
let value = 0
|
|
66
|
+
let shift = 0
|
|
67
|
+
const close = (): void => {
|
|
68
|
+
if (fields.length >= 4) {
|
|
69
|
+
column += fields[0] as number
|
|
70
|
+
source += fields[1] as number
|
|
71
|
+
line += fields[2] as number
|
|
72
|
+
sourceColumn += fields[3] as number
|
|
73
|
+
;(lines[lines.length - 1] as Segment[]).push([
|
|
74
|
+
column,
|
|
75
|
+
source,
|
|
76
|
+
line,
|
|
77
|
+
sourceColumn,
|
|
78
|
+
])
|
|
79
|
+
} else if (fields.length > 0) column += fields[0] as number
|
|
80
|
+
fields.length = 0
|
|
81
|
+
}
|
|
82
|
+
for (const character of mappings) {
|
|
83
|
+
if (character === ';') {
|
|
84
|
+
close()
|
|
85
|
+
lines.push([])
|
|
86
|
+
column = 0
|
|
87
|
+
continue
|
|
88
|
+
}
|
|
89
|
+
if (character === ',') {
|
|
90
|
+
close()
|
|
91
|
+
continue
|
|
92
|
+
}
|
|
93
|
+
const digit = VALUES.get(character) ?? 0
|
|
94
|
+
value |= (digit & 31) << shift
|
|
95
|
+
if (digit & 32) {
|
|
96
|
+
shift += 5
|
|
97
|
+
continue
|
|
98
|
+
}
|
|
99
|
+
fields.push(value & 1 ? -(value >>> 1) : value >>> 1)
|
|
100
|
+
value = 0
|
|
101
|
+
shift = 0
|
|
102
|
+
}
|
|
103
|
+
close()
|
|
104
|
+
return lines
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Where `column` on generated `line` came from: the last segment at or before it, or the line's
|
|
109
|
+
* first where the column is before every one — a frame's column points into an expression, and
|
|
110
|
+
* the segment is its start.
|
|
111
|
+
*/
|
|
112
|
+
export function segmentAt(
|
|
113
|
+
lines: readonly (readonly Segment[])[],
|
|
114
|
+
line: number,
|
|
115
|
+
column: number,
|
|
116
|
+
): Segment | undefined {
|
|
117
|
+
const segments = lines[line]
|
|
118
|
+
if (segments === undefined || segments.length === 0) return undefined
|
|
119
|
+
let found = segments[0] as Segment
|
|
120
|
+
for (const segment of segments) {
|
|
121
|
+
if (segment[0] > column) break
|
|
122
|
+
found = segment
|
|
123
|
+
}
|
|
124
|
+
return found
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The `[line, column]` generated `line` and `column` came from. Within a segment the run was copied
|
|
129
|
+
* as written, so the column moves with it.
|
|
130
|
+
*/
|
|
131
|
+
export function placeAt(
|
|
132
|
+
lines: readonly (readonly Segment[])[],
|
|
133
|
+
line: number,
|
|
134
|
+
column: number,
|
|
135
|
+
): [number, number] | undefined {
|
|
136
|
+
const segment = segmentAt(lines, line, column)
|
|
137
|
+
if (segment === undefined) return undefined
|
|
138
|
+
return [segment[2], segment[3] + Math.max(column - segment[0], 0)]
|
|
139
|
+
}
|
package/src/server/surfaceOf.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { RPC_ADDRESS } from '#shared/ADDRESSES.ts'
|
|
2
1
|
import type { Method } from '#shared/rpc.ts'
|
|
3
2
|
import type { Mount, Mounted } from './answerRpc.ts'
|
|
4
3
|
|
|
@@ -9,8 +8,10 @@ export type Surface = 'mcp' | 'openapi' | 'cli'
|
|
|
9
8
|
export type Listed = {
|
|
10
9
|
address: string
|
|
11
10
|
method: Method
|
|
12
|
-
/** Its
|
|
11
|
+
/** Its route without the leading `/` — what `call` spells it (38.8). */
|
|
13
12
|
path: string
|
|
13
|
+
/** What MCP and OpenAPI name it by. 20.13. */
|
|
14
|
+
name: string
|
|
14
15
|
description: string | undefined
|
|
15
16
|
/** Its args' JSON Schema, where it has one. 19.9, 20.11. */
|
|
16
17
|
schema: unknown
|
|
@@ -30,6 +31,8 @@ export function surfaceOf(
|
|
|
30
31
|
mount: Mount | Mounted,
|
|
31
32
|
surface: Surface,
|
|
32
33
|
): Listed | undefined {
|
|
34
|
+
// 16.71 — a private handler is its file's alone.
|
|
35
|
+
if (mount.private) return undefined
|
|
33
36
|
const live = 'handler' in mount ? mount : undefined
|
|
34
37
|
// 16.37 — what its `clients` says, and the build's default where it says nothing.
|
|
35
38
|
const carried =
|
|
@@ -39,9 +42,23 @@ export function surfaceOf(
|
|
|
39
42
|
return {
|
|
40
43
|
address: mount.address,
|
|
41
44
|
method: mount.method,
|
|
42
|
-
path: mount.address.slice(
|
|
45
|
+
path: mount.address.slice(1),
|
|
46
|
+
name: surfaceName(mount.method, mount.address),
|
|
43
47
|
description:
|
|
44
48
|
live === undefined ? mount.description : live.handler.description,
|
|
45
49
|
schema: live === undefined ? mount.args : live.argsDocument,
|
|
46
50
|
}
|
|
47
51
|
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A handler's name on MCP and OpenAPI: its method and its route, in the letters a tool's name admits.
|
|
55
|
+
*
|
|
56
|
+
* 20.13 — the method first, so two handlers at one route are two names, and a segment's brackets
|
|
57
|
+
* and dots dropped, so `/media/[id]` reads `media_id` rather than `media__id_`.
|
|
58
|
+
*/
|
|
59
|
+
export function surfaceName(method: Method, route: string): string {
|
|
60
|
+
return `${method.toLowerCase()}${route === '/' ? '' : route.replace(/[[\].]/g, '')}`.replace(
|
|
61
|
+
/[^a-zA-Z0-9-]/g,
|
|
62
|
+
'_',
|
|
63
|
+
)
|
|
64
|
+
}
|
package/src/server/testBuild.ts
CHANGED
|
@@ -7,11 +7,8 @@
|
|
|
7
7
|
import { mkdir, rename, rm, utimes, writeFile } from 'node:fs/promises' // bun exposes no directory creation, rename, removal, mtime write or exclusive create of its own
|
|
8
8
|
import { dirname } from 'node:path' // bun exposes no path helpers of its own
|
|
9
9
|
import { namesUnder } from './namesUnder.ts'
|
|
10
|
+
import { runBuild } from './runBuild.ts'
|
|
10
11
|
|
|
11
|
-
// The CLI, spawned rather than imported: the compiler is not reachable from the server seam.
|
|
12
|
-
const ABIDE_BIN = Bun.fileURLToPath(
|
|
13
|
-
new URL('../../bin/abide.ts', import.meta.url),
|
|
14
|
-
)
|
|
15
12
|
// The framework's own source is part of what made a build: a compiler change is a new build.
|
|
16
13
|
const FRAMEWORK = Bun.fileURLToPath(new URL('../..', import.meta.url))
|
|
17
14
|
const POLL_MS = 50
|
|
@@ -95,21 +92,6 @@ async function buildInto(
|
|
|
95
92
|
}
|
|
96
93
|
}
|
|
97
94
|
|
|
98
|
-
async function runBuild(root: string, out: string): Promise<void> {
|
|
99
|
-
const child = Bun.spawn(
|
|
100
|
-
[process.execPath, ABIDE_BIN, 'build', '--root', root, '--out', out],
|
|
101
|
-
{ stdout: 'ignore', stderr: 'pipe' },
|
|
102
|
-
)
|
|
103
|
-
const [exitCode, said] = await Promise.all([
|
|
104
|
-
child.exited,
|
|
105
|
-
new Response(child.stderr).text(),
|
|
106
|
-
])
|
|
107
|
-
if (exitCode !== 0)
|
|
108
|
-
throw new Error(
|
|
109
|
-
`abide: createApp could not build the app under ${root} for this test run.\n${said}`,
|
|
110
|
-
)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
95
|
/**
|
|
114
96
|
* A hash of everything a build of the app under `root` is made from.
|
|
115
97
|
*
|