1
1
import fixturez from "fixturez" ;
2
+ import path from 'node:path' ;
2
3
import { getPackages , getPackagesSync } from "./" ;
3
4
4
5
const f = fixturez ( __dirname ) ;
@@ -7,19 +8,24 @@ type GetPackages = typeof getPackages | typeof getPackagesSync;
7
8
8
9
let runTests = ( getPackages : GetPackages ) => {
9
10
it ( "should resolve workspaces for yarn" , async ( ) => {
10
- const allPackages = await getPackages ( f . copy ( "yarn-workspace-base" ) ) ;
11
+ const dir = f . copy ( "yarn-workspace-base" ) ;
11
12
12
- if ( allPackages . packages === null ) {
13
- return expect ( allPackages . packages ) . not . toBeNull ( ) ;
14
- }
13
+ // Test for both root and subdirectories
14
+ for ( const location of [ '.' , ' packages' , 'packages/pkg-a' ] ) {
15
+ const allPackages = await getPackages ( path . join ( dir , location ) ) ;
15
16
16
- expect ( allPackages . packages [ 0 ] . packageJson . name ) . toEqual (
17
- "yarn-workspace-base-pkg-a"
18
- ) ;
19
- expect ( allPackages . packages [ 1 ] . packageJson . name ) . toEqual (
20
- "yarn-workspace-base-pkg-b"
21
- ) ;
22
- expect ( allPackages . tool . type ) . toEqual ( "yarn" ) ;
17
+ if ( allPackages . packages === null ) {
18
+ return expect ( allPackages . packages ) . not . toBeNull ( ) ;
19
+ }
20
+
21
+ expect ( allPackages . packages [ 0 ] . packageJson . name ) . toEqual (
22
+ "yarn-workspace-base-pkg-a"
23
+ ) ;
24
+ expect ( allPackages . packages [ 1 ] . packageJson . name ) . toEqual (
25
+ "yarn-workspace-base-pkg-b"
26
+ ) ;
27
+ expect ( allPackages . tool . type ) . toEqual ( "yarn" ) ;
28
+ }
23
29
} ) ;
24
30
25
31
it ( "should resolve yarn workspaces if the yarn option is passed and packages field is used" , async ( ) => {
@@ -38,35 +44,45 @@ let runTests = (getPackages: GetPackages) => {
38
44
} ) ;
39
45
40
46
it ( "should resolve workspaces for bolt" , async ( ) => {
41
- const allPackages = await getPackages ( f . copy ( "bolt-workspace" ) ) ;
47
+ const dir = f . copy ( "bolt-workspace" ) ;
42
48
43
- if ( allPackages . packages === null ) {
44
- return expect ( allPackages . packages ) . not . toBeNull ( ) ;
45
- }
49
+ // Test for both root and subdirectories
50
+ for ( const location of [ '.' , ' packages' , 'packages/pkg-b' ] ) {
51
+ const allPackages = await getPackages ( path . join ( dir , location ) ) ;
46
52
47
- expect ( allPackages . packages [ 0 ] . packageJson . name ) . toEqual (
48
- "bolt-workspace-pkg-a"
49
- ) ;
50
- expect ( allPackages . packages [ 1 ] . packageJson . name ) . toEqual (
51
- "bolt-workspace-pkg-b"
52
- ) ;
53
- expect ( allPackages . tool . type ) . toEqual ( "bolt" ) ;
53
+ if ( allPackages . packages === null ) {
54
+ return expect ( allPackages . packages ) . not . toBeNull ( ) ;
55
+ }
56
+
57
+ expect ( allPackages . packages [ 0 ] . packageJson . name ) . toEqual (
58
+ "bolt-workspace-pkg-a"
59
+ ) ;
60
+ expect ( allPackages . packages [ 1 ] . packageJson . name ) . toEqual (
61
+ "bolt-workspace-pkg-b"
62
+ ) ;
63
+ expect ( allPackages . tool . type ) . toEqual ( "bolt" ) ;
64
+ }
54
65
} ) ;
55
66
56
67
it ( "should resolve workspaces for pnpm" , async ( ) => {
57
- const allPackages = await getPackages ( f . copy ( "pnpm-workspace-base" ) ) ;
68
+ const dir = f . copy ( "pnpm-workspace-base" ) ;
58
69
59
- if ( allPackages . packages === null ) {
60
- return expect ( allPackages . packages ) . not . toBeNull ( ) ;
61
- }
70
+ // Test for both root and subdirectories
71
+ for ( const location of [ '.' , ' packages' , 'packages/pkg-a' ] ) {
72
+ const allPackages = await getPackages ( path . join ( dir , location ) ) ;
62
73
63
- expect ( allPackages . packages [ 0 ] . packageJson . name ) . toEqual (
64
- "pnpm-workspace-base-pkg-a"
65
- ) ;
66
- expect ( allPackages . packages [ 1 ] . packageJson . name ) . toEqual (
67
- "pnpm-workspace-base-pkg-b"
68
- ) ;
69
- expect ( allPackages . tool . type ) . toEqual ( "pnpm" ) ;
74
+ if ( allPackages . packages === null ) {
75
+ return expect ( allPackages . packages ) . not . toBeNull ( ) ;
76
+ }
77
+
78
+ expect ( allPackages . packages [ 0 ] . packageJson . name ) . toEqual (
79
+ "pnpm-workspace-base-pkg-a"
80
+ ) ;
81
+ expect ( allPackages . packages [ 1 ] . packageJson . name ) . toEqual (
82
+ "pnpm-workspace-base-pkg-b"
83
+ ) ;
84
+ expect ( allPackages . tool . type ) . toEqual ( "pnpm" ) ;
85
+ }
70
86
} ) ;
71
87
72
88
it ( "should resolve workspace for pnpm with exclude rules" , async ( ) => {
@@ -85,20 +101,25 @@ let runTests = (getPackages: GetPackages) => {
85
101
} ) ;
86
102
87
103
it ( "should resolve workspaces for lerna" , async ( ) => {
88
- const allPackages = await getPackages ( f . copy ( "lerna-workspace-base" ) ) ;
104
+ const dir = f . copy ( "lerna-workspace-base" ) ;
89
105
90
- if ( allPackages . packages === null ) {
91
- return expect ( allPackages . packages ) . not . toBeNull ( ) ;
92
- }
106
+ // Test for both root and subdirectories
107
+ for ( const location of [ '.' , ' packages' , 'packages/pkg-b' ] ) {
108
+ const allPackages = await getPackages ( path . join ( dir , location ) ) ;
93
109
94
- expect ( allPackages . packages [ 0 ] . packageJson . name ) . toEqual (
95
- "lerna-workspace-base-pkg-a"
96
- ) ;
97
- expect ( allPackages . packages [ 1 ] . packageJson . name ) . toEqual (
98
- "lerna-workspace-base-pkg-b"
99
- ) ;
100
- expect ( allPackages . packages ) . toHaveLength ( 2 ) ;
101
- expect ( allPackages . tool . type ) . toEqual ( "lerna" ) ;
110
+ if ( allPackages . packages === null ) {
111
+ return expect ( allPackages . packages ) . not . toBeNull ( ) ;
112
+ }
113
+
114
+ expect ( allPackages . packages [ 0 ] . packageJson . name ) . toEqual (
115
+ "lerna-workspace-base-pkg-a"
116
+ ) ;
117
+ expect ( allPackages . packages [ 1 ] . packageJson . name ) . toEqual (
118
+ "lerna-workspace-base-pkg-b"
119
+ ) ;
120
+ expect ( allPackages . packages ) . toHaveLength ( 2 ) ;
121
+ expect ( allPackages . tool . type ) . toEqual ( "lerna" ) ;
122
+ }
102
123
} ) ;
103
124
104
125
it ( "should resolve workspaces for lerna without explicit packages config" , async ( ) => {
0 commit comments