1'use strict' 2var fs = require('fs') 3var test = require('tap').test 4var Tacks = require('tacks') 5var File = Tacks.File 6var Dir = Tacks.Dir 7var common = require('../common-tap.js') 8var testdir = common.pkg 9 10var fixture = new Tacks( 11 Dir({ 12 node_modules: Dir({ 13 'yes': Dir({ 14 'package.json': File({ 15 _requested: { 16 rawSpec: 'file:///mods/yes' 17 }, 18 dependencies: {}, 19 bin: { 20 'yes': 'yes.js' 21 }, 22 name: 'yes', 23 version: '1.0.0' 24 }), 25 'yes.js': File('while (true) { console.log("y") }') 26 }), 27 '.bin': Dir({ 28 // verbose, but needed for `read-cmd-shim` to properly identify which 29 // package this belongs to 30 'yes': File( 31 '#!/bin/sh\n' + 32 'basedir=$(dirname "$(echo "$0" | sed -e \'s,\\\\,/,g\')")\n' + 33 '\n' + 34 'case `uname` in\n' + 35 ' *CYGWIN*) basedir=`cygpath -w "$basedir"`;;\n' + 36 'esac\n' + 37 '\n' + 38 'if [ -x "$basedir/node" ]; then\n' + 39 ' "$basedir/node" "$basedir/../yes/yes.js" "$@"\n' + 40 ' ret=$?\n' + 41 'else\n' + 42 ' node "$basedir/../yes/yes.js" "$@"\n' + 43 ' ret=$?\n' + 44 'fi\n' + 45 'exit $ret\n'), 46 'yes.cmd': File( 47 '@IF EXIST "%~dp0\node.exe" (\n' + 48 '"%~dp0\\node.exe" "%~dp0\\..\\yes\\yes.js" %*\n' + 49 ') ELSE (\n' + 50 '@SETLOCAL\n' + 51 '@SET PATHEXT=%PATHEXT:;.JS;=;%\n' + 52 'node "%~dp0\\..\\yes\\yes.js" %*') 53 }) 54 }), 55 'package.json': File({ 56 name: 'test', 57 version: '1.0.0', 58 devDependencies: { 59 'yes': 'file:///mods/yes' 60 } 61 }) 62 }) 63) 64 65function setup () { 66 cleanup() 67 fixture.create(testdir) 68} 69 70function cleanup () { 71 fixture.remove(testdir) 72} 73 74test('setup', function (t) { 75 setup() 76 t.end() 77}) 78 79function readdir (dir) { 80 try { 81 return fs.readdirSync(dir) 82 } catch (ex) { 83 if (ex.code === 'ENOENT') return [] 84 throw ex 85 } 86} 87 88test('prune cycle in dev deps', function (t) { 89 common.npm(['prune', '--production', '--json'], {cwd: testdir}, function (err, code, stdout, stderr) { 90 if (err) throw err 91 t.is(code, 0, 'prune finished successfully') 92 t.like(JSON.parse(stdout), {removed: [{name: 'yes'}]}, 'removed the right modules') 93 var dirs = readdir(testdir + '/node_modules').sort() 94 // bindirs are never removed, it's ok for them to remain after prune 95 t.same(dirs, ['.bin']) 96 t.end() 97 }) 98}) 99 100test('cleanup', function (t) { 101 cleanup() 102 t.end() 103}) 104