Skip to content
This repository has been archived by the owner on May 10, 2021. It is now read-only.

Commit

Permalink
fix(lockfile): npm-shrinkwrap takes precedence over package-lock (#28)
Browse files Browse the repository at this point in the history
This better matches the behavior of npm5 itself.
  • Loading branch information
zkat authored Oct 11, 2017
1 parent 942707c commit 3b98fb3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Installer {
readJson(prefix, 'package-lock.json', true),
readJson(prefix, 'npm-shrinkwrap.json', true),
(pkg, lock, shrink) => {
pkg._shrinkwrap = lock || shrink
pkg._shrinkwrap = shrink || lock
this.pkg = pkg
}
)
Expand Down
49 changes: 49 additions & 0 deletions test/specs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,55 @@ test('handles dependency list with only deep subdeps', t => {
})
})

test('prioritizes npm-shrinkwrap over package-lock if both present', t => {
const fixture = new Tacks(Dir({
'package.json': File({
name: pkgName,
version: pkgVersion,
dependencies: {
'a': '^1'
}
}),
'npm-shrinkwrap.json': File({
dependencies: {
a: {
version: '1.1.1'
}
},
lockfileVersion: 1
}),
'package-lock.json': File({
dependencies: {
a: {
version: '1.2.3'
}
},
lockfileVersion: 1
})
}))
fixture.create(prefix)

extract = (name, child, childPath, opts) => {
const files = new Tacks(Dir({
'package.json': File({
name: child.name,
version: child.version
})
}))
files.create(childPath)
}

return new Installer({prefix}).run().then(details => {
t.equal(details.pkgCount, 1)
return fs.readFileAsync(path.join(prefix, 'node_modules', 'a', 'package.json'), 'utf8')
}).then(pkgJson => {
t.deepEqual(JSON.parse(pkgJson), {
name: 'a',
version: '1.1.1'
}, 'uses version from npm-shrinkwrap')
})
})

test('runs lifecycle hooks of packages with env variables', t => {
const originalConsoleLog = console.log
console.log = () => {}
Expand Down

0 comments on commit 3b98fb3

Please sign in to comment.