1var fs = require('graceful-fs') 2var path = require('path') 3var existsSync = fs.existsSync || path.existsSync 4 5var mkdirp = require('mkdirp') 6var test = require('tap').test 7 8var common = require('../common-tap.js') 9 10var pkg = common.pkg 11 12var EXEC_OPTS = { cwd: pkg } 13 14var json = { 15 name: 'install-cli-only-production', 16 description: 'fixture', 17 version: '0.0.0', 18 scripts: { 19 prepublish: 'exit 123' 20 }, 21 dependencies: { 22 dependency: 'file:./dependency' 23 }, 24 devDependencies: { 25 'dev-dependency': 'file:./dev-dependency' 26 } 27} 28 29var dependency = { 30 name: 'dependency', 31 description: 'fixture', 32 version: '0.0.0' 33} 34 35var devDependency = { 36 name: 'dev-dependency', 37 description: 'fixture', 38 version: '0.0.0' 39} 40 41test('setup', function (t) { 42 mkdirp.sync(path.join(pkg, 'dependency')) 43 fs.writeFileSync( 44 path.join(pkg, 'dependency', 'package.json'), 45 JSON.stringify(dependency, null, 2) 46 ) 47 48 mkdirp.sync(path.join(pkg, 'dev-dependency')) 49 fs.writeFileSync( 50 path.join(pkg, 'dev-dependency', 'package.json'), 51 JSON.stringify(devDependency, null, 2) 52 ) 53 54 mkdirp.sync(path.join(pkg, 'node_modules')) 55 fs.writeFileSync( 56 path.join(pkg, 'package.json'), 57 JSON.stringify(json, null, 2) 58 ) 59 60 t.end() 61}) 62 63test('\'npm install --only=production\' should only install dependencies', function (t) { 64 common.npm(['install', '--only=production'], EXEC_OPTS, function (err, code, stdout, stderr) { 65 if (err) throw err 66 t.comment('1> ' + stdout) 67 t.comment('2> ' + stderr) 68 t.equal(code, 0, 'npm install did not raise error code') 69 t.ok( 70 JSON.parse(fs.readFileSync( 71 path.resolve(pkg, 'node_modules/dependency/package.json'), 'utf8') 72 ), 73 'dependency was installed' 74 ) 75 t.notOk( 76 existsSync(path.resolve(pkg, 'node_modules/dev-dependency/package.json')), 77 'devDependency was NOT installed' 78 ) 79 t.end() 80 }) 81}) 82