From eb982f4f66d7f3c5a215d4500ece95f1f93a2fec Mon Sep 17 00:00:00 2001 From: Hoang Tien Minh Date: Thu, 6 Jun 2024 00:18:48 +0700 Subject: [PATCH 1/2] fix: add null check for link's target when calling matches to dedupe deps --- workspaces/arborist/lib/node.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/workspaces/arborist/lib/node.js b/workspaces/arborist/lib/node.js index c519a7b543d4d..ac47de8fc3000 100644 --- a/workspaces/arborist/lib/node.js +++ b/workspaces/arborist/lib/node.js @@ -1113,8 +1113,12 @@ class Node { } // if they're links, they match if the targets match - if (this.isLink) { - return node.isLink && this.target.matches(node.target) + if (node.isLink) { + // Linked to nothing, cannot matches + if (!this.target || !node.target) { + return false; + } + return this.target.matches(node.target); } // if they're two project root nodes, they're different if the paths differ From 2ab308ce3a0b3bf2d05f00bb501fc9896f0d5106 Mon Sep 17 00:00:00 2001 From: Hoang Tien Minh Date: Sun, 16 Jun 2024 22:55:57 +0700 Subject: [PATCH 2/2] chore: add test to simulate null target link --- workspaces/arborist/test/node.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/workspaces/arborist/test/node.js b/workspaces/arborist/test/node.js index f5090dc2def5a..e5fc72e4a1d66 100644 --- a/workspaces/arborist/test/node.js +++ b/workspaces/arborist/test/node.js @@ -8,6 +8,7 @@ const { resolve } = require('node:path') const treeCheck = require('../lib/tree-check.js') const { normalizePath, normalizePaths } = require('./fixtures/utils.js') +const { realpath } = require('node:fs') t.cleanSnapshot = str => str.split(process.cwd()).join('{CWD}') @@ -1548,6 +1549,13 @@ t.test('detect that two nodes are the same thing', async t => { const b = new Node({ parent: a, pkg: pkgb }) check(a, b, false, 'name/version mismatch, if no resolved/integrity') } + + { + const root = new Node({ path: '/x' }) + const a = new Link({ root, path: '/a', realpath: '/a', target: null }) + const b = new Link({ root, path: '/b', realpath: '/b', target: null }) + check(a, b, false, 'links does not match if target to null') + } }) t.test('node.satisfies(requested)', t => {