@nervur.org/installer-node 0.0.0-stage → 0.37.2
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 +105 -0
- package/README.md +159 -2
- package/SECURITY.md +8 -0
- package/bin/nervur.js +5 -0
- package/cargo/emscripten-module.wasm +0 -0
- package/cargo/manifest.json +1 -0
- package/cargo/sqlite3.wasm +0 -0
- package/cargo/table-i-i.wasm +0 -0
- package/cargo/table-i-ii.wasm +0 -0
- package/cargo/table-i-iii.wasm +0 -0
- package/cargo/table-i-iiii.wasm +0 -0
- package/cargo/table-i-iiiii.wasm +0 -0
- package/cargo/table-i-iiij.wasm +0 -0
- package/cargo/table-i-ij.wasm +0 -0
- package/cargo/table-v-ii.wasm +0 -0
- package/cargo/table-v-iii.wasm +0 -0
- package/cargo/worker.js +30808 -0
- package/organs/console/node/guard.d.ts +10 -0
- package/organs/console/node/guard.js +52 -0
- package/organs/console/node/index.d.ts +4 -0
- package/organs/console/node/index.js +5 -0
- package/organs/console/node/line.d.ts +16 -0
- package/organs/console/node/line.js +150 -0
- package/organs/console/node/main.js +51 -0
- package/organs/console/node/program.d.ts +1 -0
- package/organs/console/node/program.js +5 -0
- package/organs/console/node/proof.d.ts +15 -0
- package/organs/console/node/proof.js +84 -0
- package/organs/console/node/socket.d.ts +15 -0
- package/organs/console/node/socket.js +99 -0
- package/organs/disk/index.d.ts +1 -0
- package/organs/disk/index.js +2 -0
- package/organs/disk/node/files.js +162 -0
- package/organs/disk/node/main.js +20 -0
- package/organs/disk/node/program.d.ts +1 -0
- package/organs/disk/node/program.js +5 -0
- package/organs/disk/organ.d.ts +5 -0
- package/organs/disk/organ.js +69 -0
- package/organs/network/node/fill.d.ts +21 -0
- package/organs/network/node/fill.js +195 -0
- package/organs/network/node/flows.js +66 -0
- package/organs/network/node/half.js +260 -0
- package/organs/network/node/lines.d.ts +29 -0
- package/organs/network/node/lines.js +236 -0
- package/organs/network/node/link.d.ts +24 -0
- package/organs/network/node/link.js +215 -0
- package/organs/network/node/main.js +41 -0
- package/organs/network/node/moved.d.ts +2 -0
- package/organs/network/node/moved.js +20 -0
- package/organs/network/node/near.d.ts +63 -0
- package/organs/network/node/near.js +263 -0
- package/organs/network/node/program.d.ts +1 -0
- package/organs/network/node/program.js +5 -0
- package/organs/network/node/schemes.d.ts +1 -0
- package/organs/network/node/schemes.js +2 -0
- package/organs/network/node/sent.d.ts +13 -0
- package/organs/network/node/sent.js +101 -0
- package/organs/network/node/served.d.ts +19 -0
- package/organs/network/node/served.js +237 -0
- package/organs/screen/node/client.js +3 -0
- package/organs/screen/node/follow.js +266 -0
- package/organs/screen/node/frames.js +26 -0
- package/organs/screen/node/held.js +27 -0
- package/organs/screen/node/http.js +179 -0
- package/organs/screen/node/lay.js +116 -0
- package/organs/screen/node/leave.js +27 -0
- package/organs/screen/node/linked.js +69 -0
- package/organs/screen/node/listen.js +61 -0
- package/organs/screen/node/look.js +121 -0
- package/organs/screen/node/loop.js +154 -0
- package/organs/screen/node/main.js +74 -0
- package/organs/screen/node/mirror.js +112 -0
- package/organs/screen/node/notice.js +44 -0
- package/organs/screen/node/presser.js +11 -0
- package/organs/screen/node/presses.js +108 -0
- package/organs/screen/node/program.d.ts +1 -0
- package/organs/screen/node/program.js +5 -0
- package/organs/screen/node/shown.js +205 -0
- package/organs/screen/node/standing.js +29 -0
- package/organs/screen/node/state.js +80 -0
- package/organs/screen/node/tell.js +47 -0
- package/organs/screen/node/uid.js +65 -0
- package/organs/screen/node/worn.js +23 -0
- package/organs/shell/index.d.ts +1 -0
- package/organs/shell/index.js +2 -0
- package/organs/shell/node/main.js +26 -0
- package/organs/shell/node/output.js +70 -0
- package/organs/shell/node/pressure.js +14 -0
- package/organs/shell/node/program.d.ts +1 -0
- package/organs/shell/node/program.js +5 -0
- package/organs/shell/node/runs.js +220 -0
- package/organs/shell/node/told.js +70 -0
- package/organs/shell/organ.d.ts +5 -0
- package/organs/shell/organ.js +59 -0
- package/package.json +43 -4
- package/src/command/act.d.ts +31 -0
- package/src/command/act.js +261 -0
- package/src/command/answers.d.ts +3 -0
- package/src/command/answers.js +232 -0
- package/src/command/args.d.ts +14 -0
- package/src/command/args.js +220 -0
- package/src/command/arrive.d.ts +2 -0
- package/src/command/arrive.js +21 -0
- package/src/command/asked.d.ts +18 -0
- package/src/command/asked.js +49 -0
- package/src/command/backup.d.ts +18 -0
- package/src/command/backup.js +261 -0
- package/src/command/before.d.ts +40 -0
- package/src/command/before.js +249 -0
- package/src/command/born.d.ts +27 -0
- package/src/command/born.js +103 -0
- package/src/command/bridge.d.ts +19 -0
- package/src/command/bridge.js +152 -0
- package/src/command/chain.d.ts +9 -0
- package/src/command/chain.js +48 -0
- package/src/command/channel.d.ts +29 -0
- package/src/command/channel.js +263 -0
- package/src/command/choices.d.ts +35 -0
- package/src/command/choices.js +173 -0
- package/src/command/claim.d.ts +12 -0
- package/src/command/claim.js +46 -0
- package/src/command/commands.d.ts +16 -0
- package/src/command/commands.js +257 -0
- package/src/command/ends.d.ts +16 -0
- package/src/command/ends.js +78 -0
- package/src/command/follow.d.ts +12 -0
- package/src/command/follow.js +66 -0
- package/src/command/given.d.ts +39 -0
- package/src/command/given.js +53 -0
- package/src/command/held.d.ts +15 -0
- package/src/command/held.js +56 -0
- package/src/command/index.d.ts +1 -0
- package/src/command/index.js +203 -0
- package/src/command/jailer.d.ts +28 -0
- package/src/command/jailer.js +135 -0
- package/src/command/laid.d.ts +6 -0
- package/src/command/laid.js +31 -0
- package/src/command/left.d.ts +9 -0
- package/src/command/left.js +34 -0
- package/src/command/line.d.ts +7 -0
- package/src/command/line.js +39 -0
- package/src/command/link.d.ts +30 -0
- package/src/command/link.js +123 -0
- package/src/command/lobes.d.ts +1 -0
- package/src/command/lobes.js +10 -0
- package/src/command/locks.d.ts +17 -0
- package/src/command/locks.js +76 -0
- package/src/command/mcp/calls.d.ts +27 -0
- package/src/command/mcp/calls.js +155 -0
- package/src/command/mcp/notices.d.ts +22 -0
- package/src/command/mcp/notices.js +203 -0
- package/src/command/mcp/resources.d.ts +31 -0
- package/src/command/mcp/resources.js +108 -0
- package/src/command/mcp/server.d.ts +19 -0
- package/src/command/mcp/server.js +149 -0
- package/src/command/mcp/tools.d.ts +39 -0
- package/src/command/mcp/tools.js +131 -0
- package/src/command/mcp.d.ts +8 -0
- package/src/command/mcp.js +39 -0
- package/src/command/noticed.d.ts +11 -0
- package/src/command/noticed.js +55 -0
- package/src/command/older.d.ts +11 -0
- package/src/command/older.js +45 -0
- package/src/command/open.d.ts +24 -0
- package/src/command/open.js +107 -0
- package/src/command/passphrase.d.ts +6 -0
- package/src/command/passphrase.js +82 -0
- package/src/command/reclaim.d.ts +7 -0
- package/src/command/reclaim.js +47 -0
- package/src/command/refused.d.ts +4 -0
- package/src/command/refused.js +27 -0
- package/src/command/release.d.ts +27 -0
- package/src/command/release.js +153 -0
- package/src/command/repo.d.ts +31 -0
- package/src/command/repo.js +133 -0
- package/src/command/rewrap.d.ts +16 -0
- package/src/command/rewrap.js +175 -0
- package/src/command/runtime.d.ts +25 -0
- package/src/command/runtime.js +175 -0
- package/src/command/salvage.d.ts +4 -0
- package/src/command/salvage.js +42 -0
- package/src/command/screen.d.ts +14 -0
- package/src/command/screen.js +62 -0
- package/src/command/spawn.d.ts +23 -0
- package/src/command/spawn.js +213 -0
- package/src/command/start.d.ts +34 -0
- package/src/command/start.js +246 -0
- package/src/command/state.d.ts +5 -0
- package/src/command/state.js +39 -0
- package/src/command/token.d.ts +1 -0
- package/src/command/token.js +9 -0
- package/src/command/trial.d.ts +18 -0
- package/src/command/trial.js +108 -0
- package/src/command/undone.d.ts +3 -0
- package/src/command/undone.js +21 -0
- package/src/command/vouch.d.ts +1 -0
- package/src/command/vouch.js +15 -0
- package/src/command/windows-processes.d.ts +2 -0
- package/src/command/windows-processes.js +22 -0
- package/src/command/wipe.d.ts +9 -0
- package/src/command/wipe.js +105 -0
- package/src/command/words.d.ts +5 -0
- package/src/command/words.js +53 -0
- package/src/door/claim.d.ts +5 -0
- package/src/door/claim.js +21 -0
- package/src/door/claimed.d.ts +7 -0
- package/src/door/claimed.js +110 -0
- package/src/door/configuration.d.ts +40 -0
- package/src/door/configuration.js +206 -0
- package/src/door/design.d.ts +13 -0
- package/src/door/design.js +71 -0
- package/src/door/digests.d.ts +7 -0
- package/src/door/digests.js +36 -0
- package/src/door/distribution.d.ts +25 -0
- package/src/door/distribution.js +88 -0
- package/src/door/door.d.ts +41 -0
- package/src/door/door.js +219 -0
- package/src/door/dressed.d.ts +34 -0
- package/src/door/dressed.js +182 -0
- package/src/door/faculties.d.ts +29 -0
- package/src/door/faculties.js +88 -0
- package/src/door/longest.d.ts +6 -0
- package/src/door/longest.js +25 -0
- package/src/fills/account-only.d.ts +3 -0
- package/src/fills/account-only.js +24 -0
- package/src/fills/boot-key.d.ts +21 -0
- package/src/fills/boot-key.js +70 -0
- package/src/fills/boot-move.d.ts +25 -0
- package/src/fills/boot-move.js +86 -0
- package/src/fills/bridge.d.ts +13 -0
- package/src/fills/bridge.js +86 -0
- package/src/fills/chance.d.ts +2 -0
- package/src/fills/chance.js +7 -0
- package/src/fills/crypto.d.ts +2 -0
- package/src/fills/crypto.js +94 -0
- package/src/fills/flushed.d.ts +9 -0
- package/src/fills/flushed.js +80 -0
- package/src/fills/hardware.d.ts +18 -0
- package/src/fills/hardware.js +70 -0
- package/src/fills/held.d.ts +31 -0
- package/src/fills/held.js +171 -0
- package/src/fills/keepers.d.ts +23 -0
- package/src/fills/keepers.js +151 -0
- package/src/fills/keyring.d.ts +19 -0
- package/src/fills/keyring.js +131 -0
- package/src/fills/pages.d.ts +3 -0
- package/src/fills/pages.js +260 -0
- package/src/fills/reserve.d.ts +11 -0
- package/src/fills/reserve.js +72 -0
- package/src/fills/time.d.ts +2 -0
- package/src/fills/time.js +29 -0
- package/src/fills/unlocker.d.ts +6 -0
- package/src/fills/unlocker.js +26 -0
- package/src/fills/vitals.d.ts +8 -0
- package/src/fills/vitals.js +100 -0
- package/src/fills/windows-start.d.ts +2 -0
- package/src/fills/windows-start.js +21 -0
- package/src/halves/build.d.ts +10 -0
- package/src/halves/build.js +219 -0
- package/src/halves/end.d.ts +17 -0
- package/src/halves/end.js +157 -0
- package/src/halves/genome.d.ts +3 -0
- package/src/halves/genome.js +21 -0
- package/src/halves/handler.d.ts +8 -0
- package/src/halves/handler.js +40 -0
- package/src/halves/index.d.ts +5 -0
- package/src/halves/index.js +6 -0
- package/src/halves/laid.d.ts +12 -0
- package/src/halves/laid.js +103 -0
- package/src/halves/lent.d.ts +6 -0
- package/src/halves/lent.js +147 -0
- package/src/halves/native.d.ts +12 -0
- package/src/halves/native.js +53 -0
- package/src/halves/statements.d.ts +23 -0
- package/src/halves/statements.js +165 -0
- package/src/halves/tokens.d.ts +22 -0
- package/src/halves/tokens.js +135 -0
- package/src/link/link.d.ts +4 -0
- package/src/link/link.js +4 -0
- package/src/link/placeholder.d.ts +1 -0
- package/src/link/placeholder.js +21 -0
- package/src/link/steps.d.ts +52 -0
- package/src/link/steps.js +118 -0
- package/src/lobes/calls.d.ts +76 -0
- package/src/lobes/calls.js +61 -0
- package/src/lobes/channel.d.ts +76 -0
- package/src/lobes/channel.js +202 -0
- package/src/lobes/index.d.ts +1 -0
- package/src/lobes/index.js +2 -0
- package/src/lobes/lobes.d.ts +15 -0
- package/src/lobes/lobes.js +244 -0
- package/src/lobes/main.js +107 -0
- package/src/lobes/thread.d.ts +22 -0
- package/src/lobes/thread.js +270 -0
- package/src/organism/act.d.ts +8 -0
- package/src/organism/act.js +63 -0
- package/src/organism/beat.d.ts +5 -0
- package/src/organism/beat.js +45 -0
- package/src/organism/compiled.d.ts +2 -0
- package/src/organism/compiled.js +24 -0
- package/src/organism/folder.d.ts +88 -0
- package/src/organism/folder.js +259 -0
- package/src/organism/main.d.ts +1 -0
- package/src/organism/main.js +11 -0
- package/src/organism/organism.d.ts +1 -0
- package/src/organism/organism.js +220 -0
- package/src/organism/said.d.ts +12 -0
- package/src/organism/said.js +30 -0
- package/src/organism/told.d.ts +5 -0
- package/src/organism/told.js +110 -0
- package/src/organism/unlock.d.ts +8 -0
- package/src/organism/unlock.js +95 -0
- package/src/organism/upgrade.d.ts +24 -0
- package/src/organism/upgrade.js +145 -0
- package/src/organism/via.d.ts +7 -0
- package/src/organism/via.js +20 -0
- package/src/service/body.d.ts +8 -0
- package/src/service/body.js +34 -0
- package/src/service/handler.d.ts +20 -0
- package/src/service/handler.js +128 -0
- package/src/service/index.d.ts +4 -0
- package/src/service/index.js +16 -0
- package/src/service/manager.d.ts +18 -0
- package/src/service/manager.js +185 -0
- package/src/service/service.d.ts +24 -0
- package/src/service/service.js +200 -0
- package/src/service/swap.d.ts +12 -0
- package/src/service/swap.js +74 -0
- package/src/service/watchdog.d.ts +6 -0
- package/src/service/watchdog.js +31 -0
- package/src/tcp/crowd.d.ts +18 -0
- package/src/tcp/crowd.js +85 -0
- package/src/tcp/dial.d.ts +23 -0
- package/src/tcp/dial.js +102 -0
- package/src/tcp/frame.d.ts +23 -0
- package/src/tcp/frame.js +159 -0
- package/src/tcp/listen.d.ts +50 -0
- package/src/tcp/listen.js +207 -0
- package/src/tcp/source.d.ts +2 -0
- package/src/tcp/source.js +26 -0
- package/src/version/index.d.ts +1 -0
- package/src/version/index.js +2 -0
- package/src/version/version.d.ts +1 -0
- package/src/version/version.js +2 -0
- package/src/work/first.d.ts +11 -0
- package/src/work/first.js +91 -0
- package/src/work/index.d.ts +2 -0
- package/src/work/index.js +15 -0
- package/src/work/work.d.ts +20 -0
- package/src/work/work.js +136 -0
- package/src/ws/dial.d.ts +7 -0
- package/src/ws/dial.js +252 -0
- package/src/ws/dialing.d.ts +50 -0
- package/src/ws/dialing.js +72 -0
- package/src/ws/frame.d.ts +32 -0
- package/src/ws/frame.js +124 -0
- package/src/ws/handshake.d.ts +4 -0
- package/src/ws/handshake.js +27 -0
- package/src/ws/line.d.ts +45 -0
- package/src/ws/line.js +250 -0
- package/src/ws/listen.d.ts +42 -0
- package/src/ws/listen.js +272 -0
- package/src/ws/rfc6455.d.ts +18 -0
- package/src/ws/rfc6455.js +187 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
|
|
4
|
+
export const startSaid = (status , out ) => {
|
|
5
|
+
if (status !== 0) return undefined;
|
|
6
|
+
return out.trim() === '' ? null : out.trim();
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const windowsStart = (pid ) => {
|
|
10
|
+
const ran = spawnSync(
|
|
11
|
+
'powershell',
|
|
12
|
+
[
|
|
13
|
+
'-NoProfile',
|
|
14
|
+
'-NonInteractive',
|
|
15
|
+
'-Command',
|
|
16
|
+
`$p = Get-CimInstance Win32_Process -Filter 'ProcessId=${pid}'; if ($p) { $p.CreationDate.ToUniversalTime().ToString('o') }`,
|
|
17
|
+
],
|
|
18
|
+
{ encoding: 'utf8', windowsHide: true },
|
|
19
|
+
);
|
|
20
|
+
return ran.error === undefined ? startSaid(ran.status, ran.stdout) : undefined;
|
|
21
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type HalfModule = {
|
|
2
|
+
readonly file: string;
|
|
3
|
+
readonly label: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const modulesOf: (entry: string) => readonly HalfModule[];
|
|
6
|
+
export declare const buildHalf: (entry: string) => string;
|
|
7
|
+
export declare const buildHalves: (entries: readonly string[]) => ReadonlyMap<string, {
|
|
8
|
+
readonly text: string;
|
|
9
|
+
readonly modules: readonly HalfModule[];
|
|
10
|
+
}>;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { createRequire, isBuiltin, stripTypeScriptTypes } from 'node:module';
|
|
4
|
+
import { basename, dirname, join, relative, resolve, sep } from 'node:path';
|
|
5
|
+
import { readModule, } from './statements.js';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
const labelOf = (file ) => {
|
|
29
|
+
for (let dir = dirname(file); dir !== dirname(dir); dir = dirname(dir)) {
|
|
30
|
+
const manifest = join(dir, 'package.json');
|
|
31
|
+
if (!existsSync(manifest)) continue;
|
|
32
|
+
const read = JSON.parse(readFileSync(manifest, 'utf8'));
|
|
33
|
+
const name =
|
|
34
|
+
typeof read === 'object' && read !== null && 'name' in read && typeof read.name === 'string' ? read.name : '.';
|
|
35
|
+
return `${name}/${relative(dir, file).split(sep).join('/')}`;
|
|
36
|
+
}
|
|
37
|
+
return basename(file);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const TYPESCRIPT = /\.[cm]?ts$/;
|
|
41
|
+
|
|
42
|
+
const moduleOf = (graph , file ) => {
|
|
43
|
+
const known = graph.read.get(file);
|
|
44
|
+
if (known !== undefined) return known;
|
|
45
|
+
let kept = graph.shared.get(file);
|
|
46
|
+
if (kept === undefined) {
|
|
47
|
+
const label = labelOf(file);
|
|
48
|
+
const text = readFileSync(file, 'utf8');
|
|
49
|
+
kept = {
|
|
50
|
+
read: readModule(TYPESCRIPT.test(file) ? stripTypeScriptTypes(text, { mode: 'strip' }) : text, label),
|
|
51
|
+
label,
|
|
52
|
+
};
|
|
53
|
+
graph.shared.set(file, kept);
|
|
54
|
+
}
|
|
55
|
+
graph.read.set(file, kept.read);
|
|
56
|
+
graph.labels.set(file, kept.label);
|
|
57
|
+
return kept.read;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const targetOf = (from , spec ) => {
|
|
61
|
+
if (isBuiltin(spec)) return { builtin: spec };
|
|
62
|
+
if (spec.startsWith('.')) return { file: resolve(dirname(from), spec) };
|
|
63
|
+
return { file: createRequire(from).resolve(spec) };
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const originOf = (graph , file , name ) => {
|
|
67
|
+
const read = moduleOf(graph, file);
|
|
68
|
+
const local = read.exports.get(name);
|
|
69
|
+
if (local !== undefined) return { file, local };
|
|
70
|
+
for (const { spec, pairs } of read.reexports) {
|
|
71
|
+
const target = targetOf(file, spec);
|
|
72
|
+
const pair = pairs === 'star' ? { imported: name } : pairs.find((one) => one.exported === name);
|
|
73
|
+
if (pair === undefined || (pairs === 'star' && name === 'default')) continue;
|
|
74
|
+
if ('builtin' in target) return { builtin: target.builtin, name: pair.imported };
|
|
75
|
+
if (pair.imported === '*') return { namespace: target.file };
|
|
76
|
+
const found = originOf(graph, target.file, pair.imported);
|
|
77
|
+
if (found !== null || pairs !== 'star') return found;
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const namesOf = (graph , file ) => {
|
|
83
|
+
const read = moduleOf(graph, file);
|
|
84
|
+
return [
|
|
85
|
+
...read.exports.keys(),
|
|
86
|
+
...read.reexports.flatMap(({ spec, pairs }) => {
|
|
87
|
+
if (pairs !== 'star') return pairs.map((pair) => pair.exported);
|
|
88
|
+
const target = targetOf(file, spec);
|
|
89
|
+
return 'file' in target ? namesOf(graph, target.file).filter((name) => name !== 'default') : [];
|
|
90
|
+
}),
|
|
91
|
+
];
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const bound = (graph , file , spec , imported ) => {
|
|
95
|
+
const target = targetOf(file, spec);
|
|
96
|
+
if ('builtin' in target) return { builtin: target.builtin, name: imported };
|
|
97
|
+
if (imported === '*') return { namespace: target.file };
|
|
98
|
+
const origin = originOf(graph, target.file, imported);
|
|
99
|
+
if (origin === null)
|
|
100
|
+
throw new Error(`a half is built of plain modules: ${labelOf(target.file)} gives no ${imported}`);
|
|
101
|
+
return origin;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const includeOrigin = (graph , origin ) => {
|
|
105
|
+
if ('file' in origin) include(graph, origin.file);
|
|
106
|
+
else if ('namespace' in origin) includeWhole(graph, origin.namespace);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const include = (graph , file ) => {
|
|
110
|
+
if (graph.binds.has(file)) return;
|
|
111
|
+
if (graph.running.has(file)) throw new Error(`a half is built of plain modules: ${labelOf(file)} imports in a cycle`);
|
|
112
|
+
graph.running.add(file);
|
|
113
|
+
const binds = [];
|
|
114
|
+
for (const { spec, bindings } of moduleOf(graph, file).imports) {
|
|
115
|
+
const target = targetOf(file, spec);
|
|
116
|
+
if (bindings === null && 'file' in target) include(graph, target.file);
|
|
117
|
+
for (const { imported, local } of bindings ?? []) {
|
|
118
|
+
const origin = bound(graph, file, spec, imported);
|
|
119
|
+
includeOrigin(graph, origin);
|
|
120
|
+
binds.push([local, origin]);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
graph.running.delete(file);
|
|
124
|
+
graph.binds.set(file, binds);
|
|
125
|
+
graph.order.push(file);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const includeWhole = (graph , file ) => {
|
|
129
|
+
include(graph, file);
|
|
130
|
+
if (graph.whole.has(file)) return;
|
|
131
|
+
graph.whole.add(file);
|
|
132
|
+
for (const name of namesOf(graph, file)) {
|
|
133
|
+
const origin = originOf(graph, file, name);
|
|
134
|
+
if (origin !== null) includeOrigin(graph, origin);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
const readAs = (names , origin ) => {
|
|
144
|
+
if ('builtin' in origin) {
|
|
145
|
+
const ns = names.builtins.get(origin.builtin) ?? `__nervur_node_${names.builtins.size}`;
|
|
146
|
+
names.builtins.set(origin.builtin, ns);
|
|
147
|
+
return origin.name === '*' ? ns : `${ns}[${JSON.stringify(origin.name)}]`;
|
|
148
|
+
}
|
|
149
|
+
if ('namespace' in origin) return names.modules.get(origin.namespace) ?? '';
|
|
150
|
+
return `${names.modules.get(origin.file) ?? ''}.${origin.local}`;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const scopeOf = (graph , names , file ) => {
|
|
154
|
+
const read = moduleOf(graph, file);
|
|
155
|
+
const binds = (graph.binds.get(file) ?? []).map(([local, origin]) => `const ${local} = ${readAs(names, origin)};`);
|
|
156
|
+
const given = [...read.exports].map(([exported, local]) => `get ${exported}() { return ${local}; }`);
|
|
157
|
+
if (graph.whole.has(file))
|
|
158
|
+
for (const name of namesOf(graph, file).filter((one) => !read.exports.has(one))) {
|
|
159
|
+
const origin = originOf(graph, file, name);
|
|
160
|
+
if (origin !== null) given.push(`get ${name}() { return ${readAs(names, origin)}; }`);
|
|
161
|
+
}
|
|
162
|
+
return [
|
|
163
|
+
`const ${names.modules.get(file) ?? ''} = await (async () => {`,
|
|
164
|
+
`// ${graph.labels.get(file) ?? ''}`,
|
|
165
|
+
...binds,
|
|
166
|
+
read.body,
|
|
167
|
+
`return { ${given.join(', ')} };`,
|
|
168
|
+
'})();',
|
|
169
|
+
].join('\n');
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const graphOf = (entry , shared = new Map()) => {
|
|
173
|
+
const graph = {
|
|
174
|
+
shared,
|
|
175
|
+
read: new Map(),
|
|
176
|
+
labels: new Map(),
|
|
177
|
+
order: [],
|
|
178
|
+
running: new Set(),
|
|
179
|
+
whole: new Set(),
|
|
180
|
+
binds: new Map(),
|
|
181
|
+
};
|
|
182
|
+
include(graph, entry);
|
|
183
|
+
return graph;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
const modulesIn = (graph ) => [...graph.labels].map(([file, label]) => ({ file, label }));
|
|
189
|
+
|
|
190
|
+
export const modulesOf = (entry ) => modulesIn(graphOf(entry));
|
|
191
|
+
|
|
192
|
+
const textOf = (graph , entry ) => {
|
|
193
|
+
const names = {
|
|
194
|
+
modules: new Map(graph.order.map((file, at) => [file, `__nervur_${at}`])),
|
|
195
|
+
builtins: new Map(),
|
|
196
|
+
};
|
|
197
|
+
const scopes = graph.order.map((file) => scopeOf(graph, names, file));
|
|
198
|
+
const imports = [...names.builtins].map(([spec, ns]) => `import * as ${ns} from ${JSON.stringify(spec)};`);
|
|
199
|
+
return [
|
|
200
|
+
`// ${graph.labels.get(entry) ?? ''}, built into one module by Node's installer.`,
|
|
201
|
+
...imports,
|
|
202
|
+
...scopes,
|
|
203
|
+
'',
|
|
204
|
+
].join('\n');
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
export const buildHalf = (entry ) => textOf(graphOf(entry), entry);
|
|
208
|
+
|
|
209
|
+
export const buildHalves = (
|
|
210
|
+
entries ,
|
|
211
|
+
) => {
|
|
212
|
+
const shared = new Map ();
|
|
213
|
+
return new Map(
|
|
214
|
+
entries.map((entry) => {
|
|
215
|
+
const graph = graphOf(entry, shared);
|
|
216
|
+
return [entry, { text: textOf(graph, entry), modules: modulesIn(graph) }];
|
|
217
|
+
}),
|
|
218
|
+
);
|
|
219
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Answer, type Data, type Fields } from '@nervur.org/genome/standard';
|
|
2
|
+
export type Io = {
|
|
3
|
+
readonly write: (bytes: Uint8Array) => boolean;
|
|
4
|
+
readonly drained: (go: () => void) => void;
|
|
5
|
+
readonly read: (chunk: (bytes: Uint8Array) => void) => void;
|
|
6
|
+
readonly pause: () => void;
|
|
7
|
+
readonly resume: () => void;
|
|
8
|
+
readonly ended: (done: () => void) => void;
|
|
9
|
+
};
|
|
10
|
+
export type Answering = (method: string, args: Data, asker: string | null) => Answer | Promise<Answer>;
|
|
11
|
+
export type End = {
|
|
12
|
+
readonly ask: (placeholder: string, method: string | null, args: Data, timeout: number) => Promise<Answer>;
|
|
13
|
+
};
|
|
14
|
+
export declare const framesOf: (each: (frame: Fields) => void) => ((bytes: Uint8Array) => void);
|
|
15
|
+
export declare const serveHalf: (io: Io, blueprint: Data, answering: Answering, ended?: () => void) => End;
|
|
16
|
+
export declare const refuseHalf: (io: Io, why: string) => void;
|
|
17
|
+
export declare const processIo: () => Io;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { FRAME_SIZE } from '../door/longest.js';
|
|
3
|
+
import {
|
|
4
|
+
error,
|
|
5
|
+
isFields,
|
|
6
|
+
readAnswer,
|
|
7
|
+
frameOf,
|
|
8
|
+
frameReader,
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
} from '@nervur.org/genome/standard';
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
const writer = (io ) => {
|
|
38
|
+
const held = [];
|
|
39
|
+
let full = false;
|
|
40
|
+
const wrote = (bytes ) => {
|
|
41
|
+
if (io.write(bytes)) return true;
|
|
42
|
+
full = true;
|
|
43
|
+
io.pause();
|
|
44
|
+
io.drained(flush);
|
|
45
|
+
return false;
|
|
46
|
+
};
|
|
47
|
+
function flush() {
|
|
48
|
+
full = false;
|
|
49
|
+
for (let bytes = held.shift(); bytes !== undefined; bytes = held.shift()) if (!wrote(bytes)) return;
|
|
50
|
+
io.resume();
|
|
51
|
+
}
|
|
52
|
+
return (data) => {
|
|
53
|
+
const bytes = frameOf(data);
|
|
54
|
+
if (bytes.length - 1 > FRAME_SIZE) return false;
|
|
55
|
+
if (full) held.push(bytes);
|
|
56
|
+
else wrote(bytes);
|
|
57
|
+
return true;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const framesOf = (each ) =>
|
|
62
|
+
frameReader(
|
|
63
|
+
(read) => {
|
|
64
|
+
if ('data' in read && isFields(read.data)) each(read.data);
|
|
65
|
+
},
|
|
66
|
+
{ longest: FRAME_SIZE, past: () => undefined },
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const unavailable = error('unavailable', 'the bridge has closed');
|
|
70
|
+
|
|
71
|
+
const answerIn = (frame ) => {
|
|
72
|
+
const read = readAnswer(Object.fromEntries(Object.entries(frame).filter(([key]) => key !== 'answer')));
|
|
73
|
+
return 'why' in read ? error('fault', `the graph half answered no answer: ${read.why}`) : read.answer;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const fault = (thrown ) => error('fault', thrown instanceof Error ? thrown.message : String(thrown));
|
|
77
|
+
|
|
78
|
+
const answerOf = (answering , frame , send ) => {
|
|
79
|
+
const { method, asker } = frame;
|
|
80
|
+
let answer ;
|
|
81
|
+
try {
|
|
82
|
+
answer =
|
|
83
|
+
typeof method === 'string'
|
|
84
|
+
? answering(method, frame['args'] ?? null, typeof asker === 'string' ? asker : null)
|
|
85
|
+
: error('refused', 'the ask names no method');
|
|
86
|
+
} catch (thrown) {
|
|
87
|
+
answer = fault(thrown);
|
|
88
|
+
}
|
|
89
|
+
if (answer instanceof Promise) void answer.then(send, (thrown ) => send(fault(thrown)));
|
|
90
|
+
else send(answer);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const pastFrame = (what ) => error('refused', `${what} weighs past a frame of ${FRAME_SIZE} bytes`);
|
|
94
|
+
|
|
95
|
+
export const serveHalf = (io , blueprint , answering , ended = () => undefined) => {
|
|
96
|
+
const write = writer(io);
|
|
97
|
+
const waiting = new Map ();
|
|
98
|
+
let next = 1;
|
|
99
|
+
let open = true;
|
|
100
|
+
const answered = (n , frame ) =>
|
|
101
|
+
answerOf(answering, frame, (one) => {
|
|
102
|
+
if (open && !write({ answer: n, ...one })) write({ answer: n, ...pastFrame('the answer') });
|
|
103
|
+
});
|
|
104
|
+
io.read(
|
|
105
|
+
framesOf((frame) => {
|
|
106
|
+
const { ask, answer } = frame;
|
|
107
|
+
if (typeof ask === 'number') return answered(ask, frame);
|
|
108
|
+
const done = typeof answer === 'number' ? waiting.get(answer) : undefined;
|
|
109
|
+
if (done === undefined || typeof answer !== 'number') return;
|
|
110
|
+
waiting.delete(answer);
|
|
111
|
+
done(answerIn(frame));
|
|
112
|
+
}),
|
|
113
|
+
);
|
|
114
|
+
io.ended(() => {
|
|
115
|
+
if (!open) return;
|
|
116
|
+
open = false;
|
|
117
|
+
for (const done of waiting.values()) done(unavailable);
|
|
118
|
+
waiting.clear();
|
|
119
|
+
ended();
|
|
120
|
+
});
|
|
121
|
+
write({ blueprint });
|
|
122
|
+
return {
|
|
123
|
+
ask: (placeholder, method, args, timeout) => {
|
|
124
|
+
if (!open) return Promise.resolve(unavailable);
|
|
125
|
+
const n = next;
|
|
126
|
+
next += 1;
|
|
127
|
+
if (!write({ ask: n, placeholder, method, args, timeout })) return Promise.resolve(pastFrame('the ask'));
|
|
128
|
+
return new Promise((done) => waiting.set(n, done));
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export const refuseHalf = (io , why ) => {
|
|
134
|
+
writer(io)({ refused: why });
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export const processIo = () => {
|
|
138
|
+
const told = [];
|
|
139
|
+
let broken = false;
|
|
140
|
+
process.stdout.on('error', () => {
|
|
141
|
+
if (broken) return;
|
|
142
|
+
broken = true;
|
|
143
|
+
for (const done of told) done();
|
|
144
|
+
});
|
|
145
|
+
return {
|
|
146
|
+
write: (bytes) => broken || process.stdout.write(bytes),
|
|
147
|
+
drained: (go) => void process.stdout.once('drain', go),
|
|
148
|
+
read: (chunk) => void process.stdin.on('data', (bytes ) => chunk(bytes)),
|
|
149
|
+
pause: () => void process.stdin.pause(),
|
|
150
|
+
resume: () => void process.stdin.resume(),
|
|
151
|
+
ended: (done) => {
|
|
152
|
+
told.push(done);
|
|
153
|
+
process.stdin.on('end', done);
|
|
154
|
+
process.stdin.on('close', done);
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const NAME = '@nervur.org/genome';
|
|
7
|
+
|
|
8
|
+
const named = (folder ) => {
|
|
9
|
+
const manifest = join(folder, 'package.json');
|
|
10
|
+
if (!existsSync(manifest)) return false;
|
|
11
|
+
const read = JSON.parse(readFileSync(manifest, 'utf8'));
|
|
12
|
+
return typeof read === 'object' && read !== null && 'name' in read && read.name === NAME;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const genomeFolder = () => {
|
|
16
|
+
const entry = fileURLToPath(import.meta.resolve(NAME));
|
|
17
|
+
for (let folder = dirname(entry); folder !== dirname(folder); folder = dirname(folder)) {
|
|
18
|
+
if (named(folder)) return folder;
|
|
19
|
+
}
|
|
20
|
+
return { why: `no package ${NAME} stands above ${entry}` };
|
|
21
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Answer } from '@nervur.org/genome/standard';
|
|
2
|
+
import type { End } from './end.js';
|
|
3
|
+
export declare const handlerIn: (read: Answer) => {
|
|
4
|
+
readonly handler: string | null;
|
|
5
|
+
} | {
|
|
6
|
+
readonly why: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const speaker: (end: End, organ: string) => ((use: (handler: string) => Promise<Answer>) => Promise<Answer>);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { error, isFields, } from '@nervur.org/genome/standard';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const NERVES_WITHIN = 900;
|
|
6
|
+
|
|
7
|
+
export const handlerIn = (read ) => {
|
|
8
|
+
if ('error' in read) return { why: `nerves read: ${read.error.message}` };
|
|
9
|
+
if (!Array.isArray(read.result)) return { why: 'nerves read: answered no list of wirings' };
|
|
10
|
+
for (const one of read.result) {
|
|
11
|
+
if (!isFields(one)) continue;
|
|
12
|
+
const { placeholder, termination } = one;
|
|
13
|
+
if (typeof placeholder === 'string' && typeof termination === 'string' && placeholder === termination)
|
|
14
|
+
return { handler: placeholder };
|
|
15
|
+
}
|
|
16
|
+
return { handler: null };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const speaker = (end , organ ) => {
|
|
20
|
+
let held = null;
|
|
21
|
+
const read = async () => {
|
|
22
|
+
const named = handlerIn(await end.ask('nerves', 'read', {}, NERVES_WITHIN));
|
|
23
|
+
held = 'handler' in named ? named.handler : null;
|
|
24
|
+
return named;
|
|
25
|
+
};
|
|
26
|
+
const none = error('unavailable', `${organ} holds no handler: no lobe is wired to it`);
|
|
27
|
+
const unread = (why ) => error('unavailable', `${organ} could not read its nerves: ${why}`);
|
|
28
|
+
return async (use) => {
|
|
29
|
+
const first = held === null ? await read() : { handler: held };
|
|
30
|
+
if ('why' in first) return unread(first.why);
|
|
31
|
+
if (first.handler === null) return none;
|
|
32
|
+
const { handler } = first;
|
|
33
|
+
const answer = await use(handler);
|
|
34
|
+
if (!('error' in answer) || answer.error.code !== 'unavailable') return answer;
|
|
35
|
+
const again = await read();
|
|
36
|
+
if ('why' in again) return unread(again.why);
|
|
37
|
+
if (again.handler === null) return none;
|
|
38
|
+
return again.handler === handler ? answer : use(again.handler);
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { buildHalf } from './build.js';
|
|
2
|
+
export { framesOf, processIo, refuseHalf, serveHalf, type Answering, type End, type Io } from './end.js';
|
|
3
|
+
export { handlerIn, speaker } from './handler.js';
|
|
4
|
+
export { halvesOf, laidHalves, layHalves, programOf, pruneHalves } from './laid.js';
|
|
5
|
+
export { digestOf, nativeHalves, sourceDigestOf, sourceHalves, type Built, type Source } from './native.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
export { buildHalf } from './build.js';
|
|
3
|
+
export { framesOf, processIo, refuseHalf, serveHalf, } from './end.js';
|
|
4
|
+
export { handlerIn, speaker } from './handler.js';
|
|
5
|
+
export { halvesOf, laidHalves, layHalves, programOf, pruneHalves } from './laid.js';
|
|
6
|
+
export { digestOf, nativeHalves, sourceDigestOf, sourceHalves, } from './native.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { HostHalf } from '@nervur.org/genome/seams';
|
|
2
|
+
import type { Program } from '../fills/bridge.js';
|
|
3
|
+
import { type Built, type Source } from './native.js';
|
|
4
|
+
export declare const halvesOf: (home: string) => string;
|
|
5
|
+
export declare const laidHalves: (folder: string) => readonly string[];
|
|
6
|
+
export declare const layHalves: (folder: string, halves: Iterable<Built>) => readonly string[];
|
|
7
|
+
export declare const pruneHalves: (folder: string, named: ReadonlySet<string>) => readonly string[];
|
|
8
|
+
type Why = {
|
|
9
|
+
readonly why: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const programOf: (folder: string, sources: Iterable<Source>, work?: string, bounded?: (organ: string, program: Program) => Program, genome?: string, built?: string) => ((organ: string, half: HostHalf) => Program | Why);
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
import { chmodSync, existsSync, readdirSync, rmSync } from 'node:fs';
|
|
4
|
+
import { userInfo } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
|
|
7
|
+
import { dataText, isFields } from '@nervur.org/genome/standard';
|
|
8
|
+
|
|
9
|
+
import { foldersLaid, laidWhole } from '../fills/flushed.js';
|
|
10
|
+
import { asWork } from '../work/work.js';
|
|
11
|
+
import { digestOf, sourceDigestOf, } from './native.js';
|
|
12
|
+
|
|
13
|
+
const LAID = /^([0-9a-f]{64})\.[a-z]+$/;
|
|
14
|
+
|
|
15
|
+
export const halvesOf = (home ) => join(home, 'halves');
|
|
16
|
+
|
|
17
|
+
const fileOf = (folder , digest ) => join(folder, `${digest}.mjs`);
|
|
18
|
+
|
|
19
|
+
const laidFiles = (folder ) =>
|
|
20
|
+
existsSync(folder)
|
|
21
|
+
? readdirSync(folder).flatMap((name) => {
|
|
22
|
+
const digest = LAID.exec(name)?.[1];
|
|
23
|
+
return digest === undefined ? [] : [[digest, join(folder, name)] ];
|
|
24
|
+
})
|
|
25
|
+
: [];
|
|
26
|
+
|
|
27
|
+
export const laidHalves = (folder ) =>
|
|
28
|
+
[...new Set(laidFiles(folder).map(([digest]) => digest))].toSorted((a, b) => (a < b ? -1 : 1));
|
|
29
|
+
|
|
30
|
+
export const layHalves = (folder , halves ) => {
|
|
31
|
+
foldersLaid(folder, 0o700);
|
|
32
|
+
chmodSync(folder, 0o700);
|
|
33
|
+
const laid = [];
|
|
34
|
+
for (const { text, digest } of halves) {
|
|
35
|
+
const file = fileOf(folder, digest);
|
|
36
|
+
if (existsSync(file) && digestOf(file) === digest) continue;
|
|
37
|
+
laidWhole(file, text, 0o600);
|
|
38
|
+
laid.push(digest);
|
|
39
|
+
}
|
|
40
|
+
return laid;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const pruneHalves = (folder , named ) => {
|
|
44
|
+
const removed = laidHalves(folder).filter((digest) => !named.has(digest));
|
|
45
|
+
for (const [digest, file] of laidFiles(folder)) if (!named.has(digest)) rmSync(file, { force: true });
|
|
46
|
+
return removed;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
const digestAs = (account , file ) => {
|
|
52
|
+
try {
|
|
53
|
+
const script = '[ -f "$1" ] || exit 0; { sha256sum "$1" 2>/dev/null || shasum -a 256 "$1"; } | cut -d " " -f 1';
|
|
54
|
+
const out = execFileSync('sudo', ['-n', '-u', account, '--', 'sh', '-c', script, 'sh', file], {
|
|
55
|
+
encoding: 'utf8',
|
|
56
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
57
|
+
}).trim();
|
|
58
|
+
return /^[0-9a-f]{64}$/u.test(out) ? out : undefined;
|
|
59
|
+
} catch {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const programOf = (
|
|
65
|
+
folder ,
|
|
66
|
+
sources ,
|
|
67
|
+
work ,
|
|
68
|
+
bounded = (_organ, program) => program,
|
|
69
|
+
genome ,
|
|
70
|
+
built ,
|
|
71
|
+
) => {
|
|
72
|
+
const bySource = new Map([...sources].map((one) => [one.digest, one.file]));
|
|
73
|
+
return (organ, half) => {
|
|
74
|
+
if (half.form === 'component') return { why: 'Node runs no component yet' };
|
|
75
|
+
if (half.code !== null) return { why: 'Node runs no script yet' };
|
|
76
|
+
const account = isFields(half.reach) ? half.reach['account'] : undefined;
|
|
77
|
+
const other = work !== undefined && typeof account === 'string' && account !== userInfo().username;
|
|
78
|
+
const laid = fileOf(other ? work : folder, half.digest);
|
|
79
|
+
const custom = built === undefined ? undefined : join(built, half.digest);
|
|
80
|
+
const layed = existsSync(laid);
|
|
81
|
+
const read =
|
|
82
|
+
custom === undefined || layed || bySource.has(half.digest)
|
|
83
|
+
? undefined
|
|
84
|
+
: other
|
|
85
|
+
? digestAs(account, custom)
|
|
86
|
+
: existsSync(custom)
|
|
87
|
+
? digestOf(custom)
|
|
88
|
+
: undefined;
|
|
89
|
+
const own = custom !== undefined && read !== undefined;
|
|
90
|
+
const file = own ? custom : layed ? laid : bySource.get(half.digest);
|
|
91
|
+
if (own && work !== undefined && !other)
|
|
92
|
+
return { why: `the organ ${organ}'s half runs in the body: its reach names the work account` };
|
|
93
|
+
if (file === undefined)
|
|
94
|
+
return { why: `the device lacks the native half ${half.digest}: \`nervur update\` lays this installer's` };
|
|
95
|
+
if ((own ? read : layed ? digestOf(file) : sourceDigestOf(file)) !== half.digest)
|
|
96
|
+
return { why: `${file} no longer matches its digest ${half.digest}` };
|
|
97
|
+
const lent = organ === 'shell' && genome !== undefined ? [genome] : [];
|
|
98
|
+
const program = own
|
|
99
|
+
? { command: file, args: [dataText(half.reach)] }
|
|
100
|
+
: { command: process.execPath, args: [file, dataText(half.reach), ...lent] };
|
|
101
|
+
return bounded(organ, other ? asWork({ account }, program) : program);
|
|
102
|
+
};
|
|
103
|
+
};
|