File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -139,6 +139,12 @@ class Install extends ArboristWorkspaceCmd {
139139 args = [ '.' ]
140140 }
141141
142+ // throw usage error if trying to install empty package
143+ // name to global space, e.g: `npm i -g ""`
144+ if ( where === globalTop && ! args . every ( Boolean ) ) {
145+ throw this . usageError ( )
146+ }
147+
142148 const opts = {
143149 ...this . npm . flatOptions ,
144150 auditLevel : null ,
Original file line number Diff line number Diff line change @@ -139,6 +139,23 @@ t.test('should install globally using Arborist', async t => {
139139 t . strictSame ( SCRIPTS , [ ] , 'no scripts when installing globally' )
140140} )
141141
142+ t . test ( 'should not install invalid global package name' , async t => {
143+ const { npm } = await loadMockNpm ( t , {
144+ '@npmcli/run-script' : ( ) => { } ,
145+ '../../lib/utils/reify-finish.js' : async ( ) => { } ,
146+ '@npmcli/arborist' : function ( args ) {
147+ throw new Error ( 'should not reify' )
148+ } ,
149+ } )
150+ npm . config . set ( 'global' , true )
151+ npm . globalPrefix = path . resolve ( t . testdir ( { } ) )
152+ await t . rejects (
153+ npm . exec ( 'install' , [ '' ] ) ,
154+ / U s a g e : / ,
155+ 'should not install invalid package name'
156+ )
157+ } )
158+
142159t . test ( 'npm i -g npm engines check success' , async t => {
143160 const { npm } = await loadMockNpm ( t , {
144161 '../../lib/utils/reify-finish.js' : async ( ) => { } ,
You can’t perform that action at this time.
0 commit comments