mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-06 06:55:12 -04:00
feat!: check the packageManager field (#7635)
* feat!: check the packageManager field * test: fix * refactor: update error message to match what corepack prints * feat: add pm-strict option * refactor: pm-strict=>package-manager-strict * fix: remove packageManager field from package.json on publish
This commit is contained in:
@@ -1,17 +1,20 @@
|
||||
import { PnpmError } from '@pnpm/error'
|
||||
import { packageManager } from '@pnpm/cli-meta'
|
||||
import { logger } from '@pnpm/logger'
|
||||
import { logger, globalWarn } from '@pnpm/logger'
|
||||
import { checkPackage, UnsupportedEngineError, type WantedEngine } from '@pnpm/package-is-installable'
|
||||
import { type SupportedArchitectures } from '@pnpm/types'
|
||||
|
||||
export function packageIsInstallable (
|
||||
pkgPath: string,
|
||||
pkg: {
|
||||
packageManager?: string
|
||||
engines?: WantedEngine
|
||||
cpu?: string[]
|
||||
os?: string[]
|
||||
libc?: string[]
|
||||
},
|
||||
opts: {
|
||||
packageManagerStrict?: boolean
|
||||
engineStrict?: boolean
|
||||
nodeVersion?: string
|
||||
supportedArchitectures?: SupportedArchitectures
|
||||
@@ -20,6 +23,24 @@ export function packageIsInstallable (
|
||||
const pnpmVersion = packageManager.name === 'pnpm'
|
||||
? packageManager.stableVersion
|
||||
: undefined
|
||||
if (pkg.packageManager) {
|
||||
const [pmName, pmVersion] = pkg.packageManager.split('@')
|
||||
if (pmName && pmName !== 'pnpm') {
|
||||
const msg = `This project is configured to use ${pmName}`
|
||||
if (opts.packageManagerStrict) {
|
||||
throw new PnpmError('OTHER_PM_EXPECTED', msg)
|
||||
} else {
|
||||
globalWarn(msg)
|
||||
}
|
||||
} else if (pmVersion && pnpmVersion && pmVersion !== pnpmVersion) {
|
||||
const msg = `This project is configured to use v${pmVersion} of pnpm. Your current pnpm is v${pnpmVersion}`
|
||||
if (opts.packageManagerStrict) {
|
||||
throw new PnpmError('BAD_PM_VERSION', msg)
|
||||
} else {
|
||||
globalWarn(msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
const err = checkPackage(pkgPath, pkg, {
|
||||
nodeVersion: opts.nodeVersion,
|
||||
pnpmVersion,
|
||||
|
||||
@@ -4,6 +4,7 @@ import { packageIsInstallable } from './packageIsInstallable'
|
||||
|
||||
export interface ReadProjectManifestOpts {
|
||||
engineStrict?: boolean
|
||||
packageManagerStrict?: boolean
|
||||
nodeVersion?: string
|
||||
supportedArchitectures?: SupportedArchitectures
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user