Skip to content

Commit

Permalink
fixup! feat: add npm diff
Browse files Browse the repository at this point in the history
  • Loading branch information
ruyadorno committed Jan 28, 2021
1 parent cf4b86f commit dda1344
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const transformSingleSpec = async (a) => {
return edge.spec
}

const aSpec = node.package.version
const aSpec = `file:${node.realpath}`

// finds what version of the package to compare against, if a exact
// version or tag was passed than it should use that, otherwise
Expand Down Expand Up @@ -257,7 +257,7 @@ const findVersionsByPackageName = async (specs) => {

const res = !node || !node.package || !node.package.version
? spec.fetchSpec
: node.package.version
: `file:${node.realpath}`

return `${spec.name}@${res}`
})
Expand Down
24 changes: 12 additions & 12 deletions test/lib/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ t.test('single arg', t => {
return { version: '1.8.10' }
},
libnpmdiff: async ([a, b], opts) => {
t.equal(a, 'bar@1.0.0', 'should have current spec')
t.equal(a, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg')
t.equal(b, 'bar@1.8.10', 'should have possible semver range spec')
},
})
Expand Down Expand Up @@ -371,7 +371,7 @@ t.test('single arg', t => {
return { version: '2.1.0' }
},
libnpmdiff: async ([a, b], opts) => {
t.equal(a, 'lorem@2.0.0', 'should have current spec')
t.equal(a, `lorem@file:${resolve(path, 'globalDir/lib/node_modules/lorem')}`, 'should target local node_modules pkg')
t.equal(b, 'lorem@2.1.0', 'should have possible semver range spec')
},
})
Expand Down Expand Up @@ -403,7 +403,7 @@ t.test('single arg', t => {
})

libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'bar@1.0.0', 'should have current spec')
t.equal(a, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg')
t.equal(b, 'bar@2.0.0', 'should have expected comparison spec')
}

Expand Down Expand Up @@ -458,7 +458,7 @@ t.test('single arg', t => {
return { version: '2.2.2' }
},
libnpmdiff: async ([a, b], opts) => {
t.equal(a, 'lorem@2.0.0', 'should have current spec')
t.equal(a, `lorem@file:${resolve(path, 'node_modules/lorem')}`, 'should target local node_modules pkg')
t.equal(b, 'lorem@2.2.2', 'should have expected target spec')
},
})
Expand Down Expand Up @@ -617,7 +617,7 @@ t.test('first arg is a qualified spec', t => {
rlp = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'bar@2.0.0', 'should set expected first spec')
t.equal(b, 'bar@1.0.0', 'should set expected second spec from nm')
t.equal(b, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg')
}

npm.flatOptions.prefix = path
Expand Down Expand Up @@ -685,7 +685,7 @@ t.test('first arg is a known dependency name', t => {

rlp = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'bar@1.0.0', 'should set expected first spec from nm')
t.equal(a, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg')
t.equal(b, 'bar@2.0.0', 'should set expected second spec')
}

Expand Down Expand Up @@ -725,8 +725,8 @@ t.test('first arg is a known dependency name', t => {

rlp = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'bar@1.0.0', 'should set expected first spec from nm')
t.equal(b, 'bar-fork@1.0.0', 'should set expected second spec from nm')
t.equal(a, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg')
t.equal(b, `bar-fork@file:${resolve(path, 'node_modules/bar-fork')}`, 'should target fork local node_modules pkg')
}

npm.flatOptions.prefix = path
Expand Down Expand Up @@ -759,7 +759,7 @@ t.test('first arg is a known dependency name', t => {

rlp = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'bar@1.0.0', 'should set expected first spec from nm')
t.equal(a, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg')
t.equal(b, 'bar@2.0.0', 'should use package name from first arg')
}

Expand Down Expand Up @@ -793,7 +793,7 @@ t.test('first arg is a known dependency name', t => {

rlp = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'bar@1.0.0', 'should set expected first spec from nm')
t.equal(a, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg')
t.equal(b, 'bar-fork@latest', 'should set expected second spec')
}

Expand Down Expand Up @@ -848,7 +848,7 @@ t.test('first arg is a valid semver range', t => {
rlp = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'bar@1.0.0', 'should use name from second arg')
t.equal(b, 'bar@2.0.0', 'should set expected second spec from nm')
t.equal(b, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should set expected second spec from nm')
}

npm.flatOptions.prefix = path
Expand Down Expand Up @@ -984,7 +984,7 @@ t.test('first arg is an unknown dependency name', t => {
rlp = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'bar-fork@latest', 'should use latest tag')
t.equal(b, 'bar@2.0.0', 'should set expected second spec from nm')
t.equal(b, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg')
}

npm.flatOptions.prefix = path
Expand Down

0 comments on commit dda1344

Please sign in to comment.