1var fs = require('graceful-fs') 2var path = require('path') 3var existsSync = fs.existsSync || path.existsSync 4 5var mkdirp = require('mkdirp') 6var rimraf = require('rimraf') 7var test = require('tap').test 8 9var common = require('../common-tap.js') 10 11var pkg = common.pkg 12 13var EXEC_OPTS = { cwd: pkg, stdio: [0, 1, 2] } 14 15var json = { 16 name: 'install-windows-newlines', 17 description: 'fixture', 18 version: '0.0.0', 19 dependencies: { 20 'cli-dependency': 'file:cli-dependency' 21 } 22} 23 24var dependency = { 25 name: 'cli-dependency', 26 description: 'fixture', 27 version: '0.0.0', 28 bin: { 29 hashbang: './hashbang.js', 30 nohashbang: './nohashbang.js' 31 } 32} 33 34test('setup', function (t) { 35 cleanup() 36 mkdirp.sync(path.join(pkg, 'cli-dependency')) 37 fs.writeFileSync( 38 path.join(pkg, 'cli-dependency', 'package.json'), 39 JSON.stringify(dependency, null, 2) 40 ) 41 fs.writeFileSync( 42 path.join(pkg, 'cli-dependency', 'hashbang.js'), 43 '#!/usr/bin/env node\r\nconsole.log(\'Hello, world!\')\r\n' 44 ) 45 fs.writeFileSync( 46 path.join(pkg, 'cli-dependency', 'nohashbang.js'), 47 '\'use strict\'\r\nconsole.log(\'Goodbye, world!\')\r\n' 48 ) 49 50 mkdirp.sync(path.join(pkg, 'node_modules')) 51 fs.writeFileSync( 52 path.join(pkg, 'package.json'), 53 JSON.stringify(json, null, 2) 54 ) 55 56 return common.npm(['install'], EXEC_OPTS).spread((code) => { 57 t.equal(code, 0, 'npm install did not raise error code') 58 t.ok( 59 existsSync(path.resolve(pkg, 'node_modules/.bin/hashbang')), 60 'hashbang installed' 61 ) 62 t.ok( 63 existsSync(path.resolve(pkg, 'node_modules/.bin/nohashbang')), 64 'nohashbang installed' 65 ) 66 t.notOk( 67 fs.readFileSync( 68 path.resolve(pkg, 'node_modules/cli-dependency/hashbang.js'), 69 'utf8' 70 ).includes('node\r\n'), 71 'hashbang dependency cli newlines converted' 72 ) 73 t.ok( 74 fs.readFileSync( 75 path.resolve(pkg, 'node_modules/cli-dependency/nohashbang.js'), 76 'utf8' 77 ).includes('\r\n'), 78 'nohashbang dependency cli newlines retained' 79 ) 80 }) 81}) 82 83test('cleanup', function (t) { 84 cleanup() 85 t.end() 86}) 87 88function cleanup () { 89 rimraf.sync(pkg) 90} 91