1
1
import { compact } from '../../util/array.js' ;
2
+ import { getPackageNameFromModuleSpecifier } from '../../util/modules.js' ;
2
3
import { timerify } from '../../util/Performance.js' ;
3
4
import { getDependenciesFromScripts , hasDependency , load } from '../../util/plugin.js' ;
4
- import type { NxProjectConfiguration } from './types.js' ;
5
+ import type { NxConfigRoot , NxProjectConfiguration } from './types.js' ;
5
6
import type { IsPluginEnabledCallback , GenericPluginCallback } from '../../types/plugins.js' ;
6
7
7
8
const NAME = 'Nx' ;
@@ -10,13 +11,44 @@ const ENABLERS = ['nx', /^@nrwl\//, /^@nx\//];
10
11
11
12
const isEnabled : IsPluginEnabledCallback = ( { dependencies } ) => hasDependency ( dependencies , ENABLERS ) ;
12
13
13
- const CONFIG_FILE_PATTERNS = [ 'project.json' , '{apps,libs}/**/project.json' ] ;
14
+ const CONFIG_FILE_PATTERNS = [ 'nx.json' , 'project.json' , '{apps,libs}/**/project.json' ] ;
15
+
16
+ const findNxDependenciesInNxJson : GenericPluginCallback = async configFilePath => {
17
+ const localConfig : NxConfigRoot | undefined = await load ( configFilePath ) ;
18
+
19
+ if ( ! localConfig ) return [ ] ;
20
+
21
+ const targetsDefault = localConfig . targetDefaults
22
+ ? Object . keys ( localConfig . targetDefaults )
23
+ // Ensure we only grab executors from plugins instead of manual targets
24
+ // Limiting to scoped packages to ensure we don't have false positives
25
+ . filter ( it => it . includes ( ':' ) && it . startsWith ( '@' ) )
26
+ . map ( it => it . split ( ':' ) [ 0 ] )
27
+ : [ ] ;
28
+
29
+ const plugins =
30
+ localConfig . plugins && Array . isArray ( localConfig . plugins )
31
+ ? localConfig . plugins . map ( it => getPackageNameFromModuleSpecifier ( it . plugin ) ) . filter ( value => value !== undefined )
32
+ : [ ] ;
33
+
34
+ const generators = localConfig . generators
35
+ ? Object . keys ( localConfig . generators )
36
+ . map ( it => getPackageNameFromModuleSpecifier ( it ) )
37
+ . filter ( value => value !== undefined )
38
+ : [ ] ;
39
+
40
+ return compact ( [ ...targetsDefault , ...plugins , ...generators ] ) ;
41
+ } ;
14
42
15
43
const findNxDependencies : GenericPluginCallback = async ( configFilePath , options ) => {
16
44
const { isProduction } = options ;
17
45
18
46
if ( isProduction ) return [ ] ;
19
47
48
+ if ( configFilePath . endsWith ( 'nx.json' ) ) {
49
+ return findNxDependenciesInNxJson ( configFilePath , options ) ;
50
+ }
51
+
20
52
const localConfig : NxProjectConfiguration | undefined = await load ( configFilePath ) ;
21
53
22
54
if ( ! localConfig ) return [ ] ;
0 commit comments