From 68a19bb02aa0d7a566c8e2245f1e524b915faf09 Mon Sep 17 00:00:00 2001 From: Gar Date: Wed, 18 Aug 2021 10:05:40 -0700 Subject: [PATCH] fix(error-message): look for er.path not er.file The attribute is here, er.file was used in error on another lib, the lib got changed, and this code wasn't fixed. PR-URL: https://github.com/npm/cli/pull/3661 Credit: @wraithgar Close: #3661 Reviewed-by: @fritzy --- lib/utils/error-message.js | 4 ++-- test/lib/utils/error-message.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/utils/error-message.js b/lib/utils/error-message.js index 0782c6979ca4b..da97195dd04f0 100644 --- a/lib/utils/error-message.js +++ b/lib/utils/error-message.js @@ -99,9 +99,9 @@ module.exports = (er, npm) => { case 'EJSONPARSE': // Check whether we ran into a conflict in our own package.json - if (er.file === resolve(npm.prefix, 'package.json')) { + if (er.path === resolve(npm.prefix, 'package.json')) { const { isDiff } = require('parse-conflict-json') - const txt = require('fs').readFileSync(er.file, 'utf8') + const txt = require('fs').readFileSync(er.path, 'utf8') .replace(/\r\n/g, '\n') if (isDiff(txt)) { detail.push([ diff --git a/test/lib/utils/error-message.js b/test/lib/utils/error-message.js index 908d70fc3924d..07328d588759b 100644 --- a/test/lib/utils/error-message.js +++ b/test/lib/utils/error-message.js @@ -292,7 +292,7 @@ t.test('json parse', t => { process.argv = ['arg', 'v'] t.matchSnapshot(errorMessage(Object.assign(new Error('conflicted'), { code: 'EJSONPARSE', - file: resolve(dir, 'package.json'), + path: resolve(dir, 'package.json'), }), npm)) t.end() }) @@ -314,7 +314,7 @@ t.test('json parse', t => { process.argv = ['arg', 'v'] t.matchSnapshot(errorMessage(Object.assign(new Error('not json'), { code: 'EJSONPARSE', - file: resolve(dir, 'package.json'), + path: resolve(dir, 'package.json'), }), npm)) t.end() }) @@ -330,7 +330,7 @@ t.test('json parse', t => { process.argv = ['arg', 'v'] t.matchSnapshot(errorMessage(Object.assign(new Error('not json'), { code: 'EJSONPARSE', - file: `${dir}/blerg.json`, + path: `${dir}/blerg.json`, }), npm)) t.end() })