mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-24 07:38:12 -05:00
fix: don't fail if the pnpm version doesn't match the one in the packageManager field (#8166)
close #8087
This commit is contained in:
6
.changeset/unlucky-avocados-talk.md
Normal file
6
.changeset/unlucky-avocados-talk.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/cli-utils": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
pnpm doesn't fail if its version doesn't match the one specified in the "packageManager" field of `package.json` [#8087](https://github.com/pnpm/pnpm/issues/8087).
|
||||
8
.changeset/young-carpets-stare.md
Normal file
8
.changeset/young-carpets-stare.md
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
"@pnpm/workspace.find-packages": minor
|
||||
"@pnpm/cli-utils": minor
|
||||
"@pnpm/config": minor
|
||||
"pnpm": minor
|
||||
---
|
||||
|
||||
If `package-manager-strict-version` is set to `true` pnpm will fail if its version will not exactly match the version in the `packageManager` field of `package.json`.
|
||||
@@ -15,12 +15,13 @@ export function packageIsInstallable (
|
||||
},
|
||||
opts: {
|
||||
packageManagerStrict?: boolean
|
||||
packageManagerStrictVersion?: boolean
|
||||
engineStrict?: boolean
|
||||
nodeVersion?: string
|
||||
supportedArchitectures?: SupportedArchitectures
|
||||
}
|
||||
): void {
|
||||
const pnpmVersion = packageManager.name === 'pnpm'
|
||||
const currentPnpmVersion = packageManager.name === 'pnpm'
|
||||
? packageManager.version
|
||||
: undefined
|
||||
if (pkg.packageManager && !process.env.COREPACK_ROOT) {
|
||||
@@ -32,11 +33,11 @@ export function packageIsInstallable (
|
||||
} else {
|
||||
globalWarn(msg)
|
||||
}
|
||||
} else if (!pmReference.includes(':')) {
|
||||
} else if (opts.packageManagerStrictVersion && !pmReference.includes(':')) {
|
||||
// pmReference is semantic versioning, not URL
|
||||
const [pmVersion] = pmReference.split('+')
|
||||
if (pmVersion && pnpmVersion && pmVersion !== pnpmVersion) {
|
||||
const msg = `This project is configured to use v${pmVersion} of pnpm. Your current pnpm is v${pnpmVersion}`
|
||||
const [requiredPnpmVersion] = pmReference.split('+')
|
||||
if (requiredPnpmVersion && currentPnpmVersion && requiredPnpmVersion !== currentPnpmVersion) {
|
||||
const msg = `This project is configured to use v${requiredPnpmVersion} of pnpm. Your current pnpm is v${currentPnpmVersion}`
|
||||
if (opts.packageManagerStrict) {
|
||||
throw new PnpmError('BAD_PM_VERSION', msg, {
|
||||
hint: 'If you want to bypass this version check, you can set the "package-manager-strict" configuration to "false" or set the "COREPACK_ENABLE_STRICT" environment variable to "0"',
|
||||
@@ -49,7 +50,7 @@ export function packageIsInstallable (
|
||||
}
|
||||
const err = checkPackage(pkgPath, pkg, {
|
||||
nodeVersion: opts.nodeVersion,
|
||||
pnpmVersion,
|
||||
pnpmVersion: currentPnpmVersion,
|
||||
supportedArchitectures: opts.supportedArchitectures ?? {
|
||||
os: ['current'],
|
||||
cpu: ['current'],
|
||||
|
||||
@@ -5,6 +5,7 @@ import { packageIsInstallable } from './packageIsInstallable'
|
||||
export interface ReadProjectManifestOpts {
|
||||
engineStrict?: boolean
|
||||
packageManagerStrict?: boolean
|
||||
packageManagerStrictVersion?: boolean
|
||||
nodeVersion?: string
|
||||
supportedArchitectures?: SupportedArchitectures
|
||||
}
|
||||
|
||||
@@ -192,6 +192,7 @@ export interface Config {
|
||||
dedupeInjectedDeps?: boolean
|
||||
nodeOptions?: string
|
||||
packageManagerStrict?: boolean
|
||||
packageManagerStrictVersion?: boolean
|
||||
virtualStoreDirMaxLength: number
|
||||
}
|
||||
|
||||
|
||||
@@ -245,6 +245,7 @@ export async function getConfig (
|
||||
'package-lock': npmDefaults['package-lock'],
|
||||
pending: false,
|
||||
'package-manager-strict': process.env.COREPACK_ENABLE_STRICT !== '0',
|
||||
'package-manager-strict-version': false,
|
||||
'prefer-workspace-packages': false,
|
||||
'public-hoist-pattern': [
|
||||
'*eslint*',
|
||||
|
||||
@@ -259,7 +259,7 @@ test('install should fail if the used pnpm version does not satisfy the pnpm ver
|
||||
expect(stdout.toString()).toContain('Your pnpm version is incompatible with')
|
||||
})
|
||||
|
||||
test('install should fail if the used pnpm version does not satisfy the pnpm version specified in packageManager', async () => {
|
||||
test('install should not fail if the used pnpm version does not satisfy the pnpm version specified in packageManager', async () => {
|
||||
prepare({
|
||||
name: 'project',
|
||||
version: '1.0.0',
|
||||
@@ -267,17 +267,12 @@ test('install should fail if the used pnpm version does not satisfy the pnpm ver
|
||||
packageManager: 'pnpm@0.0.0',
|
||||
})
|
||||
|
||||
const { status, stdout } = execPnpmSync(['install'])
|
||||
expect(execPnpmSync(['install']).status).toBe(0)
|
||||
|
||||
const { status, stdout } = execPnpmSync(['install', '--config.package-manager-strict-version=true'])
|
||||
|
||||
expect(status).toBe(1)
|
||||
expect(stdout.toString()).toContain('This project is configured to use v0.0.0 of pnpm. Your current pnpm is')
|
||||
|
||||
expect(execPnpmSync(['install', '--config.package-manager-strict=false']).status).toBe(0)
|
||||
expect(execPnpmSync(['install'], {
|
||||
env: {
|
||||
COREPACK_ENABLE_STRICT: '0',
|
||||
},
|
||||
}).status).toBe(0)
|
||||
})
|
||||
|
||||
test('install should fail if the project requires a different package manager', async () => {
|
||||
|
||||
@@ -12,6 +12,7 @@ export async function findWorkspacePackages (
|
||||
opts?: {
|
||||
engineStrict?: boolean
|
||||
packageManagerStrict?: boolean
|
||||
packageManagerStrictVersion?: boolean
|
||||
nodeVersion?: string
|
||||
patterns?: string[]
|
||||
sharedWorkspaceLockfile?: boolean
|
||||
|
||||
Reference in New Issue
Block a user