Skip to content

Commit

Permalink
fix(pnpmfile): remove a dependencies field (#7704)
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed Feb 23, 2024
1 parent 086b69c commit 7edb917
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/quick-toes-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pnpm/resolve-dependencies": patch
"pnpm": patch
---

Deleting a dependencies field via a `readPackage` hook should work [#7704](https://github.com/pnpm/pnpm/pull/7704).
4 changes: 3 additions & 1 deletion pkg-manager/resolve-dependencies/src/resolveDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ import safePromiseDefer, { type SafePromiseDefer } from 'safe-promise-defer'

const dependencyResolvedLogger = logger('_dependency_resolved')

const omitDepsFields = omit(['dependencies', 'optionalDependencies', 'peerDependencies', 'peerDependenciesMeta'])

export function nodeIdToParents (
nodeId: string,
resolvedPackagesByDepPath: ResolvedPackagesByDepPath
Expand Down Expand Up @@ -1252,7 +1254,7 @@ async function resolveDependency (
hasBin = currentPkg.dependencyLockfile.hasBin === true
pkg = {
...nameVerFromPkgSnapshot(currentPkg.depPath, currentPkg.dependencyLockfile),
...currentPkg.dependencyLockfile,
...omitDepsFields(currentPkg.dependencyLockfile),
...pkg,
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion pnpm/test/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ test('adding or changing pnpmfile should change pnpmfileChecksum and module stru
const pnpmfile1 = `
function readPackage (pkg) {
if (pkg.optionalDependencies) {
pkg.optionalDependencies = {} // 'delete pkg.optionalDependencies' doesn't work here
delete pkg.optionalDependencies
}
return pkg
}
Expand Down

0 comments on commit 7edb917

Please sign in to comment.