fix: don't print a warning when --lockfile-only is used (#10044)

close #8320
This commit is contained in:
Zoltan Kochan
2025-10-05 02:28:26 +02:00
committed by GitHub
parent e2426e7e9b
commit c5e895f657
3 changed files with 6 additions and 36 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/core": patch
"pnpm": patch
---
Don't print a warning, when `--lockfile-only` is used [#8320](https://github.com/pnpm/pnpm/issues/8320).

View File

@@ -1629,12 +1629,6 @@ const installInContext: InstallFunction = async (projects, ctx, opts) => {
ignoredBuilds,
}
}
if (opts.lockfileOnly && ctx.existsCurrentLockfile) {
logger.warn({
message: '`node_modules` is present. Lockfile only installation will make it out-of-date',
prefix: ctx.lockfileDir,
})
}
return await _installInContext(projects, ctx, opts)
} catch (error: any) { // eslint-disable-line
if (

View File

@@ -8,7 +8,6 @@ import {
addDependenciesToPackage,
install,
} from '@pnpm/core'
import sinon from 'sinon'
import { testDefaults } from '../utils/index.js'
test('install with lockfileOnly = true', async () => {
@@ -46,35 +45,6 @@ test('install with lockfileOnly = true', async () => {
expect(project.readCurrentLockfile()).toBeFalsy()
})
test('warn when installing with lockfileOnly = true and node_modules exists', async () => {
const project = prepareEmpty()
const reporter = sinon.spy()
const { updatedManifest: manifest } = await addDependenciesToPackage({}, ['is-positive'], testDefaults())
await addDependenciesToPackage(manifest, ['rimraf@2.5.1'], testDefaults({
lockfileOnly: true,
reporter,
}))
expect(reporter.calledWithMatch({
level: 'warn',
message: '`node_modules` is present. Lockfile only installation will make it out-of-date',
name: 'pnpm',
})).toBeTruthy()
project.storeHas('rimraf', '2.5.1')
project.hasNot('rimraf')
expect(manifest.dependencies!.rimraf).toBeTruthy()
const lockfile = project.readLockfile()
expect(lockfile.importers['.'].dependencies?.rimraf).toBeTruthy()
expect(lockfile.packages['rimraf@2.5.1']).toBeTruthy()
const currentLockfile = project.readCurrentLockfile()
expect(currentLockfile.packages['rimraf@2.5.1']).toBeFalsy()
})
test('do not update the lockfile when lockfileOnly and frozenLockfile are both used', async () => {
prepareEmpty()
await addDependenciesToPackage({}, ['is-positive@1.0.0'], testDefaults({