File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,16 +39,25 @@ const getFilterFn = args => {
3939 const spec = npa ( arg )
4040 if ( spec . type === 'tag' && spec . rawSpec === '' )
4141 return spec
42- if ( spec . type !== 'range' && spec . type !== 'version' )
42+
43+ if ( spec . type !== 'range' && spec . type !== 'version' && spec . type !== 'directory' )
4344 throw new Error ( '`npm rebuild` only supports SemVer version/range specifiers' )
45+
4446 return spec
4547 } )
48+
4649 return node => specs . some ( spec => {
47- const { version } = node . package
50+ if ( spec . type === 'directory' )
51+ return node . path === spec . fetchSpec
52+
4853 if ( spec . name !== node . name )
4954 return false
55+
5056 if ( spec . rawSpec === '' || spec . rawSpec === '*' )
5157 return true
58+
59+ const { version } = node . package
60+ // TODO: add tests for a package with missing version
5261 return semver . satisfies ( version , spec . fetchSpec )
5362 } )
5463}
Original file line number Diff line number Diff line change @@ -174,8 +174,48 @@ t.test('filter by pkg@<range>', t => {
174174 } )
175175} )
176176
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 => {
179219 t . match (
180220 err ,
181221 / 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