Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/stale-bars-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pnpm/dependency-path": patch
"@pnpm/calc-dep-state": patch
---

Fix dependency graph hash calculation for runtime dependencies (like Node.js, Deno).
12 changes: 10 additions & 2 deletions packages/calc-dep-state/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ function calcDepGraphHash<T extends string> (
if (cache[depPath]) return cache[depPath]
const node = depsGraph[depPath]
if (!node) return ''
node.fullPkgId ??= createFullPkgId(node.pkgIdWithPatchHash!, node.resolution!)
if (!node.fullPkgId) {
if (!node.pkgIdWithPatchHash) {
throw new Error(`pkgIdWithPatchHash is not defined for ${depPath} in depsGraph`)
}
if (!node.resolution) {
throw new Error(`resolution is not defined for ${depPath} in depsGraph`)
}
node.fullPkgId = createFullPkgId(node.pkgIdWithPatchHash, node.resolution)
}
const deps: Record<string, string> = {}
if (Object.keys(node.children).length && !parents.has(node.fullPkgId)) {
const nextParents = new Set([...Array.from(parents), node.fullPkgId])
Expand Down Expand Up @@ -135,6 +143,6 @@ function lockfileDepsToGraphChildren (deps: Record<string, string>): Record<stri
}

function createFullPkgId (pkgIdWithPatchHash: PkgIdWithPatchHash, resolution: LockfileResolution): string {
const res = 'integrity' in resolution ? resolution.integrity : JSON.stringify(resolution)
const res = 'integrity' in resolution ? resolution.integrity : hashObject(resolution)
return `${pkgIdWithPatchHash}:${res}`
}
3 changes: 0 additions & 3 deletions packages/dependency-path/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ export function getPkgIdWithPatchHash (depPath: DepPath): PkgIdWithPatchHash {
if (sepIndex !== -1) {
pkgId = pkgId.substring(0, sepIndex)
}
if (pkgId.includes(':')) {
pkgId = pkgId.substring(pkgId.indexOf('@', 1) + 1)
}
return pkgId as PkgIdWithPatchHash
}

Expand Down
30 changes: 30 additions & 0 deletions packages/dependency-path/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// <reference path="../../../__typings__/index.d.ts"/>
import {
depPathToFilename,
getPkgIdWithPatchHash,
isAbsolute,
parse,
refToRelative,
Expand Down Expand Up @@ -109,3 +110,32 @@ test('tryGetPackageId', () => {
expect(tryGetPackageId('/@(-.-)/[email protected](@types/[email protected])' as DepPath)).toBe('/@(-.-)/[email protected]')
expect(tryGetPackageId('[email protected](patch_hash=xxxx)(@types/[email protected])' as DepPath)).toBe('[email protected]')
})

test('getPkgIdWithPatchHash', () => {
// Runtime dependency
expect(getPkgIdWithPatchHash('node@runtime:24.11.1' as DepPath)).toBe('node@runtime:24.11.1')

// Regular packages
expect(getPkgIdWithPatchHash('[email protected]' as DepPath)).toBe('[email protected]')

// Packages with patch hash
expect(getPkgIdWithPatchHash('[email protected](patch_hash=xxxx)' as DepPath)).toBe('[email protected](patch_hash=xxxx)')

// Packages with peer dependencies (should remove peer dependencies)
expect(getPkgIdWithPatchHash('[email protected](@types/[email protected])' as DepPath)).toBe('[email protected]')

// Packages with both patch hash and peer dependencies (should keep patch hash, remove peer dependencies)
expect(getPkgIdWithPatchHash('[email protected](patch_hash=xxxx)(@types/[email protected])' as DepPath)).toBe('[email protected](patch_hash=xxxx)')

// Scoped packages
expect(getPkgIdWithPatchHash('@foo/[email protected]' as DepPath)).toBe('@foo/[email protected]')

// Scoped packages with patch hash
expect(getPkgIdWithPatchHash('@foo/[email protected](patch_hash=yyyy)' as DepPath)).toBe('@foo/[email protected](patch_hash=yyyy)')

// Scoped packages with peer dependencies
expect(getPkgIdWithPatchHash('@foo/[email protected](@types/[email protected])' as DepPath)).toBe('@foo/[email protected]')

// Scoped packages with both patch hash and peer dependencies
expect(getPkgIdWithPatchHash('@foo/[email protected](patch_hash=zzzz)(@types/[email protected])' as DepPath)).toBe('@foo/[email protected](patch_hash=zzzz)')
})
114 changes: 87 additions & 27 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading