1+ import type { NxJsonConfiguration } from '../../config/nx-json' ;
12import { readNxJson } from '../../config/nx-json' ;
23import type { ProjectGraph } from '../../config/project-graph' ;
3- import type { ProjectConfiguration } from '../../config/workspace-json-project-json' ;
4+ import type { ProjectsConfigurations } from '../../config/workspace-json-project-json' ;
45import { FsTree , type Tree } from '../../generators/tree' ;
56import { hashArray } from '../../hasher/file-hasher' ;
67import { readProjectsConfigurationFromProjectGraph } from '../../project-graph/project-graph' ;
78import {
89 collectEnabledTaskSyncGeneratorsFromProjectGraph ,
910 collectRegisteredGlobalSyncGenerators ,
1011 flushSyncGeneratorChanges ,
11- runSyncGenerator ,
1212 type FlushSyncGeneratorChangesResult ,
13+ runSyncGenerator ,
1314 type SyncGeneratorRunResult ,
1415 type SyncGeneratorRunSuccessResult ,
1516} from '../../utils/sync-generators' ;
@@ -136,13 +137,14 @@ export function collectAndScheduleSyncGenerators(
136137 return ;
137138 }
138139
139- const { projects } =
140+ const projectsConfigurations =
140141 readProjectsConfigurationFromProjectGraph ( projectGraph ) ;
142+ const nxJsonConfiguration = readNxJson ( ) ;
141143
142144 for ( const generator of scheduledGenerators ) {
143145 syncGeneratorsCacheResultPromises . set (
144146 generator ,
145- runGenerator ( generator , projects )
147+ runGenerator ( generator , projectsConfigurations , nxJsonConfiguration )
146148 ) ;
147149 }
148150
@@ -172,21 +174,26 @@ export async function getCachedRegisteredSyncGenerators(): Promise<{
172174async function getFromCacheOrRunGenerators (
173175 generators : string [ ]
174176) : Promise < SyncGeneratorRunResult [ ] > {
175- let projects : Record < string , ProjectConfiguration > | null ;
177+ let projectsConfigurations : ProjectsConfigurations | null ;
178+ let nxJsonConfiguration : NxJsonConfiguration | null ;
176179 let errored = false ;
177- const getProjectsConfigurations = async ( ) => {
178- if ( projects || errored ) {
179- return projects ;
180+
181+ const getConfigurations = async ( ) => {
182+ if ( projectsConfigurations || errored ) {
183+ return { projectsConfigurations, nxJsonConfiguration } ;
180184 }
181185
182186 const { projectGraph, error } =
183187 await getCachedSerializedProjectGraphPromise ( ) ;
184- projects = projectGraph
185- ? readProjectsConfigurationFromProjectGraph ( projectGraph ) . projects
188+ projectsConfigurations = projectGraph
189+ ? readProjectsConfigurationFromProjectGraph ( projectGraph )
186190 : null ;
191+
192+ nxJsonConfiguration = readNxJson ( ) ;
193+
187194 errored = error !== undefined ;
188195
189- return projects ;
196+ return { projectsConfigurations , nxJsonConfiguration } ;
190197 } ;
191198
192199 return (
@@ -198,12 +205,17 @@ async function getFromCacheOrRunGenerators(
198205 ) {
199206 // it's scheduled to run (there are pending changes to process) or
200207 // it's not scheduled and there's no cached result, so run it
201- const projects = await getProjectsConfigurations ( ) ;
202- if ( projects ) {
208+ const { projectsConfigurations, nxJsonConfiguration } =
209+ await getConfigurations ( ) ;
210+ if ( projectsConfigurations ) {
203211 log ( generator , 'already scheduled or not cached, running it now' ) ;
204212 syncGeneratorsCacheResultPromises . set (
205213 generator ,
206- runGenerator ( generator , projects )
214+ runGenerator (
215+ generator ,
216+ projectsConfigurations ,
217+ nxJsonConfiguration
218+ )
207219 ) ;
208220 } else {
209221 log (
@@ -242,11 +254,12 @@ async function runConflictingGenerators(
242254 generators : string [ ]
243255) : Promise < SyncGeneratorRunResult [ ] > {
244256 const { projectGraph } = await getCachedSerializedProjectGraphPromise ( ) ;
245- const projects = projectGraph
246- ? readProjectsConfigurationFromProjectGraph ( projectGraph ) . projects
257+ const projectsConfigurations = projectGraph
258+ ? readProjectsConfigurationFromProjectGraph ( projectGraph )
247259 : null ;
260+ const nxJsonConfiguration = readNxJson ( ) ;
248261
249- if ( ! projects ) {
262+ if ( ! projectsConfigurations ) {
250263 /**
251264 * This should never happen. This is invoked imperatively, and by
252265 * the time it is invoked, the project graph would have already
@@ -266,7 +279,14 @@ async function runConflictingGenerators(
266279 const results : SyncGeneratorRunResult [ ] = [ ] ;
267280 for ( const generator of generators ) {
268281 log ( generator , 'running it now' ) ;
269- results . push ( await runGenerator ( generator , projects , tree ) ) ;
282+ results . push (
283+ await runGenerator (
284+ generator ,
285+ projectsConfigurations ,
286+ nxJsonConfiguration ,
287+ tree
288+ )
289+ ) ;
270290 }
271291
272292 return results ;
@@ -449,7 +469,8 @@ function collectAllRegisteredSyncGenerators(projectGraph: ProjectGraph): void {
449469
450470function runGenerator (
451471 generator : string ,
452- projects : Record < string , ProjectConfiguration > ,
472+ projectsConfigurations : ProjectsConfigurations ,
473+ nxJsonConfiguration : NxJsonConfiguration ,
453474 tree ?: Tree
454475) : Promise < SyncGeneratorRunResult > {
455476 log ( 'running scheduled generator' , generator ) ;
@@ -461,7 +482,12 @@ function runGenerator(
461482 `running sync generator ${ generator } `
462483 ) ;
463484
464- return runSyncGenerator ( tree , generator , projects ) . then ( ( result ) => {
485+ return runSyncGenerator (
486+ tree ,
487+ generator ,
488+ projectsConfigurations ,
489+ nxJsonConfiguration
490+ ) . then ( ( result ) => {
465491 if ( 'error' in result ) {
466492 log ( generator , 'error:' , result . error . message ) ;
467493 } else {
0 commit comments