From 18b8b94357d8f57301fbaa0f1e5dc2cf1128bf3e Mon Sep 17 00:00:00 2001 From: nlf Date: Thu, 24 Mar 2022 13:52:50 -0700 Subject: [PATCH] fix(arborist): make sure resolveParent exists before checking props --- workspaces/arborist/lib/arborist/reify.js | 2 +- workspaces/arborist/test/arborist/reify.js | 28 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/workspaces/arborist/lib/arborist/reify.js b/workspaces/arborist/lib/arborist/reify.js index acb889cebca3d..7fd0ca7f60740 100644 --- a/workspaces/arborist/lib/arborist/reify.js +++ b/workspaces/arborist/lib/arborist/reify.js @@ -1308,7 +1308,7 @@ module.exports = cls => class Reifier extends cls { // to only names that are found in this list const retrieveUpdatedNodes = names => { const filterDirectDependencies = node => - !node.isRoot && node.resolveParent.isRoot + !node.isRoot && node.resolveParent && node.resolveParent.isRoot && (!names || names.includes(node.name)) && exactVersion(node) // skip update for exact ranges diff --git a/workspaces/arborist/test/arborist/reify.js b/workspaces/arborist/test/arborist/reify.js index 7c22f7c69c183..9124b4630ca88 100644 --- a/workspaces/arborist/test/arborist/reify.js +++ b/workspaces/arborist/test/arborist/reify.js @@ -2622,5 +2622,33 @@ t.test('save package.json on update', t => { 'should save no top level dep update to root package.json' ) }) + + t.test('should not throw when trying to update a link dep', async t => { + const path = t.testdir({ + one: { + 'package.json': JSON.stringify({ + name: 'one', + version: '1.0.0', + dependencies: { + two: 'file:../two', + }, + }), + }, + two: { + 'package.json': JSON.stringify({ + name: 'two', + version: '1.0.0', + }), + }, + }) + + await t.resolves(reify(resolve(path, 'one'), { update: true, save: true, workspaces: [] })) + + t.equal( + require(resolve(path, 'one', 'package.json')).dependencies.two, + 'file:../two', + 'should have made no changes' + ) + }) t.end() })