@camunda8/cli 4.7.0-alpha.25 → 4.7.0-alpha.27

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.
@@ -3,6 +3,7 @@ export * from "./config.ts";
3
3
  export * from "./env-address.ts";
4
4
  export * from "./errors.ts";
5
5
  export * from "./logger.ts";
6
+ export * from "./node-version.ts";
6
7
  export * from "./runtime.ts";
7
8
  export * from "./update-check.ts";
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAMA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAMA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC"}
@@ -9,6 +9,7 @@ export * from "./config.js";
9
9
  export * from "./env-address.js";
10
10
  export * from "./errors.js";
11
11
  export * from "./logger.js";
12
+ export * from "./node-version.js";
12
13
  export * from "./runtime.js";
13
14
  export * from "./update-check.js";
14
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,EAAE;AACF,iFAAiF;AACjF,8EAA8E;AAC9E,gFAAgF;AAChF,kEAAkE;AAClE,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,EAAE;AACF,iFAAiF;AACjF,8EAA8E;AAC9E,gFAAgF;AAChF,kEAAkE;AAClE,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Runtime check of the Node.js version against c8ctl's `engines.node`.
3
+ *
4
+ * npm only warns about `engines` at install time (and not at all for a
5
+ * global install unless `engine-strict` is set), so an outdated Node.js can
6
+ * run c8ctl and fail later with an unrelated-looking error.
7
+ */
8
+ /** The Node.js range from c8ctl's `engines.node`. */
9
+ export declare const REQUIRED_NODE_RANGE: string | undefined;
10
+ /**
11
+ * Describe why `version` does not satisfy `range`, or `null` when it does or
12
+ * when the range is unknown or unparseable (nothing can be concluded then).
13
+ */
14
+ export declare function describeUnsupportedNode({ version, range, }?: {
15
+ version?: string;
16
+ range?: string;
17
+ }): string | null;
18
+ //# sourceMappingURL=node-version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-version.d.ts","sourceRoot":"","sources":["../../src/core/node-version.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAyBH,qDAAqD;AACrD,eAAO,MAAM,mBAAmB,oBAA0B,CAAC;AAE3D;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,EACvC,OAA+B,EAC/B,KAA2B,GAC3B,GAAE;IACF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CACV,GAAG,MAAM,GAAG,IAAI,CAIrB"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Runtime check of the Node.js version against c8ctl's `engines.node`.
3
+ *
4
+ * npm only warns about `engines` at install time (and not at all for a
5
+ * global install unless `engine-strict` is set), so an outdated Node.js can
6
+ * run c8ctl and fail later with an unrelated-looking error.
7
+ */
8
+ import { readFileSync } from "node:fs";
9
+ import { dirname, join } from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+ import semver from "semver";
12
+ import { isRecord } from "./logger.js";
13
+ function readRequiredNodeRange() {
14
+ try {
15
+ // Two levels below the package root in both src/core/ and dist/core/.
16
+ const packageJson = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "package.json");
17
+ const pkg = JSON.parse(readFileSync(packageJson, "utf-8"));
18
+ const node = isRecord(pkg) && isRecord(pkg.engines) && pkg.engines.node;
19
+ return typeof node === "string" ? node : undefined;
20
+ }
21
+ catch {
22
+ return undefined;
23
+ }
24
+ }
25
+ /** The Node.js range from c8ctl's `engines.node`. */
26
+ export const REQUIRED_NODE_RANGE = readRequiredNodeRange();
27
+ /**
28
+ * Describe why `version` does not satisfy `range`, or `null` when it does or
29
+ * when the range is unknown or unparseable (nothing can be concluded then).
30
+ */
31
+ export function describeUnsupportedNode({ version = process.versions.node, range = REQUIRED_NODE_RANGE, } = {}) {
32
+ if (!range || !semver.validRange(range))
33
+ return null;
34
+ if (semver.satisfies(version, range))
35
+ return null;
36
+ return `Node.js ${version} is not supported; c8ctl needs ${range}. Some commands may fail. Upgrade Node.js from https://nodejs.org/.`;
37
+ }
38
+ //# sourceMappingURL=node-version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-version.js","sourceRoot":"","sources":["../../src/core/node-version.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,SAAS,qBAAqB;IAC7B,IAAI,CAAC;QACJ,sEAAsE;QACtE,MAAM,WAAW,GAAG,IAAI,CACvB,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EACvC,IAAI,EACJ,IAAI,EACJ,cAAc,CACd,CAAC;QACF,MAAM,GAAG,GAAY,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;QACpE,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;QACxE,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IACpD,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC;AAED,qDAAqD;AACrD,MAAM,CAAC,MAAM,mBAAmB,GAAG,qBAAqB,EAAE,CAAC;AAE3D;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAC,EACvC,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,EAC/B,KAAK,GAAG,mBAAmB,MAIxB,EAAE;IACL,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACrD,IAAI,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAClD,OAAO,WAAW,OAAO,kCAAkC,KAAK,qEAAqE,CAAC;AACvI,CAAC"}
@@ -77,7 +77,7 @@ patch releases.
77
77
 
