@astrojs/upgrade 0.6.0 → 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 +54 -51
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -187,11 +187,7 @@ async function getContext(argv) {
187
187
  // used for installation take precedence
188
188
  strategies: ["install-metadata", "lockfile", "packageManager-field"]
189
189
  }) ?? { agent: "npm", name: "npm" };
190
- const {
191
- _: [version = "latest"] = [],
192
- "--help": help2 = false,
193
- "--dry-run": dryRun
194
- } = flags;
190
+ const { _: [version = "latest"] = [], "--help": help2 = false, "--dry-run": dryRun } = flags;
195
191
  return {
196
192
  help: help2,
197
193
  prompt,
@@ -228,7 +224,7 @@ async function shell(command, flags, opts = {}) {
228
224
  signal = controller.signal;
229
225
  }
230
226
  try {
231
- child = spawn(command, flags, {
227
+ child = spawn(`${command} ${flags.join(" ")}`, {
232
228
  cwd: opts.cwd,
233
229
  shell: true,
234
230
  stdio: opts.stdio,
@@ -443,7 +439,7 @@ import { fileURLToPath } from "node:url";
443
439
  import { color as color2, say } from "@astrojs/cli-kit";
444
440
  import { random, sleep } from "@astrojs/cli-kit/utils";
445
441
  import { resolveCommand } from "package-manager-detector";
446
- async function install(ctx) {
442
+ async function install(ctx, shellFn = shell) {
447
443
  await banner();
448
444
  newline();
449
445
  const { current, dependencies, devDependencies } = filterPackages(ctx);
@@ -490,7 +486,7 @@ async function install(ctx) {
490
486
  if (ctx.dryRun) {
491
487
  await info("--dry-run", `Skipping dependency installation`);
492
488
  } else {
493
- await runInstallCommand(ctx, dependencies, devDependencies);
489
+ await runInstallCommand(ctx, dependencies, devDependencies, shellFn);
494
490
  }
495
491
  }
496
492
  function filterPackages(ctx) {
@@ -517,7 +513,7 @@ function sortPackages(a, b) {
517
513
  if (b.name.startsWith("@astrojs") && !a.name.startsWith("@astrojs")) return 1;
518
514
  return a.name.localeCompare(b.name);
519
515
  }
520
- async function runInstallCommand(ctx, dependencies, devDependencies) {
516
+ async function runInstallCommand(ctx, dependencies, devDependencies, shellFn = shell) {
521
517
  const cwd = fileURLToPath(ctx.cwd);
522
518
  if (ctx.packageManager.name === "yarn") await ensureYarnLock({ cwd });
523
519
  const installCommand = resolveCommand(ctx.packageManager.agent, "add", []);
@@ -525,52 +521,59 @@ async function runInstallCommand(ctx, dependencies, devDependencies) {
525
521
  error("error", `Unable to find install command for ${ctx.packageManager.name}.`);
526
522
  return ctx.exit(1);
527
523
  }
528
- await spinner({
529
- start: `Installing dependencies with ${ctx.packageManager.name}...`,
530
- end: `Installed dependencies!`,
531
- while: async () => {
532
- try {
533
- if (dependencies.length > 0) {
534
- await shell(
535
- installCommand.command,
536
- [
537
- ...installCommand.args,
538
- ...dependencies.map(
539
- ({ name, targetVersion }) => `${name}@${targetVersion.replace(/^\^/, "")}`
540
- )
541
- ],
542
- { cwd, timeout: 9e4, stdio: "ignore" }
543
- );
544
- }
545
- if (devDependencies.length > 0) {
546
- await shell(
547
- installCommand.command,
548
- [
549
- ...installCommand.args,
550
- ...devDependencies.map(
551
- ({ name, targetVersion }) => `${name}@${targetVersion.replace(/^\^/, "")}`
552
- )
553
- ],
554
- { cwd, timeout: 9e4, stdio: "ignore" }
555
- );
556
- }
557
- } catch {
558
- const manualInstallCommand = [
524
+ const doInstall = async (legacyPeerDeps = false) => {
525
+ try {
526
+ if (dependencies.length > 0) {
527
+ await shellFn(
559
528
  installCommand.command,
560
- ...installCommand.args,
561
- ...[...dependencies, ...devDependencies].map(
562
- ({ name, targetVersion }) => `${name}@${targetVersion}`
563
- )
564
- ].join(" ");
565
- newline();
566
- error(
567
- "error",
568
- `Dependencies failed to install, please run the following command manually:
569
- ${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 }
570
550
  );
571
- return ctx.exit(1);
572
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);
573
571
  }
572
+ };
573
+ await spinner({
574
+ start: `Installing dependencies with ${ctx.packageManager.name}...`,
575
+ end: `Installed dependencies!`,
576
+ while: doInstall
574
577
  });
575
578
  await say([`${random(celebrations)} ${random(done)}`, random(bye)], { clear: false });
576
579
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/upgrade",
3
- "version": "0.6.0",
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",