File tree Expand file tree Collapse file tree 2 files changed +53
-4
lines changed Expand file tree Collapse file tree 2 files changed +53
-4
lines changed Original file line number Diff line number Diff line change @@ -39,16 +39,25 @@ const getFilterFn = args => {
39
39
const spec = npa ( arg )
40
40
if ( spec . type === 'tag' && spec . rawSpec === '' )
41
41
return spec
42
- if ( spec . type !== 'range' && spec . type !== 'version' )
42
+
43
+ if ( spec . type !== 'range' && spec . type !== 'version' && spec . type !== 'directory' )
43
44
throw new Error ( '`npm rebuild` only supports SemVer version/range specifiers' )
45
+
44
46
return spec
45
47
} )
48
+
46
49
return node => specs . some ( spec => {
47
- const { version } = node . package
50
+ if ( spec . type === 'directory' )
51
+ return node . path === spec . fetchSpec
52
+
48
53
if ( spec . name !== node . name )
49
54
return false
55
+
50
56
if ( spec . rawSpec === '' || spec . rawSpec === '*' )
51
57
return true
58
+
59
+ const { version } = node . package
60
+ // TODO: add tests for a package with missing version
52
61
return semver . satisfies ( version , spec . fetchSpec )
53
62
} )
54
63
}
Original file line number Diff line number Diff line change @@ -174,8 +174,48 @@ t.test('filter by pkg@<range>', t => {
174
174
} )
175
175
} )
176
176
177
- t . test ( 'filter must be a semver version/range' , t => {
178
- rebuild ( [ 'b:git+ssh://github.com/npm/arborist' ] , err => {
177
+ t . test ( 'filter by directory' , t => {
178
+ const path = t . testdir ( {
179
+ node_modules : {
180
+ a : {
181
+ 'index.js' : '' ,
182
+ 'package.json' : JSON . stringify ( {
183
+ name : 'a' ,
184
+ version : '1.0.0' ,
185
+ bin : 'index.js' ,
186
+ } ) ,
187
+ } ,
188
+ b : {
189
+ 'index.js' : '' ,
190
+ 'package.json' : JSON . stringify ( {
191
+ name : 'b' ,
192
+ version : '1.0.0' ,
193
+ bin : 'index.js' ,
194
+ } ) ,
195
+ } ,
196
+ } ,
197
+ } )
198
+
199
+ npm . prefix = path
200
+
201
+ const aBinFile = resolve ( path , 'node_modules/.bin/a' )
202
+ const bBinFile = resolve ( path , 'node_modules/.bin/b' )
203
+ t . throws ( ( ) => fs . statSync ( aBinFile ) )
204
+ t . throws ( ( ) => fs . statSync ( bBinFile ) )
205
+
206
+ rebuild ( [ 'file:node_modules/b' ] , err => {
207
+ if ( err )
208
+ throw err
209
+
210
+ t . throws ( ( ) => fs . statSync ( aBinFile ) , 'should not link a bin' )
211
+ t . ok ( ( ) => fs . statSync ( bBinFile ) , 'should link filtered pkg bin' )
212
+
213
+ t . end ( )
214
+ } )
215
+ } )
216
+
217
+ t . test ( 'filter must be a semver version/range, or directory' , t => {
218
+ rebuild ( [ 'git+ssh://github.com/npm/arborist' ] , err => {
179
219
t . match (
180
220
err ,
181
221
/ E r r o r : ` n p m r e b u i l d ` o n l y s u p p o r t s S e m V e r v e r s i o n \/ r a n g e s p e c i f i e r s / ,
You can’t perform that action at this time.
0 commit comments