0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

fix(upgrade): use preferred-pm instead of which-pm-runs (#11139)

This commit is contained in:
Erika 2024-05-24 14:58:51 +02:00 committed by GitHub
parent 4c7949d1ae
commit aaf0635cc0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 25 additions and 16 deletions

View file

@ -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

View file

@ -22,21 +22,18 @@
"dev": "astro-scripts dev \"src/**/*.ts\"", "dev": "astro-scripts dev \"src/**/*.ts\"",
"test": "astro-scripts test \"test/**/*.test.js\"" "test": "astro-scripts test \"test/**/*.test.js\""
}, },
"files": [ "files": ["dist", "upgrade.js"],
"dist",
"upgrade.js"
],
"//a": "MOST PACKAGES SHOULD GO IN DEV_DEPENDENCIES! THEY WILL BE BUNDLED.", "//a": "MOST PACKAGES SHOULD GO IN DEV_DEPENDENCIES! THEY WILL BE BUNDLED.",
"//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES", "//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES",
"dependencies": { "dependencies": {
"@astrojs/cli-kit": "^0.4.1", "@astrojs/cli-kit": "^0.4.1",
"semver": "^7.6.2", "semver": "^7.6.2",
"which-pm-runs": "^1.1.0", "preferred-pm": "^3.1.3",
"terminal-link": "^3.0.0" "terminal-link": "^3.0.0"
}, },
"devDependencies": { "devDependencies": {
"@types/semver": "^7.5.8", "@types/semver": "^7.5.8",
"@types/which-pm-runs": "^1.0.2", "@types/preferred-pm": "^3.0.0",
"arg": "^5.0.2", "arg": "^5.0.2",
"astro-scripts": "workspace:*", "astro-scripts": "workspace:*",
"strip-ansi": "^7.1.0" "strip-ansi": "^7.1.0"

View file

@ -1,7 +1,7 @@
import { pathToFileURL } from 'node:url'; import { pathToFileURL } from 'node:url';
import { prompt } from '@astrojs/cli-kit'; import { prompt } from '@astrojs/cli-kit';
import arg from 'arg'; import arg from 'arg';
import detectPackageManager from 'which-pm-runs'; import detectPackageManager from 'preferred-pm';
export interface Context { export interface Context {
help: boolean; help: boolean;
@ -38,7 +38,7 @@ export async function getContext(argv: string[]): Promise<Context> {
{ argv, permissive: true } { argv, permissive: true }
); );
const packageManager = detectPackageManager()?.name ?? 'npm'; const packageManager = (await detectPackageManager(process.cwd()))?.name ?? 'npm';
const { const {
_: [version = 'latest'] = [], _: [version = 'latest'] = [],
'--help': help = false, '--help': help = false,

View file

@ -1,8 +1,8 @@
/* eslint no-console: 'off' */ /* eslint no-console: 'off' */
import { color, label, spinner as load } from '@astrojs/cli-kit'; import { color, label, spinner as load } from '@astrojs/cli-kit';
import { align } from '@astrojs/cli-kit/utils'; import { align } from '@astrojs/cli-kit/utils';
import detectPackageManager from 'preferred-pm';
import terminalLink from 'terminal-link'; import terminalLink from 'terminal-link';
import detectPackageManager from 'which-pm-runs';
import type { PackageInfo } from './actions/context.js'; import type { PackageInfo } from './actions/context.js';
import { shell } from './shell.js'; import { shell } from './shell.js';
@ -14,7 +14,7 @@ let _registry: string;
export async function getRegistry(): Promise<string> { export async function getRegistry(): Promise<string> {
if (_registry) return _registry; if (_registry) return _registry;
const fallback = 'https://registry.npmjs.org'; const fallback = 'https://registry.npmjs.org';
const packageManager = detectPackageManager()?.name || 'npm'; const packageManager = (await detectPackageManager(process.cwd()))?.name || 'npm';
try { try {
const { stdout } = await shell(packageManager, ['config', 'get', 'registry']); const { stdout } = await shell(packageManager, ['config', 'get', 'registry']);
_registry = stdout?.trim()?.replace(/\/$/, '') || fallback; _registry = stdout?.trim()?.replace(/\/$/, '') || fallback;

View file

@ -5691,22 +5691,22 @@ importers:
'@astrojs/cli-kit': '@astrojs/cli-kit':
specifier: ^0.4.1 specifier: ^0.4.1
version: 0.4.1 version: 0.4.1
preferred-pm:
specifier: ^3.1.3
version: 3.1.3
semver: semver:
specifier: ^7.6.2 specifier: ^7.6.2
version: 7.6.2 version: 7.6.2
terminal-link: terminal-link:
specifier: ^3.0.0 specifier: ^3.0.0
version: 3.0.0 version: 3.0.0
which-pm-runs:
specifier: ^1.1.0
version: 1.1.0
devDependencies: devDependencies:
'@types/preferred-pm':
specifier: ^3.0.0
version: 3.0.0
'@types/semver': '@types/semver':
specifier: ^7.5.8 specifier: ^7.5.8
version: 7.5.8 version: 7.5.8
'@types/which-pm-runs':
specifier: ^1.0.2
version: 1.0.2
arg: arg:
specifier: ^5.0.2 specifier: ^5.0.2
version: 5.0.2 version: 5.0.2
@ -8771,6 +8771,13 @@ packages:
resolution: {integrity: sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==} resolution: {integrity: sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==}
dev: true dev: true
/@types/preferred-pm@3.0.0:
resolution: {integrity: sha512-Ub1de7EkdavsyM1KNrTb1K1QL+ISepEELELh2QWccyDcVEcyUDiGoYzzOJfonpGNwpymYXY13oRFpXQluGOC5w==}
deprecated: This is a stub types definition. preferred-pm provides its own type definitions, so you do not need this installed.
dependencies:
preferred-pm: 3.1.3
dev: true
/@types/prismjs@1.26.4: /@types/prismjs@1.26.4:
resolution: {integrity: sha512-rlAnzkW2sZOjbqZ743IHUhFcvzaGbqijwOu8QZnZCjfQzBqFE3s4lOTJEsxikImav9uzz/42I+O7YUs1mWgMlg==} resolution: {integrity: sha512-rlAnzkW2sZOjbqZ743IHUhFcvzaGbqijwOu8QZnZCjfQzBqFE3s4lOTJEsxikImav9uzz/42I+O7YUs1mWgMlg==}
dev: true dev: true