@dokebi/cli 0.4.90 → 0.4.92
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/AI.md +12 -10
- package/catalog.json +13 -11
- package/dist/bin.js +27 -5
- package/dist/capability-guide.js +1 -0
- package/dist/commands.js +27 -11
- package/dist/config-edit.d.ts +13 -3
- package/dist/config-edit.js +54 -17
- package/dist/config-paths.d.ts +3 -1
- package/dist/config-paths.js +26 -5
- package/dist/config-show.d.ts +11 -1
- package/dist/config-show.js +11 -2
- package/dist/configuration.d.ts +6 -1
- package/dist/configuration.js +6 -2
- package/dist/deploy-templates.d.ts +20 -2
- package/dist/deploy-templates.js +119 -20
- package/dist/deploy.d.ts +6 -0
- package/dist/deploy.js +19 -5
- package/dist/log-writer.js +20 -6
- package/dist/output.d.ts +1 -1
- package/dist/output.js +1 -1
- package/dist/process-set.d.ts +1 -0
- package/dist/process-set.js +161 -0
- package/dist/process-tags.d.ts +10 -0
- package/dist/process-tags.js +31 -0
- package/dist/processes.d.ts +46 -0
- package/dist/processes.js +200 -0
- package/dist/project-inspector.js +46 -0
- package/dist/project-state.d.ts +6 -0
- package/dist/project-state.js +12 -1
- package/dist/project.d.ts +6 -2
- package/dist/project.js +46 -17
- package/dist/server.d.ts +8 -0
- package/dist/server.js +235 -32
- package/package.json +2 -2
package/dist/log-writer.js
CHANGED
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
// losing lines. It ignores SIGTERM/SIGINT/SIGHUP (dokebi stop signals the app, not the writer)
|
|
5
5
|
// and exits once the app has exited and its pipes are drained.
|
|
6
6
|
//
|
|
7
|
-
// Usage: log-writer <log file> <max bytes> <rotated files to keep> <entry>
|
|
7
|
+
// Usage: log-writer <log file> <max bytes> <rotated files to keep> <entry> [process...]
|
|
8
|
+
// D-0251: with processes (the `run` of the settings file) it starts `entry` with DOKEBI_PROCESS set
|
|
9
|
+
// for one, and process-set.js for several (it starts each and tags their lines); readiness then
|
|
10
|
+
// comes from the IPC message alone, since every process writes its own start line.
|
|
8
11
|
// The CLI listens on the IPC channel until the start is decided: { spawned: pid }, { ready: true }
|
|
9
12
|
// when the start line passes, { exited: code, signal } and { failed: text }. The writer's own
|
|
10
13
|
// errors go to its stderr, which the CLI points at `.dokebi/run/log-writer.log`.
|
|
@@ -15,9 +18,11 @@
|
|
|
15
18
|
// parent, to stop it. Both sides prove the app's DOKEBI_INSTANCE_TOKEN first.
|
|
16
19
|
import { spawn } from 'node:child_process';
|
|
17
20
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
21
|
+
import { fileURLToPath } from 'node:url';
|
|
18
22
|
import { debug, describeError, reportError } from './diagnostics.js';
|
|
19
23
|
import { ControlServer } from './log-writer-control.js';
|
|
20
24
|
import { endLeftovers, PROCESS_GROUPS } from './process-group.js';
|
|
25
|
+
import { PROCESS_VARIABLE } from './process-tags.js';
|
|
21
26
|
import { forwardOutput, LineBuffer, RotatingLog } from './rotating-log.js';
|
|
22
27
|
/** Written by the generated `src/main.ts` once `app.start()` resolved. */
|
|
23
28
|
const STARTED = 'Dokebi application started';
|
|
@@ -42,7 +47,7 @@ function send(message, then) {
|
|
|
42
47
|
then?.();
|
|
43
48
|
});
|
|
44
49
|
}
|
|
45
|
-
const [file, maxArg, keepArg, entry] = process.argv.slice(2);
|
|
50
|
+
const [file, maxArg, keepArg, entry, ...processes] = process.argv.slice(2);
|
|
46
51
|
const maxBytes = Number(maxArg);
|
|
47
52
|
const keep = Number(keepArg);
|
|
48
53
|
if (!file ||
|
|
@@ -51,7 +56,7 @@ if (!file ||
|
|
|
51
56
|
maxBytes < 1 ||
|
|
52
57
|
!Number.isSafeInteger(keep) ||
|
|
53
58
|
keep < 1) {
|
|
54
|
-
const text = `usage: log-writer <log file> <max bytes> <files> <entry> (got ${JSON.stringify(process.argv.slice(2))})`;
|
|
59
|
+
const text = `usage: log-writer <log file> <max bytes> <files> <entry> [process...] (got ${JSON.stringify(process.argv.slice(2))})`;
|
|
55
60
|
reportError('LOG_WRITER_USAGE', 'Invalid log writer arguments', new Error(text));
|
|
56
61
|
send({ failed: text }, () => process.exit(2));
|
|
57
62
|
}
|
|
@@ -91,9 +96,16 @@ function run(file, maxBytes, keep, entry, control) {
|
|
|
91
96
|
// logging.level above info hides the start line, and the app is still up.
|
|
92
97
|
// The app leads a process group of its own (POSIX): what it starts and leaves behind when it
|
|
93
98
|
// exits (stopped, crashed or killed) is found there and ended, never left holding a port.
|
|
94
|
-
const
|
|
99
|
+
const several = processes.length > 1;
|
|
100
|
+
const app = spawn(process.execPath, several
|
|
101
|
+
? [fileURLToPath(new URL('./process-set.js', import.meta.url)), entry, ...processes]
|
|
102
|
+
: [entry], {
|
|
95
103
|
stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
|
|
96
|
-
env: {
|
|
104
|
+
env: {
|
|
105
|
+
...process.env,
|
|
106
|
+
DOKEBI_LOG_WRITER: '1',
|
|
107
|
+
...(processes.length === 1 ? { [PROCESS_VARIABLE]: processes[0] } : {}),
|
|
108
|
+
},
|
|
97
109
|
detached: PROCESS_GROUPS,
|
|
98
110
|
});
|
|
99
111
|
let announced = false;
|
|
@@ -109,7 +121,9 @@ function run(file, maxBytes, keep, entry, control) {
|
|
|
109
121
|
ready('ipc message');
|
|
110
122
|
});
|
|
111
123
|
// `ready` goes to the CLI after the start line is in app.log (forwardOutput), or on the message.
|
|
112
|
-
const write =
|
|
124
|
+
const write = several
|
|
125
|
+
? (data) => log.write(data)
|
|
126
|
+
: forwardOutput(log, STARTED, () => ready('start line'));
|
|
113
127
|
let exit;
|
|
114
128
|
let leftovers = Promise.resolve('none');
|
|
115
129
|
let open = 2;
|
package/dist/output.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const CLI_VERSION = "0.4.
|
|
1
|
+
export declare const CLI_VERSION = "0.4.92";
|
|
2
2
|
export declare function envelope(command: string, result: unknown, ok?: boolean): object;
|
|
3
3
|
export declare function failure(command: string, error: unknown, mutationStarted: boolean): object;
|
package/dist/output.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// The processes of one folder under `dokebi start` (D-0251). The log writer starts this instead
|
|
2
|
+
// of the app when `run` of the settings file names more than one process; it starts
|
|
3
|
+
// `node <entry>` once per process with DOKEBI_PROCESS set, and stands for them toward the writer:
|
|
4
|
+
//
|
|
5
|
+
// - their output goes on to the writer with each line tagged (a JSON record gets `"process"`,
|
|
6
|
+
// any other line a `[name] ` prefix), so app.log tells them apart;
|
|
7
|
+
// - `{ dokebi: 'started' }` goes to the writer once every process said it (its IPC message, or
|
|
8
|
+
// its start line);
|
|
9
|
+
// - SIGTERM, SIGINT and SIGHUP (a reload) go on to every process;
|
|
10
|
+
// - one process that ends while the others run is written to the log and the others are stopped:
|
|
11
|
+
// the set runs whole or not at all, as one app did. The exit code is the first failure's.
|
|
12
|
+
//
|
|
13
|
+
// Usage: process-set <entry> <process> <process>...
|
|
14
|
+
// The processes share this one's process group (the writer spawned it detached), so what any of
|
|
15
|
+
// them leaves behind is ended with it.
|
|
16
|
+
import { spawn } from 'node:child_process';
|
|
17
|
+
import { debug, reportError } from './diagnostics.js';
|
|
18
|
+
import { PROCESS_VARIABLE, tagLines } from './process-tags.js';
|
|
19
|
+
import { LineBuffer } from './rotating-log.js';
|
|
20
|
+
/** Written by the generated `src/main.ts` once the app started. */
|
|
21
|
+
const STARTED = 'Dokebi application started';
|
|
22
|
+
/** An unfinished line is written after this much quiet. */
|
|
23
|
+
const PARTIAL_MS = 200;
|
|
24
|
+
/** The reload status file (D-0154): each process gets its own beside it. */
|
|
25
|
+
const RELOAD_STATUS_ENV = 'DOKEBI_RELOAD_STATUS';
|
|
26
|
+
const [entry, ...names] = process.argv.slice(2);
|
|
27
|
+
if (!entry || names.length < 2) {
|
|
28
|
+
reportError('INVALID_ARGUMENTS', 'usage: process-set <entry> <process> <process>...', new Error(`got ${JSON.stringify(process.argv.slice(2))}`));
|
|
29
|
+
process.exit(2);
|
|
30
|
+
}
|
|
31
|
+
/** One line of this supervisor in the app log, in the records' shape. */
|
|
32
|
+
function record(level, message, fields) {
|
|
33
|
+
const line = `${JSON.stringify({ time: new Date().toISOString(), level, message, ...fields })}\n`;
|
|
34
|
+
// dokebi-check: allow console-output the supervisor's records go to the log writer like the processes' own
|
|
35
|
+
(level === 'error' ? process.stderr : process.stdout).write(line);
|
|
36
|
+
}
|
|
37
|
+
let stopping = false;
|
|
38
|
+
let failure;
|
|
39
|
+
const children = new Map();
|
|
40
|
+
const ready = new Set();
|
|
41
|
+
let announced = false;
|
|
42
|
+
function started(name, how) {
|
|
43
|
+
if (ready.has(name))
|
|
44
|
+
return;
|
|
45
|
+
ready.add(name);
|
|
46
|
+
debug('Process started', { process: name, how });
|
|
47
|
+
if (announced || ready.size < names.length)
|
|
48
|
+
return;
|
|
49
|
+
announced = true;
|
|
50
|
+
record('info', `Processes started: ${names.join(', ')}`, {
|
|
51
|
+
code: 'PROCESSES_STARTED',
|
|
52
|
+
processes: names,
|
|
53
|
+
});
|
|
54
|
+
if (process.connected)
|
|
55
|
+
process.send?.({ dokebi: 'started' });
|
|
56
|
+
}
|
|
57
|
+
/** Copies a process's output to ours, tagged, holding it while ours is full (back pressure). */
|
|
58
|
+
function follow(name, from, to) {
|
|
59
|
+
if (!from)
|
|
60
|
+
return;
|
|
61
|
+
const lines = new LineBuffer();
|
|
62
|
+
let timer;
|
|
63
|
+
const write = (data) => {
|
|
64
|
+
if (data.length === 0)
|
|
65
|
+
return;
|
|
66
|
+
if (data.includes(STARTED))
|
|
67
|
+
started(name, 'start line');
|
|
68
|
+
// dokebi-check: allow console-output the processes' output goes on to the log writer as it was, tagged
|
|
69
|
+
if (!to.write(tagLines(name, data))) {
|
|
70
|
+
from.pause();
|
|
71
|
+
to.once('drain', () => from.resume());
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
from.on('data', (chunk) => {
|
|
75
|
+
const whole = lines.push(chunk);
|
|
76
|
+
if (whole)
|
|
77
|
+
write(whole);
|
|
78
|
+
clearTimeout(timer);
|
|
79
|
+
if (lines.pending)
|
|
80
|
+
timer = setTimeout(() => write(lines.take()), PARTIAL_MS);
|
|
81
|
+
});
|
|
82
|
+
from.once('error', (error) => reportError('PROCESS_OUTPUT_FAILED', `Unable to read the output of process ${name}`, error));
|
|
83
|
+
from.once('close', () => {
|
|
84
|
+
clearTimeout(timer);
|
|
85
|
+
if (lines.pending)
|
|
86
|
+
write(lines.take());
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function signalAll(signal) {
|
|
90
|
+
for (const [name, child] of children) {
|
|
91
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
92
|
+
continue;
|
|
93
|
+
try {
|
|
94
|
+
child.kill(signal);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
reportError('PROCESS_SIGNAL_FAILED', `Unable to signal process ${name}`, error);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function stopAll(reason) {
|
|
102
|
+
if (stopping)
|
|
103
|
+
return;
|
|
104
|
+
stopping = true;
|
|
105
|
+
debug('Stopping every process', { reason });
|
|
106
|
+
signalAll('SIGTERM');
|
|
107
|
+
}
|
|
108
|
+
function exited(name, code, signal) {
|
|
109
|
+
if (!stopping) {
|
|
110
|
+
// Ending on its own while the others run is a failure of the set, also with code 0.
|
|
111
|
+
record('error', 'A process ended; stopping the others', {
|
|
112
|
+
code: 'PROCESS_EXITED',
|
|
113
|
+
process: name,
|
|
114
|
+
exitCode: code,
|
|
115
|
+
signal,
|
|
116
|
+
});
|
|
117
|
+
failure ??= { code: code || 1 };
|
|
118
|
+
stopAll(`process ${name} ended`);
|
|
119
|
+
}
|
|
120
|
+
else if (code !== null && code !== 0)
|
|
121
|
+
failure ??= { code };
|
|
122
|
+
else if (signal !== null && signal !== 'SIGTERM' && signal !== 'SIGINT')
|
|
123
|
+
failure ??= { code: 1 };
|
|
124
|
+
children.delete(name);
|
|
125
|
+
if (children.size === 0)
|
|
126
|
+
process.exit(failure?.code ?? 0);
|
|
127
|
+
}
|
|
128
|
+
for (const name of names) {
|
|
129
|
+
const status = process.env[RELOAD_STATUS_ENV];
|
|
130
|
+
const child = spawn(process.execPath, [entry], {
|
|
131
|
+
stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
|
|
132
|
+
env: {
|
|
133
|
+
...process.env,
|
|
134
|
+
[PROCESS_VARIABLE]: name,
|
|
135
|
+
...(status ? { [RELOAD_STATUS_ENV]: `${status}.${name}` } : {}),
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
children.set(name, child);
|
|
139
|
+
child.on('message', (message) => {
|
|
140
|
+
if (message?.dokebi === 'started')
|
|
141
|
+
started(name, 'ipc message');
|
|
142
|
+
});
|
|
143
|
+
child.once('error', (error) => {
|
|
144
|
+
reportError('PROCESS_SPAWN_FAILED', `Unable to start process ${name}`, error);
|
|
145
|
+
exited(name, 1, null);
|
|
146
|
+
});
|
|
147
|
+
child.once('exit', (code, signal) => exited(name, code, signal));
|
|
148
|
+
follow(name, child.stdout, process.stdout);
|
|
149
|
+
follow(name, child.stderr, process.stderr);
|
|
150
|
+
debug('Process spawned', { process: name, pid: child.pid });
|
|
151
|
+
}
|
|
152
|
+
process.on('SIGTERM', () => stopAll('SIGTERM'));
|
|
153
|
+
process.on('SIGINT', () => stopAll('SIGINT'));
|
|
154
|
+
// A reload: every process reads its settings again.
|
|
155
|
+
process.on('SIGHUP', () => signalAll('SIGHUP'));
|
|
156
|
+
process.on('disconnect', () => debug('The log writer closed the IPC channel', {}));
|
|
157
|
+
// The writer went away (its pipe closed): nothing can be logged any more; stop the set.
|
|
158
|
+
process.stdout.on('error', (error) => {
|
|
159
|
+
reportError('PROCESS_SET_OUTPUT_FAILED', 'The log writer pipe closed', error);
|
|
160
|
+
stopAll('output closed');
|
|
161
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The variable naming the process (as @dokebi/config's PROCESS_VARIABLE). */
|
|
2
|
+
export declare const PROCESS_VARIABLE = "DOKEBI_PROCESS";
|
|
3
|
+
/**
|
|
4
|
+
* A line of process `name`'s output with its name: a JSON record gets a leading `"process"` field
|
|
5
|
+
* (no parse: the record's own fields follow, so a record that names a process keeps its own),
|
|
6
|
+
* anything else a `[name] ` prefix.
|
|
7
|
+
*/
|
|
8
|
+
export declare function tagLine(name: string, line: string): string;
|
|
9
|
+
/** Whole lines of process `name` (a LineBuffer's output), each tagged (tagLine). */
|
|
10
|
+
export declare function tagLines(name: string, data: Buffer): Buffer;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// D-0251: what tells the processes of one folder apart without loading the settings code (the log
|
|
2
|
+
// writer and process-set import this): the variable naming the process, and their tagged lines.
|
|
3
|
+
/** The variable naming the process (as @dokebi/config's PROCESS_VARIABLE). */
|
|
4
|
+
export const PROCESS_VARIABLE = 'DOKEBI_PROCESS';
|
|
5
|
+
/**
|
|
6
|
+
* A line of process `name`'s output with its name: a JSON record gets a leading `"process"` field
|
|
7
|
+
* (no parse: the record's own fields follow, so a record that names a process keeps its own),
|
|
8
|
+
* anything else a `[name] ` prefix.
|
|
9
|
+
*/
|
|
10
|
+
export function tagLine(name, line) {
|
|
11
|
+
if (line.startsWith('{"'))
|
|
12
|
+
return `{"process":${JSON.stringify(name)},${line.slice(1)}`;
|
|
13
|
+
if (line.startsWith('{}'))
|
|
14
|
+
return `{"process":${JSON.stringify(name)}}${line.slice(2)}`;
|
|
15
|
+
if (line.length === 0 || line === '\n')
|
|
16
|
+
return line;
|
|
17
|
+
return `[${name}] ${line}`;
|
|
18
|
+
}
|
|
19
|
+
/** Whole lines of process `name` (a LineBuffer's output), each tagged (tagLine). */
|
|
20
|
+
export function tagLines(name, data) {
|
|
21
|
+
const text = data.toString('utf8');
|
|
22
|
+
let out = '';
|
|
23
|
+
let from = 0;
|
|
24
|
+
while (from < text.length) {
|
|
25
|
+
const end = text.indexOf('\n', from);
|
|
26
|
+
const line = end < 0 ? text.slice(from) : text.slice(from, end + 1);
|
|
27
|
+
out += tagLine(name, line);
|
|
28
|
+
from = end < 0 ? text.length : end + 1;
|
|
29
|
+
}
|
|
30
|
+
return Buffer.from(out, 'utf8');
|
|
31
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export { PROCESS_VARIABLE, tagLine, tagLines } from './process-tags.js';
|
|
2
|
+
type Options = Record<string, unknown>;
|
|
3
|
+
export interface ProcessSet {
|
|
4
|
+
/** The processes this folder starts (`run`), in order. */
|
|
5
|
+
readonly run: readonly string[];
|
|
6
|
+
/** Every process the file declares, in order. */
|
|
7
|
+
readonly declared: readonly string[];
|
|
8
|
+
/** The options each declared process gets: the shared ones with its own merged in. */
|
|
9
|
+
readonly options: ReadonlyMap<string, Options>;
|
|
10
|
+
/** The shared `options` alone. */
|
|
11
|
+
readonly shared: Options;
|
|
12
|
+
/** What each process sets itself (`processes.<name>.options`, as written). */
|
|
13
|
+
readonly own: ReadonlyMap<string, Options>;
|
|
14
|
+
}
|
|
15
|
+
/** The process set of a settings source; undefined when it declares no processes. */
|
|
16
|
+
export declare function processSetOf(source: string): ProcessSet | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* The process set of the settings file the app reads (DOKEBI_CONFIG, else dokebi.yaml); undefined
|
|
19
|
+
* when it declares none or is not there. An invalid file is INVALID_CONFIG.
|
|
20
|
+
*/
|
|
21
|
+
export declare function readProcessSet(root: string): Promise<ProcessSet | undefined>;
|
|
22
|
+
/** The process set, or undefined when the file cannot be read or parsed (doctor reports that). */
|
|
23
|
+
export declare function processSetOrNone(root: string): Promise<ProcessSet | undefined>;
|
|
24
|
+
/**
|
|
25
|
+
* The worker count a process sets itself (`processes.<name>.options.application-runtime.workers`),
|
|
26
|
+
* or undefined. Under `dokebi dev` such a process runs that many (DOKEBI_DEV_WORKERS is for the
|
|
27
|
+
* processes that set none, D-0251): a worker kept at one is never multiplied by it.
|
|
28
|
+
*/
|
|
29
|
+
export declare function ownWorkers(set: ProcessSet, name: string): number | undefined;
|
|
30
|
+
/** Whether a process with these options opens its web port (D-0221: `listen: false` does not). */
|
|
31
|
+
export declare function listens(options: Options): boolean;
|
|
32
|
+
/** The first process of `run` that opens its web port: the one dev and start show and probe. */
|
|
33
|
+
export declare function webProcess(set: ProcessSet): string | undefined;
|
|
34
|
+
/** One finding about the process set, for doctor and start. */
|
|
35
|
+
export interface ProcessIssue {
|
|
36
|
+
readonly code: string;
|
|
37
|
+
readonly severity: 'error' | 'warning';
|
|
38
|
+
readonly message: string;
|
|
39
|
+
readonly fix: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* What the declared processes leave undone or do twice. Only work of a plugin the file configures
|
|
43
|
+
* is judged (a section in the shared options or in a process); a process of `processes` that
|
|
44
|
+
* `run` leaves out runs elsewhere (another folder whose `run` names it) and counts.
|
|
45
|
+
*/
|
|
46
|
+
export declare function processIssues(set: ProcessSet): ProcessIssue[];
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// D-0251: the processes one dokebi.yaml declares (`processes.<name>.options`, what each changes
|
|
2
|
+
// from the shared `options`) and the ones this folder starts (`run`). dev and start start one
|
|
3
|
+
// `node src/main.ts` per process of `run` with DOKEBI_PROCESS set; @dokebi/config gives each
|
|
4
|
+
// process its own options. Here: the options of every declared process, which one serves the web,
|
|
5
|
+
// what the set leaves undone (a queue no process takes, two processes on one port), and the
|
|
6
|
+
// `process` field that tells their log lines apart.
|
|
7
|
+
import { ConfigError, parseConfig } from '@dokebi/config';
|
|
8
|
+
import { parseDocument } from 'yaml';
|
|
9
|
+
import { readProjectSettings } from './configuration.js';
|
|
10
|
+
import { debug, describeError, isMissing } from './diagnostics.js';
|
|
11
|
+
import { CliError } from './errors.js';
|
|
12
|
+
export { PROCESS_VARIABLE, tagLine, tagLines } from './process-tags.js';
|
|
13
|
+
/** The process set of a settings source; undefined when it declares no processes. */
|
|
14
|
+
export function processSetOf(source) {
|
|
15
|
+
const shared = parseConfig(source, undefined, { process: null });
|
|
16
|
+
if (!shared.processes || !shared.run)
|
|
17
|
+
return undefined;
|
|
18
|
+
const options = new Map();
|
|
19
|
+
for (const name of shared.processes)
|
|
20
|
+
options.set(name, parseConfig(source, undefined, { process: name }).options);
|
|
21
|
+
// The document passed @dokebi/config's checks above; this reads what each process wrote.
|
|
22
|
+
const raw = parseDocument(source, { version: '1.2' }).toJS();
|
|
23
|
+
const own = new Map();
|
|
24
|
+
for (const name of shared.processes)
|
|
25
|
+
own.set(name, raw.processes?.[name]?.options ?? {});
|
|
26
|
+
return {
|
|
27
|
+
run: shared.run,
|
|
28
|
+
declared: shared.processes,
|
|
29
|
+
options,
|
|
30
|
+
shared: shared.options,
|
|
31
|
+
own,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The process set of the settings file the app reads (DOKEBI_CONFIG, else dokebi.yaml); undefined
|
|
36
|
+
* when it declares none or is not there. An invalid file is INVALID_CONFIG.
|
|
37
|
+
*/
|
|
38
|
+
export async function readProcessSet(root) {
|
|
39
|
+
let source;
|
|
40
|
+
try {
|
|
41
|
+
source = (await readProjectSettings(root)).source;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (isMissing(error))
|
|
45
|
+
return undefined;
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
return processSetOf(source);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (!(error instanceof ConfigError))
|
|
53
|
+
throw error;
|
|
54
|
+
throw new CliError('INVALID_CONFIG', `Invalid settings file: ${error.message}`, {
|
|
55
|
+
cause: error,
|
|
56
|
+
details: {
|
|
57
|
+
code: error.code,
|
|
58
|
+
line: error.line ?? null,
|
|
59
|
+
column: error.column ?? null,
|
|
60
|
+
fix: error.fix,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** The process set, or undefined when the file cannot be read or parsed (doctor reports that). */
|
|
66
|
+
export async function processSetOrNone(root) {
|
|
67
|
+
try {
|
|
68
|
+
return await readProcessSet(root);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
debug('Process set not read; one process', { error: describeError(error) });
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function section(options, key) {
|
|
76
|
+
const value = options[key];
|
|
77
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
78
|
+
? value
|
|
79
|
+
: {};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The worker count a process sets itself (`processes.<name>.options.application-runtime.workers`),
|
|
83
|
+
* or undefined. Under `dokebi dev` such a process runs that many (DOKEBI_DEV_WORKERS is for the
|
|
84
|
+
* processes that set none, D-0251): a worker kept at one is never multiplied by it.
|
|
85
|
+
*/
|
|
86
|
+
export function ownWorkers(set, name) {
|
|
87
|
+
const value = section(set.own.get(name) ?? {}, 'application-runtime').workers;
|
|
88
|
+
return typeof value === 'number' && Number.isInteger(value) && value >= 1 && value <= 64
|
|
89
|
+
? value
|
|
90
|
+
: undefined;
|
|
91
|
+
}
|
|
92
|
+
/** Whether a process with these options opens its web port (D-0221: `listen: false` does not). */
|
|
93
|
+
export function listens(options) {
|
|
94
|
+
return section(options, 'dokebi-web').listen !== false;
|
|
95
|
+
}
|
|
96
|
+
/** The first process of `run` that opens its web port: the one dev and start show and probe. */
|
|
97
|
+
export function webProcess(set) {
|
|
98
|
+
return set.run.find((name) => listens(set.options.get(name) ?? {}));
|
|
99
|
+
}
|
|
100
|
+
function names(list) {
|
|
101
|
+
return list.join(', ');
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* What the declared processes leave undone or do twice. Only work of a plugin the file configures
|
|
105
|
+
* is judged (a section in the shared options or in a process); a process of `processes` that
|
|
106
|
+
* `run` leaves out runs elsewhere (another folder whose `run` names it) and counts.
|
|
107
|
+
*/
|
|
108
|
+
export function processIssues(set) {
|
|
109
|
+
const issues = [];
|
|
110
|
+
const declared = set.declared;
|
|
111
|
+
const of = (name) => set.options.get(name) ?? {};
|
|
112
|
+
const configured = (key) => declared.some((name) => Object.hasOwn(of(name), key));
|
|
113
|
+
// Two processes of this folder on one port: the second one's start fails (EADDRINUSE).
|
|
114
|
+
const ports = new Map();
|
|
115
|
+
for (const name of configured('dokebi-web') ? set.run : []) {
|
|
116
|
+
const options = of(name);
|
|
117
|
+
if (!listens(options))
|
|
118
|
+
continue;
|
|
119
|
+
const web = section(options, 'dokebi-web');
|
|
120
|
+
const port = typeof web.port === 'number' ? web.port : 3000;
|
|
121
|
+
if (port === 0)
|
|
122
|
+
continue;
|
|
123
|
+
const host = typeof web.host === 'string' ? web.host : '';
|
|
124
|
+
const key = `${host}:${port}`;
|
|
125
|
+
ports.set(key, [...(ports.get(key) ?? []), name]);
|
|
126
|
+
}
|
|
127
|
+
for (const [key, list] of ports)
|
|
128
|
+
if (list.length > 1)
|
|
129
|
+
issues.push({
|
|
130
|
+
code: 'PROCESS_PORT_SHARED',
|
|
131
|
+
severity: 'error',
|
|
132
|
+
message: `Processes ${names(list)} both listen on port ${key.slice(key.lastIndexOf(':') + 1)}; the second one cannot start`,
|
|
133
|
+
fix: `keep one web process, or set dokebi-web.listen: false (or another port) in processes.<name>.options of the others`,
|
|
134
|
+
});
|
|
135
|
+
// A job queue whose jobs no declared process takes: they only pile up.
|
|
136
|
+
if (configured('dokebi-job')) {
|
|
137
|
+
const queues = new Set();
|
|
138
|
+
for (const name of declared)
|
|
139
|
+
for (const queue of Object.keys(section(section(of(name), 'dokebi-job'), 'queues')))
|
|
140
|
+
queues.add(queue);
|
|
141
|
+
for (const queue of queues) {
|
|
142
|
+
const taking = declared.filter((name) => section(section(section(of(name), 'dokebi-job'), 'queues'), queue).consume !== false);
|
|
143
|
+
if (taking.length === 0)
|
|
144
|
+
issues.push({
|
|
145
|
+
code: 'PROCESS_QUEUE_NOT_TAKEN',
|
|
146
|
+
severity: 'warning',
|
|
147
|
+
message: `No declared process takes the jobs of queue ${queue} (consume: false in ${names(declared)}): they only pile up`,
|
|
148
|
+
fix: `remove consume: false for queue ${queue} from the process that should run its jobs (processes.<worker>.options.dokebi-job.queues.${queue}), or declare that process`,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// The outbox, the schedules and partition upkeep: run by at least one process.
|
|
153
|
+
const off = (key, isOff, what, fix) => {
|
|
154
|
+
if (!configured(key))
|
|
155
|
+
return;
|
|
156
|
+
if (declared.every((name) => isOff(section(of(name), key))))
|
|
157
|
+
issues.push({
|
|
158
|
+
code: 'PROCESS_WORK_NOT_RUN',
|
|
159
|
+
severity: 'warning',
|
|
160
|
+
message: `No declared process runs ${what} (${names(declared)} all turn it off)`,
|
|
161
|
+
fix,
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
off('dokebi-outbox', (outbox) => section(outbox, 'runner').enabled === false, 'the outbox (dokebi-outbox.runner.enabled: false)', 'set dokebi-outbox.runner.enabled: true in the options of the process that runs background work');
|
|
165
|
+
off('dokebi-scheduler', (scheduler) => scheduler.enabled === false, 'the schedules (dokebi-scheduler.enabled: false)', 'set dokebi-scheduler.enabled: true in the options of the process that runs the schedules');
|
|
166
|
+
off('dokebi-partitions', (partitions) => partitions.intervalMs === 0 && partitions.runAtStart === false, 'partition upkeep (dokebi-partitions.intervalMs: 0 and runAtStart: false)', 'give one process dokebi-partitions.intervalMs above 0 or runAtStart: true');
|
|
167
|
+
// The schedules in several processes without coordination: each runs every schedule.
|
|
168
|
+
if (configured('dokebi-scheduler')) {
|
|
169
|
+
const running = declared.filter((name) => {
|
|
170
|
+
const scheduler = section(of(name), 'dokebi-scheduler');
|
|
171
|
+
return scheduler.enabled !== false && scheduler.coordination === undefined;
|
|
172
|
+
});
|
|
173
|
+
if (running.length > 1)
|
|
174
|
+
issues.push({
|
|
175
|
+
code: 'PROCESS_SCHEDULES_TWICE',
|
|
176
|
+
severity: 'warning',
|
|
177
|
+
message: `Processes ${names(running)} each run the schedules without coordination: every schedule runs in each of them`,
|
|
178
|
+
fix: 'set dokebi-scheduler.enabled: false in all but one of them, or give the scheduler coordination (Redis) in every process',
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
// One websocket-hub server id for two processes: they would take each other's presence.
|
|
182
|
+
if (configured('dokebi-websocket-hub')) {
|
|
183
|
+
const ids = new Map();
|
|
184
|
+
for (const name of declared) {
|
|
185
|
+
const hub = section(of(name), 'dokebi-websocket-hub');
|
|
186
|
+
if (hub.mode !== 'cluster' || typeof hub.serverId !== 'string')
|
|
187
|
+
continue;
|
|
188
|
+
ids.set(hub.serverId, [...(ids.get(hub.serverId) ?? []), name]);
|
|
189
|
+
}
|
|
190
|
+
for (const [id, list] of ids)
|
|
191
|
+
if (list.length > 1)
|
|
192
|
+
issues.push({
|
|
193
|
+
code: 'PROCESS_SERVER_ID_SHARED',
|
|
194
|
+
severity: 'error',
|
|
195
|
+
message: `Processes ${names(list)} share the websocket-hub serverId ${id}`,
|
|
196
|
+
fix: 'give each process its own dokebi-websocket-hub.serverId in processes.<name>.options',
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
return issues;
|
|
200
|
+
}
|
|
@@ -20,6 +20,7 @@ import { dependencyMap, validateProjectPackage } from './npm-client.js';
|
|
|
20
20
|
import { optionsFix } from './option-fixes.js';
|
|
21
21
|
import { checkPlugin, checkPluginsOptions } from './plugin-lifecycle.js';
|
|
22
22
|
import { PluginOptionsValidator } from './plugin-options.js';
|
|
23
|
+
import { processIssues, processSetOf } from './processes.js';
|
|
23
24
|
import { AGENTS_FILE, guideEntries, INSTALLED_END, INSTALLED_START, installedBlockEdited, PROJECT_END, PROJECT_START, projectBlockState, } from './project-guide.js';
|
|
24
25
|
import { readState } from './project-state.js';
|
|
25
26
|
import { ADMIN_SECTION, LEGACY_ADMIN_SECTION, SEED_FILE } from './recipe-login.js';
|
|
@@ -88,6 +89,18 @@ export function lockDiagnostic(holder, transactions) {
|
|
|
88
89
|
* of the fix in the installed template and its absence in the copy.
|
|
89
90
|
*/
|
|
90
91
|
/** The apps under src/apps with an Inertia browser entry (views/app.js), sorted by name. */
|
|
92
|
+
/** A section under a process's own values: maps key by key, anything else replaced (D-0251). */
|
|
93
|
+
function mergeSection(base, own) {
|
|
94
|
+
const map = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
95
|
+
if (own === undefined)
|
|
96
|
+
return base;
|
|
97
|
+
if (!map(base) || !map(own))
|
|
98
|
+
return own;
|
|
99
|
+
const merged = { ...base };
|
|
100
|
+
for (const [key, value] of Object.entries(own))
|
|
101
|
+
merged[key] = Object.hasOwn(base, key) ? mergeSection(base[key], value) : value;
|
|
102
|
+
return merged;
|
|
103
|
+
}
|
|
91
104
|
async function inertiaAppNames(root) {
|
|
92
105
|
const apps = await securePath(root, 'src/apps');
|
|
93
106
|
if (!(await exists(apps)))
|
|
@@ -213,6 +226,20 @@ export class ProjectInspector {
|
|
|
213
226
|
});
|
|
214
227
|
}
|
|
215
228
|
});
|
|
229
|
+
// D-0251: the processes of the settings file: what they leave undone (a queue no process
|
|
230
|
+
// takes, two on one port), and each process's own options checked against the plugin schemas
|
|
231
|
+
// below.
|
|
232
|
+
const processSet = config
|
|
233
|
+
? await check(configFile, async () => processSetOf(await readProjectConfigSource(root, settingsTarget.path)) ?? null)
|
|
234
|
+
: null;
|
|
235
|
+
for (const found of processSet ? processIssues(processSet) : [])
|
|
236
|
+
result.diagnostics.push({
|
|
237
|
+
code: found.code,
|
|
238
|
+
severity: found.severity,
|
|
239
|
+
path: configFile,
|
|
240
|
+
plugin: null,
|
|
241
|
+
hint: `${found.message}: ${found.fix}`,
|
|
242
|
+
});
|
|
216
243
|
result.requiredPlugins =
|
|
217
244
|
(await check('node_modules/@dokebi/core/package.json', () => readRequiredPlugins(root))) ??
|
|
218
245
|
[];
|
|
@@ -495,6 +522,25 @@ export class ProjectInspector {
|
|
|
495
522
|
// The commands name the section (options.logging for the logger host, D-0151).
|
|
496
523
|
hint: optionsFix(plugin.id, checked.errors, `correct options.${optionsKey(plugin)} in dokebi.yaml (npx dokebi plugins info ${plugin.id} --json lists the option keys)`, optionsKey(plugin), checked.schema),
|
|
497
524
|
});
|
|
525
|
+
// D-0251: a process that changes this section has its own options checked too (the
|
|
526
|
+
// shared section with the secrets file merged, under the process's own values).
|
|
527
|
+
if (processSet && installed && !configMissing)
|
|
528
|
+
for (const name of processSet.declared) {
|
|
529
|
+
const own = processSet.options.get(name)?.[key];
|
|
530
|
+
if (JSON.stringify(own) === JSON.stringify(processSet.shared[key]))
|
|
531
|
+
continue;
|
|
532
|
+
const merged = mergeSection(options, own);
|
|
533
|
+
const ownChecked = await check(path, async () => optionsValidator.check(root, installed, merged ?? {}), plugin.id);
|
|
534
|
+
if (ownChecked?.errors.length)
|
|
535
|
+
result.diagnostics.push({
|
|
536
|
+
code: 'INVALID_PLUGIN_OPTIONS',
|
|
537
|
+
severity: 'error',
|
|
538
|
+
path: `${configFile} (processes.${name})`,
|
|
539
|
+
plugin: plugin.id,
|
|
540
|
+
details: ownChecked.errors,
|
|
541
|
+
hint: `correct processes.${name}.options.${key} in ${configFile} (npx dokebi plugins info ${plugin.id} --json lists the option keys)`,
|
|
542
|
+
});
|
|
543
|
+
}
|
|
498
544
|
// D-0162: the plugin's own rules once its section passes the schema (checked below, all
|
|
499
545
|
// plugins in one restricted child).
|
|
500
546
|
if (settings.runChecks && installed && config && checked && !checked.errors.length)
|
package/dist/project-state.d.ts
CHANGED
|
@@ -41,6 +41,12 @@ export declare const APP_NAME: RegExp;
|
|
|
41
41
|
export interface ProjectConfig {
|
|
42
42
|
schemaVersion: 1;
|
|
43
43
|
options: Record<string, unknown>;
|
|
44
|
+
/** D-0251: the processes the file declares (`processes.<name>`), when it declares any. */
|
|
45
|
+
processes?: readonly string[];
|
|
46
|
+
/** D-0251: the processes this folder starts (`run`). */
|
|
47
|
+
run?: readonly string[];
|
|
48
|
+
/** D-0251: the process whose options `options` are (absent: the shared options). */
|
|
49
|
+
process?: string;
|
|
44
50
|
}
|
|
45
51
|
export declare function emptyState(generatedHash: string): ProjectState;
|
|
46
52
|
export declare function defaultInstallation(plugin: PluginManifest): Installation;
|
package/dist/project-state.js
CHANGED
|
@@ -125,5 +125,16 @@ export function readConfig(value) {
|
|
|
125
125
|
const config = object(value, 'config');
|
|
126
126
|
if (config.schemaVersion !== 1)
|
|
127
127
|
throw new CliError('INVALID_CONFIG', 'Unsupported config');
|
|
128
|
-
|
|
128
|
+
const names = (value) => Array.isArray(value) && value.every((item) => typeof item === 'string')
|
|
129
|
+
? value
|
|
130
|
+
: undefined;
|
|
131
|
+
const processes = names(config.processes);
|
|
132
|
+
const run = names(config.run);
|
|
133
|
+
return {
|
|
134
|
+
schemaVersion: 1,
|
|
135
|
+
options: object(config.options, 'options'),
|
|
136
|
+
...(processes ? { processes } : {}),
|
|
137
|
+
...(run ? { run } : {}),
|
|
138
|
+
...(typeof config.process === 'string' ? { process: config.process } : {}),
|
|
139
|
+
};
|
|
129
140
|
}
|