File tree Expand file tree Collapse file tree 2 files changed +26
-9
lines changed Expand file tree Collapse file tree 2 files changed +26
-9
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,10 @@ export function sortPaths(paths: string[]): string[] {
147
147
}
148
148
149
149
export function readYamlFile < T > ( filePath : string ) : T | null {
150
+ if ( ! fs . existsSync ( filePath ) ) {
151
+ return null ;
152
+ }
153
+
150
154
let doc : T | null ;
151
155
try {
152
156
doc = yaml . load ( fs . readFileSync ( filePath , "utf8" ) ) as T ;
@@ -175,24 +179,22 @@ export function normalizePackageGlobOptions(
175
179
: PNPM_WORKSPACE_FILENAME ,
176
180
) ;
177
181
178
- if ( fs . existsSync ( pnpmWorkspacePath ) ) {
179
- const pnpmWorkspace =
180
- readYamlFile < Record < "packages" , string [ ] > > ( pnpmWorkspacePath ) ;
182
+ const pnpmWorkspaceRes =
183
+ readYamlFile < Record < "packages" , string [ ] > > ( pnpmWorkspacePath ) ;
181
184
182
- if ( pnpmWorkspace ?. packages ?. length ) {
183
- packagePatterns = pnpmWorkspace . packages ;
184
- }
185
+ if ( pnpmWorkspaceRes ?. packages ?. length ) {
186
+ packagePatterns = pnpmWorkspaceRes . packages ;
185
187
}
186
188
}
187
189
188
- if ( patterns ) {
190
+ if ( patterns ?. length ) {
189
191
packagePatterns = packagePatterns
190
- ? [ ...packagePatterns , ...patterns ]
192
+ ? unique ( [ ...packagePatterns , ...patterns ] )
191
193
: patterns ;
192
194
}
193
195
194
196
return {
195
- patterns : packagePatterns ? unique ( packagePatterns ) : undefined ,
197
+ patterns : packagePatterns ?. length ? packagePatterns : undefined ,
196
198
...restOptions ,
197
199
} ;
198
200
}
Original file line number Diff line number Diff line change @@ -18,6 +18,21 @@ describe("Test monorepo", () => {
18
18
} ) ;
19
19
} ) ;
20
20
21
+ it ( "pnpm monorepo" , ( ) => {
22
+ expect (
23
+ resolve ( "@lib/foo" , getMonoRepoPath ( "main/index.js" ) , {
24
+ roots,
25
+ alias : { "@lib" : "./lib" } ,
26
+ packages : {
27
+ pnpmWorkspace : true ,
28
+ } ,
29
+ } ) ,
30
+ ) . deep . equal ( {
31
+ found : true ,
32
+ path : getMonoRepoPath ( "main/lib/foo.js" ) ,
33
+ } ) ;
34
+ } ) ;
35
+
21
36
it ( "tsconfig" , ( ) => {
22
37
expect (
23
38
resolve ( "@/a" , getMonoRepoPath ( "packages/ts/index.ts" ) , {
You can’t perform that action at this time.
0 commit comments