fix: properly patch lockfile against swc bindings (#66515)
A proper fix to #66448.
The root cause of the issue is that Next.js gets SWC bindings list from
`package.json`'s `optionalDependencies` when patching the lockfile.
Recently Next.js added `sharp` to the `optionalDependencies`, which
causes `sharp` to be wrongly treated as Next.js SWC bindings when
matching versions (hence the `undefined`).
The PR adds a filter after reading `optionalDependencies`.
cc @huozhi @eps1lon
Co-authored-by: JJ Kasper <jj@jjsweb.site>