File tree Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -127,7 +127,7 @@ class Install extends ArboristWorkspaceCmd {
127127 args = args . filter ( a => resolve ( a ) !== this . npm . prefix )
128128
129129 // `npm i -g` => "install this package globally"
130- if ( where === globalTop && ! args . length ) {
130+ if ( isGlobalInstall && ! args . length ) {
131131 args = [ '.' ]
132132 }
133133
Original file line number Diff line number Diff line change @@ -107,6 +107,7 @@ const setupMockNpm = async (t, {
107107 exec = null , // optionally exec the command before returning
108108 // test dirs
109109 prefixDir = { } ,
110+ prefixOverride = null , // sets global and local prefix to this, the same as the `--prefix` flag
110111 homeDir = { } ,
111112 cacheDir = { } ,
112113 globalPrefixDir = { node_modules : { } } ,
@@ -170,9 +171,9 @@ const setupMockNpm = async (t, {
170171
171172 const dirs = {
172173 testdir : dir ,
173- prefix : path . join ( dir , 'prefix' ) ,
174+ prefix : prefixOverride ?? path . join ( dir , 'prefix' ) ,
174175 cache : path . join ( dir , 'cache' ) ,
175- globalPrefix : path . join ( dir , 'global' ) ,
176+ globalPrefix : prefixOverride ?? path . join ( dir , 'global' ) ,
176177 home : path . join ( dir , 'home' ) ,
177178 other : path . join ( dir , 'other' ) ,
178179 }
Original file line number Diff line number Diff line change @@ -126,6 +126,25 @@ t.test('exec commands', async t => {
126126 await npm . exec ( 'install' )
127127 } )
128128
129+ await t . test ( 'should not self-install package if prefix is the same as CWD' , async t => {
130+ let REIFY_CALLED_WITH = null
131+ const { npm } = await loadMockNpm ( t , {
132+ mocks : {
133+ '{LIB}/utils/reify-finish.js' : async ( ) => { } ,
134+ '@npmcli/run-script' : ( ) => { } ,
135+ '@npmcli/arborist' : function ( ) {
136+ this . reify = ( opts ) => {
137+ REIFY_CALLED_WITH = opts
138+ }
139+ } ,
140+ } ,
141+ prefixOverride : process . cwd ( ) ,
142+ } )
143+
144+ await npm . exec ( 'install' )
145+ t . equal ( REIFY_CALLED_WITH . add . length , 0 , 'did not install current directory as a dependency' )
146+ } )
147+
129148 await t . test ( 'should not install invalid global package name' , async t => {
130149 const { npm } = await loadMockNpm ( t , {
131150 config : {
You can’t perform that action at this time.
0 commit comments