@camunda8/cli 4.7.0-alpha.24 → 4.7.0-alpha.26

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,EAA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@
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';
@@ -25,6 +29,7 @@ import { chmod } from 'node:fs/promises';
25
29
  import { homedir, platform as osPlatform, arch as osArch } from 'node:os';
26
30
  import { join, dirname, 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
  // ---------------------------------------------------------------------------
@@ -3265,6 +3270,164 @@ export async function purgeClusterData(cacheDir, versionSpec) {
3265
3270
 
3266
3271
  const LOG_FILES = ['camunda.log', 'connectors.log'];
3267
3272
 
3273
+ // Like `tail -f`: show the last lines of each file, then follow appends.
3274
+ const FOLLOW_INITIAL_LINES = 10;
3275
+ // Logs can be large, so the initial lines are found by scanning back in blocks.
3276
+ const TAIL_BLOCK_BYTES = 64 * 1024;
3277
+ const NEWLINE = 0x0a;
3278
+
3279
+ function readRange(file, start, end) {
3280
+ const fd = openSync(file, 'r');
3281
+ try {
3282
+ const buffer = Buffer.alloc(end - start);
3283
+ const bytesRead = readSync(fd, buffer, 0, buffer.length, start);
3284
+ return buffer.subarray(0, bytesRead);
3285
+ } finally {
3286
+ closeSync(fd);
3287
+ }
3288
+ }
3289
+
3290
+ /**
3291
+ * Byte offset at which the last `count` lines of `file` start. Scans back
3292
+ * from the end until enough newlines are found, so a single entry longer
3293
+ * than any fixed window is still shown in full. The offset is always at a
3294
+ * line start, so decoding from it never splits a UTF-8 character. Also
3295
+ * returns the identity of the scanned file, to detect a later replacement.
3296
+ */
3297
+ function tailStart(file, count) {
3298
+ const fd = openSync(file, 'r');
3299
+ try {
3300
+ const stats = fstatSync(fd, { bigint: true });
3301
+ const id = fileIdentity(stats);
3302
+ const size = Number(stats.size);
3303
+ const buffer = Buffer.alloc(TAIL_BLOCK_BYTES);
3304
+ let newlines = 0;
3305
+ for (let end = size; end > 0;) {
3306
+ const start = Math.max(0, end - buffer.length);
3307
+ const bytesRead = readSync(fd, buffer, 0, end - start, start);
3308
+ for (let i = bytesRead - 1; i >= 0; i--) {
3309
+ // A trailing newline ends the last line rather than starting a new one.
3310
+ if (buffer[i] !== NEWLINE || start + i === size - 1) continue;
3311
+ if (++newlines === count) return { offset: start + i + 1, id };
3312
+ }
3313
+ end = start;
3314
+ }
3315
+ return { offset: 0, id };
3316
+ } finally {
3317
+ closeSync(fd);
3318
+ }
3319
+ }
3320
+
3321
+ const isMissingFile = error => error?.code === 'ENOENT';
3322
+
3323
+ const fileIdentity = stats => `${stats.dev}:${stats.ino}`;
3324
+
3325
+ /**
3326
+ * Follow log files without `tail`, which Windows does not ship. Prints the
3327
+ * last lines of each file (with `==> file <==` headers when there are several,
3328
+ * as `tail` does), then polls for appended bytes until `signal` aborts.
3329
+ * A file that shrinks or is replaced (truncated or rotated) is re-read from the start.
3330
+ */
3331
+ export async function followLogFiles(files, {
3332
+ signal,
3333
+ write = chunk => process.stdout.write(chunk),
3334
+ intervalMs = 500,
3335
+ } = {}) {
3336
+ const multiple = files.length > 1;
3337
+ let current = null;
3338
+ const emit = (file, text) => {
3339
+ if (multiple && current !== file) {
3340
+ write(`${current === null ? '' : '\n'}==> ${file} <==\n`);
3341
+ current = file;
3342
+ }
3343
+ if (text) write(text);
3344
+ };
3345
+
3346
+ // Reads whatever was appended since the last read. A file can vanish at
3347
+ // any point while it is rotated, so a missing file just yields nothing
3348
+ // and is picked up again on a later poll.
3349
+ const readAppended = (file, entry) => {
3350
+ try {
3351
+ const stats = statSync(file, { bigint: true });
3352
+ const size = Number(stats.size);
3353
+ const id = fileIdentity(stats);
3354
+ // A replaced file can be as large as the one it rotated out.
3355
+ const replaced = entry.id !== undefined && entry.id !== id;
3356
+ entry.id = id;
3357
+ if (replaced || size < entry.offset) {
3358
+ entry.offset = 0;
3359
+ entry.decoder = new StringDecoder('utf8');
3360
+ }
3361
+ if (size === entry.offset) return '';
3362
+ const chunk = readRange(file, entry.offset, size);
3363
+ entry.offset += chunk.length;
3364
+ return entry.decoder.write(chunk);
3365
+ } catch (error) {
3366
+ if (isMissingFile(error)) return '';
3367
+ throw error;
3368
+ }
3369
+ };
3370
+
3371
+ const state = new Map();
3372
+ for (const file of files) {
3373
+ let start = { offset: 0, id: undefined };
3374
+ try {
3375
+ start = tailStart(file, FOLLOW_INITIAL_LINES);
3376
+ } catch (error) {
3377
+ if (!isMissingFile(error)) throw error;
3378
+ }
3379
+ const entry = { ...start, decoder: new StringDecoder('utf8') };
3380
+ state.set(file, entry);
3381
+ // Emitted even when empty, so every file gets its header up front.
3382
+ emit(file, readAppended(file, entry));
3383
+ }
3384
+
3385
+ const poll = () => {
3386
+ for (const file of files) {
3387
+ const text = readAppended(file, state.get(file));
3388
+ if (text) emit(file, text);
3389
+ }
3390
+ };
3391
+
3392
+ await new Promise((resolve, reject) => {
3393
+ let timer;
3394
+ const settle = error => {
3395
+ clearInterval(timer);
3396
+ signal?.removeEventListener('abort', stop);
3397
+ if (error) reject(error);
3398
+ else resolve();
3399
+ };
3400
+ // An unexpected read error ends following instead of escaping the timer.
3401
+ const tick = () => {
3402
+ try {
3403
+ poll();
3404
+ return true;
3405
+ } catch (error) {
3406
+ settle(error);
3407
+ return false;
3408
+ }
3409
+ };
3410
+ function stop() {
3411
+ if (tick()) settle();
3412
+ }
3413
+ timer = setInterval(tick, intervalMs);
3414
+ if (signal?.aborted) stop();
3415
+ else signal?.addEventListener('abort', stop, { once: true });
3416
+ });
3417
+ }
3418
+
3419
+ /** Follows log files until Ctrl+C, which ends the command cleanly. */
3420
+ export async function followLogsUntilInterrupted(files, options = {}) {
3421
+ const controller = new AbortController();
3422
+ const sigintHandler = () => controller.abort();
3423
+ process.on('SIGINT', sigintHandler);
3424
+ try {
3425
+ await followLogFiles(files, { ...options, signal: controller.signal });
3426
+ } finally {
3427
+ process.removeListener('SIGINT', sigintHandler);
3428
+ }
3429
+ }
3430
+
3268
3431
  export async function streamLogs(cacheDir) {
3269
3432
  const logger = getLogger();
3270
3433
  const markerFile = join(cacheDir, ACTIVE_MARKER_FILE);
@@ -3310,6 +3473,12 @@ export async function streamLogs(cacheDir) {
3310
3473
  logger.info(`Streaming logs from ${logDir} (Ctrl+C to stop)...`);
3311
3474
  logger.info('');
3312
3475
 
3476
+ if (osPlatform() === 'win32') {
3477
+ // Windows has no `tail`, so follow the files in-process.
3478
+ await followLogsUntilInterrupted(existingLogs);
3479
+ return;
3480
+ }
3481
+
3313
3482
  // Use tail -f to follow all log files
3314
3483
  const tailArgs = ['-f', ...existingLogs];
3315
3484
  const tail = spawn('tail', tailArgs, { stdio: 'inherit' });
@@ -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
  }