blun-king-cli 9.1.392 → 9.1.393

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.
@@ -35,6 +35,7 @@ const UPDATE_SIGNAL_EXIT_CODES = Object.freeze({
35
35
  SIGTERM: 143,
36
36
  });
37
37
  const INTERACTIVE_START_MODE_FLAGS = new Set([
38
+ '-c',
38
39
  '-y',
39
40
  '--auto',
40
41
  '--auto-approve',
@@ -556,51 +557,6 @@ function pendingUpdatePath(blunDir) {
556
557
  return path.join(blunDir, PENDING_UPDATE_FILE);
557
558
  }
558
559
 
559
- function readPendingUpdate(blunDir) {
560
- try {
561
- const filePath = pendingUpdatePath(blunDir);
562
- if (!fs.existsSync(filePath)) return undefined;
563
- securePrivateFile(filePath);
564
- const stat = fs.lstatSync(filePath);
565
- if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 1_024) return undefined;
566
- const record = exactDataRecord(JSON.parse(fs.readFileSync(filePath, 'utf8')), [
567
- 'targetVersion',
568
- 'version',
569
- ]);
570
- if (!record || record.version !== 1 || !parseSemver(record.targetVersion)) return undefined;
571
- return record.targetVersion;
572
- } catch {
573
- return undefined;
574
- }
575
- }
576
-
577
- function writePendingUpdate(blunDir, targetVersion) {
578
- if (!parseSemver(targetVersion)) throw new Error('INVALID_UPDATE_VERSION');
579
- ensurePrivateDirectory(blunDir);
580
- const filePath = pendingUpdatePath(blunDir);
581
- const temporaryPath = path.join(
582
- blunDir,
583
- `.${PENDING_UPDATE_FILE}.${process.pid}.${randomUUID()}.tmp`,
584
- );
585
- try {
586
- writePrivateFile(temporaryPath, `${JSON.stringify({
587
- version: 1,
588
- targetVersion,
589
- })}\n`);
590
- const handle = fs.openSync(temporaryPath, 'r+');
591
- try {
592
- fs.fsyncSync(handle);
593
- } finally {
594
- fs.closeSync(handle);
595
- }
596
- fs.renameSync(temporaryPath, filePath);
597
- securePrivateFile(filePath);
598
- } catch (error) {
599
- fs.rmSync(temporaryPath, { force: true });
600
- throw error;
601
- }
602
- }
603
-
604
560
  function clearPendingUpdate(blunDir) {
605
561
  fs.rmSync(pendingUpdatePath(blunDir), { force: true });
606
562
  }
@@ -1029,14 +985,6 @@ function pathIsWithin(root, candidate) {
1029
985
  && !path.isAbsolute(relative));
1030
986
  }
1031
987
 
