File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -140,6 +140,12 @@ class Install extends ArboristWorkspaceCmd {
140140 args = [ '.' ]
141141 }
142142
143+ // throw usage error if trying to install empty package
144+ // name to global space, e.g: `npm i -g ""`
145+ if ( where === globalTop && ! args . every ( Boolean ) ) {
146+ throw this . usageError ( )
147+ }
148+
143149 // TODO: Add warnings for other deprecated flags? or remove this one?
144150 if ( isDev ) {
145151 log . warn (
Original file line number Diff line number Diff line change @@ -142,6 +142,26 @@ t.test('should install globally using Arborist', async t => {
142142 t . strictSame ( SCRIPTS , [ ] , 'no scripts when installing globally' )
143143} )
144144
145+ t . test ( 'should not install invalid global package name' , async t => {
146+ const SCRIPTS = [ ]
147+ let ARB_ARGS = null
148+ let REIFY_CALLED
149+ const { npm } = await loadMockNpm ( t , {
150+ '@npmcli/run-script' : ( ) => { } ,
151+ '../../lib/utils/reify-finish.js' : async ( ) => { } ,
152+ '@npmcli/arborist' : function ( args ) {
153+ throw new Error ( 'should not reify' )
154+ } ,
155+ } )
156+ npm . config . set ( 'global' , true )
157+ npm . globalPrefix = path . resolve ( t . testdir ( { } ) )
158+ await t . rejects (
159+ npm . exec ( 'install' , [ '' ] ) ,
160+ / U s a g e : / ,
161+ 'should not install invalid package name'
162+ )
163+ } )
164+
145165t . test ( 'npm i -g npm engines check success' , async t => {
146166 const { npm } = await loadMockNpm ( t , {
147167 '../../lib/utils/reify-finish.js' : async ( ) => { } ,
You can’t perform that action at this time.
0 commit comments