Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
install: include devDependencies when installing
Browse files Browse the repository at this point in the history
add unit test
use fn to identify required version
  • Loading branch information
smikes authored and othiym23 committed Apr 23, 2015
1 parent faf65a7 commit 9ad2100
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,15 @@ function installMany (what, where, context, cb) {
// there's no harm in using that.)
if (context.explicit) wrap = null

var getVersion = function (name) {
return d[name] || (data.devDependencies && data.devDependencies[name]) || "*"
}


// what is a list of things.
// resolve each one.
asyncMap( what
, targetResolver(where, context, d)
, targetResolver(where, context, d, getVersion)
, function (er, targets) {

if (er) return cb(er)
Expand Down Expand Up @@ -774,7 +779,7 @@ function installMany (what, where, context, cb) {
})
}

function targetResolver (where, context, deps) {
function targetResolver (where, context, deps, getVersion) {
var alreadyInstalledManually = []
, resolveLeft = 0
, nm = path.resolve(where, "node_modules")
Expand Down Expand Up @@ -807,7 +812,8 @@ function targetResolver (where, context, deps) {
// otherwise, make sure that it's a semver match with what we want.
var bd = parent.bundleDependencies
var isBundled = bd && bd.indexOf(d.name) !== -1
var currentIsSatisfactory = semver.satisfies(d.version, deps[d.name] || "*", true)
var expectedVersion = getVersion(d.name)
var currentIsSatisfactory = semver.satisfies(d.version, expectedVersion, true)
if (isBundled || currentIsSatisfactory || deps[d.name] === d._resolved) {
return cb(null, d.name)
}
Expand Down
109 changes: 109 additions & 0 deletions test/tap/install-noargs-dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
var fs = require('fs')
var path = require('path')

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

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

var pkg = path.join(__dirname, 'install-noargs-dev')

var EXEC_OPTS = { cwd: pkg }

var PACKAGE_JSON1 = {
name: 'install-noargs-dev',
version: '0.0.1',
devDependencies: {
'underscore': '1.3.1'
}
}

var PACKAGE_JSON2 = {
name: 'install-noargs-dev',
version: '0.0.2',
devDependencies: {
'underscore': '1.5.1'
}
}

test('setup', function (t) {
setup()
mr({ port: common.port }, function (er, s) {
t.ifError(er, 'started mock registry')
server = s
t.end()
})
})

test('install noargs installs devDependencies', function (t) {
common.npm(
[
'--registry', common.registry,
'--loglevel', 'silent',
'install'
],
EXEC_OPTS,
function (err, code) {
t.ifError(err, 'npm install ran without issue')
t.notOk(code, 'npm install exited with code 0')

var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
var pkgJson = JSON.parse(fs.readFileSync(p))

t.equal(pkgJson.version, '1.3.1')
t.end()
}
)
})

test('install noargs installs updated devDependencies', function (t) {
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(PACKAGE_JSON2, null, 2)
)

common.npm(
[
'--registry', common.registry,
'--loglevel', 'silent',
'install'
],
EXEC_OPTS,
function (err, code) {
t.ifError(err, 'npm install ran without issue')
t.notOk(code, 'npm install exited with code 0')

var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
var pkgJson = JSON.parse(fs.readFileSync(p))

t.equal(pkgJson.version, '1.5.1')
t.end()
}
)
})

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

function cleanup () {
process.chdir(osenv.tmpdir())
rimraf.sync(pkg)
}

function setup () {
cleanup()
mkdirp.sync(path.resolve(pkg, 'node_modules'))
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(PACKAGE_JSON1, null, 2)
)

process.chdir(pkg)
}

0 comments on commit 9ad2100

Please sign in to comment.