Repository navigation
fix(engine): handle Yarn Berry workspace, patch and alias descriptors… - #516
Janil-ship-it wants to merge 0 commit into
Conversation
|
Hi @Janil-ship-it, thanks for picking up #510, and sorry this sat for a few days without a review. I've approved the CI run for your branch now, so checks should report shortly. Automated review: changes needed (one small fix) The What's blocking right now is the new test itself:
Before you push, please run |
There was a problem hiding this comment.
Hi @Janil-ship-it, welcome, and thanks for your first contribution to Vibgrate! 🎉
Automated review: changes requested. The fix in src/engine/lockfile.ts looks right. Reusing splitYarnDescriptor in headerNamesPackage and skipping workspace: headers is exactly the approach we'd want. No security concerns, and we checked that the new test catches a regression when either half of the fix is reverted. There's one blocker in the test file, plus a couple of small tidy-ups:
- The new test calls
writewith the wrong signature, so typecheck and the test both fail. The file'swritehelper iswrite(name: string, body: string): void, and it writes into the sharedrootcreated inbeforeEach. It doesn't take an object or return a path. Right nowpnpm typecheckreports TS2554/TS2345 at lines 165, 197, 208 and 209, and the test throwsThe "path" argument must be of type string. The fix is small:With only that change, typecheck is clean and the full suite passes on top of currentwrite( 'yarn.lock', ` __metadata: ... `.trimStart(), ); const tree = fullDependencyTree(root);
main. - Please remove the two extra blank lines added before
describe('lockfileVersion — npm precedence'). - Please drop the
// or string-width-cjs depending on yarnHeaderRealNamecomment. It resolves tostring-width, which is what the assertion checks. - Optional: your branch is 17 commits behind
main. It still merges cleanly, but rebasing or mergingmainwould let CI run against the latest code.
CI has now run on this PR and fails at the Typecheck step for the reason above. Push the fix and we'll make sure CI runs again, then take another look. Thanks again!
|
Thanks for the feedback! I've updated src/engine/lockfile.test.ts to use the correct write(name, body) signature, cleaned up the extra lines/comments, and verified pnpm typecheck and pnpm test pass cleanly. Ready for another review! |
vibgrate-team
left a comment
There was a problem hiding this comment.
Thanks for turning the write-helper fix around so quickly, @Janil-ship-it! Typecheck is clean now and the lockfile.ts change still looks great. Two things still need sorting before this can go in:
Automated review: changes requested.
-
The new test's first assertion fails.
fullDependencyTree()returns an array of{ package, version }objects, soObject.keys(tree || {})gives['0', '1', '2']andexpect(names).toContain('lodash')fails. Your first version's assertions were right; bringing them back fixes it:const tree = fullDependencyTree(root); expect(tree).toEqual( expect.arrayContaining([ expect.objectContaining({ package: 'lodash', version: '4.17.21' }), expect.objectContaining({ package: 'resolve', version: '1.22.8' }), expect.objectContaining({ package: 'string-width', version: '4.2.3' }), ]), ); expect(tree?.some((c) => c.package === 'my-app')).toBe(false); expect(tree?.some((c) => c.package === '__metadata')).toBe(false);
We tried exactly that on top of current
main: the file passes 56/56, the full suite passes, and the test fails if you revert the whole fix, only the workspace skip, or only the header matching. So it pins both halves nicely. -
Please drop the docs commit (
9d0cd50) from this PR. It replaces six existing rows indocs/sbom-dependency-scope.md(the fivemix.exsrows and the .NET<PackageReference>row) instead of adding new ones, andcomposer.jsonrequire-devalready has a row higher up the table. It's also outside the scope of #510. The Dart and PHP dev-dependency behaviour is changing in #559 and #560 right now, so those rows would go stale quickly anyway. A separate docs PR that only adds rows is very welcome once those settle.
CI was waiting for approval, so we've started it. It will fail at the test step for the reason in point 1. Push those two changes and we'll take another look. Nearly there!
fix(lockfile): skip workspace entries and resolve patch/alias descriptors in yarn.lock
Summary
Fixes Yarn Berry (v2+)
yarn.lockparsing issues insrc/engine/lockfile.ts:lastIndexOf('@')splitting logic inheaderNamesPackagewithsplitYarnDescriptor. This enables correct package name matching forpatch:andalias:descriptors containing multiple@characters (e.g.,resolve@patch:...andstring-width-cjs@npm:...), allowinglockfileVersion()to resolve their actual version strings.yarnLockTreeto skip__metadatablocks and entries where descriptor ranges start withworkspace:(e.g.,"my-app@workspace:."), preventing local project roots from being included as registry components in SBOM exports.describe('Yarn Berry lockfile')test suite insrc/engine/lockfile.test.tsusing Yarn Berry fixtures to verify workspace skipping, metadata filtering, and patch/alias version resolution.Related issues
Closes #510
Checklist
pnpm testpassespnpm lintis cleanpnpm typecheckis cleangraph.json/ report output (content-hashed IDs, stable sorts; no time, randomness, or filesystem-order dependence)git commit -s, DCO)Notes for reviewers
splitYarnDescriptorhelper function insideheaderNamesPackageto maintain consistent descriptor parsing rules across the codebase.