mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-24 07:38:12 -05:00
refactor: add a function for corepack context detection
This commit is contained in:
5
.changeset/sixty-bulldogs-pretend.md
Normal file
5
.changeset/sixty-bulldogs-pretend.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/cli-meta": minor
|
||||
---
|
||||
|
||||
Added isExecutedByCorepack.
|
||||
@@ -39,3 +39,7 @@ export const packageManager = {
|
||||
export function detectIfCurrentPkgIsExecutable (proc: NodeJS.Process = process): boolean {
|
||||
return 'pkg' in proc && proc.pkg != null
|
||||
}
|
||||
|
||||
export function isExecutedByCorepack (env: NodeJS.ProcessEnv = process.env): boolean {
|
||||
return env.COREPACK_ROOT != null
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { PnpmError } from '@pnpm/error'
|
||||
import { packageManager } from '@pnpm/cli-meta'
|
||||
import { isExecutedByCorepack, packageManager } from '@pnpm/cli-meta'
|
||||
import { logger, globalWarn } from '@pnpm/logger'
|
||||
import { checkPackage, UnsupportedEngineError, type WantedEngine } from '@pnpm/package-is-installable'
|
||||
import { type SupportedArchitectures } from '@pnpm/types'
|
||||
@@ -24,7 +24,7 @@ export function packageIsInstallable (
|
||||
const currentPnpmVersion = packageManager.name === 'pnpm'
|
||||
? packageManager.version
|
||||
: undefined
|
||||
if (pkg.packageManager && !process.env.COREPACK_ROOT) {
|
||||
if (pkg.packageManager && !isExecutedByCorepack()) {
|
||||
const [pmName, pmReference] = pkg.packageManager.split('@')
|
||||
if (pmName && pmName !== 'pnpm') {
|
||||
const msg = `This project is configured to use ${pmName}`
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { type UpdateCheckLog } from '@pnpm/core-loggers'
|
||||
import { detectIfCurrentPkgIsExecutable } from '@pnpm/cli-meta'
|
||||
import { detectIfCurrentPkgIsExecutable, isExecutedByCorepack } from '@pnpm/cli-meta'
|
||||
import boxen from 'boxen'
|
||||
import chalk from 'chalk'
|
||||
import * as Rx from 'rxjs'
|
||||
@@ -54,7 +54,7 @@ function renderUpdateMessage (opts: UpdateMessageOptions): string {
|
||||
}
|
||||
|
||||
function renderUpdateCommand (opts: UpdateMessageOptions): string {
|
||||
if (opts.env.COREPACK_ROOT) {
|
||||
if (isExecutedByCorepack(opts.env)) {
|
||||
return `corepack install -g pnpm@${opts.latestVersion}`
|
||||
}
|
||||
const pkgName = opts.currentPkgIsExecutable ? '@pnpm/exe' : 'pnpm'
|
||||
|
||||
Reference in New Issue
Block a user