@@ -34,6 +34,14 @@ describe('explicit package json dependencies', () => {
3434 root : 'libs/proj4' ,
3535 name : 'proj4' ,
3636 } ,
37+ proj5 : {
38+ root : 'libs/proj5' ,
39+ name : 'proj5' ,
40+ } ,
41+ proj6 : {
42+ root : 'libs/proj6' ,
43+ name : 'proj6' ,
44+ } ,
3745 } ,
3846 } ;
3947
@@ -65,6 +73,16 @@ describe('explicit package json dependencies', () => {
6573 name : 'proj4' ,
6674 version : '2.0.0' , // the source version in the workspace
6775 } ) ,
76+ './libs/proj5/index.js' : '' ,
77+ './libs/proj5/package.json' : JSON . stringify ( {
78+ name : 'proj5' ,
79+ version : '1.1.0' , // the source version in the workspace
80+ } ) ,
81+ './libs/proj6/index.js' : '' ,
82+ './libs/proj6/package.json' : JSON . stringify ( {
83+ name : 'proj6' ,
84+ version : '1.1.0' , // the source version in the workspace
85+ } ) ,
6886 './libs/proj3/node_modules/lodash/index.js' : '' ,
6987 './libs/proj3/node_modules/lodash/package.json' : JSON . stringify ( {
7088 name : 'lodash' ,
@@ -79,6 +97,8 @@ describe('explicit package json dependencies', () => {
7997 dependencies : {
8098 proj2 : '*' ,
8199 proj4 : '1.0.0' , // references an installed older version from package manager
100+ proj5 : '^1.0.0' ,
101+ proj6 : 'file:../proj6' ,
82102 lodash : '4.0.0' ,
83103 } ,
84104 devDependencies : { proj3 : '*' } ,
@@ -136,6 +156,37 @@ describe('explicit package json dependencies', () => {
136156 metadata : {
137157 js : {
138158 packageName : 'proj4' ,
159+ packageVersion : '2.0.0' ,
160+ packageExports : undefined ,
161+ isInPackageManagerWorkspaces : true ,
162+ } ,
163+ } ,
164+ } ,
165+ } ,
166+ proj5 : {
167+ name : 'proj5' ,
168+ type : 'lib' ,
169+ data : {
170+ root : 'libs/proj5' ,
171+ metadata : {
172+ js : {
173+ packageName : 'proj5' ,
174+ packageVersion : '1.1.0' ,
175+ packageExports : undefined ,
176+ isInPackageManagerWorkspaces : true ,
177+ } ,
178+ } ,
179+ } ,
180+ } ,
181+ proj6 : {
182+ name : 'proj6' ,
183+ type : 'lib' ,
184+ data : {
185+ root : 'libs/proj6' ,
186+ metadata : {
187+ js : {
188+ packageName : 'proj6' ,
189+ packageVersion : '1.1.0' ,
139190 packageExports : undefined ,
140191 isInPackageManagerWorkspaces : true ,
141192 } ,
@@ -201,46 +252,37 @@ describe('explicit package json dependencies', () => {
201252 ) ;
202253
203254 const res = buildExplicitPackageJsonDependencies ( ctx , targetProjectLocator ) ;
204- expect ( res ) . toEqual ( [
205- {
206- source : 'proj' ,
207- target : 'proj3' ,
208- sourceFile : 'libs/proj/package.json' ,
209- type : 'static' ,
210- } ,
211- {
212- source : 'proj' ,
213- target : 'proj2' ,
214- sourceFile : 'libs/proj/package.json' ,
215- type : 'static' ,
216- } ,
217- {
218- source : 'proj' ,
219- sourceFile : 'libs/proj/package.json' ,
220- target : 'npm:proj4' , // correctly resolves to the npm package of the project rather than the workspace project
221- type : 'static' ,
222- } ,
223- {
224- sourceFile : 'libs/proj/package.json' ,
225- source : 'proj' ,
226- target : 'npm:lodash' ,
227- type : 'static' ,
228- } ,
229- {
230- sourceFile : 'libs/proj3/package.json' ,
231- source : 'proj3' ,
232- 233- type : 'static' ,
234- } ,
235- {
236- source : 'proj3' ,
237- sourceFile : 'libs/proj3/package.json' ,
238- target : 'proj4' , // correctly resolves to the workspace dependency of the project in the workspace
239- type : 'static' ,
240- } ,
241- ] ) ;
255+ expect ( res ) . toEqual (
256+ expect . arrayContaining ( [
257+ {
258+ source : 'proj' ,
259+ target : 'proj3' ,
260+ sourceFile : 'libs/proj/package.json' ,
261+ type : 'static' ,
262+ } ,
263+ {
264+ source : 'proj' ,
265+ target : 'proj2' ,
266+ sourceFile : 'libs/proj/package.json' ,
267+ type : 'static' ,
268+ } ,
269+ {
270+ sourceFile : 'libs/proj/package.json' ,
271+ source : 'proj' ,
272+ target : 'npm:lodash' ,
273+ type : 'static' ,
274+ } ,
275+ {
276+ sourceFile : 'libs/proj3/package.json' ,
277+ source : 'proj3' ,
278+ 279+ type : 'static' ,
280+ } ,
281+ ] )
282+ ) ;
242283 expect ( npmResolutionCache ) . toMatchInlineSnapshot ( `
243284 Map {
285+ "proj4__libs/proj" => "npm:proj4",
244286 "lodash__libs/proj" => "npm:lodash",
245287 "lodash__libs/proj3" => "npm:[email protected] ", 246288 }
@@ -260,46 +302,20 @@ describe('explicit package json dependencies', () => {
260302 npmResolutionCache . set ( 'lodash__libs/proj3' , 'npm:[email protected] ' ) ; 261303
262304 const res = buildExplicitPackageJsonDependencies ( ctx , targetProjectLocator ) ;
263- expect ( res ) . toEqual ( [
264- {
265- source : 'proj' ,
266- target : 'proj3' ,
267- sourceFile : 'libs/proj/package.json' ,
268- type : 'static' ,
269- } ,
270- {
271- source : 'proj' ,
272- target : 'proj2' ,
273- sourceFile : 'libs/proj/package.json' ,
274- type : 'static' ,
275- } ,
276- {
277- source : 'proj' ,
278- sourceFile : 'libs/proj/package.json' ,
279- target : 'npm:proj4' , // correctly resolves to the npm package of the project rather than the workspace project
280- type : 'static' ,
281- } ,
282- {
283- sourceFile : 'libs/proj/package.json' ,
284- source : 'proj' ,
285- // Preferred the cached version of lodash, instead of 4.0.0 resolved from tempFs node_modules
286- 287- type : 'static' ,
288- } ,
289- {
290- sourceFile : 'libs/proj3/package.json' ,
291- source : 'proj3' ,
292- // Preferred the cached version of lodash, instead of 3.0.0 resolved from tempFs node_modules
293- 294- type : 'static' ,
295- } ,
296- {
297- source : 'proj3' ,
298- sourceFile : 'libs/proj3/package.json' ,
299- target : 'proj4' , // correctly resolves to the workspace dependency of the project in the workspace
300- type : 'static' ,
301- } ,
302- ] ) ;
305+ expect ( res ) . toContainEqual ( {
306+ sourceFile : 'libs/proj/package.json' ,
307+ source : 'proj' ,
308+ // Preferred the cached version of lodash, instead of 4.0.0 resolved from tempFs node_modules
309+ 310+ type : 'static' ,
311+ } ) ;
312+ expect ( res ) . toContainEqual ( {
313+ sourceFile : 'libs/proj3/package.json' ,
314+ source : 'proj3' ,
315+ // Preferred the cached version of lodash, instead of 3.0.0 resolved from tempFs node_modules
316+ 317+ type : 'static' ,
318+ } ) ;
303319 } ) ;
304320
305321 it ( 'should add correct npm dependencies for projects that use an older installed version of a package that exists in the workspace' , async ( ) => {
@@ -322,4 +338,46 @@ describe('explicit package json dependencies', () => {
322338 ] )
323339 ) ;
324340 } ) ;
341+
342+ it ( 'should add correct workspace dependencies for projects that use a range for packages which exist in the workspace' , async ( ) => {
343+ const npmResolutionCache = new Map ( ) ;
344+ const targetProjectLocator = new TargetProjectLocator (
345+ projects ,
346+ ctx . externalNodes ,
347+ npmResolutionCache
348+ ) ;
349+
350+ const res = buildExplicitPackageJsonDependencies ( ctx , targetProjectLocator ) ;
351+ expect ( res ) . toEqual (
352+ expect . arrayContaining ( [
353+ {
354+ source : 'proj' ,
355+ sourceFile : 'libs/proj/package.json' ,
356+ target : 'proj5' , // correctly resolves to the npm package of the project rather than the workspace project
357+ type : 'static' ,
358+ } ,
359+ ] )
360+ ) ;
361+ } ) ;
362+
363+ it ( 'should add correct workspace dependencies for projects that use a file reference of a package that exists in the workspace' , async ( ) => {
364+ const npmResolutionCache = new Map ( ) ;
365+ const targetProjectLocator = new TargetProjectLocator (
366+ projects ,
367+ ctx . externalNodes ,
368+ npmResolutionCache
369+ ) ;
370+
371+ const res = buildExplicitPackageJsonDependencies ( ctx , targetProjectLocator ) ;
372+ expect ( res ) . toEqual (
373+ expect . arrayContaining ( [
374+ {
375+ source : 'proj' ,
376+ sourceFile : 'libs/proj/package.json' ,
377+ target : 'proj6' , // correctly resolves to the npm package of the project rather than the workspace project
378+ type : 'static' ,
379+ } ,
380+ ] )
381+ ) ;
382+ } ) ;
325383} ) ;
0 commit comments