@penvhq/launcher 0.10.0 → 0.11.0

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/dist/bin.cjs CHANGED
@@ -53,6 +53,8 @@ var import_core2 = require("@penvhq/core");
53
53
  // src/errors.ts
54
54
  var import_core = require("@penvhq/core");
55
55
  var INSTALL_COMMAND = "penv install";
56
+ var UPGRADE_COMMAND = "penv upgrade";
57
+ var YES_FLAG = "--yes";
56
58
  var MIN_PACKAGE_AGE_DAYS = 7;
57
59
  var TRUST_YOUNG_FLAG = "--trust-young";
58
60
  function addCommand(name, version, extra) {
@@ -235,11 +237,11 @@ var OfficialRegistryError = class extends import_core.PenvError {
235
237
  };
236
238
  var RegistryUnreadableError = class extends import_core.PenvError {
237
239
  name = "RegistryUnreadableError";
238
- constructor(name, url, detail) {
240
+ constructor(name, url, detail, retry = addCommand(name)) {
239
241
  super(
240
242
  "PENV_REGISTRY_UNREADABLE",
241
243
  `Reading ${name} from ${url} failed: ${detail}`,
242
- `Run \`${addCommand(name)}\` again when the registry is reachable.`
244
+ `Run \`${retry}\` again when the registry is reachable.`
243
245
  );
244
246
  }
245
247
  };
@@ -255,11 +257,11 @@ var PackageUnknownError = class extends import_core.PenvError {
255
257
  };
256
258
  var VersionUnknownError = class extends import_core.PenvError {
257
259
  name = "VersionUnknownError";
258
- constructor(name, version, url) {
260
+ constructor(name, version, url, retry = addCommand(name)) {
259
261
  super(
260
262
  "PENV_VERSION_UNKNOWN",
261
263
  `${url} publishes no ${version} of ${name}`,
262
- `Run \`${addCommand(name)}\` to take the version \`latest\` points at.`
264
+ `Run \`${retry}\` to take the version \`latest\` points at.`
263
265
  );
264
266
  }
265
267
  };
@@ -384,6 +386,66 @@ var EnginePinMismatchError = class extends import_core.PenvError {
384
386
  );
385
387
  }
386
388
  };
389
+ var UpgradeSubjectError = class extends import_core.PenvError {
390
+ name = "UpgradeSubjectError";
391
+ constructor() {
392
+ super(
393
+ "PENV_UPGRADE_SUBJECT",
394
+ "`penv upgrade` takes one version, or none",
395
+ `Run \`${UPGRADE_COMMAND}\` to move to whatever \`latest\` points at, or \`${UPGRADE_COMMAND} 0.9.6\` to move to an exact release.`
396
+ );
397
+ }
398
+ };
399
+ var UpgradeFlagError = class extends import_core.PenvError {
400
+ name = "UpgradeFlagError";
401
+ constructor(flag) {
402
+ super(
403
+ "PENV_UPGRADE_FLAG",
404
+ `\`${UPGRADE_COMMAND}\` does not understand \`${flag}\``,
405
+ `Run \`${UPGRADE_COMMAND} [version]\` with \`${YES_FLAG}\` \u2014 that is the one flag it takes.`
406
+ );
407
+ }
408
+ };
409
+ var UpgradeNoDownloadError = class extends import_core.PenvError {
410
+ name = "UpgradeNoDownloadError";
411
+ constructor() {
412
+ super(
413
+ "PENV_UPGRADE_NO_DOWNLOAD",
414
+ `Upgrading means reading the registry for the version and integrity to pin, and \`--no-download\` says this run does not`,
415
+ `Run \`${UPGRADE_COMMAND}\` without \`--no-download\`. Nothing was fetched or written.`
416
+ );
417
+ }
418
+ };
419
+ var UpgradeUnattendedError = class extends import_core.PenvError {
420
+ name = "UpgradeUnattendedError";
421
+ constructor() {
422
+ super(
423
+ "PENV_UPGRADE_UNATTENDED",
424
+ `Upgrading rewrites ${import_core.MANIFEST_PATH} and package.json, and this run has nobody to decide that`,
425
+ `Run \`${UPGRADE_COMMAND} <version> ${YES_FLAG}\` \u2014 unattended, penv moves the pin only to a version you named. In CI, run \`${INSTALL_COMMAND}\`: it installs what the committed manifest already pins.`
426
+ );
427
+ }
428
+ };
429
+ var UpgradeDeclinedError = class extends import_core.PenvError {
430
+ name = "UpgradeDeclinedError";
431
+ constructor(version) {
432
+ super(
433
+ "PENV_UPGRADE_DECLINED",
434
+ `${import_core.ENGINE_PACKAGE} ${version} was not installed, so ${import_core.MANIFEST_PATH} and package.json are unchanged`,
435
+ `Run \`${UPGRADE_COMMAND} ${version}\` again when you want both of them to move.`
436
+ );
437
+ }
438
+ };
439
+ var UpgradeInstallFailedError = class extends import_core.PenvError {
440
+ name = "UpgradeInstallFailedError";
441
+ constructor(command) {
442
+ super(
443
+ "PENV_UPGRADE_INSTALL_FAILED",
444
+ `${command} did not finish, so ${import_core.MANIFEST_PATH} still pins the engine it pinned before`,
445
+ `Run \`${command}\` yourself, then run \`${UPGRADE_COMMAND}\` again \u2014 the pin and the dependency move together or not at all.`
446
+ );
447
+ }
448
+ };
387
449
  var EngineEntryError = class extends import_core.PenvError {
388
450
  name = "EngineEntryError";
389
451
  constructor(name, version, dir) {
@@ -460,9 +522,9 @@ function httpFetcher() {
460
522
  }
461
523
 
462
524
  // src/launcher.ts
463
- var import_node_fs7 = require("fs");
525
+ var import_node_fs8 = require("fs");
464
526
  var import_node_path7 = require("path");
465
- var import_core10 = require("@penvhq/core");
527
+ var import_core11 = require("@penvhq/core");
466
528
 
467
529
  // src/add.ts
468
530
  var import_node_fs5 = require("fs");
@@ -926,7 +988,8 @@ async function fetchRelease(query) {
926
988
  throw new RegistryUnreadableError(
927
989
  query.name,
928
990
  url,
929
- cause instanceof Error ? cause.message : String(cause)
991
+ cause instanceof Error ? cause.message : String(cause),
992
+ query.retry
930
993
  );
931
994
  }
932
995
  let parsed;
@@ -936,7 +999,8 @@ async function fetchRelease(query) {
936
999
  throw new RegistryUnreadableError(
937
1000
  query.name,
938
1001
  url,
939
- cause instanceof Error ? cause.message : String(cause)
1002
+ cause instanceof Error ? cause.message : String(cause),
1003
+ query.retry
940
1004
  );
941
1005
  }
942
1006
  const packument = record(parsed);
@@ -952,7 +1016,7 @@ async function fetchRelease(query) {
952
1016
  const version = record(at(versions, asked)) === void 0 ? text3(at(tags, asked)) ?? asked : asked;
953
1017
  const release = record(at(versions, version));
954
1018
  if (release === void 0) {
955
- throw new VersionUnknownError(query.name, asked, url);
1019
+ throw new VersionUnknownError(query.name, asked, url, query.retry);
956
1020
  }
957
1021
  const dist = record(at(release, "dist"));
958
1022
  const integrity = text3(at(dist, "integrity"));
@@ -1351,6 +1415,7 @@ async function add(options) {
1351
1415
  }
1352
1416
 
1353
1417
  // src/help.ts
1418
+ var import_install = require("@penvhq/cli/install");
1354
1419
  var import_core7 = require("@penvhq/core");
1355
1420
  function printLauncherCommands(io2) {
1356
1421
  io2.out("");
@@ -1359,6 +1424,7 @@ function printLauncherCommands(io2) {
1359
1424
  io2.out(` install Installs everything ${import_core7.MANIFEST_PATH} pins`);
1360
1425
  io2.out(" add <package> Pins a provider extension, and commits the decision");
1361
1426
  io2.out(` add ${LOCAL_FLAG} <package> Adds the one this repository builds \u2014 nothing is pinned`);
1427
+ io2.out(` upgrade [version] Moves the engine pin and ${import_install.RUNTIME_PACKAGE} together`);
1362
1428
  io2.out("");
1363
1429
  }
1364
1430
  function printInstallHelp(io2) {
@@ -1381,6 +1447,17 @@ function printAddHelp(io2) {
1381
1447
  io2.out(`${import_core7.EXTENSIONS_PATH}/. Both are committed, so \`${INSTALL_COMMAND}\` gives every machine`);
1382
1448
  io2.out(`the bytes you reviewed. \`${LOCAL_FLAG}\` pins nothing and touches no manifest.`);
1383
1449
  }
1450
+ function printUpgradeHelp(io2) {
1451
+ io2.out("penv upgrade [version]");
1452
+ io2.out("");
1453
+ io2.out(` ${YES_FLAG} Skip the question \u2014 unattended runs need it and a version`);
1454
+ io2.out("");
1455
+ io2.out(`Moves the ${import_core7.ENGINE_PACKAGE} pin in ${import_core7.MANIFEST_PATH} and this project's`);
1456
+ io2.out(`${import_install.RUNTIME_PACKAGE} dependency to the same exact version. No version takes whatever`);
1457
+ io2.out("`latest` points at; the integrity is the one the registry states, never one penv");
1458
+ io2.out("computed. Both files are shown before either moves, and they move together or not");
1459
+ io2.out("at all. Extensions keep their own pins.");
1460
+ }
1384
1461
 
1385
1462
  // src/pins.ts
1386
1463
  var import_core8 = require("@penvhq/core");
@@ -1388,8 +1465,8 @@ var DEV_PIN_INTEGRITY = "sha512-development-build-not-a-published-release";
1388
1465
  var DEV_PIN_VERSION = "0.0.0-dev";
1389
1466
  var BUNDLED_ENGINE_PIN = {
1390
1467
  package: import_core8.ENGINE_PACKAGE,
1391
- version: "0.10.0",
1392
- integrity: "sha512-b+U0c3xWbk1ILtMfPjJW8x5XBxSLAaw/IAOLMBmGvT2uuYv41JPED8PrenEj4s3ZJY5BxpWU9mQcJHEBouaw/Q=="
1468
+ version: "0.11.0",
1469
+ integrity: "sha512-Y+WKyuPsX4U8/1j0e+VMUhj0LaGrp67YEoDAWyyinrgA+c8IM4H1blqje/YK4LsQwzQDQQDF9bhWIhfmDAWoxA=="
1393
1470
  };
1394
1471
  function assertReleasePin(pin) {
1395
1472
  if (pin.integrity === DEV_PIN_INTEGRITY || pin.version === DEV_PIN_VERSION) {
@@ -1430,9 +1507,110 @@ function findAdoptedRoot(cwd) {
1430
1507
  return findUp(cwd, (dir) => (0, import_node_fs6.existsSync)((0, import_core9.stateDir)(dir)));
1431
1508
  }
1432
1509
 
1510
+ // src/upgrade.ts
1511
+ var import_node_fs7 = require("fs");
1512
+ var import_install2 = require("@penvhq/cli/install");
1513
+ var import_core10 = require("@penvhq/core");
1514
+ function parseRequest2(argv) {
1515
+ let version;
1516
+ let yes = false;
1517
+ for (const token of argv) {
1518
+ if (token === YES_FLAG) {
1519
+ yes = true;
1520
+ continue;
1521
+ }
1522
+ if (token.startsWith("-")) {
1523
+ throw new UpgradeFlagError(token);
1524
+ }
1525
+ if (version !== void 0 || token === "") {
1526
+ throw new UpgradeSubjectError();
1527
+ }
1528
+ version = token;
1529
+ }
1530
+ return { version, yes };
1531
+ }
1532
+ function renderPinChange(engine, release) {
1533
+ return [
1534
+ import_core10.MANIFEST_PATH,
1535
+ ` - "integrity": "${engine.integrity}"`,
1536
+ ` - "version": "${engine.version}"`,
1537
+ ` + "integrity": "${release.integrity}"`,
1538
+ ` + "version": "${release.version}"`
1539
+ ];
1540
+ }
1541
+ function pinnedElsewhere(manifest, version) {
1542
+ return Object.entries(manifest.extensions).filter(([, entry]) => entry.version !== version).map(([name]) => name);
1543
+ }
1544
+ async function consent(options, release, plan, yes) {
1545
+ const { io: io2, manifest } = options;
1546
+ io2.out(`${import_core10.ENGINE_PACKAGE} ${manifest.engine.version} \u2192 ${release.version}`);
1547
+ io2.out("");
1548
+ for (const line of renderPinChange(manifest.engine, release)) {
1549
+ io2.out(line);
1550
+ }
1551
+ for (const line of (0, import_install2.renderInstallPlan)(plan)) {
1552
+ io2.out(line);
1553
+ }
1554
+ if (yes) {
1555
+ return;
1556
+ }
1557
+ if (!await io2.confirm(`Move this project to ${release.version}?`)) {
1558
+ throw new UpgradeDeclinedError(release.version);
1559
+ }
1560
+ }
1561
+ async function upgrade(options) {
1562
+ const { io: io2, fetcher, home, root, manifest, manifestFile } = options;
1563
+ const request = parseRequest2(options.argv);
1564
+ if (options.noDownload === true) {
1565
+ throw new UpgradeNoDownloadError();
1566
+ }
1567
+ if ((options.ci === true || !io2.interactive) && !(request.yes && request.version !== void 0)) {
1568
+ throw new UpgradeUnattendedError();
1569
+ }
1570
+ const release = await fetchRelease({
1571
+ name: import_core10.ENGINE_PACKAGE,
1572
+ ...request.version === void 0 ? {} : { version: request.version },
1573
+ retry: UPGRADE_COMMAND,
1574
+ fetcher
1575
+ });
1576
+ const plan = (0, import_install2.planInstall)(root, release.version);
1577
+ if (manifest.engine.version === release.version && plan.satisfied) {
1578
+ io2.out(`\u2713 Already on ${import_core10.ENGINE_PACKAGE} ${release.version} \u2014 nothing to move`);
1579
+ return;
1580
+ }
1581
+ const manifestText = (0, import_core10.serializeManifest)({
1582
+ ...manifest,
1583
+ engine: { package: import_core10.ENGINE_PACKAGE, version: release.version, integrity: release.integrity }
1584
+ });
1585
+ await consent(options, release, plan, request.yes);
1586
+ await installPin({
1587
+ home,
1588
+ kind: "engines",
1589
+ pin: { name: import_core10.ENGINE_PACKAGE, version: release.version, integrity: release.integrity },
1590
+ fetcher
1591
+ });
1592
+ io2.out(`\u2713 ${import_core10.ENGINE_PACKAGE} ${release.version} installed`);
1593
+ if (!plan.satisfied) {
1594
+ try {
1595
+ await (options.install ?? import_install2.installWithPackageManager)(plan);
1596
+ } catch {
1597
+ throw new UpgradeInstallFailedError(plan.command.join(" "));
1598
+ }
1599
+ io2.out(`\u2713 package.json depends on ${import_install2.RUNTIME_PACKAGE} ${release.version}`);
1600
+ }
1601
+ (0, import_node_fs7.writeFileSync)(manifestFile, manifestText);
1602
+ io2.out(`\u2713 ${import_core10.MANIFEST_PATH} pins ${import_core10.ENGINE_PACKAGE} ${release.version}`);
1603
+ const kept = pinnedElsewhere(manifest, release.version);
1604
+ if (kept.length > 0) {
1605
+ const subject = kept.length === 1 ? "keeps its own pin" : "keep their own pins";
1606
+ io2.out(`\u2192 ${kept.join(", ")} ${subject} \u2014 \`penv add <package>@<version>\` moves one.`);
1607
+ }
1608
+ }
1609
+
1433
1610
  // src/launcher.ts
1434
1611
  var INSTALL = "install";
1435
1612
  var ADD = "add";
1613
+ var UPGRADE = "upgrade";
1436
1614
  var VERSION_FLAGS = /* @__PURE__ */ new Set(["--version", "-v"]);
1437
1615
  var HELP_FLAGS = /* @__PURE__ */ new Set(["--help", "-h"]);
1438
1616
  var NO_DOWNLOAD = "--no-download";
@@ -1476,27 +1654,27 @@ function pinsOf(manifest) {
1476
1654
  ];
1477
1655
  }
1478
1656
  function reportable(error, home, argv) {
1479
- return error instanceof import_core10.UnsupportedManifestFormatError ? error.withLauncherUpdate({
1657
+ return error instanceof import_core11.UnsupportedManifestFormatError ? error.withLauncherUpdate({
1480
1658
  updateCommand: launcherUpdateCommand(home),
1481
1659
  invokedCommand: invokedCommand(argv)
1482
1660
  }) : error;
1483
1661
  }
1484
1662
  function readManifest(manifestFile, home, argv) {
1485
1663
  try {
1486
- return (0, import_core10.parseManifest)((0, import_node_fs7.readFileSync)(manifestFile, "utf8"));
1664
+ return (0, import_core11.parseManifest)((0, import_node_fs8.readFileSync)(manifestFile, "utf8"));
1487
1665
  } catch (error) {
1488
1666
  throw reportable(error, home, argv);
1489
1667
  }
1490
1668
  }
1491
1669
  function readManifestToRepair(manifestFile, home, argv) {
1492
1670
  try {
1493
- return readManifestForRepair((0, import_node_fs7.readFileSync)(manifestFile, "utf8"));
1671
+ return readManifestForRepair((0, import_node_fs8.readFileSync)(manifestFile, "utf8"));
1494
1672
  } catch (error) {
1495
1673
  throw reportable(error, home, argv);
1496
1674
  }
1497
1675
  }
1498
1676
  function report(error, io2) {
1499
- if (error instanceof import_core10.PenvError && error.remedy !== void 0) {
1677
+ if (error instanceof import_core11.PenvError && error.remedy !== void 0) {
1500
1678
  const suffix = `
1501
1679
  ${error.remedy}`;
1502
1680
  const message = error.message.endsWith(suffix) ? error.message.slice(0, -suffix.length) : error.message;
@@ -1518,7 +1696,7 @@ async function launch(options) {
1518
1696
  const { argv, cwd, env, io: io2 } = options;
1519
1697
  const { noDownload, forwarded } = splitLauncherFlags(argv);
1520
1698
  const first = forwarded[0];
1521
- const home = (0, import_core10.penvHome)(env);
1699
+ const home = (0, import_core11.penvHome)(env);
1522
1700
  if (first !== void 0 && forwarded.slice(1).some((token) => HELP_FLAGS.has(token))) {
1523
1701
  if (first === INSTALL) {
1524
1702
  printInstallHelp(io2);
@@ -1528,6 +1706,10 @@ async function launch(options) {
1528
1706
  printAddHelp(io2);
1529
1707
  return 0;
1530
1708
  }
1709
+ if (first === UPGRADE) {
1710
+ printUpgradeHelp(io2);
1711
+ return 0;
1712
+ }
1531
1713
  }
1532
1714
  const project = findProject(cwd);
1533
1715
  if (project === void 0) {
@@ -1555,6 +1737,20 @@ async function launch(options) {
1555
1737
  io2.out(`penv ${manifest.engine.version}`);
1556
1738
  return 0;
1557
1739
  }
1740
+ if (first === UPGRADE) {
1741
+ await upgrade({
1742
+ argv: forwarded.slice(1),
1743
+ root: project.root,
1744
+ manifestFile: project.manifestFile,
1745
+ manifest,
1746
+ home,
1747
+ io: io2,
1748
+ fetcher: options.fetcher,
1749
+ noDownload,
1750
+ ci: isCi(env)
1751
+ });
1752
+ return 0;
1753
+ }
1558
1754
  const enginePin = enginePinOf(manifest);
1559
1755
  const engineDir = await ensure(options, "engines", enginePin, home, noDownload);
1560
1756
  for (const pin of extensionPinsOf(manifest)) {
@@ -1573,16 +1769,16 @@ async function adopt(options, forwarded, home, cwd, noDownload) {
1573
1769
  if (root === void 0) {
1574
1770
  return 0;
1575
1771
  }
1576
- const manifestFile = (0, import_node_path7.join)(root, ...import_core10.MANIFEST_PATH.split("/"));
1577
- if ((0, import_node_fs7.existsSync)(manifestFile)) {
1772
+ const manifestFile = (0, import_node_path7.join)(root, ...import_core11.MANIFEST_PATH.split("/"));
1773
+ if ((0, import_node_fs8.existsSync)(manifestFile)) {
1578
1774
  return 0;
1579
1775
  }
1580
1776
  const pin = releaseEnginePin(options.bundledPin, engine.version);
1581
- (0, import_node_fs7.writeFileSync)(
1777
+ (0, import_node_fs8.writeFileSync)(
1582
1778
  manifestFile,
1583
- (0, import_core10.serializeManifest)({ format: import_core10.MANIFEST_FORMAT, engine: pin, extensions: {} })
1779
+ (0, import_core11.serializeManifest)({ format: import_core11.MANIFEST_FORMAT, engine: pin, extensions: {} })
1584
1780
  );
1585
- options.io.out(`\u2713 ${import_core10.MANIFEST_PATH} pins ${pin.package} ${pin.version}`);
1781
+ options.io.out(`\u2713 ${import_core11.MANIFEST_PATH} pins ${pin.package} ${pin.version}`);
1586
1782
  await ensureAdoptedEngine(
1587
1783
  options,
1588
1784
  { name: pin.package, version: pin.version, integrity: pin.integrity },
@@ -1670,7 +1866,7 @@ async function delegate(options, engine, forwarded, home, cwd) {
1670
1866
  command: process.execPath,
1671
1867
  args: [engine.entry, ...forwarded],
1672
1868
  cwd,
1673
- env: { ...options.env, [import_core10.PENV_HOME_VAR]: home }
1869
+ env: { ...options.env, [import_core11.PENV_HOME_VAR]: home }
1674
1870
  });
1675
1871
  if (code === 0 && isRootHelp(forwarded)) {
1676
1872
  printLauncherCommands(options.io);