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
37 changes: 20 additions & 17 deletions server/loader/versions/pnpm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { basename } from 'node:path'
import { parse } from 'yaml'
import { parseAllDocuments } from 'yaml'

import { type Dependency, dependencyType } from '../../../common/types.ts'
import type { VersionsLoader } from './common.ts'
Expand Down Expand Up @@ -32,23 +32,26 @@ export const pnpm = {
let directDeps = getDirectDependencies(packageJsonFiles)

for (let file of lockFiles) {
let lock = parse(file.content)
if (isLockFile9(lock)) {
for (let pkg in lock.packages) {
let { name, version } = splitPackage(pkg)
dependencies.push(
dependencyType({
direct: directDeps.has(name),
from: 'pnpm',
name,
source: file.path,
type: 'npm',
version
})
)
for (let doc of parseAllDocuments(file.content)) {
if (doc.errors[0]) throw doc.errors[0]
let lock = doc.toJS()
if (isLockFile9(lock)) {
for (let pkg in lock.packages) {
let { name, version } = splitPackage(pkg)
dependencies.push(
dependencyType({
direct: directDeps.has(name),
from: 'pnpm',
name,
source: file.path,
type: 'npm',
version
})
)
}
} else {
throw new Error('Unknown pnpm lock file')
}
} else {
throw new Error('Unknown pnpm lock file')
}
}

Expand Down
33 changes: 33 additions & 0 deletions server/test/pnpm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,36 @@ test('shows nested dependency updates in pnpm', async () => {
}
])
})

test('supports pnpm lock file with config dependencies', async () => {
await run('pnpm add --config nanoevents@9.1.0')
await run('pnpm add nanoid@5.1.4')
await run('git add .')
await run('git commit -m "Add dependencies"')
await run('pnpm add nanoid@5.1.5')

await cliJsonMatch([
{
after: '5.1.5',
before: '5.1.4',
name: 'nanoid'
}
])
})

test('shows config dependency changes with pnpm', async () => {
await run('pnpm add --config nanoid@5.1.4')
await run('pnpm add nanoevents@9.1.0')
await run('git add .')
await run('git commit -m "Add dependencies"')
await run('pnpm add --config nanoid@5.1.5')

await cliJsonMatch([
{
after: '5.1.5',
before: '5.1.4',
from: 'pnpm',
name: 'nanoid'
}
])
})
Loading