@@ -14,38 +14,50 @@ import {
14
14
readTargetsFromPackageJson ,
15
15
} from '../../utils/package-json' ;
16
16
import { joinPathFragments } from '../../utils/path' ;
17
- import { workspaceRoot } from '../../utils/workspace-root' ;
18
17
import { CreateNodes } from '../../project-graph/plugins' ;
19
18
20
- const readJson = ( f ) => readJsonFile ( join ( workspaceRoot , f ) ) ;
21
- const patterns = getGlobPatternsFromPackageManagerWorkspaces (
22
- workspaceRoot ,
23
- readJson
24
- ) ;
25
-
26
- const negativePatterns = patterns . filter ( ( p ) => p . startsWith ( '!' ) ) ;
27
- const positivePatterns = patterns . filter ( ( p ) => ! p . startsWith ( '!' ) ) ;
28
- if (
29
- // There are some negative patterns
30
- negativePatterns . length > 0 &&
31
- // No positive patterns
32
- ( positivePatterns . length === 0 ||
33
- // Or only a single positive pattern that is the default coming from root package
34
- ( positivePatterns . length === 1 && positivePatterns [ 0 ] === 'package.json' ) )
35
- ) {
36
- positivePatterns . push ( '**/package.json' ) ;
37
- }
38
19
export const createNodes : CreateNodes = [
39
- combineGlobPatterns ( positivePatterns ) ,
20
+ combineGlobPatterns ( 'package.json' , '**/package.json' ) ,
40
21
( p , _ , { workspaceRoot } ) => {
41
- if ( ! negativePatterns . some ( ( negative ) => minimatch ( p , negative ) ) ) {
22
+ const readJson = ( f ) => readJsonFile ( join ( workspaceRoot , f ) ) ;
23
+ const matcher = buildPackageJsonWorkspacesMatcher ( workspaceRoot , readJson ) ;
24
+
25
+ if ( matcher ( p ) ) {
42
26
return createNodeFromPackageJson ( p , workspaceRoot ) ;
43
27
}
44
- // A negative pattern matched, so we should not create a node for this package.json
28
+ // The given package.json is not part of the workspaces configuration.
45
29
return { } ;
46
30
} ,
47
31
] ;
48
32
33
+ export function buildPackageJsonWorkspacesMatcher (
34
+ workspaceRoot : string ,
35
+ readJson : ( string ) => any
36
+ ) {
37
+ const patterns = getGlobPatternsFromPackageManagerWorkspaces (
38
+ workspaceRoot ,
39
+ readJson
40
+ ) ;
41
+
42
+ const negativePatterns = patterns . filter ( ( p ) => p . startsWith ( '!' ) ) ;
43
+ const positivePatterns = patterns . filter ( ( p ) => ! p . startsWith ( '!' ) ) ;
44
+
45
+ if (
46
+ // There are some negative patterns
47
+ negativePatterns . length > 0 &&
48
+ // No positive patterns
49
+ ( positivePatterns . length === 0 ||
50
+ // Or only a single positive pattern that is the default coming from root package
51
+ ( positivePatterns . length === 1 && positivePatterns [ 0 ] === 'package.json' ) )
52
+ ) {
53
+ positivePatterns . push ( '**/package.json' ) ;
54
+ }
55
+
56
+ return ( p : string ) =>
57
+ positivePatterns . some ( ( positive ) => minimatch ( p , positive ) ) &&
58
+ ! negativePatterns . some ( ( negative ) => minimatch ( p , negative ) ) ;
59
+ }
60
+
49
61
export function createNodeFromPackageJson ( pkgJsonPath : string , root : string ) {
50
62
const json : PackageJson = readJsonFile ( join ( root , pkgJsonPath ) ) ;
51
63
const project = buildProjectConfigurationFromPackageJson (
0 commit comments