@camunda8/cli 4.6.0-alpha.3 → 4.6.0-alpha.5

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.
@@ -43,11 +43,15 @@ version resolution.
43
43
  Detection happens in `parseTemplateRef()` in `template-ref.ts`
44
44
  before any cache call. An id found locally (`.camunda/element-templates/`
45
45
  or the Modeler user-data dir, see `resolveTemplateId`) never reaches
46
- `requireCachePresent()`; only the OOTB fallback does.
46
+ `requireCachePresent()`; only the OOTB fallback does. `update` reads the
47
+ cache only on a local gap (see `templatePool` in `commands/migrate.ts`).
47
48
  - **`saveCache` and `apply --in-place` writes are atomic.** Both
48
49
  use a sibling temp file + `renameSync`. Anything else that
49
50
  overwrites a user-owned file (cache or BPMN) must follow the same
50
51
  pattern — a kill mid-write must not leave a truncated file.
52
+ `atomicOverwriteFile` resolves the target with `realpathSync` first,
53
+ so a symlinked BPMN keeps its link; locks on a BPMN path must use the
54
+ resolved path too.
51
55
  - **`syncTemplates` is serialised by an advisory lockfile.** The
52
56
  helper `withSyncLock` in `cache.ts` holds
53
57
  `<cacheDir>/.sync.lock` while the body runs, with stale-lock
@@ -179,10 +179,14 @@ c8ctl element-template update old.id process.bpmn --dry-run --json
179
179
  `apply --in-place` and `edit --in-place` do not take the lock, but refuse to
180
180
  replace a file whose contents changed since they read it, so they never
181
181
  overwrite a migration that committed in between.
182
+ In-place writes follow symlinks: the link stays and its target receives the new
183
+ XML. The lock and temporary file sit beside the real file, so links to one file
184
+ share a lock. Relative local template lookup starts at the directory of the
185
+ path you pass, not of the link's target. Hard links are not preserved; the file gets a new inode.
182
186
  A killed writer can leave a stale lock and temporary file; confirm no writer is
183
187
  active before inspecting and removing them. Recovery is manual. External edits
184
- between the final comparison and rename and symlink aliases are not covered by
185
- the cooperative lock; this design has no atomic compare-and-swap. Tests cover
188
+ between the final comparison and rename are not covered by the cooperative
189
+ lock; this design has no atomic compare-and-swap. Tests cover
186
190
  injected ENOSPC/EIO before and after actual partial bytes and real SIGINT/SIGTERM
187
191
  termination during paused split writes, preserving original bytes. Physical
188
192
  disk exhaustion and interruption of an executing kernel syscall are not proven.
@@ -8345,6 +8345,7 @@ var import_semver = __toESM(require_semver2(), 1);
8345
8345
  import {
8346
8346
  existsSync,
8347
8347
  readFileSync,
8348
+ realpathSync,
8348
8349
  renameSync,
8349
8350
  unlinkSync,
8350
8351
  writeFileSync
@@ -8700,7 +8701,7 @@ function emptyFacts() {
8700
8701
  feelSkipped: []
8701
8702
  };
8702
8703
  }
