Skip to content

Commit cfda867

Browse files
fix(arborist): warn once for workspace packageExtensions selector match (#9570)
A workspace `packageExtensions` warning was printed twice per matching workspace. A workspace appears in the inventory as two `isWorkspace` nodes — the Link and its target — and `#warnWorkspacePackageExtensions` warned for both. The fix skips the link (`node.isLink`) so each workspace is warned once via its target node; the selector/`wouldMatch` checks are otherwise unchanged. ## References Follow up of #9496
1 parent f9c977c commit cfda867

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

workspaces/arborist/lib/arborist/build-ideal-tree.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ module.exports = cls => class IdealTreeBuilder extends cls {
283283
return
284284
}
285285
for (const node of this.idealTree.inventory.values()) {
286-
if (!node.isWorkspace) {
286+
// a workspace is in the inventory as both a Link and its target node; warn once by skipping the link
287+
if (!node.isWorkspace || node.isLink) {
287288
continue
288289
}
289290
if (node.package.packageExtensions !== undefined) {

workspaces/arborist/test/arborist/package-extensions.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,11 @@ t.test('does not extend workspace members but warns', async t => {
179179
const tree = await buildIdeal(path)
180180
const ws = [...tree.inventory.values()].find(n => n.name === 'ws')
181181
t.notOk(ws.edgesOut.get('bar'), 'workspace member is not extended')
182-
t.ok(warnings.some(w => /workspace package ws/.test(w[2])), 'warns about the workspace selector match')
183-
t.ok(warnings.some(w => /in workspace ws is ignored/.test(w[2])), 'warns about non-root workspace packageExtensions')
182+
// a workspace appears in the inventory as both a Link and its target node, so the warning must be deduped to fire once
183+
t.equal(warnings.filter(w => /workspace package ws/.test(w[2])).length, 1,
184+
'warns exactly once about the workspace selector match')
185+
t.equal(warnings.filter(w => /in workspace ws is ignored/.test(w[2])).length, 1,
186+
'warns exactly once about non-root workspace packageExtensions')
184187
})
185188

186189
t.test('ignores packageExtensions from an installed dependency', async t => {

0 commit comments

Comments
 (0)