File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -112,14 +112,23 @@ const linkInstall = async args => {
112
112
)
113
113
}
114
114
115
+ // npm link should not save=true by default unless you're
116
+ // using any of --save-dev or other types
117
+ const save =
118
+ Boolean ( npm . config . find ( 'save' ) !== 'default' || npm . flatOptions . saveType )
119
+
115
120
// create a new arborist instance for the local prefix and
116
121
// reify all the pending names as symlinks there
117
122
const localArb = new Arborist ( {
118
123
...npm . flatOptions ,
119
124
path : npm . prefix ,
125
+ save,
120
126
} )
121
127
await localArb . reify ( {
128
+ ...npm . flatOptions ,
129
+ path : npm . prefix ,
122
130
add : names . map ( l => `file:${ resolve ( globalTop , 'node_modules' , l ) } ` ) ,
131
+ save,
123
132
} )
124
133
125
134
await reifyFinish ( localArb )
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ const npm = {
23
23
get ( ) {
24
24
return false
25
25
} ,
26
+ find ( ) { } ,
26
27
} ,
27
28
}
28
29
const printLinks = async ( opts ) => {
@@ -196,7 +197,7 @@ t.test('link global linked pkg to local nm when using args', (t) => {
196
197
} )
197
198
198
199
t . test ( 'link pkg already in global space' , ( t ) => {
199
- t . plan ( 2 )
200
+ t . plan ( 3 )
200
201
201
202
const testdir = t . testdir ( {
202
203
'global-prefix' : {
@@ -224,17 +225,26 @@ t.test('link pkg already in global space', (t) => {
224
225
npm . globalDir = resolve ( testdir , 'global-prefix' , 'lib' , 'node_modules' )
225
226
npm . prefix = resolve ( testdir , 'my-project' )
226
227
228
+ npm . config . find = ( ) => 'default'
229
+
227
230
const _cwd = process . cwd ( )
228
231
process . chdir ( npm . prefix )
229
232
230
233
reifyOutput = async ( ) => {
231
234
reifyOutput = undefined
232
235
process . chdir ( _cwd )
236
+ npm . config . find = ( ) => null
233
237
234
238
const links = await printLinks ( {
235
239
path : npm . prefix ,
236
240
} )
237
241
242
+ t . equal (
243
+ require ( resolve ( testdir , 'my-project' , 'package.json' ) ) . dependencies ,
244
+ undefined ,
245
+ 'should not save to package.json upon linking'
246
+ )
247
+
238
248
t . matchSnapshot ( links , 'should create a local symlink to global pkg' )
239
249
}
240
250
You can’t perform that action at this time.
0 commit comments