@astrojs/upgrade 0.5.0 → 0.5.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 +28 -16
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -172,7 +172,7 @@ var require_arg = __commonJS({
172
172
  var import_arg = __toESM(require_arg(), 1);
173
173
  import { pathToFileURL } from "node:url";
174
174
  import { prompt } from "@astrojs/cli-kit";
175
- import detectPackageManager from "preferred-pm";
175
+ import { detect } from "package-manager-detector";
176
176
  async function getContext(argv) {
177
177
  const flags = (0, import_arg.default)(
178
178
  {
@@ -182,7 +182,11 @@ async function getContext(argv) {
182
182
  },
183
183
  { argv, permissive: true }
184
184
  );
185
- const packageManager = (await detectPackageManager(process.cwd()))?.name ?? "npm";
185
+ const packageManager = await detect({
186
+ // Include the `install-metadata` strategy to have the package manager that's
187
+ // used for installation take precedence
188
+ strategies: ["install-metadata", "lockfile", "packageManager-field"]
189
+ }) ?? { agent: "npm", name: "npm" };
186
190
  const {
187
191
  _: [version = "latest"] = [],
188
192
  "--help": help2 = false,
@@ -205,7 +209,7 @@ async function getContext(argv) {
205
209
  // src/messages.ts
206
210
  import { color, label, spinner as load } from "@astrojs/cli-kit";
207
211
  import { align } from "@astrojs/cli-kit/utils";
208
- import detectPackageManager2 from "preferred-pm";
212
+ import { detect as detect2 } from "package-manager-detector";
209
213
  import terminalLink from "terminal-link";
210
214
 
211
215
  // src/shell.ts
@@ -252,7 +256,7 @@ var _registry;
252
256
  async function getRegistry() {
253
257
  if (_registry) return _registry;
254
258
  const fallback = "https://registry.npmjs.org";
255
- const packageManager = (await detectPackageManager2(process.cwd()))?.name || "npm";
259
+ const packageManager = (await detect2())?.name || "npm";
256
260
  try {
257
261
  const { stdout: stdout2 } = await shell(packageManager, ["config", "get", "registry"]);
258
262
  _registry = stdout2?.trim()?.replace(/\/$/, "") || fallback;
@@ -438,6 +442,7 @@ import path from "node:path";
438
442
  import { fileURLToPath } from "node:url";
439
443
  import { color as color2, say } from "@astrojs/cli-kit";
440
444
  import { random, sleep } from "@astrojs/cli-kit/utils";
445
+ import { resolveCommand } from "package-manager-detector";
441
446
  async function install(ctx) {
442
447
  await banner();
443
448
  newline();
@@ -514,18 +519,22 @@ function sortPackages(a, b) {
514
519
  }
515
520
  async function runInstallCommand(ctx, dependencies, devDependencies) {
516
521
  const cwd = fileURLToPath(ctx.cwd);
517
- if (ctx.packageManager === "yarn") await ensureYarnLock({ cwd });
518
- const installCmd = ctx.packageManager === "yarn" || ctx.packageManager === "pnpm" ? "add" : "install";
522
+ if (ctx.packageManager.name === "yarn") await ensureYarnLock({ cwd });
523
+ const installCommand = resolveCommand(ctx.packageManager.agent, "add", []);
524
+ if (!installCommand) {
525
+ error("error", `Unable to find install command for ${ctx.packageManager.name}.`);
526
+ return ctx.exit(1);
527
+ }
519
528
  await spinner({
520
- start: `Installing dependencies with ${ctx.packageManager}...`,
529
+ start: `Installing dependencies with ${ctx.packageManager.name}...`,
521
530
  end: `Installed dependencies!`,
522
531
  while: async () => {
523
532
  try {
524
533
  if (dependencies.length > 0) {
525
534
  await shell(
526
- ctx.packageManager,
535
+ installCommand.command,
527
536
  [
528
- installCmd,
537
+ ...installCommand.args,
529
538
  ...dependencies.map(
530
539
  ({ name, targetVersion }) => `${name}@${targetVersion.replace(/^\^/, "")}`
531
540
  )
@@ -535,10 +544,9 @@ async function runInstallCommand(ctx, dependencies, devDependencies) {
535
544
  }
536
545
  if (devDependencies.length > 0) {
537
546
  await shell(
538
- ctx.packageManager,
547
+ installCommand.command,
539
548
  [
540
- installCmd,
541
- "--save-dev",
549
+ ...installCommand.args,
542
550
  ...devDependencies.map(
543
551
  ({ name, targetVersion }) => `${name}@${targetVersion.replace(/^\^/, "")}`
544
552
  )
@@ -547,14 +555,18 @@ async function runInstallCommand(ctx, dependencies, devDependencies) {
547
555
  );
548
556
  }
549
557
  } catch {
550
- const packages = [...dependencies, ...devDependencies].map(({ name, targetVersion }) => `${name}@${targetVersion}`).join(" ");
558
+ const manualInstallCommand = [
559
+ installCommand.command,
560
+ ...installCommand.args,
561
+ ...[...dependencies, ...devDependencies].map(
562
+ ({ name, targetVersion }) => `${name}@${targetVersion}`
563
+ )
564
+ ].join(" ");
551
565
  newline();
552
566
  error(
553
567
  "error",
554
568
  `Dependencies failed to install, please run the following command manually:
555
- ${color2.bold(
556
- `${ctx.packageManager} ${installCmd} ${packages}`
557
- )}`
569
+ ${color2.bold(manualInstallCommand)}`
558
570
  );
559
571
  return ctx.exit(1);
560
572
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/upgrade",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -24,12 +24,12 @@
24
24
  "//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES",
25
25
  "dependencies": {
26
26
  "@astrojs/cli-kit": "^0.4.1",
27
- "preferred-pm": "^4.1.1",
27
+ "package-manager-detector": "^1.1.0",
28
28
  "semver": "^7.7.1",
29
29
  "terminal-link": "^3.0.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@types/semver": "^7.5.8",
32
+ "@types/semver": "^7.7.0",
33
33
  "arg": "^5.0.2",
34
34
  "astro-scripts": "0.0.14"
35
35
  },