1032
- function isManagedReleasePackageRoot(blunDir, packageRoot) {
1033
- if (typeof blunDir !== 'string' || typeof packageRoot !== 'string') return false;
1034
- return pathIsWithin(
1035
- path.join(path.resolve(blunDir), UPDATE_DIRECTORY, 'releases'),
1036
- path.resolve(packageRoot),
1037
- );
1038
- }
1039
-
1040
988
  function resolveInstallTempRoot(options) {
1041
989
  if (typeof options.blunDir !== 'string' || options.blunDir.trim().length === 0) {
1042
990
  throw new Error('INVALID_UPDATE_BLUN_HOME');
@@ -1363,19 +1311,6 @@ function explicitFailure(stderr, reason, exitCode) {
1363
1311
  };
1364
1312
  }
1365
1313
 
1366
- function queueExplicitUpdate(blunDir, release, stdout, stderr) {
1367
- try {
1368
- ensurePrivateDirectory(blunDir);
1369
- writePendingUpdate(blunDir, release.version);
1370
- } catch {
1371
- return explicitFailure(stderr, 'private_home_unavailable');
1372
- }
1373
- stdout.write(
1374
- `Update ${release.version} vorgemerkt. Es wird beim ersten freien Start automatisch installiert.\n`,
1375
- );
1376
- return { kind: 'queued', version: release.version };
1377
- }
1378
-
1379
1314
  async function runUpdateFlow(options, explicitUpdate) {
1380
1315
  const {
1381
1316
  currentVersion,
@@ -1395,11 +1330,6 @@ async function runUpdateFlow(options, explicitUpdate) {
1395
1330
  : { kind: 'continue', reason: 'invalid_current_version' };
1396
1331
  }
1397
1332
 
1398
- let pendingVersion = readPendingUpdate(blunDir);
1399
- if (pendingVersion !== undefined && compareSemver(currentVersion, pendingVersion) >= 0) {
1400
- clearPendingUpdate(blunDir);
1401
- pendingVersion = undefined;
1402
- }
1403
1333
  const now = (options.now || Date.now)();
1404
1334
 
1405
1335
  const packageRoot = path.resolve(options.packageRoot || path.resolve(__dirname, '..'));
@@ -1448,26 +1378,14 @@ async function runUpdateFlow(options, explicitUpdate) {
1448
1378
  ? explicitNoTarget(stdout, reason, currentVersion)
1449
1379
  : { kind: 'continue', reason };
1450
1380
  }
1451
- const preparedRuntime = options.preparedRuntime;
1452
- const preparedRuntimeReady = preparedRuntime !== null
1453
- && typeof preparedRuntime === 'object'
1454
- && preparedRuntime.version === release.version
1455
- && typeof preparedRuntime.packageRoot === 'string'
1456
- && path.isAbsolute(preparedRuntime.packageRoot)
1457
- && verifyInstalledPackageVersion(preparedRuntime.packageRoot, release.version);
1458
- const automaticPreparedRuntimeReady = options.autoInstallPreparedRuntime === true
1459
- && preparedRuntimeReady;
1460
1381
  if (!explicitUpdate
1461
- && pendingVersion === undefined
1462
- && !automaticPreparedRuntimeReady
1463
1382
  && readSnoozeState(blunDir, release.version, now)) {
1464
1383
  return { kind: 'continue', reason: 'snoozed' };
1465
1384
  }
1466
- const queuedForRelease = pendingVersion === release.version;
1467
1385
  const initialInstallLease = await probeInstallLease(options, packageRoot);
1468
1386
  if (initialInstallLease === 'busy') {
1469
1387
  return explicitUpdate
1470
- ? queueExplicitUpdate(blunDir, release, stdout, stderr)
1388
+ ? explicitFailure(stderr, 'update_in_progress')
1471
1389
  : { kind: 'update_in_progress' };
1472
1390
  }
1473
1391
  if (initialInstallLease !== 'clear') {
@@ -1476,12 +1394,10 @@ async function runUpdateFlow(options, explicitUpdate) {
1476
1394
  : { kind: 'continue', reason: 'lease_unavailable' };
1477
1395
  }
1478
1396
  if (!explicitUpdate
1479
- && !queuedForRelease
1480
- && !automaticPreparedRuntimeReady
1481
1397
  && readSkippedVersion(blunDir) === release.version) {
1482
1398
  return { kind: 'continue', reason: 'skipped_version' };
1483
1399
  }
1484
- if (explicitUpdate || queuedForRelease) {
1400
+ if (explicitUpdate) {
1485
1401
  try {
1486
1402
  ensurePrivateDirectory(blunDir);
1487
1403
  } catch {
@@ -1498,7 +1414,7 @@ async function runUpdateFlow(options, explicitUpdate) {
1498
1414
  const prePromptInstallLease = await probeInstallLease(options, packageRoot);
1499
1415
  if (prePromptInstallLease === 'busy') {
1500
1416
  return explicitUpdate
1501
- ? queueExplicitUpdate(blunDir, release, stdout, stderr)
1417
+ ? explicitFailure(stderr, 'update_in_progress')
1502
1418
  : { kind: 'update_in_progress' };
1503
1419
  }
1504
1420
  if (prePromptInstallLease !== 'clear') {
@@ -1506,7 +1422,7 @@ async function runUpdateFlow(options, explicitUpdate) {
1506
1422
  ? explicitFailure(stderr, 'lease_unavailable')
1507
1423
  : { kind: 'continue', reason: 'lease_unavailable' };
1508
1424
  }
1509
- if (!options.installVersion && !preparedRuntimeReady) {
1425
+ if (!options.installVersion) {
1510
1426
  installerSession = await (options.prepareInstaller || preparePinnedInstaller)(
1511
1427
  release.version,
1512
1428
  { blunDir, packageRoot },
@@ -1521,7 +1437,7 @@ async function runUpdateFlow(options, explicitUpdate) {
1521
1437
  }
1522
1438
  }
1523
1439
  let action;
1524
- if (explicitUpdate || queuedForRelease || automaticPreparedRuntimeReady) {
1440
+ if (explicitUpdate) {
1525
1441
  action = 'install';
1526
1442
  } else {
1527
1443
  try {
@@ -1536,7 +1452,10 @@ async function runUpdateFlow(options, explicitUpdate) {
1536
1452
  }
1537
1453
  }
1538
1454
  if (action !== 'install') {
1539
- if (installerSession?.ready) await installerSession.cancel();
1455
+ if (installerSession?.ready) {
1456
+ await installerSession.cancel();
1457
+ installerSession = undefined;
1458
+ }
1540
1459
  if (action === 'skip-once') {
1541
1460
  return { kind: 'continue', reason: 'skipped_once' };
1542
1461
  }
@@ -1570,11 +1489,9 @@ async function runUpdateFlow(options, explicitUpdate) {
1570
1489
  let installResult;
1571
1490
  updateProgress(3, 'Paket wird installiert');
1572
1491
  try {
1573
- installResult = preparedRuntimeReady
1574
- ? { code: 0, verified: true, preparedRuntime: true }
1575
- : options.installVersion
1576
- ? await options.installVersion(release.version)
1577
- : await installerSession.commit();
1492
+ installResult = options.installVersion
1493
+ ? await options.installVersion(release.version)
1494
+ : await installerSession.commit();
1578
1495
  } catch {
1579
1496
  installResult = { code: undefined };
1580
1497
  }
@@ -1588,22 +1505,14 @@ async function runUpdateFlow(options, explicitUpdate) {
1588
1505
  }
1589
1506
  if (installResult?.code === 0 && installResult?.verified === true) {
1590
1507
  updateProgress(4, 'Installation geprüft');
1591
- if (explicitUpdate && installResult.preparedRuntime === true) {
1592
- writePendingUpdate(blunDir, release.version);
1593
- } else {
1594
- clearPendingUpdate(blunDir);
1595
- }
1508
+ clearPendingUpdate(blunDir);
1596
1509
  try {
1597
1510
  writeCoreInstallSuccess(
1598
1511
  blunDir,
1599
1512
  currentVersion,
1600
1513
  release.version,
1601
1514
  release.releaseNotes,
1602
- explicitUpdate || queuedForRelease
1603
- ? 'manual'
1604
- : automaticPreparedRuntimeReady
1605
- ? 'automatic'
1606
- : 'startup_prompt',
1515
+ explicitUpdate ? 'manual' : 'startup_prompt',
1607
1516
  (options.now || Date.now)(),
1608
1517
  );
1609
1518
  } catch {
@@ -1611,14 +1520,16 @@ async function runUpdateFlow(options, explicitUpdate) {
1611
1520
  `Update ${release.version} wurde installiert, aber die Startmeldung konnte nicht gespeichert werden.\n`,
1612
1521
  );
1613
1522
  }
1614
- stdout.write(
1615
- `Update ${currentVersion} -> ${release.version} erfolgreich installiert. Starte BLUN Code neu, um die neue Version zu verwenden.\n`,
1616
- );
1523
+ const continuesLastSession = Array.isArray(options.argv)
1524
+ && options.argv.length === 1
1525
+ && options.argv[0] === '-c';
1526
+ stdout.write(continuesLastSession
1527
+ ? `Update ${currentVersion} -> ${release.version} erfolgreich installiert. Die letzte Sitzung wird mit der neuen Version fortgesetzt.\n`
1528
+ : `Update ${currentVersion} -> ${release.version} erfolgreich installiert. Starte BLUN Code neu, um die neue Version zu verwenden.\n`);
1617
1529
  if (release.notesUrl) stdout.write(`Versionshinweise: ${release.notesUrl}\n`);
1618
1530
  return {
1619
1531
  kind: 'installed',
1620
1532
  version: release.version,
1621
- ...(installResult.preparedRuntime === true ? { source: 'prepared_runtime' } : {}),
1622
1533
  };
1623
1534
  }
1624
1535
 
@@ -1649,22 +1560,7 @@ async function runUpdateFlow(options, explicitUpdate) {
1649
1560
  }
1650
1561
 
1651
1562
  async function runExplicitUpdate(options) {
1652
- let preparedRuntime = options.preparedRuntime;
1653
- if (preparedRuntime === undefined
1654
- && isManagedReleasePackageRoot(options.blunDir, options.packageRoot)) {
1655
- const runningUpdate = options.prepareRunningUpdate && options.stageRuntime
1656
- ? undefined
1657
- : require('./running-update.cjs');
1658
- preparedRuntime = await (options.prepareRunningUpdate || runningUpdate.prepareRunningUpdate)({
1659
- currentVersion: options.currentVersion,
1660
- sharedHome: options.blunDir,
1661
- env: options.env,
1662
- });
1663
- if (preparedRuntime !== null) {
1664
- (options.stageRuntime || runningUpdate.stageRuntime)(options.blunDir, preparedRuntime);
1665
- }
1666
- }
1667
- return runUpdateFlow({ ...options, preparedRuntime }, true);
1563
+ return runUpdateFlow(options, true);
1668
1564
  }
1669
1565
 
1670
1566
  function runUpdateNotice(options) {