@@ -84,6 +84,60 @@ t.test('link to globalDir when in current working dir of pkg and no args', (t) =
84
84
} )
85
85
} )
86
86
87
+ t . test ( 'link ws to globalDir when workspace specified and no args' , ( t ) => {
88
+ t . plan ( 2 )
89
+
90
+ const testdir = t . testdir ( {
91
+ 'global-prefix' : {
92
+ lib : {
93
+ node_modules : {
94
+ a : {
95
+ 'package.json' : JSON . stringify ( {
96
+ name : 'a' ,
97
+ version : '1.0.0' ,
98
+ } ) ,
99
+ } ,
100
+ } ,
101
+ } ,
102
+ } ,
103
+ 'test-pkg-link' : {
104
+ 'package.json' : JSON . stringify ( {
105
+ name : 'test-pkg-link' ,
106
+ version : '1.0.0' ,
107
+ workspaces : [ 'packages/*' ] ,
108
+ } ) ,
109
+ packages : {
110
+ a : {
111
+ 'package.json' : JSON . stringify ( {
112
+ name : 'a' ,
113
+ version : '1.0.0' ,
114
+ } ) ,
115
+ } ,
116
+ } ,
117
+ } ,
118
+ } )
119
+ npm . globalDir = resolve ( testdir , 'global-prefix' , 'lib' , 'node_modules' )
120
+ npm . prefix = resolve ( testdir , 'test-pkg-link' )
121
+ npm . localPrefix = resolve ( testdir , 'test-pkg-link' )
122
+
123
+ reifyOutput = async ( ) => {
124
+ reifyOutput = undefined
125
+
126
+ const links = await printLinks ( {
127
+ path : resolve ( npm . globalDir , '..' ) ,
128
+ global : true ,
129
+ } )
130
+
131
+ t . matchSnapshot ( links , 'should create a global link to current pkg' )
132
+ }
133
+
134
+ // link.workspaces = ['a']
135
+ // link.workspacePaths = [resolve(testdir, 'test-pkg-link/packages/a')]
136
+ link . execWorkspaces ( [ ] , [ 'a' ] , ( err ) => {
137
+ t . error ( err , 'should not error out' )
138
+ } )
139
+ } )
140
+
87
141
t . test ( 'link global linked pkg to local nm when using args' , ( t ) => {
88
142
t . plan ( 2 )
89
143
@@ -192,6 +246,124 @@ t.test('link global linked pkg to local nm when using args', (t) => {
192
246
} )
193
247
} )
194
248
249
+ t . test ( 'link global linked pkg to local workspace using args' , ( t ) => {
250
+ t . plan ( 2 )
251
+
252
+ const testdir = t . testdir ( {
253
+ 'global-prefix' : {
254
+ lib : {
255
+ node_modules : {
256
+ '@myscope' : {
257
+ foo : {
258
+ 'package.json' : JSON . stringify ( {
259
+ name : '@myscope/foo' ,
260
+ version : '1.0.0' ,
261
+ } ) ,
262
+ } ,
263
+ bar : {
264
+ 'package.json' : JSON . stringify ( {
265
+ name : '@myscope/bar' ,
266
+ version : '1.0.0' ,
267
+ } ) ,
268
+ } ,
269
+ linked : t . fixture ( 'symlink' , '../../../../scoped-linked' ) ,
270
+ } ,
271
+ a : {
272
+ 'package.json' : JSON . stringify ( {
273
+ name : 'a' ,
274
+ version : '1.0.0' ,
275
+ } ) ,
276
+ } ,
277
+ b : {
278
+ 'package.json' : JSON . stringify ( {
279
+ name : 'b' ,
280
+ version : '1.0.0' ,
281
+ } ) ,
282
+ } ,
283
+ 'test-pkg-link' : t . fixture ( 'symlink' , '../../../test-pkg-link' ) ,
284
+ } ,
285
+ } ,
286
+ } ,
287
+ 'test-pkg-link' : {
288
+ 'package.json' : JSON . stringify ( {
289
+ name : 'test-pkg-link' ,
290
+ version : '1.0.0' ,
291
+ } ) ,
292
+ } ,
293
+ 'link-me-too' : {
294
+ 'package.json' : JSON . stringify ( {
295
+ name : 'link-me-too' ,
296
+ version : '1.0.0' ,
297
+ } ) ,
298
+ } ,
299
+ 'scoped-linked' : {
300
+ 'package.json' : JSON . stringify ( {
301
+ name : '@myscope/linked' ,
302
+ version : '1.0.0' ,
303
+ } ) ,
304
+ } ,
305
+ 'my-project' : {
306
+ 'package.json' : JSON . stringify ( {
307
+ name : 'my-project' ,
308
+ version : '1.0.0' ,
309
+ workspaces : [ 'packages/*' ] ,
310
+ } ) ,
311
+ packages : {
312
+ x : {
313
+ 'package.json' : JSON . stringify ( {
314
+ name : 'x' ,
315
+ version : '1.0.0' ,
316
+ dependencies : {
317
+ foo : '^1.0.0' ,
318
+ } ,
319
+ } ) ,
320
+ } ,
321
+ } ,
322
+ node_modules : {
323
+ foo : {
324
+ 'package.json' : JSON . stringify ( {
325
+ name : 'foo' ,
326
+ version : '1.0.0' ,
327
+ } ) ,
328
+ } ,
329
+ } ,
330
+ } ,
331
+ } )
332
+ npm . globalDir = resolve ( testdir , 'global-prefix' , 'lib' , 'node_modules' )
333
+ npm . prefix = resolve ( testdir , 'my-project' )
334
+ npm . localPrefix = resolve ( testdir , 'my-project' )
335
+
336
+ const _cwd = process . cwd ( )
337
+ process . chdir ( npm . prefix )
338
+
339
+ reifyOutput = async ( ) => {
340
+ reifyOutput = undefined
341
+ process . chdir ( _cwd )
342
+
343
+ const links = await printLinks ( {
344
+ path : npm . prefix ,
345
+ } )
346
+
347
+ t . matchSnapshot ( links , 'should create a local symlink to global pkg' )
348
+ }
349
+
350
+ // installs examples for:
351
+ // - test-pkg-link: pkg linked to globalDir from local fs
352
+ // - @myscope/linked: scoped pkg linked to globalDir from local fs
353
+ // - @myscope/bar: prev installed scoped package available in globalDir
354
+ // - a: prev installed package available in globalDir
355
+ // - file:./link-me-too: pkg that needs to be reified in globalDir first
356
+ link . execWorkspaces ( [
357
+ 'test-pkg-link' ,
358
+ '@myscope/linked' ,
359
+ '@myscope/bar' ,
360
+ 'a' ,
361
+ 'file:../link-me-too' ,
362
+ ] , [ 'x' ] , ( err ) => {
363
+ t . error ( err , 'should not error out' )
364
+ } )
365
+ } )
366
+
195
367
t . test ( 'link pkg already in global space' , ( t ) => {
196
368
t . plan ( 3 )
197
369
0 commit comments