@akanjs/devkit 3.2.0-rc.12 → 3.2.0-rc.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/akanApp/akanApp.host.test.ts +113 -0
- package/akanApp/akanApp.host.ts +145 -1215
- package/akanApp/builderGap.ts +68 -0
- package/akanApp/builderRequestRelay.test.ts +93 -0
- package/akanApp/builderRequestRelay.ts +101 -0
- package/akanApp/builderRssRecycler.ts +182 -0
- package/akanApp/devBackend.ts +392 -0
- package/akanApp/devBuildStatusBoard.ts +128 -0
- package/akanApp/devBuilder.ts +196 -0
- package/akanApp/devIdleSuspend.test.ts +130 -0
- package/akanApp/devIdleSuspend.ts +169 -0
- package/akanApp/devRecycler.test.ts +66 -0
- package/akanApp/devRecycler.ts +305 -0
- package/akanApp/processRss.ts +61 -0
- package/akanConfig/akanConfig.test.ts +23 -0
- package/akanConfig/akanConfig.ts +9 -9
- package/executors/appExecutor.ts +448 -0
- package/executors/commandExecutionError.ts +53 -0
- package/executors/executor.ts +527 -0
- package/executors/libExecutor.ts +23 -0
- package/executors/moduleExecutor.ts +18 -0
- package/executors/pkgExecutor.ts +129 -0
- package/executors/sysExecutor.ts +301 -0
- package/executors/workspaceExecutor.ts +278 -0
- package/executors.test.ts +44 -0
- package/executors.ts +8 -1749
- package/package.json +3 -3
- package/scanInfo.ts +19 -8
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { Logger } from "akanjs/common";
|
|
3
|
+
import type { BuilderMessage, ChangeBatch, DevBuildStatus } from "akanjs/server";
|
|
4
|
+
import type { App } from "../commandDecorators";
|
|
5
|
+
import type { BackendImportGraph } from "./BackendImportGraph";
|
|
6
|
+
import type { BuilderGap } from "./builderGap";
|
|
7
|
+
import type { BuilderRssRecycler } from "./builderRssRecycler";
|
|
8
|
+
import type { DevBackend } from "./devBackend";
|
|
9
|
+
import type { BuilderRecoveryReason, DevBuilder } from "./devBuilder";
|
|
10
|
+
import type { DevBuildStatusBoard } from "./devBuildStatusBoard";
|
|
11
|
+
import {
|
|
12
|
+
backendRestartReasonFromMessage,
|
|
13
|
+
isLegacyBackendFallbackFile,
|
|
14
|
+
mergeInvalidateMessages,
|
|
15
|
+
shouldRefreshConfigOnIdleWake,
|
|
16
|
+
shouldRestartBackendByDevPlan,
|
|
17
|
+
shouldRestartBuilderByDevPlan,
|
|
18
|
+
shouldRestartDevHostByDevPlan,
|
|
19
|
+
} from "./devHostPolicy";
|
|
20
|
+
|
|
21
|
+
type InvalidateMessage = Extract<BuilderMessage, { type: "invalidate" }>;
|
|
22
|
+
|
|
23
|
+
export class DevRecycler {
|
|
24
|
+
readonly #app: App;
|
|
25
|
+
readonly #env: Record<string, string>;
|
|
26
|
+
readonly #logger: Logger;
|
|
27
|
+
readonly #isStopping: () => boolean;
|
|
28
|
+
readonly #graph: BackendImportGraph;
|
|
29
|
+
readonly #statuses: DevBuildStatusBoard;
|
|
30
|
+
readonly #backend: DevBackend;
|
|
31
|
+
readonly #builder: DevBuilder;
|
|
32
|
+
readonly #gap: BuilderGap;
|
|
33
|
+
readonly #rss: BuilderRssRecycler;
|
|
34
|
+
#pending: {
|
|
35
|
+
message: InvalidateMessage;
|
|
36
|
+
refreshConfig: boolean;
|
|
37
|
+
failed?: boolean;
|
|
38
|
+
failedGeneration?: number;
|
|
39
|
+
} | null = null;
|
|
40
|
+
//? A restart that failed after its change applied (the builder or backend did not come up): the builder's return is
|
|
41
|
+
//? its recovery, reported past the failure's generation so the scan overlay clears.
|
|
42
|
+
#restartFailedAfterApply: number | null = null;
|
|
43
|
+
|
|
44
|
+
constructor(
|
|
45
|
+
app: App,
|
|
46
|
+
parts: {
|
|
47
|
+
env: Record<string, string>;
|
|
48
|
+
logger: Logger;
|
|
49
|
+
isStopping: () => boolean;
|
|
50
|
+
graph: BackendImportGraph;
|
|
51
|
+
statuses: DevBuildStatusBoard;
|
|
52
|
+
backend: DevBackend;
|
|
53
|
+
builder: DevBuilder;
|
|
54
|
+
gap: BuilderGap;
|
|
55
|
+
rss: BuilderRssRecycler;
|
|
56
|
+
},
|
|
57
|
+
) {
|
|
58
|
+
this.#app = app;
|
|
59
|
+
this.#env = parts.env;
|
|
60
|
+
this.#logger = parts.logger;
|
|
61
|
+
this.#isStopping = parts.isStopping;
|
|
62
|
+
this.#graph = parts.graph;
|
|
63
|
+
this.#statuses = parts.statuses;
|
|
64
|
+
this.#backend = parts.backend;
|
|
65
|
+
this.#builder = parts.builder;
|
|
66
|
+
this.#gap = parts.gap;
|
|
67
|
+
this.#rss = parts.rss;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get pending(): boolean {
|
|
71
|
+
return !!this.#pending;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
drop(): void {
|
|
75
|
+
this.#pending = null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async handleInvalidate(message: InvalidateMessage) {
|
|
79
|
+
this.#logDevPlan(message);
|
|
80
|
+
this.#rss.rearm();
|
|
81
|
+
// Checked first: a dev-host restart also recycles the builder and backend.
|
|
82
|
+
const wantsDevHostRestart = shouldRestartDevHostByDevPlan(message);
|
|
83
|
+
const pending = this.#pending;
|
|
84
|
+
// A deferred recycle resumes on the next code batch; a css-only batch cannot heal a compile error.
|
|
85
|
+
const resumes = !!pending && message.kinds.includes("code") && this.#touchesFailedRecycle(message.files);
|
|
86
|
+
if (wantsDevHostRestart || shouldRestartBuilderByDevPlan(message) || resumes) {
|
|
87
|
+
const refreshConfig = wantsDevHostRestart || (pending?.refreshConfig ?? false);
|
|
88
|
+
const merged = pending ? mergeInvalidateMessages(pending.message, message) : message;
|
|
89
|
+
const generation = message.devPlan?.generation ?? message.generation;
|
|
90
|
+
if (this.#statuses.failedAt(generation)) {
|
|
91
|
+
this.#defer(merged, { refreshConfig, generation });
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
await this.apply(merged, refreshConfig);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (await this.#shouldRestartBackend(message)) {
|
|
98
|
+
this.#backend.scheduleRestart(backendRestartReasonFromMessage(message));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.#backend.send(message);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async apply(message: InvalidateMessage, refreshConfig: boolean): Promise<void> {
|
|
105
|
+
if (this.#isStopping()) return;
|
|
106
|
+
this.#pending = null;
|
|
107
|
+
const progress = { applied: !refreshConfig };
|
|
108
|
+
try {
|
|
109
|
+
if (refreshConfig) await this.#restartDevHost(message, progress);
|
|
110
|
+
else await this.#restartDevChildren(message);
|
|
111
|
+
} catch (err) {
|
|
112
|
+
const kind = refreshConfig ? "Config" : "Runtime metadata";
|
|
113
|
+
const generation = this.#recordRestartFailure(message, err, kind, { applied: progress.applied });
|
|
114
|
+
//? Kept only when the change itself did not apply: a builder that booted degraded (a broken akan.config.ts)
|
|
115
|
+
//? takes the fixing save itself and sends no invalidate, so without this the old config would keep running.
|
|
116
|
+
if (progress.applied) this.#restartFailedAfterApply = generation;
|
|
117
|
+
else this.#pending = { message, refreshConfig, failed: true, failedGeneration: generation };
|
|
118
|
+
this.#resurrectDevChildren(message);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//? The first green pages build after a failed restart that touches its change is the fix: the change applies then. A
|
|
123
|
+
//? cause no save fixes (an env value) waits for the next change of those files, not for every green save.
|
|
124
|
+
async resumeFailed(status: DevBuildStatus): Promise<void> {
|
|
125
|
+
const pending = this.#pending;
|
|
126
|
+
if (!pending?.failed || !status.ok || status.phase !== "pages" || !this.#touchesFailedRecycle(status.files)) return;
|
|
127
|
+
//? Newer than the failure: the batch that carried the change reports its own pages ok while the restart runs.
|
|
128
|
+
if (status.generation <= (pending.failedGeneration ?? -1)) return;
|
|
129
|
+
await this.apply(pending.message, pending.refreshConfig);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async applyIdleWake(batch: ChangeBatch | null): Promise<void> {
|
|
133
|
+
const files = batch?.files ?? [];
|
|
134
|
+
if (shouldRefreshConfigOnIdleWake(batch)) {
|
|
135
|
+
this.#logger.verbose("[idle-suspend] config changed while suspended; restarting the dev host");
|
|
136
|
+
// Replaces the backend too, and a baseline kept past its own gap costs a restart at the next one.
|
|
137
|
+
this.#gap.discard("config change replaces the backend anyway");
|
|
138
|
+
//? Through the same path as a save's: a failure is reported and stays pending, as one would be awake.
|
|
139
|
+
await this.apply({ type: "invalidate", kinds: [...(batch?.kinds ?? [])], files }, true);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
// Refresh before deciding: a file created while suspended is not in the graph yet.
|
|
143
|
+
if (files.length > 0) await this.#graph.refresh();
|
|
144
|
+
await this.#builder.start({ announceBootState: true });
|
|
145
|
+
// Merged: the watcher's batch and the stamps overlap on the ordinary one-save-during-suspend case.
|
|
146
|
+
const missed = await this.#gap.take();
|
|
147
|
+
const backendFiles = [...new Set([...files.filter((file) => this.#graph.has(file)), ...missed])];
|
|
148
|
+
if (backendFiles.length === 0) return;
|
|
149
|
+
this.#logger.verbose(`[idle-suspend] ${backendFiles.length} backend file(s) changed while suspended`);
|
|
150
|
+
this.#backend.scheduleRestart({ files: backendFiles, roles: [] });
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
builderRecovered(reason: BuilderRecoveryReason): void {
|
|
154
|
+
void this.#gap.restartBackendForChanges();
|
|
155
|
+
const failedAfterApply = this.#restartFailedAfterApply;
|
|
156
|
+
this.#restartFailedAfterApply = null;
|
|
157
|
+
const status: DevBuildStatus = {
|
|
158
|
+
generation:
|
|
159
|
+
failedAfterApply !== null
|
|
160
|
+
? this.#statuses.nextBackendGeneration(failedAfterApply + 1)
|
|
161
|
+
: (reason.generation ?? this.#statuses.nextBackendGeneration()),
|
|
162
|
+
phase: "scan",
|
|
163
|
+
ok: true,
|
|
164
|
+
files: reason.files,
|
|
165
|
+
message: "Builder recovered",
|
|
166
|
+
};
|
|
167
|
+
this.#statuses.record(status);
|
|
168
|
+
this.#backend.sendOrQueueStatus(status);
|
|
169
|
+
if (!this.#backend.running && !this.#backend.recovering) {
|
|
170
|
+
this.#backend.start({ generation: reason.generation, files: reason.files });
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
#touchesFailedRecycle(files: string[]): boolean {
|
|
175
|
+
const pending = this.#pending;
|
|
176
|
+
if (!pending?.failed) return true;
|
|
177
|
+
const changed = new Set(pending.message.files);
|
|
178
|
+
return files.some((file) => changed.has(file));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
#defer(message: InvalidateMessage, { refreshConfig, generation }: { refreshConfig: boolean; generation?: number }) {
|
|
182
|
+
this.#pending = { message, refreshConfig };
|
|
183
|
+
const kind = refreshConfig ? "Config" : "Runtime metadata";
|
|
184
|
+
this.#logger.warn(
|
|
185
|
+
`[dev-host] ${kind.toLowerCase()} restart deferred generation=${generation ?? "(unknown)"}; keeping the running dev server until the build error is fixed`,
|
|
186
|
+
);
|
|
187
|
+
const status: DevBuildStatus = {
|
|
188
|
+
generation: generation ?? this.#statuses.nextBackendGeneration(),
|
|
189
|
+
phase: "scan",
|
|
190
|
+
ok: false,
|
|
191
|
+
files: message.files,
|
|
192
|
+
message: `${kind} change is on hold while the build is failing; it will apply automatically once the error is fixed.`,
|
|
193
|
+
};
|
|
194
|
+
this.#statuses.record(status);
|
|
195
|
+
this.#backend.sendOrQueueStatus(status);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// The backend returns on the last-good artifact so the error overlay stays reachable.
|
|
199
|
+
#resurrectDevChildren(message: InvalidateMessage): void {
|
|
200
|
+
const generation = message.devPlan?.generation ?? message.generation;
|
|
201
|
+
if (!this.#backend.running) this.#backend.start({ generation, files: message.files });
|
|
202
|
+
this.#builder.scheduleRecovery({ generation, files: message.files });
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async #restartDevChildren(message: InvalidateMessage): Promise<void> {
|
|
206
|
+
const generation = message.devPlan?.generation ?? message.generation;
|
|
207
|
+
this.#logger.warn(
|
|
208
|
+
`[dev-host] recycling builder/backend for runtime metadata generation=${generation ?? "(unknown)"} files=${message.files.length}`,
|
|
209
|
+
);
|
|
210
|
+
await this.#recycleDevChildren(message);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// The config is re-imported with a cache-busting query, but modules it imports stay cached: a change inside an
|
|
214
|
+
// imported plugin file still needs a manual `akan start` restart.
|
|
215
|
+
async #restartDevHost(message: InvalidateMessage, progress?: { applied: boolean }): Promise<void> {
|
|
216
|
+
const generation = message.devPlan?.generation ?? message.generation;
|
|
217
|
+
this.#logger.warn(
|
|
218
|
+
`[dev-host] config change detected; restarting dev host generation=${generation ?? "(unknown)"} files=${message.files.length}`,
|
|
219
|
+
);
|
|
220
|
+
await this.#recycleDevChildren(message, { refreshConfig: true, progress });
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async #recycleDevChildren(
|
|
224
|
+
message: InvalidateMessage,
|
|
225
|
+
{ refreshConfig = false, progress }: { refreshConfig?: boolean; progress?: { applied: boolean } } = {},
|
|
226
|
+
): Promise<void> {
|
|
227
|
+
const generation = message.devPlan?.generation ?? message.generation;
|
|
228
|
+
this.#backend.cancelTimers();
|
|
229
|
+
this.#builder.cancelRecovery();
|
|
230
|
+
this.#builder.resetRecovery();
|
|
231
|
+
this.#backend.dropPendingRestart();
|
|
232
|
+
await this.#backend.restarting;
|
|
233
|
+
this.#statuses.reset();
|
|
234
|
+
this.#backend.dropQueuedStatuses();
|
|
235
|
+
await this.#backend.stop();
|
|
236
|
+
this.#builder.stop();
|
|
237
|
+
this.#builder.clearPatcherOff();
|
|
238
|
+
if (refreshConfig) {
|
|
239
|
+
await this.#app.getConfig({ refresh: true });
|
|
240
|
+
// Merge, not replace: `start()` added values prepare does not produce (REDIS_HOST from the tunnel).
|
|
241
|
+
const { env } = await this.#app.prepareCommand("start");
|
|
242
|
+
Object.assign(this.#env, env);
|
|
243
|
+
if (progress) progress.applied = true;
|
|
244
|
+
}
|
|
245
|
+
await this.#graph.refresh();
|
|
246
|
+
await this.#builder.start();
|
|
247
|
+
this.#backend.start({ generation, files: message.files });
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
#recordRestartFailure(
|
|
251
|
+
message: InvalidateMessage,
|
|
252
|
+
err: unknown,
|
|
253
|
+
kind: "Config" | "Runtime metadata",
|
|
254
|
+
{ applied }: { applied: boolean },
|
|
255
|
+
): number {
|
|
256
|
+
const generation = message.devPlan?.generation ?? message.generation ?? this.#statuses.nextBackendGeneration();
|
|
257
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
258
|
+
this.#logger.warn(`[dev-host] ${kind.toLowerCase()} restart failed generation=${generation}: ${detail}`);
|
|
259
|
+
const names = message.files.slice(0, 3).map((file) => path.basename(file));
|
|
260
|
+
const saved = names.length > 0 ? names.join(", ") : "the changed file";
|
|
261
|
+
const status: DevBuildStatus = {
|
|
262
|
+
generation,
|
|
263
|
+
phase: "scan",
|
|
264
|
+
ok: false,
|
|
265
|
+
files: message.files,
|
|
266
|
+
message: applied
|
|
267
|
+
? `${kind} change applied, but the dev server failed to restart: ${detail}. It is recovering on its own.`
|
|
268
|
+
: `${kind} change failed to apply: ${detail}. The dev server keeps running on the previous ${kind.toLowerCase()}; once it is fixed, save ${saved} again or restart the dev server to apply it.`,
|
|
269
|
+
};
|
|
270
|
+
this.#statuses.record(status);
|
|
271
|
+
this.#backend.sendOrQueueStatus(status);
|
|
272
|
+
return generation;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
#logDevPlan(message: InvalidateMessage): void {
|
|
276
|
+
if (!message.devPlan) return;
|
|
277
|
+
const { generation, roles, actions, reasonByFile } = message.devPlan;
|
|
278
|
+
this.#logger.verbose(
|
|
279
|
+
`[dev-plan] generation=${generation} roles=${roles.join(",") || "(none)"} actions=${actions.join(",") || "(none)"} reasons=${Object.keys(reasonByFile).length}`,
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async #shouldRestartBackend(message: InvalidateMessage): Promise<boolean> {
|
|
284
|
+
if (message.kinds.length === 1 && message.kinds[0] === "css") return false;
|
|
285
|
+
if (message.devPlan) {
|
|
286
|
+
const shouldRestart = shouldRestartBackendByDevPlan(message) ?? false;
|
|
287
|
+
if (shouldRestart && message.kinds.includes("code")) await this.#graph.refresh();
|
|
288
|
+
return shouldRestart;
|
|
289
|
+
}
|
|
290
|
+
if (message.kinds.includes("code")) await this.#graph.refresh();
|
|
291
|
+
if (message.files.some((file) => this.#graph.has(file))) return true;
|
|
292
|
+
if (!this.#graph.lastRefreshSucceeded) {
|
|
293
|
+
const fallbackFiles = message.files.filter((file) =>
|
|
294
|
+
isLegacyBackendFallbackFile(file, this.#app.workspace.workspaceRoot),
|
|
295
|
+
);
|
|
296
|
+
if (fallbackFiles.length > 0) {
|
|
297
|
+
this.#logger.warn(
|
|
298
|
+
`[backend-graph] using path-role fallback for legacy invalidate; restart files=${fallbackFiles.length}`,
|
|
299
|
+
);
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const PS_RSS_TIMEOUT_MS = 2_000;
|
|
2
|
+
|
|
3
|
+
export class ProcessRss {
|
|
4
|
+
static async bytesOf(pid: number): Promise<number | null> {
|
|
5
|
+
if (process.platform === "win32")
|
|
6
|
+
return await ProcessRss.#readRssKbVia(
|
|
7
|
+
["tasklist", "/FI", `PID eq ${pid}`, "/FO", "CSV", "/NH"],
|
|
8
|
+
ProcessRss.#tasklistRssKb,
|
|
9
|
+
);
|
|
10
|
+
if (process.platform === "darwin") {
|
|
11
|
+
const footprintBytes = await ProcessRss.#readRssKbVia(
|
|
12
|
+
["footprint", "-p", String(pid), "-f", "bytes"],
|
|
13
|
+
ProcessRss.#footprintKb,
|
|
14
|
+
);
|
|
15
|
+
if (footprintBytes !== null) return footprintBytes;
|
|
16
|
+
}
|
|
17
|
+
const status = await Bun.file(`/proc/${pid}/status`)
|
|
18
|
+
.text()
|
|
19
|
+
.catch(() => null);
|
|
20
|
+
const vmRssKb = status === null ? null : /VmRSS:\s+(\d+) kB/.exec(status)?.[1];
|
|
21
|
+
if (vmRssKb) return Number(vmRssKb) * 1024;
|
|
22
|
+
return await ProcessRss.#readRssKbVia(["ps", "-o", "rss=", "-p", String(pid)], (output) => Number(output.trim()));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Bounded: a `ps` that hangs under load would silently cancel the recycle awaiting it.
|
|
26
|
+
static async #readRssKbVia(
|
|
27
|
+
command: string[],
|
|
28
|
+
parseKb: (output: string) => number,
|
|
29
|
+
timeoutMs = PS_RSS_TIMEOUT_MS,
|
|
30
|
+
): Promise<number | null> {
|
|
31
|
+
let proc: Bun.Subprocess<"ignore", "pipe", "ignore">;
|
|
32
|
+
try {
|
|
33
|
+
proc = Bun.spawn(command, { stdio: ["ignore", "pipe", "ignore"] });
|
|
34
|
+
} catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const killer = setTimeout(() => proc.kill("SIGKILL"), timeoutMs);
|
|
38
|
+
try {
|
|
39
|
+
const output = await new Response(proc.stdout).text();
|
|
40
|
+
await proc.exited;
|
|
41
|
+
const rssKb = parseKb(output);
|
|
42
|
+
return Number.isFinite(rssKb) && rssKb > 0 ? rssKb * 1024 : null;
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
} finally {
|
|
46
|
+
clearTimeout(killer);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// `Mem Usage` is the working set (what `process.memoryUsage.rss()` reports on Windows) in locale-grouped KB.
|
|
51
|
+
static #tasklistRssKb(output: string): number {
|
|
52
|
+
const memUsage = /"([^"]*)"\s*$/m.exec(output)?.[1];
|
|
53
|
+
return memUsage ? Number(memUsage.replace(/\D/g, "")) : Number.NaN;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// The footprint is what `process.memoryUsage.rss()` reports on macOS; `ps` also counts pages freed for reuse.
|
|
57
|
+
static #footprintKb(output: string): number {
|
|
58
|
+
const bytes = /Footprint: (\d+) B\b/.exec(output)?.[1];
|
|
59
|
+
return bytes ? Number(bytes) / 1024 : Number.NaN;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -1079,6 +1079,29 @@ describe("AkanAppConfig.importConfigModule", () => {
|
|
|
1079
1079
|
});
|
|
1080
1080
|
});
|
|
1081
1081
|
|
|
1082
|
+
describe("AkanAppConfig.from", () => {
|
|
1083
|
+
test("a busted reload re-reads an edited lib config", async () => {
|
|
1084
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "akan-config-lib-bust-"));
|
|
1085
|
+
try {
|
|
1086
|
+
const libConfigPath = path.join(root, "libs/extlib/akan.config.ts");
|
|
1087
|
+
fs.mkdirSync(path.join(root, "apps/extapp"), { recursive: true });
|
|
1088
|
+
fs.mkdirSync(path.join(root, "libs/extlib"), { recursive: true });
|
|
1089
|
+
fs.writeFileSync(path.join(root, "apps/extapp/akan.config.ts"), "export default {};\n");
|
|
1090
|
+
fs.writeFileSync(libConfigPath, "export default { externalLibs: ['first'] };\n");
|
|
1091
|
+
fs.writeFileSync(path.join(root, "package.json"), JSON.stringify({ name: "extrepo", version: "1.0.0" }));
|
|
1092
|
+
fs.writeFileSync(path.join(root, ".env"), "AKAN_PUBLIC_REPO_NAME=extrepo\nAKAN_PUBLIC_SERVE_DOMAIN=ext.test\n");
|
|
1093
|
+
const workspace = WorkspaceExecutor.fromRoot({ workspaceRoot: root, repoName: "extrepo" });
|
|
1094
|
+
const app = AppExecutor.from(workspace, "extapp");
|
|
1095
|
+
expect((await AkanAppConfig.from(app)).externalLibs).toEqual(["first"]);
|
|
1096
|
+
|
|
1097
|
+
fs.writeFileSync(libConfigPath, "export default { externalLibs: ['second'] };\n");
|
|
1098
|
+
expect((await AkanAppConfig.from(app, { bustImportCache: true })).externalLibs).toEqual(["second"]);
|
|
1099
|
+
} finally {
|
|
1100
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
1101
|
+
}
|
|
1102
|
+
});
|
|
1103
|
+
});
|
|
1104
|
+
|
|
1082
1105
|
describe("pipeline and workspace keys in app and lib configs", () => {
|
|
1083
1106
|
test("an app's pipeline is dropped before the instance exists, so it never reaches akan.app.json", async () => {
|
|
1084
1107
|
const config = await loadExtAppConfig(
|
package/akanConfig/akanConfig.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { type AkanI18nConfig, resolveAkanI18nConfig, trimSlashes } from "akanjs/
|
|
|
7
7
|
import type { ServerPolicy } from "akanjs/native/api";
|
|
8
8
|
import type { AkanImageConfig } from "akanjs/server";
|
|
9
9
|
import type { App, Lib } from "../commandDecorators";
|
|
10
|
-
import {
|
|
10
|
+
import { WorkspaceExecutor } from "../executors/workspaceExecutor";
|
|
11
11
|
import { ServerEnvProfile } from "../transforms/serverEnvProfile";
|
|
12
12
|
import type { BaseDevEnv, PackageJson } from "../types";
|
|
13
13
|
import { AkanBin } from "./akanBin";
|
|
@@ -708,16 +708,16 @@ CMD [${command.map((c) => `"${c}"`).join(",")}]`;
|
|
|
708
708
|
//* Every workspace lib is read, not just this app's lib deps: narrowing the set needs the dependency
|
|
709
709
|
//* scan, and the incremental page rebundle re-reads this config on every file change.
|
|
710
710
|
static async #collectLibContributions(app: App, libs: string[], bustImportCache: boolean): Promise<LibContributions> {
|
|
711
|
+
//? Imported on use: sysExecutor.ts imports this file, so a static import would load a SysExecutor subclass first.
|
|
712
|
+
const { LibExecutor } = await import("../executors/libExecutor");
|
|
711
713
|
const libConfigs = await Promise.all(
|
|
712
714
|
libs.map(async (libName) =>
|
|
713
|
-
LibExecutor.from(app, libName)
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
return null;
|
|
720
|
-
}),
|
|
715
|
+
AkanLibConfig.from(LibExecutor.from(app, libName), { bustImportCache }).catch((error: unknown) => {
|
|
716
|
+
//? Skipping a refused lib config would build the image without its docker steps, and the build would pass.
|
|
717
|
+
if (error instanceof LibConfigRefusal) throw error;
|
|
718
|
+
app.logger.warn(`Skipped libs/${libName}/akan.config.ts contributions: ${String(error)}`);
|
|
719
|
+
return null;
|
|
720
|
+
}),
|
|
721
721
|
),
|
|
722
722
|
);
|
|
723
723
|
return {
|