@@ -684,6 +684,44 @@ test('update with tag @latest will downgrade prerelease', async function () {
684684 expect ( lockfile2 ) . toHaveProperty ( [ 'packages' , '@pnpm.e2e/[email protected] ' ] ) 685685} )
686686
687+ test ( 'update indirect dependency should not update package.json' , async function ( ) {
688+ const project = prepare ( {
689+ dependencies : {
690+ '@pnpm.e2e/pkg-with-1-dep' : '^100.0.0' ,
691+ } ,
692+ } )
693+
694+ // Ensure the initial versions
695+ await addDistTag ( '@pnpm.e2e/pkg-with-1-dep' , '100.0.0' , 'latest' )
696+ await addDistTag ( '@pnpm.e2e/dep-of-pkg-with-1-dep' , '100.0.0' , 'latest' )
697+
698+ await execPnpm ( [ 'install' ] )
699+
700+ const pkg1 = await readPackageJsonFromDir ( process . cwd ( ) )
701+ expect ( pkg1 . dependencies ?. [ '@pnpm.e2e/pkg-with-1-dep' ] ) . toBe ( '^100.0.0' )
702+
703+ const lockfile1 = project . readLockfile ( )
704+ expect ( lockfile1 . importers [ '.' ] . dependencies ?. [ '@pnpm.e2e/pkg-with-1-dep' ] . version ) . toBe ( '100.0.0' )
705+
706+ // Now publish a new version of the direct dependency and update the indirect dependency
707+ await addDistTag ( '@pnpm.e2e/pkg-with-1-dep' , '100.1.0' , 'latest' )
708+ await addDistTag ( '@pnpm.e2e/dep-of-pkg-with-1-dep' , '100.1.0' , 'latest' )
709+
710+ // Update the indirect dependency only
711+ await execPnpm ( [ 'update' , '@pnpm.e2e/dep-of-pkg-with-1-dep@latest' ] )
712+
713+ // The direct dependency in package.json should remain unchanged at ^100.0.0
714+ const pkg2 = await readPackageJsonFromDir ( process . cwd ( ) )
715+ expect ( pkg2 . dependencies ?. [ '@pnpm.e2e/pkg-with-1-dep' ] ) . toBe ( '^100.0.0' )
716+
717+ // But the lockfile should have the updated indirect dependency
718+ const lockfile2 = project . readLockfile ( )
719+ expect ( Object . keys ( lockfile2 . packages ?? { } ) ) . toContain ( '@pnpm.e2e/[email protected] ' ) 720+
721+ // The direct dependency should remain at 100.0.0 in the lockfile (not upgraded to 100.1.0)
722+ expect ( lockfile2 . importers [ '.' ] . dependencies ?. [ '@pnpm.e2e/pkg-with-1-dep' ] . version ) . toBe ( '100.0.0' )
723+ } )
724+
687725test ( 'update to latest recursive workspace (outdated, updated, prerelease, outdated)' , async function ( ) {
688726 await addDistTag ( '@pnpm.e2e/has-prerelease' , '2.0.0' , 'latest' )
689727
0 commit comments