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