78
78
  ### `start` vs `install` update behavior
79
79
 
80
- - **`start`** uses the local version if available. A non-blocking remote check runs in the background — if a newer rolling release exists, a hint is printed (e.g. *"A newer server version is available. Install it with: c8ctl cluster install 8.9"*). If the network is unreachable, the hint is silently skipped.
80
+ - **`start`** uses the local version if available. A non-blocking remote check runs in the background — if a newer rolling release exists, a hint is printed (e.g. *"A newer server version is available. Install it with: c8ctl cluster install 8.9"*). If the network is unreachable, the hint is silently skipped. When starting a named alias (`stable`, `alpha`) whose newer target is already installed (e.g. via `c8ctl cluster install 8.10`), the check instead updates the cached alias so the next `start` uses that version, without downloading anything. If `start` fails, c8ctl waits up to one second for these checks before exiting, so the hint is not lost.
81
81
  - **`install`** always checks the remote for a newer rolling release (via ETag comparison) and re-downloads if one is available.
82
82
 
83
83
  If the download server is unreachable, the aliases fall back to the values
@@ -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
- const config = { cacheDir, version: value };
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 print
269
- * a hint if the remote alias resolves to a different (newer) version.
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
- * Important: does NOT update the persisted alias mapping. The mapping is only
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 && isRemoteMinorNewer(remoteVersion, resolvedVersion)) {
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
  // ---------------------------------------------------------------------------
@@ -1711,9 +1775,13 @@ async function startC8Run(config, debug = false, startArgs = []) {
1711
1775
  });
1712
1776
 
