From b3e7dd19bb4888dad2bfb6702aed6560a7f91bf8 Mon Sep 17 00:00:00 2001 From: Ruy Adorno Date: Thu, 4 Mar 2021 15:16:35 -0500 Subject: [PATCH] fix(diff): set option where for pacote pacote expects a **where** option that sets the cwd for all its operations, ref: https://github.com/npm/pacote#options This change properly sets that option in libnpmdiff options that will then properly forward it to pacote, this is specially important for when reading local file system specs. PR-URL: https://github.com/npm/cli/pull/2822 Credit: @ruyadorno Close: #2822 Reviewed-by: @wraithgar --- lib/diff.js | 9 +++++---- test/lib/diff.js | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/diff.js b/lib/diff.js index ea0340a4909d2..859e6f76feeef 100644 --- a/lib/diff.js +++ b/lib/diff.js @@ -50,10 +50,11 @@ class Diff { const [a, b] = await this.retrieveSpecs(specs) npmlog.info('diff', { src: a, dst: b }) - const res = await libdiff( - [a, b], - { ...this.npm.flatOptions, diffFiles: args } - ) + const res = await libdiff([a, b], { + ...this.npm.flatOptions, + diffFiles: args, + where: this.where, + }) return output(res) } diff --git a/test/lib/diff.js b/test/lib/diff.js index 5e60f125cec3d..2af3bd69bc2e5 100644 --- a/test/lib/diff.js +++ b/test/lib/diff.js @@ -951,12 +951,13 @@ t.test('first arg is a valid semver range', t => { t.test('first arg is an unknown dependency name', t => { t.test('second arg is a qualified spec', t => { - t.plan(3) + t.plan(4) libnpmdiff = async ([a, b], opts) => { t.equal(a, 'bar@latest', 'should set expected first spec') t.equal(b, 'bar@2.0.0', 'should set expected second spec') t.match(opts, npm.flatOptions, 'should forward flat options') + t.match(opts, { where: '.' }, 'should forward pacote options') } npm.flatOptions.diff = ['bar', 'bar@2.0.0']