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.
  • Loading branch information
ruyadorno committed Mar 4, 2021
1 parent 0c881fc commit b674c71
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/diff.js
Expand Up @@ -42,7 +42,11 @@ const diff = async (args) => {
const [a, b] = await retrieveSpecs(specs)
npmlog.info('diff', { src: a, dst: b })

const res = await libdiff([a, b], { ...npm.flatOptions, diffFiles: args })
const res = await libdiff([a, b], {
...npm.flatOptions,
diffFiles: args,
where: where(),
})
return output(res)
}

Expand Down
3 changes: 2 additions & 1 deletion test/lib/diff.js
Expand Up @@ -946,12 +946,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 b674c71

Please sign in to comment.