Skip to content

Commit

Permalink
fix(upgrade): use preferred-pm instead of which-pm-runs (#11139)
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh committed May 24, 2024
1 parent 4c7949d commit aaf0635
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-singers-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/upgrade": patch
---

Fixes @astrojs/upgrade not using the package manager that was used to install the project to install dependencies
9 changes: 3 additions & 6 deletions packages/upgrade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,18 @@
"dev": "astro-scripts dev \"src/**/*.ts\"",
"test": "astro-scripts test \"test/**/*.test.js\""
},
"files": [
"dist",
"upgrade.js"
],
"files": ["dist", "upgrade.js"],
"//a": "MOST PACKAGES SHOULD GO IN DEV_DEPENDENCIES! THEY WILL BE BUNDLED.",
"//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES",
"dependencies": {
"@astrojs/cli-kit": "^0.4.1",
"semver": "^7.6.2",
"which-pm-runs": "^1.1.0",
"preferred-pm": "^3.1.3",
"terminal-link": "^3.0.0"
},
"devDependencies": {
"@types/semver": "^7.5.8",
"@types/which-pm-runs": "^1.0.2",
"@types/preferred-pm": "^3.0.0",
"arg": "^5.0.2",
"astro-scripts": "workspace:*",
"strip-ansi": "^7.1.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/upgrade/src/actions/context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { pathToFileURL } from 'node:url';
import { prompt } from '@astrojs/cli-kit';
import arg from 'arg';
import detectPackageManager from 'which-pm-runs';
import detectPackageManager from 'preferred-pm';

export interface Context {
help: boolean;
Expand Down Expand Up @@ -38,7 +38,7 @@ export async function getContext(argv: string[]): Promise<Context> {
{ argv, permissive: true }
);

const packageManager = detectPackageManager()?.name ?? 'npm';
const packageManager = (await detectPackageManager(process.cwd()))?.name ?? 'npm';
const {
_: [version = 'latest'] = [],
'--help': help = false,
Expand Down
4 changes: 2 additions & 2 deletions packages/upgrade/src/messages.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint no-console: 'off' */
import { color, label, spinner as load } from '@astrojs/cli-kit';
import { align } from '@astrojs/cli-kit/utils';
import detectPackageManager from 'preferred-pm';
import terminalLink from 'terminal-link';
import detectPackageManager from 'which-pm-runs';
import type { PackageInfo } from './actions/context.js';
import { shell } from './shell.js';

Expand All @@ -14,7 +14,7 @@ let _registry: string;
export async function getRegistry(): Promise<string> {
if (_registry) return _registry;
const fallback = 'https://registry.npmjs.org';
const packageManager = detectPackageManager()?.name || 'npm';
const packageManager = (await detectPackageManager(process.cwd()))?.name || 'npm';
try {
const { stdout } = await shell(packageManager, ['config', 'get', 'registry']);
_registry = stdout?.trim()?.replace(/\/$/, '') || fallback;
Expand Down
19 changes: 13 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aaf0635

Please sign in to comment.