refactor: add a function for corepack context detection
This commit is contained in:
4 files changed
+13
-4
No files matched your search
@@ -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 {
|
export function detectIfCurrentPkgIsExecutable (proc: NodeJS.Process = process): boolean {
|
||||||
return 'pkg' in proc && proc.pkg != null
|
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 { PnpmError } from '@pnpm/error'
|
||||||
import { packageManager } from '@pnpm/cli-meta'
|
import { isExecutedByCorepack, packageManager } from '@pnpm/cli-meta'
|
||||||
import { logger, globalWarn } from '@pnpm/logger'
|
import { logger, globalWarn } from '@pnpm/logger'
|
||||||
import { checkPackage, UnsupportedEngineError, type WantedEngine } from '@pnpm/package-is-installable'
|
import { checkPackage, UnsupportedEngineError, type WantedEngine } from '@pnpm/package-is-installable'
|
||||||
import { type SupportedArchitectures } from '@pnpm/types'
|
import { type SupportedArchitectures } from '@pnpm/types'
|
||||||
@@ -24,7 +24,7 @@ export function packageIsInstallable (
|
|||||||
const currentPnpmVersion = packageManager.name === 'pnpm'
|
const currentPnpmVersion = packageManager.name === 'pnpm'
|
||||||
? packageManager.version
|
? packageManager.version
|
||||||
: undefined
|
: undefined
|
||||||
if (pkg.packageManager && !process.env.COREPACK_ROOT) {
|
if (pkg.packageManager && !isExecutedByCorepack()) {
|
||||||
const [pmName, pmReference] = pkg.packageManager.split('@')
|
const [pmName, pmReference] = pkg.packageManager.split('@')
|
||||||
if (pmName && pmName !== 'pnpm') {
|
if (pmName && pmName !== 'pnpm') {
|
||||||
const msg = `This project is configured to use ${pmName}`
|
const msg = `This project is configured to use ${pmName}`
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { type UpdateCheckLog } from '@pnpm/core-loggers'
|
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 boxen from 'boxen'
|
||||||
import chalk from 'chalk'
|
import chalk from 'chalk'
|
||||||
import * as Rx from 'rxjs'
|
import * as Rx from 'rxjs'
|
||||||
@@ -54,7 +54,7 @@ function renderUpdateMessage (opts: UpdateMessageOptions): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderUpdateCommand (opts: UpdateMessageOptions): string {
|
function renderUpdateCommand (opts: UpdateMessageOptions): string {
|
||||||
if (opts.env.COREPACK_ROOT) {
|
if (isExecutedByCorepack(opts.env)) {
|
||||||
return `corepack install -g pnpm@${opts.latestVersion}`
|
return `corepack install -g pnpm@${opts.latestVersion}`
|
||||||
}
|
}
|
||||||
const pkgName = opts.currentPkgIsExecutable ? '@pnpm/exe' : 'pnpm'
|
const pkgName = opts.currentPkgIsExecutable ? '@pnpm/exe' : 'pnpm'
|
||||||
|
|||||||
Reference in new issue
Block a user