@@ -11,10 +11,13 @@ const read = BB.promisify(fs.read, {multiArgs: true})
11
11
const chmod = BB . promisify ( fs . chmod )
12
12
const readFile = BB . promisify ( fs . readFile )
13
13
const writeFileAtomic = BB . promisify ( require ( 'write-file-atomic' ) )
14
+ const normalize = require ( 'npm-normalize-package-bin' )
14
15
15
16
module . exports = BB . promisify ( binLinks )
16
17
17
18
function binLinks ( pkg , folder , global , opts , cb ) {
19
+ pkg = normalize ( pkg )
20
+
18
21
// if it's global, and folder is in {prefix}/node_modules,
19
22
// then bins are in {prefix}/bin
20
23
// otherwise, then bins are in folder/../.bin
@@ -77,6 +80,12 @@ function linkBins (pkg, folder, parent, gtop, opts) {
77
80
var dest = path . resolve ( binRoot , bin )
78
81
var src = path . resolve ( folder , pkg . bin [ bin ] )
79
82
83
+ /* istanbul ignore if - that unpossible */
84
+ if ( src . indexOf ( folder ) !== 0 ) {
85
+ throw new Error ( 'invalid bin entry for package ' +
86
+ pkg . _id + '. key=' + bin + ', value=' + pkg . bin [ bin ] )
87
+ }
88
+
80
89
return linkBin ( src , dest , linkOpts ) . then ( ( ) => {
81
90
// bins should always be executable.
82
91
// XXX skip chmod on windows?
@@ -123,7 +132,8 @@ function linkMans (pkg, folder, parent, gtop, opts) {
123
132
// make sure that the mans are unique.
124
133
// otherwise, if there are dupes, it'll fail with EEXIST
125
134
var set = pkg . man . reduce ( function ( acc , man ) {
126
- acc [ path . basename ( man ) ] = man
135
+ const cleanMan = path . join ( '/' , man ) . replace ( / \\ | : / g, '/' ) . substr ( 1 )
136
+ acc [ path . basename ( man ) ] = cleanMan
127
137
return acc
128
138
} , { } )
129
139
var manpages = pkg . man . filter ( function ( man ) {
@@ -146,6 +156,12 @@ function linkMans (pkg, folder, parent, gtop, opts) {
146
156
var sxn = parseMan [ 2 ]
147
157
var bn = path . basename ( stem )
148
158
var manSrc = path . resolve ( folder , man )
159
+ /* istanbul ignore if - that unpossible */
160
+ if ( manSrc . indexOf ( folder ) !== 0 ) {
161
+ throw new Error ( 'invalid man entry for package ' +
162
+ pkg . _id + '. man=' + manSrc )
163
+ }
164
+
149
165
var manDest = path . join ( manRoot , 'man' + sxn , bn )
150
166
151
167
return linkIfExists ( manSrc , manDest , getLinkOpts ( opts , gtop && folder ) )
0 commit comments