@@ -78,28 +78,25 @@ export async function findRoot(
78
78
let monorepoRoot : MonorepoRoot | undefined ;
79
79
const tools = options . tools || DEFAULT_TOOLS ;
80
80
81
- await findUp (
82
- async ( directory ) => {
83
- return Promise . all (
84
- tools . map ( async ( tool ) : Promise < MonorepoRoot | undefined > => {
85
- if ( await tool . isMonorepoRoot ( directory ) ) {
86
- return {
87
- tool : tool ,
88
- rootDir : directory ,
89
- } ;
90
- }
91
- } )
92
- )
93
- . then ( ( x ) => x . find ( ( value ) => value ) )
94
- . then ( ( result ) => {
95
- if ( result ) {
96
- monorepoRoot = result ;
97
- return directory ;
98
- }
99
- } ) ;
100
- } ,
101
- cwd
102
- ) ;
81
+ await findUp ( async ( directory ) => {
82
+ return Promise . all (
83
+ tools . map ( async ( tool ) : Promise < MonorepoRoot | undefined > => {
84
+ if ( await tool . isMonorepoRoot ( directory ) ) {
85
+ return {
86
+ tool : tool ,
87
+ rootDir : directory ,
88
+ } ;
89
+ }
90
+ } )
91
+ )
92
+ . then ( ( x ) => x . find ( ( value ) => value ) )
93
+ . then ( ( result ) => {
94
+ if ( result ) {
95
+ monorepoRoot = result ;
96
+ return directory ;
97
+ }
98
+ } ) ;
99
+ } , cwd ) ;
103
100
104
101
if ( monorepoRoot ) {
105
102
return monorepoRoot ;
@@ -112,19 +109,16 @@ export async function findRoot(
112
109
// If there is no monorepo root, but we can find a single package json file, we will
113
110
// return a "RootTool" repo, which is the special case where we just have a root package
114
111
// with no monorepo implementation (i.e.: a normal package folder).
115
- let rootDir = await findUp (
116
- async ( directory ) => {
117
- try {
118
- await fsp . access ( path . join ( directory , "package.json" ) ) ;
119
- return directory ;
120
- } catch ( err ) {
121
- if ( ! isNoEntryError ( err ) ) {
122
- throw err ;
123
- }
112
+ let rootDir = await findUp ( async ( directory ) => {
113
+ try {
114
+ await fsp . access ( path . join ( directory , "package.json" ) ) ;
115
+ return directory ;
116
+ } catch ( err ) {
117
+ if ( ! isNoEntryError ( err ) ) {
118
+ throw err ;
124
119
}
125
- } ,
126
- cwd
127
- ) ;
120
+ }
121
+ } , cwd ) ;
128
122
129
123
if ( ! rootDir ) {
130
124
throw new NoPkgJsonFound ( cwd ) ;
@@ -146,20 +140,17 @@ export function findRootSync(
146
140
let monorepoRoot : MonorepoRoot | undefined ;
147
141
const tools = options . tools || DEFAULT_TOOLS ;
148
142
149
- findUpSync (
150
- ( directory ) => {
151
- for ( const tool of tools ) {
152
- if ( tool . isMonorepoRootSync ( directory ) ) {
153
- monorepoRoot = {
154
- tool : tool ,
155
- rootDir : directory ,
156
- } ;
157
- return directory ;
158
- }
143
+ findUpSync ( ( directory ) => {
144
+ for ( const tool of tools ) {
145
+ if ( tool . isMonorepoRootSync ( directory ) ) {
146
+ monorepoRoot = {
147
+ tool : tool ,
148
+ rootDir : directory ,
149
+ } ;
150
+ return directory ;
159
151
}
160
- } ,
161
- cwd
162
- ) ;
152
+ }
153
+ } , cwd ) ;
163
154
164
155
if ( monorepoRoot ) {
165
156
return monorepoRoot ;
@@ -172,13 +163,10 @@ export function findRootSync(
172
163
// If there is no monorepo root, but we can find a single package json file, we will
173
164
// return a "RootTool" repo, which is the special case where we just have a root package
174
165
// with no monorepo implementation (i.e.: a normal package folder).
175
- const rootDir = findUpSync (
176
- ( directory ) => {
177
- const exists = fs . existsSync ( path . join ( directory , "package.json" ) ) ;
178
- return exists ? directory : undefined ;
179
- } ,
180
- cwd
181
- ) ;
166
+ const rootDir = findUpSync ( ( directory ) => {
167
+ const exists = fs . existsSync ( path . join ( directory , "package.json" ) ) ;
168
+ return exists ? directory : undefined ;
169
+ } , cwd ) ;
182
170
183
171
if ( ! rootDir ) {
184
172
throw new NoPkgJsonFound ( cwd ) ;
@@ -190,30 +178,36 @@ export function findRootSync(
190
178
} ;
191
179
}
192
180
193
- async function findUp ( matcher : ( directory : string ) => Promise < string | undefined > , cwd : string ) {
194
- let directory = path . resolve ( cwd ) ;
195
- const { root } = path . parse ( directory ) ;
181
+ async function findUp (
182
+ matcher : ( directory : string ) => Promise < string | undefined > ,
183
+ cwd : string
184
+ ) {
185
+ let directory = path . resolve ( cwd ) ;
186
+ const { root } = path . parse ( directory ) ;
196
187
197
- while ( directory && directory !== root ) {
198
- const filePath = await matcher ( directory ) ;
199
- if ( filePath ) {
200
- return path . resolve ( directory , filePath ) ;
201
- }
188
+ while ( directory && directory !== root ) {
189
+ const filePath = await matcher ( directory ) ;
190
+ if ( filePath ) {
191
+ return path . resolve ( directory , filePath ) ;
192
+ }
202
193
203
- directory = path . dirname ( directory ) ;
204
- }
194
+ directory = path . dirname ( directory ) ;
195
+ }
205
196
}
206
197
207
- function findUpSync ( matcher : ( directory : string ) => string | undefined , cwd : string ) {
208
- let directory = path . resolve ( cwd ) ;
209
- const { root } = path . parse ( directory ) ;
198
+ function findUpSync (
199
+ matcher : ( directory : string ) => string | undefined ,
200
+ cwd : string
201
+ ) {
202
+ let directory = path . resolve ( cwd ) ;
203
+ const { root } = path . parse ( directory ) ;
210
204
211
- while ( directory && directory !== root ) {
212
- const filePath = matcher ( directory ) ;
213
- if ( filePath ) {
214
- return path . resolve ( directory , filePath ) ;
215
- }
205
+ while ( directory && directory !== root ) {
206
+ const filePath = matcher ( directory ) ;
207
+ if ( filePath ) {
208
+ return path . resolve ( directory , filePath ) ;
209
+ }
216
210
217
- directory = path . dirname ( directory ) ;
218
- }
211
+ directory = path . dirname ( directory ) ;
212
+ }
219
213
}
0 commit comments