8703
- function buildStepPlan(entries, sourceValues, template) {
8704
+ function buildStepPlan(entries, sourceValues, template, unverifiedReads = false) {
8704
8705
  const facts = emptyFacts();
8705
8706
  const writes = [];
8706
8707
  const write = (entry, to, value) => {
@@ -8726,6 +8727,13 @@ function buildStepPlan(entries, sourceValues, template) {
8726
8727
  return target;
8727
8728
  };
8728
8729
  for (const entry of entries) {
8730
+ if (unverifiedReads) {
8731
+ for (const guard of entry.when) {
8732
+ if (!lookup(sourceValues, guard.path)) {
8733
+ facts.noMatch.push({ from: guard.path, to: entry.to });
8734
+ }
8735
+ }
8736
+ }
8729
8737
  const active = entry.when.every((g) => evalGuard(g, sourceValues));
8730
8738
  if (entry.kind === "set") {
8731
8739
  if (active) {
@@ -8768,6 +8776,9 @@ function buildStepPlan(entries, sourceValues, template) {
8768
8776
  continue;
8769
8777
  }
8770
8778
  if (!source) {
8779
+ if (unverifiedReads) {
8780
+ facts.noMatch.push({ from: entry.from, to: entry.to });
8781
+ }
8771
8782
  continue;
8772
8783
  }
8773
8784
  let value = source.value;
@@ -8867,7 +8878,7 @@ function isRecord(value) {
8867
8878
  }
8868
8879
  var CONCURRENT_EDIT_MESSAGE = "BPMN changed while this command ran; refusing to overwrite concurrent edits.";
8869
8880
  function atomicOverwriteFile(targetPath, contents, expectedContents, directWriteFallback = false) {
8870
- const target = resolvePath(targetPath);
8881
+ const target = realpathSync(targetPath);
8871
8882
  const tmp = `${target}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
8872
8883
  try {
8873
8884
  writeFileSync(tmp, contents, "utf-8");
@@ -8888,6 +8899,9 @@ function atomicOverwriteFile(targetPath, contents, expectedContents, directWrite
8888
8899
  throw error3;
8889
8900
  }
8890
8901
  }
8902
+ function pinFilePath(path) {
8903
+ return existsSync(path) ? realpathSync(path) : path;
8904
+ }
8891
8905
  var ENGINE_VERSION_PATTERN = /^\d+\.\d+(?:\.\d+)?(?:-[0-9A-Za-z.-]+)?$/;
8892
8906
  function isUrl(input) {
8893
8907
  return input.startsWith("https://") || input.startsWith("http://");
@@ -10064,12 +10078,12 @@ async function resolveTemplateId(ref, {
10064
10078
  async function resolveOotbTemplate(ref, {
10065
10079
  executionPlatformVersion,
10066
10080
  requireEngineCompatibility = false,
10067
- templates
10081
+ loadTemplates
10068
10082
  } = {}) {
10069
10083
  const logger = c8ctl2.getLogger();
10070
10084
  requireCachePresent();
10071
10085
  nudgeIfStale(logger);
10072
- const candidates = templates ? templates.filter((t) => t.id === ref.id) : findById(ref.id);
10086
+ const candidates = loadTemplates ? loadTemplates().filter((t) => t.id === ref.id) : findById(ref.id);
10073
10087
  if (candidates.length === 0) {
10074
10088
  throw new Error(
10075
10089
  `Element template '${ref.id}' not found. Run 'c8ctl element-template sync' to refresh the cache, or use 'c8ctl element-template search <query>' to find an id.`
@@ -10228,6 +10242,7 @@ async function applySubcommand(args) {
10228
10242
  if (parsed.inPlace && !bpmnFilePath) {
10229
10243
  throw new Error("--in-place cannot be used with stdin input");
10230
10244
  }
10245
+ const writePath = parsed.inPlace && bpmnFilePath ? pinFilePath(bpmnFilePath) : void 0;
10231
10246
  const input = await readBpmnInput(bpmnFilePath);
10232
10247
  if (!input) {
10233
10248
  throw new Error(
@@ -10312,8 +10327,8 @@ async function applySubcommand(args) {
10312
10327
  if (setProperties.length > 0) {
10313
10328
  warnUnmetConditions(logger, resultXml, setProperties);
10314
10329
  }
10315
- if (parsed.inPlace && bpmnFilePath) {
10316
- atomicOverwriteFile(bpmnFilePath, resultXml, input.xml, true);
10330
+ if (writePath) {
10331
+ atomicOverwriteFile(writePath, resultXml, input.xml, true);
10317
10332
  logger.info(`Updated ${bpmnFilePath}`);
10318
10333
  return;
10319
10334
  }
@@ -10478,6 +10493,7 @@ async function editSubcommand(args) {
10478
10493
  if (parsed.inPlace && !bpmnFilePath) {
10479
10494
  throw new Error("--in-place cannot be used with stdin input");
10480
10495
  }
10496
+ const writePath = parsed.inPlace && bpmnFilePath ? pinFilePath(bpmnFilePath) : void 0;
10481
10497
  const input = await readBpmnInput(bpmnFilePath);
10482
10498
  if (!input) {
10483
10499
  throw new Error(
@@ -10545,8 +10561,8 @@ async function editSubcommand(args) {
10545
10561
  }
10546
10562
  const result = await modeler.saveXML({ format: true });
10547
10563
  const resultXml = result.xml;
10548
- if (parsed.inPlace && bpmnFilePath) {
10549
- atomicOverwriteFile(bpmnFilePath, resultXml, input.xml, true);
10564
+ if (writePath) {
10565
+ atomicOverwriteFile(writePath, resultXml, input.xml, true);
10550
10566
  logger.info(`Updated ${bpmnFilePath}`);
10551
10567
  return;
10552
10568
  }
@@ -11217,6 +11233,7 @@ import {
11217
11233
  existsSync as existsSync5,
11218
11234
  openSync as openSync2,
11219
11235
  readFileSync as readFileSync5,
11236
+ realpathSync as realpathSync2,
11220
11237
  unlinkSync as unlinkSync3
11221
11238
  } from "node:fs";
11222
11239
  import { createRequire as createRequire4 } from "node:module";
@@ -11501,6 +11518,7 @@ function withNames(template, field, value) {
11501
11518
  function buildReport({
11502
11519
  fromTemplate,
11503
11520
  toTemplate,
11521
+ via = [toTemplate],
11504
11522
  before,
11505
11523
  after,
11506
11524
  facts,
@@ -11620,7 +11638,7 @@ function buildReport({
11620
11638
  template: facts.templateSkipped,
11621
11639
  noMatch: facts.noMatch,
11622
11640
  feel: facts.feelSkipped,
11623
- unchecked: uncheckedFields(fromTemplate, toTemplate)
11641
+ unchecked: uncheckedFields(fromTemplate, via)
11624
11642
  };
11625
11643
  return {
11626
11644
  from: templateRef(fromTemplate),
@@ -11639,10 +11657,12 @@ function buildReport({
11639
11657
  ).length && survivingSets.length === facts.set.length && dropped.length === 0 && skipped.guard.length === 0 && skipped.template.length === 0 && skipped.noMatch.length === 0 && skipped.unchecked.length === 0
11640
11658
  };
11641
11659
  }
11642
- function uncheckedFields(fromTemplate, toTemplate) {
11660
+ function uncheckedFields(fromTemplate, via) {
11643
11661
  return fromTemplate.properties.filter(
11644
- (p) => p.binding && p.type !== "Hidden" && bindingTargetKey(p.binding) === void 0 && !toTemplate.properties.some(
11645
- (t) => t.type !== "Hidden" && sameBinding(t.binding, p.binding)
11662
+ (p) => p.binding && p.type !== "Hidden" && bindingTargetKey(p.binding) === void 0 && via.some(
11663
+ (template) => !template.properties.some(
11664
+ (t) => t.type !== "Hidden" && sameBinding(t.binding, p.binding)
11665
+ )
11646
11666
  )
11647
11667
  ).map((p) => {
11648
11668
  const binding = { ...p.binding };
@@ -12034,10 +12054,10 @@ function readPaths(entry) {
12034
12054
  }
12035
12055
  return paths;
12036
12056
  }
12037
- function findCoverageGap(steps, appliedId, appliedVersion, templates, hop) {
12038
- let shape = templates.find(
12057
+ function findCoverageGap(steps, appliedId, appliedVersion, appliedShapeKnown, templates, hop) {
12058
+ let shape = appliedShapeKnown ? templates.find(
12039
12059
  (t) => t.id === appliedId && (versionOf(t) ?? 0) === appliedVersion
12040
- );
12060
+ ) : void 0;
12041
12061
  for (const step of steps) {
12042
12062
  for (const entry of step.entries) {
12043
12063
  for (const path of readPaths(entry)) {
@@ -12079,6 +12099,7 @@ function reachableHop(recipe, sourceId, drainedVersion) {
12079
12099
  function resolveSteps({
12080
12100
  appliedId,
12081
12101
  appliedVersion,
12102
+ appliedShapeKnown = true,
12082
12103
  target,
12083
12104
  templates,
12084
12105
  recipe
@@ -12106,6 +12127,7 @@ function resolveSteps({
12106
12127
  rungs,
12107
12128
  appliedId,
12108
12129
  appliedVersion,
12130
+ appliedShapeKnown,
12109
12131
  templates,
12110
12132
  hop && { targetId: target.id, entries: hop.entries }
12111
12133
  );
@@ -12273,7 +12295,7 @@ function resolveMapWrites(maps, before, fromTemplate, target) {
12273
12295
  function valuesOf(element) {
12274
12296
  return enumerateElementValues(getExtensionElements(element.businessObject));
12275
12297
  }
12276
- function applyApplication(modeler, catalog, element, application, mapWrites = []) {
12298
+ function applyApplication(modeler, catalog, element, application, mapWrites = [], unverifiedReads = false) {
12277
12299
  const { template, step } = application;
12278
12300
  const applied = readAppliedTemplate(element.businessObject);
12279
12301
  if (applied?.id === template.id && applied.version === (template.version ?? 0)) {
@@ -12285,7 +12307,7 @@ function applyApplication(modeler, catalog, element, application, mapWrites = []
12285
12307
  writes: recipeWrites,
12286
12308
  facts,
12287
12309
  activeProperties
12288
- } = buildStepPlan(step?.entries ?? [], values, clone);
12310
+ } = buildStepPlan(step?.entries ?? [], values, clone, unverifiedReads);
12289
12311
  assertNoAmbiguousWrites([...recipeWrites, ...mapWrites]);
12290
12312
  const stepWrites = [...recipeWrites, ...mapWrites];
12291
12313
  const writes = [
@@ -12372,6 +12394,7 @@ function migrateElement({
12372
12394
  modeler,
12373
12395
  element,
12374
12396
  fromTemplate,
12397
+ sourceKnown = true,
12375
12398
  target,
12376
12399
  templates,
12377
12400
  recipe,
@@ -12387,6 +12410,7 @@ function migrateElement({
12387
12410
  const { steps, refusal } = resolveSteps({
12388
12411
  appliedId: fromTemplate.id,
12389
12412
  appliedVersion: fromTemplate.version ?? 0,
12413
+ appliedShapeKnown: sourceKnown,
12390
12414
  target,
12391
12415
  templates,
12392
12416
  recipe
@@ -12419,7 +12443,8 @@ function migrateElement({
12419
12443
  catalog,
12420
12444
  current,
12421
12445
  application,
12422
- isFinal ? mapPlan.writes : []
12446
+ isFinal ? mapPlan.writes : [],
12447
+ index === 0 && !sourceKnown
12423
12448
  );
12424
12449
  if (result) {
12425
12450
  current = result.element;
@@ -12451,6 +12476,7 @@ function migrateElement({
12451
12476
  const report = buildReport({
12452
12477
  fromTemplate: reportSource,
12453
12478
  toTemplate: target,
12479
+ via: applications.map((a) => a.template),
12454
12480
  before,
12455
12481
  after: allFacts.at(-1)?.after ?? before,
12456
12482
  facts,
@@ -13281,22 +13307,33 @@ function createModeler() {
13281
13307
  moddleExtensions: { zeebe: vendor.ZeebeModdleExtension }
13282
13308
  });
13283
13309
  }
13284
- function templatePool(cachedTemplates, searchDir) {
13310
+ function templatePool(searchDir) {
13285
13311
  const local = /* @__PURE__ */ new Map();
13286
13312
  const localOf = (id) => {
13287
13313
  const templates = local.get(id) ?? findLocalTemplates(searchDir, id);
13288
13314
  local.set(id, templates);
13289
13315
  return templates;
13290
13316
  };
13317
+ const withoutCache = /* @__PURE__ */ new Set();
13318
+ let cached;
13319
+ const cache = () => {
13320
+ cached ??= loadCache() ?? [];
13321
+ return cached;
13322
+ };
13291
13323
  const identity2 = (t) => JSON.stringify([t.id, t.version ?? 0]);
13292
13324
  return {
13293
13325
  localOf,
13326
+ cache,
13327
+ resolvedWithoutCache: (id) => withoutCache.add(id),
13294
13328
  pool(ids) {
13295
- const shadowing = [...new Set(ids)].filter((id) => id !== void 0).flatMap(localOf);
13329
+ const known = [...new Set(ids)].filter((id) => id !== void 0);
13330
+ const shadowing = known.flatMap(localOf);
13331
+ const isLocal = (id) => withoutCache.has(id) || localOf(id).length > 0;
13332
+ if (cached === void 0 && known.every(isLocal)) return shadowing;
13296
13333
  const shadowed = new Set(shadowing.map(identity2));
13297
13334
  return [
13298
13335
  ...shadowing,
13299
- ...cachedTemplates.filter((t) => !shadowed.has(identity2(t)))
13336
+ ...cache().filter((t) => !shadowed.has(identity2(t)))
13300
13337
  ];
13301
13338
  }
13302
13339
  };
@@ -13305,27 +13342,28 @@ async function resolveTarget({
13305
13342
  templateId,
13306
13343
  to,
13307
13344
  executionPlatformVersion,
13308
- cachedTemplates,
13309
13345
  templatePool: templatePool2
13310
13346
  }) {
13311
13347
  const arg = to ?? templateId;
13312
13348
  const ref = parseTemplateRef(arg);
13313
- if (ref?.kind === "id") {
13314
- resolveCatalog(
13315
- migrationTemplates(
13316
- templatePool2.pool([ref.id]).filter((t) => t.id === ref.id)
13317
- )
13318
- );
13319
- }
13349
+ const checkConflicts = (id) => resolveCatalog(
13350
+ migrationTemplates(templatePool2.pool([id]).filter((t) => t.id === id))
13351
+ );
13352
+ if (ref?.kind === "id") checkConflicts(ref.id);
13320
13353
  const target = ref?.kind === "id" ? await resolveTemplateId(ref, {
13321
13354
  localTemplates: templatePool2.localOf(ref.id),
13322
13355
  executionPlatformVersion,
13323
13356
  requireEngineCompatibility: true,
13324
- templates: cachedTemplates
13357
+ loadTemplates: () => {
13358
+ const cached = templatePool2.cache();
13359
+ checkConflicts(ref.id);
13360
+ return cached;
13361
+ }
13325
13362
  }) : await readTemplateFromPathOrUrl(arg);
13326
13363
  if (!isMigrationTemplate(target)) {
13327
13364
  throw new Error("The target template has no id.");
13328
13365
  }
13366
+ if (ref?.kind !== "id") templatePool2.resolvedWithoutCache(target.id);
13329
13367
  return target;
13330
13368
  }
13331
13369
  var selected = (element, id) => ({
@@ -13392,7 +13430,7 @@ function describeDropped(report) {
13392
13430
  const unchecked = report.skipped.unchecked.map((u) => u.key);
13393
13431
  return names.length > 0 ? `${names.length} dropped (${names.join(", ")})` : unchecked.length > 0 ? `${unchecked.length} unchecked (${unchecked.join(", ")})` : report.refusal ? `recipe not used: ${report.refusal}` : "values not migrated";
13394
13432
  }
13395
- async function runMigrateInternal({ parsed, templateId, elementId, bpmnFilePath }, redaction) {
13433
+ async function runMigrateInternal({ parsed, templateId, elementId, bpmnFilePath }, redaction, lockedPath) {
13396
13434
  const logger = c8ctl10.getLogger();
13397
13435
  installStdoutEpipeHandler();
13398
13436
  const dryRun = c8ctl10.dryRun === true;
@@ -13407,7 +13445,8 @@ async function runMigrateInternal({ parsed, templateId, elementId, bpmnFilePath
13407
13445
  );
13408
13446
  }
13409
13447
  const maps = parsed.maps.map(parseMapArg);
13410
- const input = await readBpmnInput(bpmnFilePath);
13448
+ const bpmnPath = lockedPath ?? bpmnFilePath;
13449
+ const input = await readBpmnInput(bpmnPath);
13411
13450
  if (!input) {
13412
13451
  throw new Error(
13413
13452
  "No BPMN input provided. Pass a file path or pipe BPMN XML via stdin."
@@ -13426,13 +13465,23 @@ async function runMigrateInternal({ parsed, templateId, elementId, bpmnFilePath
13426
13465
  const selected2 = selectElements(modeler, templateId, elementId);
13427
13466
  const valuesOf2 = (element) => enumerateElementValues(getExtensionElements(element.businessObject));
13428
13467
  redaction.values = selected2.flatMap(({ element }) => valuesOf2(element));
13429
- const cachedTemplates = loadCache() ?? [];
13430
13468
  const pool2 = templatePool(
13431
- cachedTemplates,
13432
- bpmnFilePath ? dirname6(input.source) : process.cwd()
13469
+ bpmnFilePath ? dirname6(resolvePath4(bpmnFilePath)) : process.cwd()
13433
13470
  );
13471
+ const localVersions = pool2.localOf(templateId).map((t) => t.version ?? 0);
13472
+ if (selected2.some(
13473
+ ({ element }) => !localVersions.includes(
13474
+ readAppliedTemplate(element.businessObject)?.version ?? 0
13475
+ )
13476
+ )) {
13477
+ pool2.cache();
13478
+ }
13434
13479
  const lineages = (ids) => migrationTemplates(pool2.pool(ids)).filter((t) => ids.includes(t.id));
13435
- redaction.templates = lineages([templateId, parsed.to]);
13480
+ redaction.templates = lineages([templateId]);
13481
+ const toRef = parseTemplateRef(parsed.to);
13482
+ if (toRef?.kind === "id") {
13483
+ redaction.templates = lineages([templateId, toRef.id]);
13484
+ }
13436
13485
  const recipe = parsed.recipePath ? loadRecipeFile(parsed.recipePath) : void 0;
13437
13486
  if (recipe && !recipe.sources.some((s) => s.sourceTemplateId === templateId)) {
13438
13487
  throw new Error(
@@ -13443,9 +13492,60 @@ async function runMigrateInternal({ parsed, templateId, elementId, bpmnFilePath
13443
13492
  templateId,
13444
13493
  to: parsed.to,
13445
13494
  executionPlatformVersion: engineVersion,
13446
- cachedTemplates,
13447
13495
  templatePool: pool2
13448
13496
  });
13497
+ redaction.templates = [...lineages([templateId, target.id]), target];
13498
+ const targetRecipe = recipe ?? embeddedRecipe(target);
13499
+ const floors = (targetRecipe?.sources ?? []).flatMap(
13500
+ (s) => s.kind === "change" && s.sourceTemplateId === templateId ? [s.minSourceVersion ?? 0] : []
13501
+ );
13502
+ const localLatest = latestOf(
13503
+ compatibleTemplates(pool2.localOf(templateId), engineVersion),
13504
+ templateId
13505
+ );
13506
+ let localRecipe;
13507
+ try {
13508
+ localRecipe = localLatest && readEmbeddedRecipe(localLatest);
13509
+ } catch {
13510
+ }
13511
+ const reachedLocally = (appliedVersion) => Math.max(
13512
+ appliedVersion,
13513
+ ...(localRecipe?.sources ?? []).flatMap(
13514
+ (s) => s.kind === "upgrade" && s.sourceTemplateId === templateId && s.toVersion > appliedVersion && s.toVersion <= (localLatest?.version ?? 0) ? [s.toVersion] : []
13515
+ )
13516
+ );
13517
+ if (floors.length > 0 && selected2.some(({ element }) => {
13518
+ const reached = reachedLocally(
13519
+ readAppliedTemplate(element.businessObject)?.version ?? 0
13520
+ );
13521
+ return floors.every((floor) => floor > reached);
13522
+ })) {
13523
+ pool2.cache();
13524
+ }
13525
+ const sourceLatest = target.id === templateId ? void 0 : latestOf(
13526
+ compatibleTemplates(pool2.pool([templateId]), engineVersion).filter(
13527
+ (t) => t.id === templateId
13528
+ ),
13529
+ templateId
13530
+ );
13531
+ let sourceRecipe;
13532
+ try {
13533
+ sourceRecipe = sourceLatest && readEmbeddedRecipe(sourceLatest);
13534
+ } catch {
13535
+ }
13536
+ const stepVersions = [targetRecipe, sourceRecipe].flatMap((r) => r?.sources ?? []).flatMap(
13537
+ (s) => s.kind === "upgrade" && s.sourceTemplateId === templateId ? [s.toVersion] : []
13538
+ );
13539
+ const lowestApplied = Math.min(
13540
+ ...selected2.map(
13541
+ ({ element }) => readAppliedTemplate(element.businessObject)?.version ?? 0
13542
+ )
13543
+ );
13544
+ if (stepVersions.some(
13545
+ (v) => v > lowestApplied && !localVersions.includes(v) && !(target.id === templateId && (target.version ?? 0) === v)
13546
+ )) {
13547
+ pool2.cache();
13548
+ }
13449
13549
  const cache = compatibleTemplates(
13450
13550
  pool2.pool([templateId, target.id]),
13451
13551
  engineVersion
@@ -13455,25 +13555,28 @@ async function runMigrateInternal({ parsed, templateId, elementId, bpmnFilePath
13455
13555
  [target]
13456
13556
  );
13457
13557
  redaction.templates = [...lineages([templateId, target.id]), target];
13458
- if (recipe) validateRecipeOwner(recipe, target);
13459
- const targetRecipe = recipe ?? embeddedRecipe(target);
13558
+ if (targetRecipe) validateRecipeOwner(targetRecipe, target);
13460
13559
  const fromTemplateOf = (applied) => {
13461
13560
  const isApplied = (t) => t.id === applied.id && (t.version ?? 0) === applied.version;
13462
- return templates.find(isApplied) ?? lineages([applied.id]).find(isApplied) ?? {
13463
- id: applied.id,
13464
- version: applied.version,
13465
- properties: []
13561
+ const source = templates.find(isApplied) ?? lineages([applied.id]).find(isApplied);
13562
+ return {
13563
+ source,
13564
+ fromTemplate: source ?? {
13565
+ id: applied.id,
13566
+ version: applied.version,
13567
+ properties: []
13568
+ }
13466
13569
  };
13467
13570
  };
13468
13571
  for (const { element } of selected2) {
13469
13572
  const applied = readAppliedTemplate(element.businessObject);
13470
13573
  if (!applied || applied.id === target.id) continue;
13471
13574
  const catalog = resolveCatalog(templates, [
13472
- fromTemplateOf(applied),
13575
+ fromTemplateOf(applied).fromTemplate,
13473
13576
  target
13474
13577
  ]);
13475
- const sourceLatest = latestOf(catalog, applied.id);
13476
- if (sourceLatest) embeddedRecipe(sourceLatest);
13578
+ const sourceLatest2 = latestOf(catalog, applied.id);
13579
+ if (sourceLatest2) embeddedRecipe(sourceLatest2);
13477
13580
  }
13478
13581
  if (!isEngineCompatible(target, engineVersion)) {
13479
13582
  throw new Error(
@@ -13518,12 +13621,13 @@ async function runMigrateInternal({ parsed, templateId, elementId, bpmnFilePath
13518
13621
  });
13519
13622
  continue;
13520
13623
  }
13521
- const fromTemplate = fromTemplateOf(applied);
13624
+ const { source, fromTemplate } = fromTemplateOf(applied);
13522
13625
  try {
13523
13626
  const result = migrateElement({
13524
13627
  modeler: migrationModeler,
13525
13628
  element,
13526
13629
  fromTemplate,
13630
+ sourceKnown: source !== void 0,
13527
13631
  target,
13528
13632
  templates,
13529
13633
  recipe,
@@ -13575,10 +13679,10 @@ async function runMigrateInternal({ parsed, templateId, elementId, bpmnFilePath
13575
13679
  }
13576
13680
  const canWrite = !dryRun && failed.length === 0 && !wouldBlock;
13577
13681
  const saved = canWrite && updated.length > 0 ? await modeler.saveXML({ format: true }) : void 0;
13578
- if (saved && parsed.inPlace && bpmnFilePath) {
13579
- if (readFileSync5(bpmnFilePath, "utf-8") !== input.xml)
13682
+ if (saved && parsed.inPlace && bpmnPath) {
13683
+ if (readFileSync5(bpmnPath, "utf-8") !== input.xml)
13580
13684
  throw new Error(CONCURRENT_EDIT_MESSAGE);
13581
- atomicOverwriteFile(bpmnFilePath, saved.xml, input.xml);
13685
+ atomicOverwriteFile(bpmnPath, saved.xml, input.xml);
13582
13686
  }
13583
13687
  const summary = {
13584
13688
  updated: updated.length,
@@ -13752,7 +13856,8 @@ async function runLockedMigrate(args, redaction) {
13752
13856
  return runMigrateInternal(resolved, redaction);
13753
13857
  if (!existsSync5(resolvePath4(file)))
13754
13858
  throw new Error(`File not found: ${file}`);
13755
- const lock = `${resolvePath4(file)}.migration.lock`;
13859
+ const lockedPath = realpathSync2(file);
13860
+ const lock = `${lockedPath}.migration.lock`;
13756
13861
  let descriptor;
13757
13862
  try {
13758
13863
  descriptor = openSync2(lock, "wx");
@@ -13764,7 +13869,7 @@ async function runLockedMigrate(args, redaction) {
13764
13869
  }
13765
13870
  let cleanupFailure;
13766
13871
  try {
13767
- await runMigrateInternal(resolved, redaction);
13872
+ await runMigrateInternal(resolved, redaction, lockedPath);
13768
13873
  } finally {
13769
13874
  try {
13770
13875
  try {
@@ -228,7 +228,17 @@ that moved.
228
228
  templates first (see above), with `isEngineCompatible` as the eligibility
229
229
  rule; the cache is required only on the fallback. Steps, the applied source
230
230
  and redaction read template versions from the cache, with the local versions
231
- of the involved ids shadowing cached ones of the same id and version.
231
+ of the involved ids shadowing cached ones of the same id and version. The
232
+ cache is read only on a local gap: the target falls back to it, an involved
233
+ id has neither a local template nor a `--to` file or URL, or an applied
234
+ version or a recipe step version has no local template. A fully local
235
+ update never reads the cache, so a corrupt cache does not stop it.
236
+ - **Unavailable source.** When the applied version is found nowhere, the
237
+ engine gets a stub with the applied id and version and no properties. Recipe
238
+ reads against the stub are not checked for coverage. Values it cannot read,
239
+ such as `zeebe:calledElement`, are taken from the element and count as
240
+ unchecked unless the target binds them identically, so a write still needs
241
+ `--allow-lossy`.
232
242
  - **Recipe location.** A recipe is carried by the template it migrates *to*, in
233
243
  `metadata.migratesFrom`, so it travels with the template through the
234
244
  marketplace and the cache. `metadata` is the schema's free-form area; it
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camunda8/cli",
3
- "version": "4.6.0-alpha.3",
3
+ "version": "4.6.0-alpha.5",
4
4
  "description": "Camunda 8 CLI - minimal-dependency CLI for Camunda 8 operations",
5
5
  "type": "module",
6
6
  "engines": {