mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-24 07:38:12 -05:00
refactor: add detectIfCurrentPkgIsExecutable to cli-meta package (#8362)
This commit is contained in:
5
.changeset/wicked-cooks-share.md
Normal file
5
.changeset/wicked-cooks-share.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/cli-meta": minor
|
||||
---
|
||||
|
||||
Add detectIfCurrentPkgIsExecutable.
|
||||
@@ -35,3 +35,7 @@ export const packageManager = {
|
||||
// This may be a 3.0.0-beta.2
|
||||
version: pkgJson.version,
|
||||
}
|
||||
|
||||
export function detectIfCurrentPkgIsExecutable (proc: NodeJS.Process = process): boolean {
|
||||
return 'pkg' in proc && proc.pkg != null
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
"@pnpm/logger": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pnpm/cli-meta": "workspace:*",
|
||||
"@pnpm/config": "workspace:*",
|
||||
"@pnpm/core-loggers": "workspace:*",
|
||||
"@pnpm/dedupe.issues-renderer": "workspace:*",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { type UpdateCheckLog } from '@pnpm/core-loggers'
|
||||
import { detectIfCurrentPkgIsExecutable } from '@pnpm/cli-meta'
|
||||
import boxen from 'boxen'
|
||||
import chalk from 'chalk'
|
||||
import * as Rx from 'rxjs'
|
||||
@@ -59,7 +60,3 @@ function renderUpdateCommand (opts: UpdateMessageOptions): string {
|
||||
const pkgName = opts.currentPkgIsExecutable ? '@pnpm/exe' : 'pnpm'
|
||||
return `pnpm add -g ${pkgName}`
|
||||
}
|
||||
|
||||
function detectIfCurrentPkgIsExecutable (process: NodeJS.Process): boolean {
|
||||
return process['pkg'] != null
|
||||
}
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
},
|
||||
{
|
||||
"path": "../../packages/types"
|
||||
},
|
||||
{
|
||||
"path": "../cli-meta"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
"compile": "tsc --build && pnpm run lint --fix"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pnpm/cli-meta": "workspace:*",
|
||||
"@pnpm/core-loggers": "workspace:*",
|
||||
"@pnpm/error": "workspace:*",
|
||||
"@pnpm/types": "workspace:*",
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { detectIfCurrentPkgIsExecutable } from '@pnpm/cli-meta'
|
||||
import mem from 'mem'
|
||||
import * as execa from 'execa'
|
||||
|
||||
export function getSystemNodeVersionNonCached (): string {
|
||||
// @ts-expect-error
|
||||
if (process['pkg'] != null) {
|
||||
if (detectIfCurrentPkgIsExecutable()) {
|
||||
return execa.sync('node', ['--version']).stdout.toString()
|
||||
}
|
||||
return process.version
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
"../../__typings__/**/*.d.ts"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../cli/cli-meta"
|
||||
},
|
||||
{
|
||||
"path": "../../packages/core-loggers"
|
||||
},
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/pnpm/pnpm/blob/main/packages/plugin-commands-setup#readme",
|
||||
"dependencies": {
|
||||
"@pnpm/cli-meta": "workspace:*",
|
||||
"@pnpm/cli-utils": "workspace:*",
|
||||
"@pnpm/os.env.path-extender": "catalog:",
|
||||
"render-help": "catalog:"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { detectIfCurrentPkgIsExecutable } from '@pnpm/cli-meta'
|
||||
import { docsUrl } from '@pnpm/cli-utils'
|
||||
import { logger } from '@pnpm/logger'
|
||||
import {
|
||||
@@ -41,8 +42,7 @@ export function help (): string {
|
||||
}
|
||||
|
||||
function getExecPath (): string {
|
||||
// @ts-expect-error
|
||||
if (process['pkg'] != null) {
|
||||
if (detectIfCurrentPkgIsExecutable()) {
|
||||
// If the pnpm CLI was bundled by vercel/pkg then we cannot use the js path for npm_execpath
|
||||
// because in that case the js is in a virtual filesystem inside the executor.
|
||||
// Instead, we use the path to the exe file.
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
{
|
||||
"path": "../../__utils__/prepare"
|
||||
},
|
||||
{
|
||||
"path": "../../cli/cli-meta"
|
||||
},
|
||||
{
|
||||
"path": "../../cli/cli-utils"
|
||||
},
|
||||
|
||||
9
pnpm-lock.yaml
generated
9
pnpm-lock.yaml
generated
@@ -1113,6 +1113,9 @@ importers:
|
||||
|
||||
cli/default-reporter:
|
||||
dependencies:
|
||||
'@pnpm/cli-meta':
|
||||
specifier: workspace:*
|
||||
version: link:../cli-meta
|
||||
'@pnpm/config':
|
||||
specifier: workspace:*
|
||||
version: link:../../config/config
|
||||
@@ -1398,6 +1401,9 @@ importers:
|
||||
|
||||
config/package-is-installable:
|
||||
dependencies:
|
||||
'@pnpm/cli-meta':
|
||||
specifier: workspace:*
|
||||
version: link:../../cli/cli-meta
|
||||
'@pnpm/core-loggers':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/core-loggers
|
||||
@@ -3555,6 +3561,9 @@ importers:
|
||||
|
||||
packages/plugin-commands-setup:
|
||||
dependencies:
|
||||
'@pnpm/cli-meta':
|
||||
specifier: workspace:*
|
||||
version: link:../../cli/cli-meta
|
||||
'@pnpm/cli-utils':
|
||||
specifier: workspace:*
|
||||
version: link:../../cli/cli-utils
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { packageManager } from '@pnpm/cli-meta'
|
||||
import { packageManager, detectIfCurrentPkgIsExecutable } from '@pnpm/cli-meta'
|
||||
import renderHelp from 'render-help'
|
||||
|
||||
export function createHelp (helpByCommandName: Record<string, () => string>): (opts: unknown, params: string[]) => string {
|
||||
@@ -12,7 +12,7 @@ export function createHelp (helpByCommandName: Record<string, () => string>): (o
|
||||
helpText = `No results for "${params[0]}"`
|
||||
}
|
||||
return `Version ${packageManager.version}\
|
||||
${process['pkg'] != null ? ` (compiled to binary; bundled Node.js ${process.version})` : ''}\
|
||||
${detectIfCurrentPkgIsExecutable() != null ? ` (compiled to binary; bundled Node.js ${process.version})` : ''}\
|
||||
\n${helpText}\n`
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user