Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dedupe: get deps from shrinkwrap #118

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/dedupe.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ Deduper.prototype.loadIdealTree = function (cb) {
[this, this.cloneCurrentTreeToIdealTree],
[this, this.finishTracker, 'cloneCurrentTree'],

[this.newTracker(this.progress.loadIdealTree, 'loadIdealTree:loadShrinkwrap')],
[this, this.loadShrinkwrap],
[this, this.finishTracker, 'loadIdealTree:loadShrinkwrap'],

[this.newTracker(this.progress.loadIdealTree, 'loadAllDepsIntoIdealTree', 10)],
[ function (next) {
loadExtraneous(self.idealTree, self.progress.loadAllDepsIntoIdealTree, next)
Expand Down
82 changes: 82 additions & 0 deletions test/tap/dedupe-optional.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
var fs = require('graceful-fs')
var path = require('path')

var mkdirp = require('mkdirp')
var mr = require('npm-registry-mock')
var rimraf = require('rimraf')
var test = require('tap').test

var common = require('../common-tap.js')
var server

var pkg = path.join(__dirname, 'dedupe-optional')

var EXEC_OPTS = { cwd: pkg }

var json = {
author: 'Dedupe tester',
name: 'dedupe',
version: '0.0.0',
dependencies: {
clean: '2.1.6'
}
}

var shrinkwrap = {
name: 'dedupe',
version: '0.0.0',
dependencies: {
clean: {
version: '2.1.6'
}
}
}

test('setup', function (t) {
t.comment('test for https://npm.community/t/3807')
setup(function () {
t.end()
})
})

test('dedupe keeps uninstalled packages in package-lock.json', function (t) {
common.npm(['dedupe'], EXEC_OPTS, function (err, code) {
t.ifError(err, 'successfully deduped against previous install')
t.notOk(code, 'npm dedupe exited with code')

var shrinkwrap = JSON.parse(fs.readFileSync('package-lock.json', 'utf8'))

t.ok(shrinkwrap.dependencies, 'npm dedupe kept packages')
t.end()
})
})

test('cleanup', function (t) {
server.close()
cleanup()

t.end()
})

function cleanup () {
rimraf.sync(pkg)
}

function setup (cb) {
cleanup()
mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
)
fs.writeFileSync(
path.join(pkg, 'package-lock.json'),
JSON.stringify(shrinkwrap, null, 2)
)
process.chdir(pkg)

mr({ port: common.port }, function (er, s) {
server = s
cb()
})
}