@yaks/cli 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +1059 -2
- package/_dist/account-forward.d.ts +12 -0
- package/_dist/account-forward.d.ts.map +1 -0
- package/_dist/accounts.d.ts +23 -0
- package/_dist/accounts.d.ts.map +1 -0
- package/_dist/answer.d.ts +88 -0
- package/_dist/answer.d.ts.map +1 -0
- package/_dist/apply.d.ts +17 -0
- package/_dist/apply.d.ts.map +1 -0
- package/_dist/args.d.ts +86 -0
- package/_dist/args.d.ts.map +1 -0
- package/_dist/commands.d.ts +15 -0
- package/_dist/commands.d.ts.map +1 -0
- package/_dist/complete.d.ts +15 -0
- package/_dist/complete.d.ts.map +1 -0
- package/_dist/config.d.ts +37 -0
- package/_dist/config.d.ts.map +1 -0
- package/_dist/dependencies.d.ts +6 -0
- package/_dist/dependencies.d.ts.map +1 -0
- package/_dist/facets.d.ts +71 -0
- package/_dist/facets.d.ts.map +1 -0
- package/_dist/grammar.d.ts +5 -0
- package/_dist/grammar.d.ts.map +1 -0
- package/_dist/host.d.ts +164 -0
- package/_dist/host.d.ts.map +1 -0
- package/_dist/install.d.ts +43 -0
- package/_dist/install.d.ts.map +1 -0
- package/_dist/main.d.ts +16 -0
- package/_dist/main.d.ts.map +1 -0
- package/_dist/memo.d.ts +60 -0
- package/_dist/memo.d.ts.map +1 -0
- package/_dist/mod.d.ts +46 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/page.d.ts +73 -0
- package/_dist/page.d.ts.map +1 -0
- package/_dist/platform.d.ts +27 -0
- package/_dist/platform.d.ts.map +1 -0
- package/_dist/reader.d.ts +10 -0
- package/_dist/reader.d.ts.map +1 -0
- package/_dist/release.d.ts +48 -0
- package/_dist/release.d.ts.map +1 -0
- package/_dist/remote.d.ts +13 -0
- package/_dist/remote.d.ts.map +1 -0
- package/_dist/reported.d.ts +11 -0
- package/_dist/reported.d.ts.map +1 -0
- package/_dist/roles.d.ts +2 -0
- package/_dist/roles.d.ts.map +1 -0
- package/_dist/roster.d.ts +41 -0
- package/_dist/roster.d.ts.map +1 -0
- package/_dist/rpc.d.ts +29 -0
- package/_dist/rpc.d.ts.map +1 -0
- package/_dist/run.d.ts +164 -0
- package/_dist/run.d.ts.map +1 -0
- package/_dist/runtime.d.ts +4 -0
- package/_dist/runtime.d.ts.map +1 -0
- package/_dist/searching.d.ts +7 -0
- package/_dist/searching.d.ts.map +1 -0
- package/_dist/show.d.ts +22 -0
- package/_dist/show.d.ts.map +1 -0
- package/_dist/store.d.ts +25 -0
- package/_dist/store.d.ts.map +1 -0
- package/_dist/terminal.d.ts +17 -0
- package/_dist/terminal.d.ts.map +1 -0
- package/_dist/tool.d.ts +55 -0
- package/_dist/tool.d.ts.map +1 -0
- package/_dist/tty.d.ts +3 -0
- package/_dist/tty.d.ts.map +1 -0
- package/_dist/vault.d.ts +9 -0
- package/_dist/vault.d.ts.map +1 -0
- package/_dist/words.d.ts +11 -0
- package/_dist/words.d.ts.map +1 -0
- package/_dist/yak.d.ts +10 -0
- package/_dist/yak.d.ts.map +1 -0
- package/account-forward.js +40 -0
- package/account-forward.js.map +1 -0
- package/account-forward.ts +50 -0
- package/accounts.js +162 -0
- package/accounts.js.map +1 -0
- package/accounts.ts +228 -0
- package/answer.js +394 -0
- package/answer.js.map +1 -0
- package/answer.ts +569 -0
- package/apply.js +49 -0
- package/apply.js.map +1 -0
- package/apply.ts +54 -0
- package/args.js +420 -0
- package/args.js.map +1 -0
- package/args.ts +494 -0
- package/code.js +209 -0
- package/code.js.map +1 -0
- package/code.ts +227 -0
- package/commands.js +131 -0
- package/commands.js.map +1 -0
- package/commands.ts +142 -0
- package/complete.js +104 -0
- package/complete.js.map +1 -0
- package/complete.ts +152 -0
- package/config.js +125 -0
- package/config.js.map +1 -0
- package/config.ts +180 -0
- package/declarations.js +67 -0
- package/declarations.js.map +1 -0
- package/declarations.ts +84 -0
- package/deno.json +1 -0
- package/dependencies.js +126 -0
- package/dependencies.js.map +1 -0
- package/dependencies.ts +141 -0
- package/derive.js +102 -0
- package/derive.js.map +1 -0
- package/derive.ts +125 -0
- package/drain.js +83 -0
- package/drain.js.map +1 -0
- package/drain.ts +115 -0
- package/duties.ts +17 -0
- package/exports.json +1486 -0
- package/external.js +373 -0
- package/external.js.map +1 -0
- package/external.ts +435 -0
- package/facets.js +214 -0
- package/facets.js.map +1 -0
- package/facets.ts +232 -0
- package/feedback.js +54 -0
- package/feedback.js.map +1 -0
- package/feedback.ts +57 -0
- package/files.js +84 -0
- package/files.js.map +1 -0
- package/files.ts +112 -0
- package/get_starts.js +31 -0
- package/get_starts.js.map +1 -0
- package/get_starts.ts +34 -0
- package/git-credential.js +79 -0
- package/git-credential.js.map +1 -0
- package/git-credential.ts +77 -0
- package/grammar.js +4 -0
- package/grammar.js.map +1 -0
- package/grammar.ts +5 -0
- package/held.js +51 -0
- package/held.js.map +1 -0
- package/held.ts +66 -0
- package/host.js +1174 -0
- package/host.js.map +1 -0
- package/host.ts +1343 -0
- package/init.js +138 -0
- package/init.js.map +1 -0
- package/init.ts +139 -0
- package/install.js +216 -0
- package/install.js.map +1 -0
- package/install.ts +223 -0
- package/lifetime.js +56 -0
- package/lifetime.js.map +1 -0
- package/lifetime.ts +66 -0
- package/local-page.ts +114 -0
- package/local.js +417 -0
- package/local.js.map +1 -0
- package/local.ts +537 -0
- package/lockfile.js +20 -0
- package/lockfile.js.map +1 -0
- package/lockfile.ts +32 -0
- package/machines.js +33 -0
- package/machines.js.map +1 -0
- package/machines.ts +51 -0
- package/made/4f855610bdabcd736100d34e4e467ea5.json +1 -0
- package/main.js +534 -0
- package/main.js.map +1 -0
- package/main.ts +547 -0
- package/mcp.js +108 -0
- package/mcp.js.map +1 -0
- package/mcp.ts +113 -0
- package/member.js +103 -0
- package/member.js.map +1 -0
- package/member.ts +133 -0
- package/memo.js +503 -0
- package/memo.js.map +1 -0
- package/memo.ts +634 -0
- package/mod.js +46 -0
- package/mod.js.map +1 -0
- package/mod.ts +99 -0
- package/operations.js +53 -0
- package/operations.js.map +1 -0
- package/operations.ts +68 -0
- package/package.json +115 -4
- package/page.js +211 -0
- package/page.js.map +1 -0
- package/page.ts +308 -0
- package/parser.js +45 -0
- package/parser.js.map +1 -0
- package/parser.ts +77 -0
- package/people-search.js +112 -0
- package/people-search.js.map +1 -0
- package/people-search.ts +162 -0
- package/platform.js +184 -0
- package/platform.js.map +1 -0
- package/platform.ts +224 -0
- package/platform_effects.js +5 -0
- package/platform_effects.js.map +1 -0
- package/platform_effects.ts +13 -0
- package/prepare.js +40 -0
- package/prepare.js.map +1 -0
- package/prepare.ts +46 -0
- package/read_activity.js +54 -0
- package/read_activity.js.map +1 -0
- package/read_activity.ts +61 -0
- package/read_thread.js +387 -0
- package/read_thread.js.map +1 -0
- package/read_thread.ts +506 -0
- package/read_worker.ts +164 -0
- package/reader.js +48 -0
- package/reader.js.map +1 -0
- package/reader.ts +57 -0
- package/release.js +82 -0
- package/release.js.map +1 -0
- package/release.json +127 -0
- package/release.ts +98 -0
- package/remote-page.ts +70 -0
- package/remote.js +96 -0
- package/remote.js.map +1 -0
- package/remote.ts +153 -0
- package/report.js +83 -0
- package/report.js.map +1 -0
- package/report.ts +101 -0
- package/reported.js +32 -0
- package/reported.js.map +1 -0
- package/reported.ts +38 -0
- package/restart.js +349 -0
- package/restart.js.map +1 -0
- package/restart.ts +478 -0
- package/restore.js +32 -0
- package/restore.js.map +1 -0
- package/restore.ts +38 -0
- package/roles.js +32 -0
- package/roles.js.map +1 -0
- package/roles.ts +49 -0
- package/roster.js +65 -0
- package/roster.js.map +1 -0
- package/roster.ts +84 -0
- package/rpc.js +113 -0
- package/rpc.js.map +1 -0
- package/rpc.ts +159 -0
- package/run.js +533 -0
- package/run.js.map +1 -0
- package/run.ts +741 -0
- package/runtime.js +381 -0
- package/runtime.js.map +1 -0
- package/runtime.ts +433 -0
- package/sandboxes.js +26 -0
- package/sandboxes.js.map +1 -0
- package/sandboxes.ts +30 -0
- package/searching.js +33 -0
- package/searching.js.map +1 -0
- package/searching.ts +50 -0
- package/show.js +109 -0
- package/show.js.map +1 -0
- package/show.ts +144 -0
- package/shown.js +13 -0
- package/shown.js.map +1 -0
- package/shown.ts +44 -0
- package/stall.js +90 -0
- package/stall.js.map +1 -0
- package/stall.ts +156 -0
- package/stall_profile.js +113 -0
- package/stall_profile.js.map +1 -0
- package/stall_profile.ts +142 -0
- package/stall_wait.js +183 -0
- package/stall_wait.js.map +1 -0
- package/stall_wait.ts +249 -0
- package/stall_wait_worker.ts +11 -0
- package/start.js +349 -0
- package/start.js.map +1 -0
- package/start.ts +343 -0
- package/starvation.js +147 -0
- package/starvation.js.map +1 -0
- package/starvation.ts +224 -0
- package/store.js +118 -0
- package/store.js.map +1 -0
- package/store.ts +193 -0
- package/subcommands.js +62 -0
- package/subcommands.js.map +1 -0
- package/subcommands.ts +77 -0
- package/terminal.js +93 -0
- package/terminal.js.map +1 -0
- package/terminal.ts +128 -0
- package/text.js +20 -0
- package/text.js.map +1 -0
- package/text.ts +37 -0
- package/tool.js +76 -0
- package/tool.js.map +1 -0
- package/tool.ts +157 -0
- package/trace_control.js +231 -0
- package/trace_control.js.map +1 -0
- package/trace_control.ts +233 -0
- package/traces.js +138 -0
- package/traces.js.map +1 -0
- package/traces.ts +160 -0
- package/tracker.js +22 -0
- package/tracker.js.map +1 -0
- package/tracker.ts +27 -0
- package/tty.js +82 -0
- package/tty.js.map +1 -0
- package/tty.ts +142 -0
- package/unit_failure.js +178 -0
- package/unit_failure.js.map +1 -0
- package/unit_failure.ts +191 -0
- package/upkeep_thread.js +32 -0
- package/upkeep_thread.js.map +1 -0
- package/upkeep_thread.ts +35 -0
- package/upkeep_worker.ts +27 -0
- package/vault.js +186 -0
- package/vault.js.map +1 -0
- package/vault.ts +220 -0
- package/vocab-ids.js +63 -0
- package/vocab-ids.js.map +1 -0
- package/vocab-ids.ts +62 -0
- package/vocab.json +35 -0
- package/warm.js +138 -0
- package/warm.js.map +1 -0
- package/warm.ts +171 -0
- package/watch_revision.js +25 -0
- package/watch_revision.js.map +1 -0
- package/watch_revision.ts +30 -0
- package/words.js +29 -0
- package/words.js.map +1 -0
- package/words.ts +41 -0
- package/workspaces.js +40 -0
- package/workspaces.js.map +1 -0
- package/workspaces.ts +58 -0
- package/yak-unit-failure.conf +6 -0
- package/yak-unit-handoff.conf +2 -0
- package/yak.js +123 -0
- package/yak.js.map +1 -0
- package/yak.ts +136 -0
package/install.ts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import * as system from '@yaks/process/system'
|
|
2
|
+
import * as disk from '@yaks/file/io'
|
|
3
|
+
import { command as launchCommand } from '@yaks/process/command'
|
|
4
|
+
// `deno run -A jsr:@yaks/cli/install`: puts `yak` on this machine at the
|
|
5
|
+
// release this module came from, so the command, every plugin a config names
|
|
6
|
+
// by package (./config.ts `located`) and the canvas it bundles are one set.
|
|
7
|
+
//
|
|
8
|
+
// A bare `deno install -g jsr:@yaks/cli/yak` is not that on the day a release
|
|
9
|
+
// publishes (./release.ts): the install takes the release before, and a `yak`
|
|
10
|
+
// pinned to the new one has every plugin it names refused until the day is
|
|
11
|
+
// out, since a global install's command keeps none of the flags it was
|
|
12
|
+
// installed with. What it does keep is a config, copied beside the command,
|
|
13
|
+
// so the config written here is the release's (./release.ts `released`).
|
|
14
|
+
//
|
|
15
|
+
// It installs the newest release a day old, whole; `--minimum-dependency-age=0`
|
|
16
|
+
// takes the release published today. Deno keeps the release list it fetched,
|
|
17
|
+
// so an update adds `--reload=jsr:@yaks/cli`, or it installs the release it
|
|
18
|
+
// found before.
|
|
19
|
+
|
|
20
|
+
import cli from './package.json' with { type: 'json' }
|
|
21
|
+
import { released } from './release.js'
|
|
22
|
+
|
|
23
|
+
/** The `deno` arguments that install `yak` at `version` under `config`.
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { assertEquals } from '@std/assert'
|
|
27
|
+
* assertEquals(install('1.2.3', '/tmp/c.json').at(-1), 'jsr:@yaks/cli@1.2.3/yak')
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export let install = (version: string, config: string): string[] => [
|
|
31
|
+
'install',
|
|
32
|
+
'--global',
|
|
33
|
+
'--allow-all',
|
|
34
|
+
// Deno's own lines as a first command fetches modules say nothing to whoever
|
|
35
|
+
// ran it; its errors print all the same.
|
|
36
|
+
'--quiet',
|
|
37
|
+
// TODO: drop once Deno honors deno.json's "no-legacy-abort" (2.9.1 does not)
|
|
38
|
+
'--unstable-no-legacy-abort',
|
|
39
|
+
'--force',
|
|
40
|
+
'--name',
|
|
41
|
+
'yak',
|
|
42
|
+
'--config',
|
|
43
|
+
config,
|
|
44
|
+
`jsr:${cli.name}@${version}/yak`,
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
/** The `deno` arguments that run `yak` at `version` under `config`, with
|
|
48
|
+
* `args`: what the installed command runs, without installing it.
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { assertEquals } from '@std/assert'
|
|
52
|
+
* assertEquals(run('1.2.3', '/tmp/c.json', ['help']).slice(-2), ['jsr:@yaks/cli@1.2.3/yak', 'help'])
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export let run = (
|
|
56
|
+
version: string,
|
|
57
|
+
config: string,
|
|
58
|
+
args: string[],
|
|
59
|
+
): string[] => [
|
|
60
|
+
'run',
|
|
61
|
+
'--allow-all',
|
|
62
|
+
'--config',
|
|
63
|
+
config,
|
|
64
|
+
`jsr:${cli.name}@${version}/yak`,
|
|
65
|
+
...args,
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
/** A first `yak init` and `yak task list`, against a scratch graph in `dir`:
|
|
69
|
+
* a command imports the plugins a config names by name, which `deno install`
|
|
70
|
+
* never fetched, since it follows literal imports only. Run here, the wait to
|
|
71
|
+
* fetch and compile them is part of installing, and a person's first command
|
|
72
|
+
* finds them. */
|
|
73
|
+
export let warming = (dir: string): string[][] => [
|
|
74
|
+
['--config', `${dir}/warm/yak.json`, 'init'],
|
|
75
|
+
['--config', `${dir}/warm/yak.json`, 'task', 'list'],
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
/** A first `yak serve` on that scratch graph, at `port`, asked for its canvas
|
|
79
|
+
* and stopped once it says it is ready, in the file `ready`: serving imports
|
|
80
|
+
* the facets of the web role, bundles the page, and, as it warms, starts its
|
|
81
|
+
* readers and the workers for its duty roles, none of which a command before
|
|
82
|
+
* it fetched, so a person's first `yak serve` would otherwise download them as
|
|
83
|
+
* it starts.
|
|
84
|
+
*
|
|
85
|
+
* ```ts
|
|
86
|
+
* import { assertEquals } from '@std/assert'
|
|
87
|
+
* assertEquals(serving('/tmp/i', 9).slice(-5), ['serve', '--port', '9', '--ready', '/tmp/i/ready'])
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export let serving = (dir: string, port: number): string[] => [
|
|
91
|
+
'--config',
|
|
92
|
+
`${dir}/warm/yak.json`,
|
|
93
|
+
'serve',
|
|
94
|
+
'--port',
|
|
95
|
+
String(port),
|
|
96
|
+
'--ready',
|
|
97
|
+
`${dir}/ready`,
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
/** What a warm-up of `yak serve` asks for once it listens, after the page at
|
|
101
|
+
* `/`: everything the page loads (its canvas, stylesheet, icons, manifest),
|
|
102
|
+
* which serve makes from the files Deno then keeps, so a first `yak serve`
|
|
103
|
+
* answers with them offline too.
|
|
104
|
+
*
|
|
105
|
+
* ```ts
|
|
106
|
+
* import { assertEquals } from '@std/assert'
|
|
107
|
+
* assertEquals(loads('<link href="/web/s.css" /><a href="https://x"><script src="/web/app.js">'), ['/web/s.css', '/web/app.js'])
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export let loads = (page: string): string[] =>
|
|
111
|
+
[...page.matchAll(/(?:href|src)="(\/[^"]*)"/g)].map(([, path]) => path)
|
|
112
|
+
|
|
113
|
+
// Once `path` exists, or an error at `by`.
|
|
114
|
+
let appeared = async (path: string, by: number) => {
|
|
115
|
+
for (;;) {
|
|
116
|
+
try {
|
|
117
|
+
return void await disk.stat(path)
|
|
118
|
+
} catch (error) {
|
|
119
|
+
if (!disk.isNotFound(error)) throw error
|
|
120
|
+
}
|
|
121
|
+
if (Date.now() > by) throw new Error(`${path} never appeared`)
|
|
122
|
+
await new Promise((r) => setTimeout(r, 100))
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// A port nothing listens on, from the system, released for serve to take.
|
|
127
|
+
let free = () => {
|
|
128
|
+
let listener = Deno.listen({ hostname: '127.0.0.1', port: 0 })
|
|
129
|
+
let { port } = listener.addr as Deno.NetAddr
|
|
130
|
+
listener.close()
|
|
131
|
+
return port
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// The answer to `url`, once something listens there and makes it, or an
|
|
135
|
+
// error at `by`. A page that fails is asked for again, since serve makes it
|
|
136
|
+
// again on the next request (./page.ts `kept`): on a cold cache the canvas's
|
|
137
|
+
// first make can outrun serve's limit while it downloads, and what it fetched
|
|
138
|
+
// stays for the next.
|
|
139
|
+
let answered = async (url: string, by: number) => {
|
|
140
|
+
for (;;) {
|
|
141
|
+
let failure: unknown
|
|
142
|
+
try {
|
|
143
|
+
let res = await fetch(url)
|
|
144
|
+
let body = await res.text()
|
|
145
|
+
if (res.ok) return body
|
|
146
|
+
failure = new Error(`${url} answered ${res.status}: ${body}`)
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (!(error instanceof TypeError)) throw error
|
|
149
|
+
failure = error
|
|
150
|
+
}
|
|
151
|
+
if (Date.now() > by) throw failure
|
|
152
|
+
await new Promise((r) => setTimeout(r, 100))
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let deno = (args: string[], cwd: string, quiet = false) =>
|
|
157
|
+
launchCommand(system.execPath(), {
|
|
158
|
+
args,
|
|
159
|
+
cwd,
|
|
160
|
+
stdout: quiet ? 'null' : 'inherit',
|
|
161
|
+
stderr: quiet ? 'piped' : 'inherit',
|
|
162
|
+
}).output()
|
|
163
|
+
|
|
164
|
+
if (import.meta.main) {
|
|
165
|
+
let dir = await disk.makeTempDir({ prefix: 'yak-install-' })
|
|
166
|
+
try {
|
|
167
|
+
let config = `${dir}/deno.json`
|
|
168
|
+
await disk.writeTextFile(config, JSON.stringify(released))
|
|
169
|
+
// Run from the empty directory, since `deno install` also folds in the
|
|
170
|
+
// dependencies of any package.json it finds above where it runs.
|
|
171
|
+
let { code } = await deno(install(cli.version, config), dir)
|
|
172
|
+
if (code == 0) {
|
|
173
|
+
console.log('fetching the plugins a first command needs…')
|
|
174
|
+
// A warm-up is a first command: one that fails is a `yak` that does not
|
|
175
|
+
// run, whatever `deno install` said.
|
|
176
|
+
let failed: string | undefined
|
|
177
|
+
for (let args of warming(dir)) {
|
|
178
|
+
let warmed = await deno(run(cli.version, config, args), dir, true)
|
|
179
|
+
if (!warmed.success) {
|
|
180
|
+
console.error(new TextDecoder().decode(warmed.stderr).trim())
|
|
181
|
+
failed = `yak ${args.slice(2).join(' ')}`
|
|
182
|
+
break
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (!failed) {
|
|
186
|
+
let port = free()
|
|
187
|
+
let server = launchCommand(system.execPath(), {
|
|
188
|
+
args: run(cli.version, config, serving(dir, port)),
|
|
189
|
+
cwd: dir,
|
|
190
|
+
stdout: 'null',
|
|
191
|
+
stderr: 'null',
|
|
192
|
+
}).spawn()
|
|
193
|
+
try {
|
|
194
|
+
let by = Date.now() + 300_000
|
|
195
|
+
let at = (path: string) =>
|
|
196
|
+
answered(`http://127.0.0.1:${port}${path}`, by)
|
|
197
|
+
for (let path of loads(await at('/'))) await at(path)
|
|
198
|
+
await appeared(`${dir}/ready`, by)
|
|
199
|
+
} catch (error) {
|
|
200
|
+
console.error(String(error))
|
|
201
|
+
failed = 'yak serve'
|
|
202
|
+
} finally {
|
|
203
|
+
server.kill('SIGINT')
|
|
204
|
+
await server.status
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (failed) {
|
|
208
|
+
console.error(
|
|
209
|
+
`yak ${cli.version} is installed but does not run: \`${failed}\` failed (above)`,
|
|
210
|
+
)
|
|
211
|
+
code = 1
|
|
212
|
+
} else {
|
|
213
|
+
console.log(
|
|
214
|
+
`yak ${cli.version} is installed. Next: yak auth yaks.app ` +
|
|
215
|
+
'signs you in to yaks.app, or yak init starts a graph on this machine',
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
system.setExitCode(code)
|
|
220
|
+
} finally {
|
|
221
|
+
await disk.remove(dir, { recursive: true })
|
|
222
|
+
}
|
|
223
|
+
}
|
package/lifetime.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as disk from "@yaks/file/io";
|
|
2
|
+
// A worker serves an existing file, never an unlinked SQLite connection. A
|
|
3
|
+
// fallback also belongs to the web that requested it; managed workers do not.
|
|
4
|
+
/** Capture the file identity before opening SQLite, so a removed graph cannot
|
|
5
|
+
* be silently recreated, and a replacement at the same path is a new graph.
|
|
6
|
+
* A `tether` is a stream its starter holds open and never writes: its end,
|
|
7
|
+
* however the starter ended, ends the worker's reason to serve. A worker's
|
|
8
|
+
* `ready` file ({@link superseded}) ends it once a newer one of its role is
|
|
9
|
+
* ready. */ export let lifetime = async (path, tether, ready)=>{
|
|
10
|
+
let replaced = ready ? superseded(ready) : ()=>Promise.resolve(false);
|
|
11
|
+
let original = path == ':memory:' ? undefined : await disk.stat(path);
|
|
12
|
+
let cut = false;
|
|
13
|
+
let end = ()=>void (cut = true);
|
|
14
|
+
tether?.pipeTo(new WritableStream()).then(end, end);
|
|
15
|
+
return async ()=>{
|
|
16
|
+
if (cut || await replaced()) return false;
|
|
17
|
+
try {
|
|
18
|
+
if (original) {
|
|
19
|
+
let current = await disk.stat(path);
|
|
20
|
+
if (current.dev != original.dev || current.ino != original.ino) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
if (error instanceof disk.errors.NotFound) return false;
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
// `<dir>/<role>-<instance>.ready` (./restart.ts `readyFile`). The service
|
|
32
|
+
// template's default instance is boot, and handovers mint UUIDs.
|
|
33
|
+
let INSTANCE = /^(.+)-(?:boot|[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})\.ready$/;
|
|
34
|
+
/**
|
|
35
|
+
* Whether an instance of the same role became ready after this one: its
|
|
36
|
+
* replacement, which it leaves to. The handover's own process stops the old
|
|
37
|
+
* instances once its replacements are ready, but a handover that dies between
|
|
38
|
+
* the two (killed with the box out of memory, T-1463) left two of every role
|
|
39
|
+
* running, each starting agents. So the old one leaves on its own.
|
|
40
|
+
*/ export let superseded = (ready)=>{
|
|
41
|
+
let at = ready.lastIndexOf('/');
|
|
42
|
+
let dir = ready.slice(0, at);
|
|
43
|
+
let role = INSTANCE.exec(ready.slice(at + 1))?.[1];
|
|
44
|
+
let mtime = (path)=>disk.stat(path).then((s)=>s.mtime?.getTime(), ()=>undefined);
|
|
45
|
+
return async ()=>{
|
|
46
|
+
let mine = role && await mtime(ready);
|
|
47
|
+
if (!mine) return false;
|
|
48
|
+
for await (let file of disk.readDir(dir)){
|
|
49
|
+
if (INSTANCE.exec(file.name)?.[1] != role) continue;
|
|
50
|
+
let theirs = await mtime(`${dir}/${file.name}`);
|
|
51
|
+
if (theirs && theirs > mine) return true;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=lifetime.js.map
|
package/lifetime.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifetime.js","sources":["./lifetime.ts"],"names":[],"mappings":"AAAA,YAAY,+BAAoC;AAChD,2EAA2E;AAC3E,8EAA8E;AAE9E;;;;;UAKU,GACV,OAAO,IAAI,WAAW,OACpB,MACA,QACA;EAEA,IAAI,WAAW,QAAQ,WAAW,SAAS,IAAM,QAAQ,OAAO,CAAC;EACjE,IAAI,WAAW,QAAQ,aAAa,YAAY,MAAM,KAAK,IAAI,CAAC;EAChE,IAAI,MAAM;EACV,IAAI,MAAM,IAAM,KAAK,CAAC,MAAM,IAAI;EAChC,QAAQ,OAAO,IAAI,kBAAkB,KAAK,KAAK;EAC/C,OAAO;IACL,IAAI,OAAO,MAAM,YAAY,OAAO;IACpC,IAAI;MACF,IAAI,UAAU;QACZ,IAAI,UAAU,MAAM,KAAK,IAAI,CAAC;QAC9B,IAAI,QAAQ,GAAG,IAAI,SAAS,GAAG,IAAI,QAAQ,GAAG,IAAI,SAAS,GAAG,EAAE;UAC9D,OAAO;QACT;MACF;MACA,OAAO;IACT,EAAE,OAAO,OAAO;MACd,IAAI,iBAAiB,KAAK,MAAM,CAAC,QAAQ,EAAE,OAAO;MAClD,MAAM;IACR;EACF;AACF,EAAC;AAED,0EAA0E;AAC1E,iEAAiE;AACjE,IAAI,WACF;AAEF;;;;;;CAMC,GACD,OAAO,IAAI,aAAa,CAAC;EACvB,IAAI,KAAK,MAAM,WAAW,CAAC;EAC3B,IAAI,MAAM,MAAM,KAAK,CAAC,GAAG;EACzB,IAAI,OAAO,SAAS,IAAI,CAAC,MAAM,KAAK,CAAC,KAAK,KAAK,CAAC,EAAE;EAClD,IAAI,QAAQ,CAAC,OACX,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,IAAM,EAAE,KAAK,EAAE,WAAW,IAAM;EACxD,OAAO;IACL,IAAI,OAAO,QAAQ,MAAM,MAAM;IAC/B,IAAI,CAAC,MAAM,OAAO;IAClB,WAAW,IAAI,QAAQ,KAAK,OAAO,CAAC,KAAM;MACxC,IAAI,SAAS,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC,EAAE,IAAI,MAAM;MAC3C,IAAI,SAAS,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,KAAK,IAAI,EAAE;MAC9C,IAAI,UAAU,SAAS,MAAM,OAAO;IACtC;IACA,OAAO;EACT;AACF,EAAC"}
|
package/lifetime.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as disk from '@yaks/file/io'
|
|
2
|
+
// A worker serves an existing file, never an unlinked SQLite connection. A
|
|
3
|
+
// fallback also belongs to the web that requested it; managed workers do not.
|
|
4
|
+
|
|
5
|
+
/** Capture the file identity before opening SQLite, so a removed graph cannot
|
|
6
|
+
* be silently recreated, and a replacement at the same path is a new graph.
|
|
7
|
+
* A `tether` is a stream its starter holds open and never writes: its end,
|
|
8
|
+
* however the starter ended, ends the worker's reason to serve. A worker's
|
|
9
|
+
* `ready` file ({@link superseded}) ends it once a newer one of its role is
|
|
10
|
+
* ready. */
|
|
11
|
+
export let lifetime = async (
|
|
12
|
+
path: string,
|
|
13
|
+
tether?: ReadableStream<Uint8Array>,
|
|
14
|
+
ready?: string,
|
|
15
|
+
) => {
|
|
16
|
+
let replaced = ready ? superseded(ready) : () => Promise.resolve(false)
|
|
17
|
+
let original = path == ':memory:' ? undefined : await disk.stat(path)
|
|
18
|
+
let cut = false
|
|
19
|
+
let end = () => void (cut = true)
|
|
20
|
+
tether?.pipeTo(new WritableStream()).then(end, end)
|
|
21
|
+
return async (): Promise<boolean> => {
|
|
22
|
+
if (cut || await replaced()) return false
|
|
23
|
+
try {
|
|
24
|
+
if (original) {
|
|
25
|
+
let current = await disk.stat(path)
|
|
26
|
+
if (current.dev != original.dev || current.ino != original.ino) {
|
|
27
|
+
return false
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return true
|
|
31
|
+
} catch (error) {
|
|
32
|
+
if (error instanceof disk.errors.NotFound) return false
|
|
33
|
+
throw error
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// `<dir>/<role>-<instance>.ready` (./restart.ts `readyFile`). The service
|
|
39
|
+
// template's default instance is boot, and handovers mint UUIDs.
|
|
40
|
+
let INSTANCE =
|
|
41
|
+
/^(.+)-(?:boot|[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12})\.ready$/
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Whether an instance of the same role became ready after this one: its
|
|
45
|
+
* replacement, which it leaves to. The handover's own process stops the old
|
|
46
|
+
* instances once its replacements are ready, but a handover that dies between
|
|
47
|
+
* the two (killed with the box out of memory, T-1463) left two of every role
|
|
48
|
+
* running, each starting agents. So the old one leaves on its own.
|
|
49
|
+
*/
|
|
50
|
+
export let superseded = (ready: string): () => Promise<boolean> => {
|
|
51
|
+
let at = ready.lastIndexOf('/')
|
|
52
|
+
let dir = ready.slice(0, at)
|
|
53
|
+
let role = INSTANCE.exec(ready.slice(at + 1))?.[1]
|
|
54
|
+
let mtime = (path: string) =>
|
|
55
|
+
disk.stat(path).then((s) => s.mtime?.getTime(), () => undefined)
|
|
56
|
+
return async () => {
|
|
57
|
+
let mine = role && await mtime(ready)
|
|
58
|
+
if (!mine) return false
|
|
59
|
+
for await (let file of disk.readDir(dir)) {
|
|
60
|
+
if (INSTANCE.exec(file.name)?.[1] != role) continue
|
|
61
|
+
let theirs = await mtime(`${dir}/${file.name}`)
|
|
62
|
+
if (theirs && theirs > mine) return true
|
|
63
|
+
}
|
|
64
|
+
return false
|
|
65
|
+
}
|
|
66
|
+
}
|
package/local-page.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// A page bundled from a checkout: esbuild resolves its imports through the npm
|
|
2
|
+
// workspace. ./page.ts imports this only when it makes a body, so a host that
|
|
3
|
+
// makes none never loads esbuild.
|
|
4
|
+
import { context, type PluginBuild } from 'npm:esbuild@0.28.1'
|
|
5
|
+
import { imported } from 'jsr:@yaks/fp@0.2.36/imports'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
import { relative } from 'node:path'
|
|
8
|
+
import {
|
|
9
|
+
type Built,
|
|
10
|
+
type Bundling,
|
|
11
|
+
CHUNK,
|
|
12
|
+
compiled,
|
|
13
|
+
finished,
|
|
14
|
+
pageExternals,
|
|
15
|
+
type Written,
|
|
16
|
+
} from './page.ts'
|
|
17
|
+
|
|
18
|
+
let FILE_URLS = {
|
|
19
|
+
name: 'file-urls',
|
|
20
|
+
setup(build: PluginBuild) {
|
|
21
|
+
build.onResolve(
|
|
22
|
+
{ filter: /^file:/ },
|
|
23
|
+
({ path }) => ({ path: fileURLToPath(path) }),
|
|
24
|
+
)
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// React and the packages like it choose their production build, without
|
|
29
|
+
// development checks, by this.
|
|
30
|
+
let PRODUCTION = { 'process.env.NODE_ENV': '"production"' }
|
|
31
|
+
|
|
32
|
+
let BROWSER = {
|
|
33
|
+
bundle: true,
|
|
34
|
+
format: 'esm',
|
|
35
|
+
platform: 'browser',
|
|
36
|
+
target: 'esnext',
|
|
37
|
+
jsx: 'automatic',
|
|
38
|
+
jsxImportSource: 'react',
|
|
39
|
+
minify: true,
|
|
40
|
+
define: PRODUCTION,
|
|
41
|
+
write: false,
|
|
42
|
+
metafile: true,
|
|
43
|
+
logLevel: 'silent',
|
|
44
|
+
} as const
|
|
45
|
+
|
|
46
|
+
// The modules bundled are loaded for the browser, by this loader: what
|
|
47
|
+
// watches this process's imports sees them too (./code.ts).
|
|
48
|
+
let watched = (dir: URL) => ({ metafile }: Built) =>
|
|
49
|
+
imported(
|
|
50
|
+
Object.keys(metafile?.inputs ?? {}).filter((i) => i != '<stdin>')
|
|
51
|
+
.map((i) => new URL(i, dir).href),
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
export let bundle = async (
|
|
55
|
+
entry: URL | Written,
|
|
56
|
+
signal?: AbortSignal,
|
|
57
|
+
opts: Bundling = {},
|
|
58
|
+
): Promise<string> => {
|
|
59
|
+
let at = entry instanceof URL ? entry : entry.at
|
|
60
|
+
let dir = new URL('./', at)
|
|
61
|
+
let build = await context({
|
|
62
|
+
absWorkingDir: fileURLToPath(dir),
|
|
63
|
+
...entry instanceof URL ? { entryPoints: [fileURLToPath(entry)] } : {
|
|
64
|
+
stdin: {
|
|
65
|
+
contents: entry.code,
|
|
66
|
+
sourcefile: fileURLToPath(at),
|
|
67
|
+
resolveDir: fileURLToPath(new URL('./', at)),
|
|
68
|
+
loader: 'ts',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
plugins: [pageExternals(opts.external), FILE_URLS],
|
|
72
|
+
...BROWSER,
|
|
73
|
+
alias: opts.alias,
|
|
74
|
+
format: opts.format ?? BROWSER.format,
|
|
75
|
+
})
|
|
76
|
+
return compiled(build, signal, watched(dir))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** ./page.ts `split`: one build of every entry, its shared modules in
|
|
80
|
+
* chunks the entries import from the site's root. */
|
|
81
|
+
export let split = async (
|
|
82
|
+
entries: Record<string, URL>,
|
|
83
|
+
signal?: AbortSignal,
|
|
84
|
+
opts: Bundling = {},
|
|
85
|
+
): Promise<
|
|
86
|
+
{ entries: Record<string, string>; chunks: Record<string, string> }
|
|
87
|
+
> => {
|
|
88
|
+
let dir = new URL('./', Object.values(entries)[0])
|
|
89
|
+
let out = fileURLToPath(dir)
|
|
90
|
+
let build = await context({
|
|
91
|
+
absWorkingDir: out,
|
|
92
|
+
entryPoints: Object.fromEntries(
|
|
93
|
+
Object.entries(entries).map((
|
|
94
|
+
[name, at],
|
|
95
|
+
) => [name.replace(/\.js$/, ''), fileURLToPath(at)]),
|
|
96
|
+
),
|
|
97
|
+
plugins: [pageExternals(opts.external), FILE_URLS],
|
|
98
|
+
splitting: true,
|
|
99
|
+
outdir: out,
|
|
100
|
+
entryNames: '[name]',
|
|
101
|
+
chunkNames: `${CHUNK}.[hash]`,
|
|
102
|
+
publicPath: '/',
|
|
103
|
+
...BROWSER,
|
|
104
|
+
})
|
|
105
|
+
let built = await finished(build, signal)
|
|
106
|
+
watched(dir)(built)
|
|
107
|
+
let made = { entries: {}, chunks: {} } as Awaited<ReturnType<typeof split>>
|
|
108
|
+
for (let { path, text } of built.outputFiles!) {
|
|
109
|
+
let name = relative(out, path)
|
|
110
|
+
if (name in entries) made.entries[name] = text
|
|
111
|
+
else made.chunks[name] = text
|
|
112
|
+
}
|
|
113
|
+
return made
|
|
114
|
+
}
|