@astrojs/upgrade 0.6.1 → 0.6.2

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.
Files changed (2) hide show
  1. package/dist/index.js +52 -45
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -439,7 +439,7 @@ import { fileURLToPath } from "node:url";
439
439
  import { color as color2, say } from "@astrojs/cli-kit";
440
440
  import { random, sleep } from "@astrojs/cli-kit/utils";
441
441
  import { resolveCommand } from "package-manager-detector";
442
- async function install(ctx) {
442
+ async function install(ctx, shellFn = shell) {
443
443
  await banner();
444
444
  newline();
445
445
  const { current, dependencies, devDependencies } = filterPackages(ctx);
@@ -486,7 +486,7 @@ async function install(ctx) {
486
486
  if (ctx.dryRun) {
487
487
  await info("--dry-run", `Skipping dependency installation`);
488
488
  } else {
489
- await runInstallCommand(ctx, dependencies, devDependencies);
489
+ await runInstallCommand(ctx, dependencies, devDependencies, shellFn);
490
490
  }
491
491
  }
492
492
  function filterPackages(ctx) {
@@ -513,7 +513,7 @@ function sortPackages(a, b) {
513
513
  if (b.name.startsWith("@astrojs") && !a.name.startsWith("@astrojs")) return 1;
514
514
  return a.name.localeCompare(b.name);
515
515
  }
516
- async function runInstallCommand(ctx, dependencies, devDependencies) {
516
+ async function runInstallCommand(ctx, dependencies, devDependencies, shellFn = shell) {
517
517
  const cwd = fileURLToPath(ctx.cwd);
518
518
  if (ctx.packageManager.name === "yarn") await ensureYarnLock({ cwd });
519
519
  const installCommand = resolveCommand(ctx.packageManager.agent, "add", []);
@@ -521,52 +521,59 @@ async function runInstallCommand(ctx, dependencies, devDependencies) {
521
521
  error("error", `Unable to find install command for ${ctx.packageManager.name}.`);
522
522
  return ctx.exit(1);
523
523
  }
524
- await spinner({
525
- start: `Installing dependencies with ${ctx.packageManager.name}...`,
526
- end: `Installed dependencies!`,
527
- while: async () => {
528
- try {
529
- if (dependencies.length > 0) {
530
- await shell(
531
- installCommand.command,
532
- [
533
- ...installCommand.args,
534
- ...dependencies.map(
535
- ({ name, targetVersion }) => `${name}@${targetVersion.replace(/^\^/, "")}`
536
- )
537
- ],
538
- { cwd, timeout: 9e4, stdio: "ignore" }
539
- );
540
- }
541
- if (devDependencies.length > 0) {
542
- await shell(
543
- installCommand.command,
544
- [
545
- ...installCommand.args,
546
- ...devDependencies.map(
547
- ({ name, targetVersion }) => `${name}@${targetVersion.replace(/^\^/, "")}`
548
- )
549
- ],
550
- { cwd, timeout: 9e4, stdio: "ignore" }
551
- );
552
- }
553
- } catch {
554
- const manualInstallCommand = [
524
+ const doInstall = async (legacyPeerDeps = false) => {
525
+ try {
526
+ if (dependencies.length > 0) {
527
+ await shellFn(
555
528
  installCommand.command,
556
- ...installCommand.args,
557
- ...[...dependencies, ...devDependencies].map(
558
- ({ name, targetVersion }) => `${name}@${targetVersion}`
559
- )
560
- ].join(" ");
561
- newline();
562
- error(
563
- "error",
564
- `Dependencies failed to install, please run the following command manually:
565
- ${color2.bold(manualInstallCommand)}`
529
+ [
530
+ ...installCommand.args,
531
+ ...legacyPeerDeps ? ["--legacy-peer-deps"] : [],
532
+ ...dependencies.map(
533
+ ({ name, targetVersion }) => `${name}@${targetVersion.replace(/^\^/, "")}`
534
+ )
535
+ ],
536
+ { cwd, timeout: 9e4 }
537
+ );
538
+ }
539
+ if (devDependencies.length > 0) {
540
+ await shellFn(
541
+ installCommand.command,
542
+ [
543
+ ...installCommand.args,
544
+ ...legacyPeerDeps ? ["--legacy-peer-deps"] : [],
545
+ ...devDependencies.map(
546
+ ({ name, targetVersion }) => `${name}@${targetVersion.replace(/^\^/, "")}`
547
+ )
548
+ ],
549
+ { cwd, timeout: 9e4 }
566
550
  );
567
- return ctx.exit(1);
568
551
  }
552
+ } catch (err) {
553
+ const errorMessage = err instanceof Error ? err.message : String(err);
554
+ if (ctx.packageManager.name === "npm" && !legacyPeerDeps && errorMessage.includes("peer dependenc")) {
555
+ return doInstall(true);
556
+ }
557
+ const manualInstallCommand = [
558
+ installCommand.command,
559
+ ...installCommand.args,
560
+ ...[...dependencies, ...devDependencies].map(
561
+ ({ name, targetVersion }) => `${name}@${targetVersion}`
562
+ )
563
+ ].join(" ");
564
+ newline();
565
+ error(
566
+ "error",
567
+ `Dependencies failed to install, please run the following command manually:
568
+ ${color2.bold(manualInstallCommand)}`
569
+ );
570
+ return ctx.exit(1);
569
571
  }
572
+ };
573
+ await spinner({
574
+ start: `Installing dependencies with ${ctx.packageManager.name}...`,
575
+ end: `Installed dependencies!`,
576
+ while: doInstall
570
577
  });
571
578
  await say([`${random(celebrations)} ${random(done)}`, random(bye)], { clear: false });
572
579
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/upgrade",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  "@astrojs/cli-kit": "^0.4.1",
27
27
  "package-manager-detector": "^1.1.0",
28
28
  "semver": "^7.7.1",
29
- "terminal-link": "^3.0.0"
29
+ "terminal-link": "^4.0.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/semver": "^7.7.0",