diff --git a/e2e/utils/project-config-utils.ts b/e2e/utils/project-config-utils.ts index 37990e11c27f3e..d0738ce6b6a9e9 100644 --- a/e2e/utils/project-config-utils.ts +++ b/e2e/utils/project-config-utils.ts @@ -21,7 +21,7 @@ export async function readResolvedConfiguration(): Promise< > { process.env.NX_PROJECT_GLOB_CACHE = 'false'; const root = tmpProjPath(); - return (await retrieveProjectConfigurations(root, readNxJson(root))) + return (await retrieveProjectConfigurations(root, readNxJson(root), true)) .projectNodes; } diff --git a/packages/nx/src/project-graph/utils/retrieve-workspace-files.ts b/packages/nx/src/project-graph/utils/retrieve-workspace-files.ts index 4c736b3865ad16..6413b58825ca52 100644 --- a/packages/nx/src/project-graph/utils/retrieve-workspace-files.ts +++ b/packages/nx/src/project-graph/utils/retrieve-workspace-files.ts @@ -100,10 +100,12 @@ export async function retrieveWorkspaceFiles( * * @param workspaceRoot * @param nxJson + * @param resetWorkspaceContext manually reset the workspace context so that files are updated (this should only be used for testing) */ export async function retrieveProjectConfigurations( workspaceRoot: string, - nxJson: NxJsonConfiguration + nxJson: NxJsonConfiguration, + resetWorkspaceContext = false ): Promise<{ externalNodes: Record; projectNodes: Record; @@ -115,7 +117,13 @@ export async function retrieveProjectConfigurations( ); const globs = configurationGlobs(workspaceRoot, plugins); - return _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins, globs); + return _retrieveProjectConfigurations( + workspaceRoot, + nxJson, + plugins, + globs, + resetWorkspaceContext + ); } export async function retrieveProjectConfigurationsWithAngularProjects( @@ -166,7 +174,8 @@ function _retrieveProjectConfigurations( workspaceRoot: string, nxJson: NxJsonConfiguration, plugins: NxPluginV2[], - globs: string[] + globs: string[], + resetWorkspaceContext = false ): { externalNodes: Record; projectNodes: Record; @@ -186,7 +195,8 @@ function _retrieveProjectConfigurations( projectNodes: projectConfigurations.projects, externalNodes: projectConfigurations.externalNodes, }; - } + }, + resetWorkspaceContext ) as { externalNodes: Record; projectNodes: Record; diff --git a/packages/nx/src/utils/workspace-context.ts b/packages/nx/src/utils/workspace-context.ts index e3bc726a034ec3..e95b149409ea1b 100644 --- a/packages/nx/src/utils/workspace-context.ts +++ b/packages/nx/src/utils/workspace-context.ts @@ -36,14 +36,21 @@ export function getProjectConfigurationFilesFromContext( export function getProjectConfigurationsFromContext( workspaceRoot: string, globs: string[], - parseConfigurations: (files: string[]) => ConfigurationParserResult + parseConfigurations: (files: string[]) => ConfigurationParserResult, + resetWorkspaceContext = false ) { - ensureContextAvailable(workspaceRoot); + ensureContextAvailable(workspaceRoot, resetWorkspaceContext); return workspaceContext.getProjectConfigurations(globs, parseConfigurations); } -function ensureContextAvailable(workspaceRoot: string) { - if (!workspaceContext && workspaceContext?.workspaceRoot !== workspaceRoot) { +function ensureContextAvailable( + workspaceRoot: string, + resetWorkspaceContext = false +) { + if ( + resetWorkspaceContext || + (!workspaceContext && workspaceContext?.workspaceRoot !== workspaceRoot) + ) { setupWorkspaceContext(workspaceRoot); } }