@camunda8/cli 4.7.0-alpha.3 → 4.7.0-alpha.30
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/CONTEXT.md +11 -0
- package/PLUGIN-HELP.md +1 -1
- package/README.md +9 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +48 -9
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/helpers/deploy-helpers.d.ts +96 -2
- package/dist/commands/helpers/deploy-helpers.d.ts.map +1 -1
- package/dist/commands/helpers/deploy-helpers.js +213 -70
- package/dist/commands/helpers/deploy-helpers.js.map +1 -1
- package/dist/commands/mcp-proxy.d.ts.map +1 -1
- package/dist/commands/mcp-proxy.js +13 -8
- package/dist/commands/mcp-proxy.js.map +1 -1
- package/dist/commands/profiles.d.ts.map +1 -1
- package/dist/commands/profiles.js +13 -7
- package/dist/commands/profiles.js.map +1 -1
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +1 -8
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/watch.d.ts.map +1 -1
- package/dist/commands/watch.js +309 -16
- package/dist/commands/watch.js.map +1 -1
- package/dist/core/client.d.ts +13 -0
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/client.js +48 -21
- package/dist/core/client.js.map +1 -1
- package/dist/core/config.d.ts +34 -3
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +91 -9
- package/dist/core/config.js.map +1 -1
- package/dist/core/env-address.d.ts +22 -0
- package/dist/core/env-address.d.ts.map +1 -0
- package/dist/core/env-address.js +30 -0
- package/dist/core/env-address.js.map +1 -0
- package/dist/core/errors.d.ts +17 -0
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +32 -0
- package/dist/core/errors.js.map +1 -1
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/logger.d.ts.map +1 -1
- package/dist/core/logger.js +2 -1
- package/dist/core/logger.js.map +1 -1
- package/dist/core/node-version.d.ts +18 -0
- package/dist/core/node-version.d.ts.map +1 -0
- package/dist/core/node-version.js +38 -0
- package/dist/core/node-version.js.map +1 -0
- package/dist/default-plugins/cluster/README.md +1 -1
- package/dist/default-plugins/cluster/c8ctl-plugin.js +289 -36
- package/dist/default-plugins/element-template/c8ctl-plugin.js +248 -7
- package/dist/default-plugins/mcp/README.md +33 -0
- package/dist/default-plugins/mcp/c8ctl-plugin.js +4870 -0
- package/dist/default-plugins/mcp/package.json +8 -0
- package/dist/default-plugins/modeler/README.md +23 -0
- package/dist/default-plugins/modeler/c8ctl-plugin.js +4314 -0
- package/dist/default-plugins/modeler/package.json +8 -0
- package/dist/default-plugins/setup/README.md +43 -0
- package/dist/default-plugins/setup/c8ctl-plugin.js +6903 -0
- package/dist/default-plugins/setup/package.json +8 -0
- package/dist/default-plugins/skills/README.md +35 -0
- package/dist/default-plugins/skills/c8ctl-plugin.js +3352 -0
- package/dist/default-plugins/skills/package.json +8 -0
- package/dist/framework/argv-parser.d.ts +14 -0
- package/dist/framework/argv-parser.d.ts.map +1 -1
- package/dist/framework/argv-parser.js +25 -0
- package/dist/framework/argv-parser.js.map +1 -1
- package/dist/framework/command-registry.d.ts +26 -0
- package/dist/framework/command-registry.d.ts.map +1 -1
- package/dist/framework/command-registry.js +45 -0
- package/dist/framework/command-registry.js.map +1 -1
- package/dist/framework/plugins/plugin-loader.d.ts +20 -2
- package/dist/framework/plugins/plugin-loader.d.ts.map +1 -1
- package/dist/framework/plugins/plugin-loader.js.map +1 -1
- package/dist/framework/ui/help.d.ts.map +1 -1
- package/dist/framework/ui/help.js +57 -14
- package/dist/framework/ui/help.js.map +1 -1
- package/dist/framework/ui/prompt.d.ts +88 -0
- package/dist/framework/ui/prompt.d.ts.map +1 -1
- package/dist/framework/ui/prompt.js +344 -0
- package/dist/framework/ui/prompt.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +68 -12
- package/dist/index.js.map +1 -1
- package/dist/utils/command-local/mcp-install-helpers.d.ts +49 -0
- package/dist/utils/command-local/mcp-install-helpers.d.ts.map +1 -0
- package/dist/utils/command-local/mcp-install-helpers.js +394 -0
- package/dist/utils/command-local/mcp-install-helpers.js.map +1 -0
- package/dist/utils/command-local/process-instance-helpers.d.ts +6 -0
- package/dist/utils/command-local/process-instance-helpers.d.ts.map +1 -1
- package/dist/utils/command-local/process-instance-helpers.js +9 -0
- package/dist/utils/command-local/process-instance-helpers.js.map +1 -1
- package/dist/utils/command-local/skills-install-helpers.d.ts +45 -0
- package/dist/utils/command-local/skills-install-helpers.d.ts.map +1 -0
- package/dist/utils/command-local/skills-install-helpers.js +423 -0
- package/dist/utils/command-local/skills-install-helpers.js.map +1 -0
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/shared/camunda-json.d.ts +24 -3
- package/dist/utils/shared/camunda-json.d.ts.map +1 -1
- package/dist/utils/shared/camunda-json.js +23 -5
- package/dist/utils/shared/camunda-json.js.map +1 -1
- package/dist/utils/shared/deploy-resource-selection.d.ts +165 -0
- package/dist/utils/shared/deploy-resource-selection.d.ts.map +1 -0
- package/dist/utils/shared/deploy-resource-selection.js +466 -0
- package/dist/utils/shared/deploy-resource-selection.js.map +1 -0
- package/dist/utils/shared/ignore.d.ts +26 -0
- package/dist/utils/shared/ignore.d.ts.map +1 -1
- package/dist/utils/shared/ignore.js +6 -2
- package/dist/utils/shared/ignore.js.map +1 -1
- package/package.json +3 -2
- package/dist/utils/command-local/setup-prerequisites.d.ts +0 -67
- package/dist/utils/command-local/setup-prerequisites.d.ts.map +0 -1
- package/dist/utils/command-local/setup-prerequisites.js +0 -238
- package/dist/utils/command-local/setup-prerequisites.js.map +0 -1
|
@@ -10,21 +10,26 @@
|
|
|
10
10
|
|
|
11
11
|
import { spawn, execFileSync } from 'node:child_process';
|
|
12
12
|
import {
|
|
13
|
+
closeSync,
|
|
13
14
|
createWriteStream,
|
|
14
15
|
existsSync,
|
|
16
|
+
fstatSync,
|
|
15
17
|
mkdirSync,
|
|
18
|
+
openSync,
|
|
16
19
|
writeFileSync,
|
|
17
20
|
renameSync,
|
|
18
21
|
rmSync,
|
|
19
22
|
readdirSync,
|
|
20
23
|
readFileSync,
|
|
24
|
+
readSync,
|
|
21
25
|
statSync,
|
|
22
26
|
} from 'node:fs';
|
|
23
27
|
import { once } from 'node:events';
|
|
24
28
|
import { chmod } from 'node:fs/promises';
|
|
25
29
|
import { homedir, platform as osPlatform, arch as osArch } from 'node:os';
|
|
26
|
-
import { join, dirname, isAbsolute, resolve } from 'node:path';
|
|
30
|
+
import { join, dirname, basename, isAbsolute, resolve } from 'node:path';
|
|
27
31
|
import { finished } from 'node:stream/promises';
|
|
32
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
28
33
|
import { fileURLToPath } from 'node:url';
|
|
29
34
|
|
|
30
35
|
// ---------------------------------------------------------------------------
|
|
@@ -210,37 +215,57 @@ function readLocalAliasMapping(cacheDir, alias) {
|
|
|
210
215
|
const filePath = getAliasMappingPath(cacheDir, alias);
|
|
211
216
|
if (!existsSync(filePath)) return null;
|
|
212
217
|
try {
|
|
213
|
-
const value = readFileSync(filePath, 'utf-8').trim();
|
|
214
218
|
// Only use the cached mapping if the version is actually installed
|
|
215
|
-
|
|
216
|
-
if (isC8RunInstalled(config)) return value;
|
|
217
|
-
|
|
218
|
-
// For rolling versions (minor version patterns like "8.9"), check if any
|
|
219
|
-
// installed version matches the minor version prefix (e.g. "8.9" matches
|
|
220
|
-
// "8.9.5"). This prevents re-downloading a rolling alias when a compatible
|
|
221
|
-
// pinned version is already installed locally (#431).
|
|
222
|
-
if (isMinorVersionPattern(value)) {
|
|
223
|
-
const installedVersions = getInstalledVersionsList(cacheDir)
|
|
224
|
-
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
|
|
225
|
-
const match = installedVersions
|
|
226
|
-
.filter((v) => v.startsWith(value + '.'))
|
|
227
|
-
.reverse()
|
|
228
|
-
.find((v) => isC8RunInstalled({ cacheDir, version: v }));
|
|
229
|
-
if (match) return match;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return null;
|
|
219
|
+
return findInstalledAliasTarget(cacheDir, readFileSync(filePath, 'utf-8').trim(), alias);
|
|
233
220
|
} catch {
|
|
234
221
|
return null;
|
|
235
222
|
}
|
|
236
223
|
}
|
|
237
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Return the installed version that satisfies an alias target, or null.
|
|
227
|
+
* An exact install wins; for a rolling minor pattern ("8.9") the highest
|
|
228
|
+
* installed pin in that minor line ("8.9.5") also counts, so a compatible
|
|
229
|
+
* pinned install is not re-downloaded (#431). For `stable`, an install whose
|
|
230
|
+
* build is a prerelease never counts — whether pinned ("c8run-8.10.0-alpha1")
|
|
231
|
+
* or a rolling dir that still holds an alpha build ("c8run-8.10/c8run-8.10.0-alpha1").
|
|
232
|
+
*/
|
|
233
|
+
function findInstalledAliasTarget(cacheDir, value, alias) {
|
|
234
|
+
const accepts = (version) => {
|
|
235
|
+
const binaryPath = findC8RunBinaryPath({ cacheDir, version });
|
|
236
|
+
if (!binaryPath) return false;
|
|
237
|
+
return alias !== 'stable' || !isPrereleaseBuild(basename(dirname(binaryPath)));
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
if (accepts(value)) return value;
|
|
241
|
+
|
|
242
|
+
if (isMinorVersionPattern(value)) {
|
|
243
|
+
const installedVersions = getInstalledVersionsList(cacheDir)
|
|
244
|
+
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
|
|
245
|
+
const match = installedVersions
|
|
246
|
+
.filter((v) => v.startsWith(value + '.'))
|
|
247
|
+
.reverse()
|
|
248
|
+
.find(accepts);
|
|
249
|
+
if (match) return match;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** True for a build dir like "c8run-8.10.0-alpha1" (anything with a semver prerelease suffix). */
|
|
256
|
+
function isPrereleaseBuild(buildDirName) {
|
|
257
|
+
return /^c8run-\d+\.\d+(\.\d+)?-/.test(buildDirName);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Persist an alias mapping. Returns false if it could not be written. */
|
|
238
261
|
export function storeLocalAliasMapping(cacheDir, alias, resolved) {
|
|
239
262
|
try {
|
|
240
263
|
mkdirSync(cacheDir, { recursive: true });
|
|
241
264
|
writeFileSync(getAliasMappingPath(cacheDir, alias), resolved);
|
|
265
|
+
return true;
|
|
242
266
|
} catch {
|
|
243
267
|
// Best-effort — don't break the command if we can't persist
|
|
268
|
+
return false;
|
|
244
269
|
}
|
|
245
270
|
}
|
|
246
271
|
|
|
@@ -265,16 +290,21 @@ export function _resetDynamicAliasCache() {
|
|
|
265
290
|
}
|
|
266
291
|
|
|
267
292
|
/**
|
|
268
|
-
* Non-blocking background check: query the remote download server and
|
|
269
|
-
*
|
|
293
|
+
* Non-blocking background check: query the remote download server and act
|
|
294
|
+
* if the remote alias resolves to a newer minor than the one being started.
|
|
295
|
+
*
|
|
296
|
+
* - Newer version already installed (e.g. via `cluster install 8.10`): the
|
|
297
|
+
* persisted alias mapping is advanced to it, so the *next* `start` uses it.
|
|
298
|
+
* Nothing is downloaded — the user already chose to install that version.
|
|
299
|
+
* - Newer version not installed: only a hint is printed; the mapping is left
|
|
300
|
+
* alone so `start` never silently switches to a version it would have to
|
|
301
|
+
* download.
|
|
270
302
|
*
|
|
271
|
-
*
|
|
272
|
-
* updated when the user explicitly runs `cluster install`, keeping `start`
|
|
273
|
-
* deterministic across runs.
|
|
303
|
+
* The current run is never affected: it has already resolved its version.
|
|
274
304
|
*
|
|
275
305
|
* Returns the fire-and-forget promise (for testing).
|
|
276
306
|
*/
|
|
277
|
-
export function checkBackgroundAliasFreshness(versionSpec, resolvedVersion) {
|
|
307
|
+
export function checkBackgroundAliasFreshness(versionSpec, resolvedVersion, cacheDir) {
|
|
278
308
|
const logger = getLogger();
|
|
279
309
|
const controller = new AbortController();
|
|
280
310
|
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
|
@@ -285,7 +315,22 @@ export function checkBackgroundAliasFreshness(versionSpec, resolvedVersion) {
|
|
|
285
315
|
if (html) {
|
|
286
316
|
const remote = parseVersionsFromHtml(html);
|
|
287
317
|
const remoteVersion = remote?.[versionSpec];
|
|
288
|
-
if (remoteVersion
|
|
318
|
+
if (!remoteVersion || !isRemoteMinorNewer(remoteVersion, resolvedVersion)) return;
|
|
319
|
+
const installed = cacheDir && findInstalledAliasTarget(cacheDir, remoteVersion, versionSpec);
|
|
320
|
+
if (installed) {
|
|
321
|
+
if (storeLocalAliasMapping(cacheDir, versionSpec, remoteVersion)) {
|
|
322
|
+
logger.info(
|
|
323
|
+
`"${versionSpec}" now resolves to ${remoteVersion}, which is already installed. ` +
|
|
324
|
+
`The next "c8ctl cluster start ${versionSpec}" will use it.`,
|
|
325
|
+
);
|
|
326
|
+
} else {
|
|
327
|
+
// Name the exact install: a plain "8.10" would look for c8run-8.10 and download it.
|
|
328
|
+
logger.info(
|
|
329
|
+
`"${versionSpec}" now resolves to ${remoteVersion}, which is already installed, ` +
|
|
330
|
+
`but the cached alias could not be updated. Start it with: c8ctl cluster start ${installed}`,
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
} else {
|
|
289
334
|
logger.info(
|
|
290
335
|
`A newer "${versionSpec}" release is available (${remoteVersion}). ` +
|
|
291
336
|
`Install it with: c8ctl cluster install ${versionSpec}`,
|
|
@@ -310,6 +355,25 @@ function fireAndForget(promise) {
|
|
|
310
355
|
return promise.catch(() => {});
|
|
311
356
|
}
|
|
312
357
|
|
|
358
|
+
/**
|
|
359
|
+
* Give the background `start` hints (alias freshness, rolling update) a short,
|
|
360
|
+
* bounded chance to print before a failed start calls process.exit(), which
|
|
361
|
+
* would otherwise drop them mid-flight. A failed start is when a newer version
|
|
362
|
+
* is most worth knowing about.
|
|
363
|
+
*/
|
|
364
|
+
export async function flushStartHints(config, timeoutMs = 1000) {
|
|
365
|
+
const pending = [config?._aliasHintPromise, config?._hintPromise].filter(Boolean);
|
|
366
|
+
if (pending.length === 0) return;
|
|
367
|
+
let timer;
|
|
368
|
+
await Promise.race([
|
|
369
|
+
Promise.all(pending),
|
|
370
|
+
new Promise((resolve) => {
|
|
371
|
+
timer = setTimeout(resolve, timeoutMs);
|
|
372
|
+
}),
|
|
373
|
+
]);
|
|
374
|
+
clearTimeout(timer);
|
|
375
|
+
}
|
|
376
|
+
|
|
313
377
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
314
378
|
|
|
315
379
|
// ---------------------------------------------------------------------------
|
|
@@ -414,7 +478,7 @@ const CLUSTER_STARTUP_TIMEOUT_MS = 120000;
|
|
|
414
478
|
const HEALTH_CHECK_TIMEOUT_MS = 3_000;
|
|
415
479
|
const ALIAS_COLUMN_WIDTH = 22;
|
|
416
480
|
|
|
417
|
-
function getCacheDir() {
|
|
481
|
+
export function getCacheDir() {
|
|
418
482
|
const envDir = process.env.C8RUN_CACHE_DIR;
|
|
419
483
|
if (envDir) {
|
|
420
484
|
return envDir;
|
|
@@ -1578,12 +1642,27 @@ export async function ensureC8RunInstalled(config) {
|
|
|
1578
1642
|
|
|
1579
1643
|
const STARTUP_SUMMARY_MARKER = '- Operate:';
|
|
1580
1644
|
|
|
1581
|
-
|
|
1645
|
+
/**
|
|
1646
|
+
* c8run's zerolog console lines (`9:57AM INF …`). The summary is printed
|
|
1647
|
+
* as soon as Camunda is healthy, but the captured output continues with
|
|
1648
|
+
* these log lines while the Connectors runtime still starts. Cut there —
|
|
1649
|
+
* printing them after the summary looks like the cluster started twice.
|
|
1650
|
+
*/
|
|
1651
|
+
const C8RUN_LOG_LINE =
|
|
1652
|
+
/^\d{1,2}:\d{2}(?::\d{2})?(?:AM|PM)?\s+(?:DBG|INF|WRN|ERR|FTL|PNC|TRC)\s/;
|
|
1653
|
+
|
|
1654
|
+
export function extractStartupSummary(rawOutput) {
|
|
1582
1655
|
const startIndex = rawOutput.indexOf(STARTUP_SUMMARY_MARKER);
|
|
1583
1656
|
if (startIndex === -1) {
|
|
1584
1657
|
return null;
|
|
1585
1658
|
}
|
|
1586
|
-
|
|
1659
|
+
const lines = rawOutput.slice(startIndex).split('\n');
|
|
1660
|
+
const summaryLines = [];
|
|
1661
|
+
for (const line of lines) {
|
|
1662
|
+
if (C8RUN_LOG_LINE.test(line.trimStart())) break;
|
|
1663
|
+
summaryLines.push(line);
|
|
1664
|
+
}
|
|
1665
|
+
return summaryLines.join('\n').trim();
|
|
1587
1666
|
}
|
|
1588
1667
|
|
|
1589
1668
|
async function waitForClusterReady(maxWaitMs = CLUSTER_STARTUP_TIMEOUT_MS) {
|
|
@@ -1696,9 +1775,13 @@ async function startC8Run(config, debug = false, startArgs = []) {
|
|
|
1696
1775
|
});
|
|
1697
1776
|
|
|
1698
1777
|
if (typeof proc.pid !== 'number') {
|
|
1778
|
+
// spawn() reports this failure via an async 'error' event; without a
|
|
1779
|
+
// listener it would crash the process while the hints are flushed below.
|
|
1780
|
+
proc.on('error', (err) => logger.error(`Failed to spawn c8run: ${err.message}`));
|
|
1699
1781
|
logger.error('Failed to start cluster process: no PID received from c8run.');
|
|
1700
1782
|
logger.error(`Check logs in: ${logDir}`);
|
|
1701
1783
|
logger.info(`Print logs with: cat "${logDir}"/*.log`, { essential: true });
|
|
1784
|
+
await flushStartHints(config);
|
|
1702
1785
|
process.exit(1);
|
|
1703
1786
|
}
|
|
1704
1787
|
|
|
@@ -1752,6 +1835,7 @@ async function startC8Run(config, debug = false, startArgs = []) {
|
|
|
1752
1835
|
logger.error(
|
|
1753
1836
|
`c8run start exited with code ${exitCode ?? 'unknown'}${exitSignal ? ` (signal: ${exitSignal})` : ''}. Cluster will not be marked as running.`,
|
|
1754
1837
|
);
|
|
1838
|
+
await flushStartHints(config);
|
|
1755
1839
|
process.exit(typeof exitCode === 'number' && exitCode > 0 ? exitCode : 1);
|
|
1756
1840
|
}
|
|
1757
1841
|
|
|
@@ -3142,7 +3226,10 @@ export async function deleteVersion(cacheDir, versionSpec) {
|
|
|
3142
3226
|
|
|
3143
3227
|
const config = { cacheDir, version: resolvedVersion };
|
|
3144
3228
|
|
|
3145
|
-
|
|
3229
|
+
// Guard on the install dir, not on the binary: the dir can survive
|
|
3230
|
+
// without its launcher (partial/corrupt install), and delete should
|
|
3231
|
+
// still remove what is left rather than report the version unremovable.
|
|
3232
|
+
if (!existsSync(join(cacheDir, `c8run-${resolvedVersion}`))) {
|
|
3146
3233
|
logger.warn(`Version ${versionSpec} is not installed locally.`);
|
|
3147
3234
|
return;
|
|
3148
3235
|
}
|
|
@@ -3250,6 +3337,164 @@ export async function purgeClusterData(cacheDir, versionSpec) {
|
|
|
3250
3337
|
|
|
3251
3338
|
const LOG_FILES = ['camunda.log', 'connectors.log'];
|
|
3252
3339
|
|
|
3340
|
+
// Like `tail -f`: show the last lines of each file, then follow appends.
|
|
3341
|
+
const FOLLOW_INITIAL_LINES = 10;
|
|
3342
|
+
// Logs can be large, so the initial lines are found by scanning back in blocks.
|
|
3343
|
+
const TAIL_BLOCK_BYTES = 64 * 1024;
|
|
3344
|
+
const NEWLINE = 0x0a;
|
|
3345
|
+
|
|
3346
|
+
function readRange(file, start, end) {
|
|
3347
|
+
const fd = openSync(file, 'r');
|
|
3348
|
+
try {
|
|
3349
|
+
const buffer = Buffer.alloc(end - start);
|
|
3350
|
+
const bytesRead = readSync(fd, buffer, 0, buffer.length, start);
|
|
3351
|
+
return buffer.subarray(0, bytesRead);
|
|
3352
|
+
} finally {
|
|
3353
|
+
closeSync(fd);
|
|
3354
|
+
}
|
|
3355
|
+
}
|
|
3356
|
+
|
|
3357
|
+
/**
|
|
3358
|
+
* Byte offset at which the last `count` lines of `file` start. Scans back
|
|
3359
|
+
* from the end until enough newlines are found, so a single entry longer
|
|
3360
|
+
* than any fixed window is still shown in full. The offset is always at a
|
|
3361
|
+
* line start, so decoding from it never splits a UTF-8 character. Also
|
|
3362
|
+
* returns the identity of the scanned file, to detect a later replacement.
|
|
3363
|
+
*/
|
|
3364
|
+
function tailStart(file, count) {
|
|
3365
|
+
const fd = openSync(file, 'r');
|
|
3366
|
+
try {
|
|
3367
|
+
const stats = fstatSync(fd, { bigint: true });
|
|
3368
|
+
const id = fileIdentity(stats);
|
|
3369
|
+
const size = Number(stats.size);
|
|
3370
|
+
const buffer = Buffer.alloc(TAIL_BLOCK_BYTES);
|
|
3371
|
+
let newlines = 0;
|
|
3372
|
+
for (let end = size; end > 0;) {
|
|
3373
|
+
const start = Math.max(0, end - buffer.length);
|
|
3374
|
+
const bytesRead = readSync(fd, buffer, 0, end - start, start);
|
|
3375
|
+
for (let i = bytesRead - 1; i >= 0; i--) {
|
|
3376
|
+
// A trailing newline ends the last line rather than starting a new one.
|
|
3377
|
+
if (buffer[i] !== NEWLINE || start + i === size - 1) continue;
|
|
3378
|
+
if (++newlines === count) return { offset: start + i + 1, id };
|
|
3379
|
+
}
|
|
3380
|
+
end = start;
|
|
3381
|
+
}
|
|
3382
|
+
return { offset: 0, id };
|
|
3383
|
+
} finally {
|
|
3384
|
+
closeSync(fd);
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3387
|
+
|
|
3388
|
+
const isMissingFile = error => error?.code === 'ENOENT';
|
|
3389
|
+
|
|
3390
|
+
const fileIdentity = stats => `${stats.dev}:${stats.ino}`;
|
|
3391
|
+
|
|
3392
|
+
/**
|
|
3393
|
+
* Follow log files without `tail`, which Windows does not ship. Prints the
|
|
3394
|
+
* last lines of each file (with `==> file <==` headers when there are several,
|
|
3395
|
+
* as `tail` does), then polls for appended bytes until `signal` aborts.
|
|
3396
|
+
* A file that shrinks or is replaced (truncated or rotated) is re-read from the start.
|
|
3397
|
+
*/
|
|
3398
|
+
export async function followLogFiles(files, {
|
|
3399
|
+
signal,
|
|
3400
|
+
write = chunk => process.stdout.write(chunk),
|
|
3401
|
+
intervalMs = 500,
|
|
3402
|
+
} = {}) {
|
|
3403
|
+
const multiple = files.length > 1;
|
|
3404
|
+
let current = null;
|
|
3405
|
+
const emit = (file, text) => {
|
|
3406
|
+
if (multiple && current !== file) {
|
|
3407
|
+
write(`${current === null ? '' : '\n'}==> ${file} <==\n`);
|
|
3408
|
+
current = file;
|
|
3409
|
+
}
|
|
3410
|
+
if (text) write(text);
|
|
3411
|
+
};
|
|
3412
|
+
|
|
3413
|
+
// Reads whatever was appended since the last read. A file can vanish at
|
|
3414
|
+
// any point while it is rotated, so a missing file just yields nothing
|
|
3415
|
+
// and is picked up again on a later poll.
|
|
3416
|
+
const readAppended = (file, entry) => {
|
|
3417
|
+
try {
|
|
3418
|
+
const stats = statSync(file, { bigint: true });
|
|
3419
|
+
const size = Number(stats.size);
|
|
3420
|
+
const id = fileIdentity(stats);
|
|
3421
|
+
// A replaced file can be as large as the one it rotated out.
|
|
3422
|
+
const replaced = entry.id !== undefined && entry.id !== id;
|
|
3423
|
+
entry.id = id;
|
|
3424
|
+
if (replaced || size < entry.offset) {
|
|
3425
|
+
entry.offset = 0;
|
|
3426
|
+
entry.decoder = new StringDecoder('utf8');
|
|
3427
|
+
}
|
|
3428
|
+
if (size === entry.offset) return '';
|
|
3429
|
+
const chunk = readRange(file, entry.offset, size);
|
|
3430
|
+
entry.offset += chunk.length;
|
|
3431
|
+
return entry.decoder.write(chunk);
|
|
3432
|
+
} catch (error) {
|
|
3433
|
+
if (isMissingFile(error)) return '';
|
|
3434
|
+
throw error;
|
|
3435
|
+
}
|
|
3436
|
+
};
|
|
3437
|
+
|
|
3438
|
+
const state = new Map();
|
|
3439
|
+
for (const file of files) {
|
|
3440
|
+
let start = { offset: 0, id: undefined };
|
|
3441
|
+
try {
|
|
3442
|
+
start = tailStart(file, FOLLOW_INITIAL_LINES);
|
|
3443
|
+
} catch (error) {
|
|
3444
|
+
if (!isMissingFile(error)) throw error;
|
|
3445
|
+
}
|
|
3446
|
+
const entry = { ...start, decoder: new StringDecoder('utf8') };
|
|
3447
|
+
state.set(file, entry);
|
|
3448
|
+
// Emitted even when empty, so every file gets its header up front.
|
|
3449
|
+
emit(file, readAppended(file, entry));
|
|
3450
|
+
}
|
|
3451
|
+
|
|
3452
|
+
const poll = () => {
|
|
3453
|
+
for (const file of files) {
|
|
3454
|
+
const text = readAppended(file, state.get(file));
|
|
3455
|
+
if (text) emit(file, text);
|
|
3456
|
+
}
|
|
3457
|
+
};
|
|
3458
|
+
|
|
3459
|
+
await new Promise((resolve, reject) => {
|
|
3460
|
+
let timer;
|
|
3461
|
+
const settle = error => {
|
|
3462
|
+
clearInterval(timer);
|
|
3463
|
+
signal?.removeEventListener('abort', stop);
|
|
3464
|
+
if (error) reject(error);
|
|
3465
|
+
else resolve();
|
|
3466
|
+
};
|
|
3467
|
+
// An unexpected read error ends following instead of escaping the timer.
|
|
3468
|
+
const tick = () => {
|
|
3469
|
+
try {
|
|
3470
|
+
poll();
|
|
3471
|
+
return true;
|
|
3472
|
+
} catch (error) {
|
|
3473
|
+
settle(error);
|
|
3474
|
+
return false;
|
|
3475
|
+
}
|
|
3476
|
+
};
|
|
3477
|
+
function stop() {
|
|
3478
|
+
if (tick()) settle();
|
|
3479
|
+
}
|
|
3480
|
+
timer = setInterval(tick, intervalMs);
|
|
3481
|
+
if (signal?.aborted) stop();
|
|
3482
|
+
else signal?.addEventListener('abort', stop, { once: true });
|
|
3483
|
+
});
|
|
3484
|
+
}
|
|
3485
|
+
|
|
3486
|
+
/** Follows log files until Ctrl+C, which ends the command cleanly. */
|
|
3487
|
+
export async function followLogsUntilInterrupted(files, options = {}) {
|
|
3488
|
+
const controller = new AbortController();
|
|
3489
|
+
const sigintHandler = () => controller.abort();
|
|
3490
|
+
process.on('SIGINT', sigintHandler);
|
|
3491
|
+
try {
|
|
3492
|
+
await followLogFiles(files, { ...options, signal: controller.signal });
|
|
3493
|
+
} finally {
|
|
3494
|
+
process.removeListener('SIGINT', sigintHandler);
|
|
3495
|
+
}
|
|
3496
|
+
}
|
|
3497
|
+
|
|
3253
3498
|
export async function streamLogs(cacheDir) {
|
|
3254
3499
|
const logger = getLogger();
|
|
3255
3500
|
const markerFile = join(cacheDir, ACTIVE_MARKER_FILE);
|
|
@@ -3295,6 +3540,12 @@ export async function streamLogs(cacheDir) {
|
|
|
3295
3540
|
logger.info(`Streaming logs from ${logDir} (Ctrl+C to stop)...`);
|
|
3296
3541
|
logger.info('');
|
|
3297
3542
|
|
|
3543
|
+
if (osPlatform() === 'win32') {
|
|
3544
|
+
// Windows has no `tail`, so follow the files in-process.
|
|
3545
|
+
await followLogsUntilInterrupted(existingLogs);
|
|
3546
|
+
return;
|
|
3547
|
+
}
|
|
3548
|
+
|
|
3298
3549
|
// Use tail -f to follow all log files
|
|
3299
3550
|
const tailArgs = ['-f', ...existingLogs];
|
|
3300
3551
|
const tail = spawn('tail', tailArgs, { stdio: 'inherit' });
|
|
@@ -3637,11 +3888,6 @@ export const commands = {
|
|
|
3637
3888
|
logger.info(`Resolved alias "${versionSpec}" → ${version}`);
|
|
3638
3889
|
}
|
|
3639
3890
|
|
|
3640
|
-
// For start with a named alias, check in the background whether the
|
|
3641
|
-
// remote resolves to a different (newer) version and hint if so.
|
|
3642
|
-
if (isStart && isVersionAlias(versionSpec)) {
|
|
3643
|
-
checkBackgroundAliasFreshness(versionSpec, version);
|
|
3644
|
-
}
|
|
3645
3891
|
const rolling = isRollingVersion(versionSpec);
|
|
3646
3892
|
const config = {
|
|
3647
3893
|
cacheDir: theCacheDir,
|
|
@@ -3655,12 +3901,19 @@ export const commands = {
|
|
|
3655
3901
|
verbose: ctx?.verbose === true,
|
|
3656
3902
|
};
|
|
3657
3903
|
|
|
3904
|
+
// For start with a named alias, check in the background whether the
|
|
3905
|
+
// remote resolves to a different (newer) version and hint if so.
|
|
3906
|
+
if (isStart && isVersionAlias(versionSpec)) {
|
|
3907
|
+
config._aliasHintPromise = checkBackgroundAliasFreshness(versionSpec, version, theCacheDir);
|
|
3908
|
+
}
|
|
3909
|
+
|
|
3658
3910
|
if (parsed.subcommand === 'start') {
|
|
3659
3911
|
try {
|
|
3660
3912
|
await ensureC8RunInstalled(config);
|
|
3661
3913
|
await startC8Run(config, parsed.debug, parsed.startArgs);
|
|
3662
3914
|
} catch (error) {
|
|
3663
3915
|
logger.error(`Failed to start cluster: ${formatErrorWithCause(error)}`);
|
|
3916
|
+
await flushStartHints(config);
|
|
3664
3917
|
process.exit(1);
|
|
3665
3918
|
}
|
|
3666
3919
|
} else if (parsed.subcommand === 'stop') {
|