1713
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}`));
1714
1781
  logger.error('Failed to start cluster process: no PID received from c8run.');
1715
1782
  logger.error(`Check logs in: ${logDir}`);
1716
1783
  logger.info(`Print logs with: cat "${logDir}"/*.log`, { essential: true });
1784
+ await flushStartHints(config);
1717
1785
  process.exit(1);
1718
1786
  }
1719
1787
 
@@ -1767,6 +1835,7 @@ async function startC8Run(config, debug = false, startArgs = []) {
1767
1835
  logger.error(
1768
1836
  `c8run start exited with code ${exitCode ?? 'unknown'}${exitSignal ? ` (signal: ${exitSignal})` : ''}. Cluster will not be marked as running.`,
1769
1837
  );
1838
+ await flushStartHints(config);
1770
1839
  process.exit(typeof exitCode === 'number' && exitCode > 0 ? exitCode : 1);
1771
1840
  }
1772
1841
 
@@ -3265,6 +3334,164 @@ export async function purgeClusterData(cacheDir, versionSpec) {
3265
3334
 
3266
3335
  const LOG_FILES = ['camunda.log', 'connectors.log'];
3267
3336
 
3337
+ // Like `tail -f`: show the last lines of each file, then follow appends.
3338
+ const FOLLOW_INITIAL_LINES = 10;
3339
+ // Logs can be large, so the initial lines are found by scanning back in blocks.
3340
+ const TAIL_BLOCK_BYTES = 64 * 1024;
3341
+ const NEWLINE = 0x0a;
3342
+
3343
+ function readRange(file, start, end) {
3344
+ const fd = openSync(file, 'r');
3345
+ try {
3346
+ const buffer = Buffer.alloc(end - start);
3347
+ const bytesRead = readSync(fd, buffer, 0, buffer.length, start);
3348
+ return buffer.subarray(0, bytesRead);
3349
+ } finally {
3350
+ closeSync(fd);
3351
+ }
3352
+ }
3353
+
3354
+ /**
3355
+ * Byte offset at which the last `count` lines of `file` start. Scans back
3356
+ * from the end until enough newlines are found, so a single entry longer
3357
+ * than any fixed window is still shown in full. The offset is always at a
3358
+ * line start, so decoding from it never splits a UTF-8 character. Also
3359
+ * returns the identity of the scanned file, to detect a later replacement.
3360
+ */
3361
+ function tailStart(file, count) {
3362
+ const fd = openSync(file, 'r');
3363
+ try {
3364
+ const stats = fstatSync(fd, { bigint: true });
3365
+ const id = fileIdentity(stats);
3366
+ const size = Number(stats.size);
3367
+ const buffer = Buffer.alloc(TAIL_BLOCK_BYTES);
3368
+ let newlines = 0;
3369
+ for (let end = size; end > 0;) {
3370
+ const start = Math.max(0, end - buffer.length);
3371
+ const bytesRead = readSync(fd, buffer, 0, end - start, start);
3372
+ for (let i = bytesRead - 1; i >= 0; i--) {
3373
+ // A trailing newline ends the last line rather than starting a new one.
3374
+ if (buffer[i] !== NEWLINE || start + i === size - 1) continue;
3375
+ if (++newlines === count) return { offset: start + i + 1, id };
3376
+ }
3377
+ end = start;
3378
+ }
3379
+ return { offset: 0, id };
3380
+ } finally {
3381
+ closeSync(fd);
3382
+ }
3383
+ }
3384
+
3385
+ const isMissingFile = error => error?.code === 'ENOENT';
3386
+
3387
+ const fileIdentity = stats => `${stats.dev}:${stats.ino}`;
3388
+
3389
+ /**
3390
+ * Follow log files without `tail`, which Windows does not ship. Prints the
3391
+ * last lines of each file (with `==> file <==` headers when there are several,
3392
+ * as `tail` does), then polls for appended bytes until `signal` aborts.
3393
+ * A file that shrinks or is replaced (truncated or rotated) is re-read from the start.
3394
+ */
3395
+ export async function followLogFiles(files, {
3396
+ signal,
3397
+ write = chunk => process.stdout.write(chunk),
3398
+ intervalMs = 500,
3399
+ } = {}) {
3400
+ const multiple = files.length > 1;
3401
+ let current = null;
3402
+ const emit = (file, text) => {
3403
+ if (multiple && current !== file) {
3404
+ write(`${current === null ? '' : '\n'}==> ${file} <==\n`);
3405
+ current = file;
3406
+ }
3407
+ if (text) write(text);
3408
+ };
3409
+
3410
+ // Reads whatever was appended since the last read. A file can vanish at
3411
+ // any point while it is rotated, so a missing file just yields nothing
3412
+ // and is picked up again on a later poll.
3413
+ const readAppended = (file, entry) => {
3414
+ try {
3415
+ const stats = statSync(file, { bigint: true });
3416
+ const size = Number(stats.size);
3417
+ const id = fileIdentity(stats);
3418
+ // A replaced file can be as large as the one it rotated out.
3419
+ const replaced = entry.id !== undefined && entry.id !== id;
3420
+ entry.id = id;
3421
+ if (replaced || size < entry.offset) {
3422
+ entry.offset = 0;
3423
+ entry.decoder = new StringDecoder('utf8');
3424
+ }
3425
+ if (size === entry.offset) return '';
3426
+ const chunk = readRange(file, entry.offset, size);
3427
+ entry.offset += chunk.length;
3428
+ return entry.decoder.write(chunk);
3429
+ } catch (error) {
3430
+ if (isMissingFile(error)) return '';
3431
+ throw error;
3432
+ }
3433
+ };
3434
+
3435
+ const state = new Map();
3436
+ for (const file of files) {
3437
+ let start = { offset: 0, id: undefined };
3438
+ try {
3439
+ start = tailStart(file, FOLLOW_INITIAL_LINES);
3440
+ } catch (error) {
3441
+ if (!isMissingFile(error)) throw error;
3442
+ }
3443
+ const entry = { ...start, decoder: new StringDecoder('utf8') };
3444
+ state.set(file, entry);
3445
+ // Emitted even when empty, so every file gets its header up front.
3446
+ emit(file, readAppended(file, entry));
3447
+ }
3448
+
3449
+ const poll = () => {
3450
+ for (const file of files) {
3451
+ const text = readAppended(file, state.get(file));
3452
+ if (text) emit(file, text);
3453
+ }
3454
+ };
3455
+
3456
+ await new Promise((resolve, reject) => {
3457
+ let timer;
3458
+ const settle = error => {
3459
+ clearInterval(timer);
3460
+ signal?.removeEventListener('abort', stop);
3461
+ if (error) reject(error);
3462
+ else resolve();
3463
+ };
3464
+ // An unexpected read error ends following instead of escaping the timer.
3465
+ const tick = () => {
3466
+ try {
3467
+ poll();
3468
+ return true;
3469
+ } catch (error) {
3470
+ settle(error);
3471
+ return false;
3472
+ }
3473
+ };
3474
+ function stop() {
3475
+ if (tick()) settle();
3476
+ }
3477
+ timer = setInterval(tick, intervalMs);
3478
+ if (signal?.aborted) stop();
3479
+ else signal?.addEventListener('abort', stop, { once: true });
3480
+ });
3481
+ }
3482
+
3483
+ /** Follows log files until Ctrl+C, which ends the command cleanly. */
3484
+ export async function followLogsUntilInterrupted(files, options = {}) {
3485
+ const controller = new AbortController();
3486
+ const sigintHandler = () => controller.abort();
3487
+ process.on('SIGINT', sigintHandler);
3488
+ try {
3489
+ await followLogFiles(files, { ...options, signal: controller.signal });
3490
+ } finally {
3491
+ process.removeListener('SIGINT', sigintHandler);
3492
+ }
3493
+ }
3494
+
3268
3495
  export async function streamLogs(cacheDir) {
3269
3496
  const logger = getLogger();
3270
3497
  const markerFile = join(cacheDir, ACTIVE_MARKER_FILE);
@@ -3310,6 +3537,12 @@ export async function streamLogs(cacheDir) {
3310
3537
  logger.info(`Streaming logs from ${logDir} (Ctrl+C to stop)...`);
3311
3538
  logger.info('');
3312
3539
 
3540
+ if (osPlatform() === 'win32') {
3541
+ // Windows has no `tail`, so follow the files in-process.
3542
+ await followLogsUntilInterrupted(existingLogs);
3543
+ return;
3544
+ }
3545
+
3313
3546
  // Use tail -f to follow all log files
3314
3547
  const tailArgs = ['-f', ...existingLogs];
3315
3548
  const tail = spawn('tail', tailArgs, { stdio: 'inherit' });
@@ -3652,11 +3885,6 @@ export const commands = {
3652
3885
  logger.info(`Resolved alias "${versionSpec}" → ${version}`);
3653
3886
  }
3654
3887
 
3655
- // For start with a named alias, check in the background whether the
3656
- // remote resolves to a different (newer) version and hint if so.
3657
- if (isStart && isVersionAlias(versionSpec)) {
3658
- checkBackgroundAliasFreshness(versionSpec, version);
3659
- }
3660
3888
  const rolling = isRollingVersion(versionSpec);
3661
3889
  const config = {
3662
3890
  cacheDir: theCacheDir,
@@ -3670,12 +3898,19 @@ export const commands = {
3670
3898
  verbose: ctx?.verbose === true,
3671
3899
  };
3672
3900
 
3901
+ // For start with a named alias, check in the background whether the
3902
+ // remote resolves to a different (newer) version and hint if so.
3903
+ if (isStart && isVersionAlias(versionSpec)) {
3904
+ config._aliasHintPromise = checkBackgroundAliasFreshness(versionSpec, version, theCacheDir);
3905
+ }
3906
+
3673
3907
  if (parsed.subcommand === 'start') {
3674
3908
  try {
3675
3909
  await ensureC8RunInstalled(config);
3676
3910
  await startC8Run(config, parsed.debug, parsed.startArgs);
3677
3911
  } catch (error) {
3678
3912
  logger.error(`Failed to start cluster: ${formatErrorWithCause(error)}`);
3913
+ await flushStartHints(config);
3679
3914
  process.exit(1);
3680
3915
  }
3681
3916
  } else if (parsed.subcommand === 'stop') {
@@ -11122,12 +11122,12 @@ import {
11122
11122
  closeSync as closeSync2,
11123
11123
  existsSync as existsSync5,
11124
11124
  openSync as openSync2,
11125
- readFileSync as readFileSync5,
11125
+ readFileSync as readFileSync6,
11126
11126
  realpathSync as realpathSync2,
11127
11127
  unlinkSync as unlinkSync3
11128
11128
  } from "node:fs";
11129
11129
  import { createRequire as createRequire4 } from "node:module";
11130
- import { dirname as dirname6, resolve as resolvePath4 } from "node:path";
11130
+ import { dirname as dirname7, resolve as resolvePath4 } from "node:path";
11131
11131
 
11132
11132
  // default-plugins/element-template/migration/element-values.ts
11133
11133
  var AD_HOC_PROPERTIES = [
@@ -12707,6 +12707,28 @@ var VALIDATION_PATTERNS = {
12707
12707
  var CAMUNDA_CLOUD_URL_PATTERN = VALIDATION_PATTERNS.CAMUNDA_CLOUD_REST_URL;
12708
12708
  var isWindows = platform() === "win32";
12709
12709
 
12710
+ // src/core/node-version.ts
12711
+ var import_semver4 = __toESM(require_semver2(), 1);
12712
+ import { readFileSync as readFileSync5 } from "node:fs";
12713
+ import { dirname as dirname6, join as join4 } from "node:path";
12714
+ import { fileURLToPath as fileURLToPath3 } from "node:url";
12715
+ function readRequiredNodeRange() {
12716
+ try {
12717
+ const packageJson = join4(
12718
+ dirname6(fileURLToPath3(import.meta.url)),
12719
+ "..",
12720
+ "..",
12721
+ "package.json"
12722
+ );
12723
+ const pkg = JSON.parse(readFileSync5(packageJson, "utf-8"));
12724
+ const node = isRecord3(pkg) && isRecord3(pkg.engines) && pkg.engines.node;
12725
+ return typeof node === "string" ? node : void 0;
12726
+ } catch {
12727
+ return void 0;
12728
+ }
12729
+ }
12730
+ var REQUIRED_NODE_RANGE = readRequiredNodeRange();
12731
+
12710
12732
  // src/core/update-check.ts
12711
12733
  var CHECK_INTERVAL_MS = 60 * 60 * 1e3;
12712
12734
 
@@ -13348,7 +13370,7 @@ function compatibleTemplates(templates, engineVersion) {
13348
13370
  function loadRecipeFile(path) {
13349
13371
  let raw;
13350
13372
  try {
13351
- raw = JSON.parse(readFileSync5(resolvePath4(path), "utf-8"));
13373
+ raw = JSON.parse(readFileSync6(resolvePath4(path), "utf-8"));
13352
13374
  } catch (error3) {
13353
13375
  const message = error3 instanceof Error ? error3.message : String(error3);
13354
13376
  throw new Error(`Cannot read recipe ${path}: ${message}`);
@@ -13538,7 +13560,7 @@ async function runMigrateInternal({ parsed, templateId, elementId, bpmnFilePath
13538
13560
  const valuesOf2 = (element) => enumerateElementValues(getExtensionElements(element.businessObject));
13539
13561
  redaction.values = selected2.flatMap(({ element }) => valuesOf2(element));
13540
13562
  const pool = templatePool(
13541
- bpmnFilePath ? dirname6(resolvePath4(bpmnFilePath)) : process.cwd()
13563
+ bpmnFilePath ? dirname7(resolvePath4(bpmnFilePath)) : process.cwd()
13542
13564
  );
13543
13565
  const localVersions = pool.localOf(templateId).map((t) => t.version ?? 0);
13544
13566
  if (selected2.some(
@@ -13761,7 +13783,7 @@ async function runMigrateInternal({ parsed, templateId, elementId, bpmnFilePath
13761
13783
  const canWrite = !dryRun && failed.length === 0 && !wouldBlock;
13762
13784
  const saved = canWrite && updated.length > 0 ? await modeler.saveXML({ format: true }) : void 0;
13763
13785
  if (saved && parsed.inPlace && bpmnPath) {
13764
- if (readFileSync5(bpmnPath, "utf-8") !== input.xml)
13786
+ if (readFileSync6(bpmnPath, "utf-8") !== input.xml)
13765
13787
  throw new Error(CONCURRENT_EDIT_MESSAGE);
13766
13788
  atomicOverwriteFile(bpmnPath, saved.xml, input.xml);
13767
13789
  }