Skip to content

Commit

Permalink
fix(diff): set option where for pacote
Browse files Browse the repository at this point in the history
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: #2822
Credit: @ruyadorno
Close: #2822
Reviewed-by: @wraithgar
  • Loading branch information
ruyadorno committed Mar 4, 2021
1 parent 5d92239 commit b3e7dd1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion test/lib/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit b3e7dd1

Please sign in to comment.