Skip to content

Commit

Permalink
fix(core): reset context if the root path does not match what's alrea…
Browse files Browse the repository at this point in the history
…dy in the context class.
  • Loading branch information
Cammisuli committed Sep 7, 2023
1 parent 02dd568 commit 6ae0d3f
Showing 4 changed files with 10 additions and 24 deletions.
2 changes: 1 addition & 1 deletion e2e/utils/command-utils.ts
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ export async function setMaxWorkers() {
if (isCI) {
const root = tmpProjPath();
const projects: Record<string, ProjectConfiguration> = (
await retrieveProjectConfigurations(root, readNxJson(root), true)
await retrieveProjectConfigurations(root, readNxJson(root))
).projectNodes;

Object.keys(projects).forEach((appName) => {
2 changes: 1 addition & 1 deletion e2e/utils/project-config-utils.ts
Original file line number Diff line number Diff line change
@@ -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), true))
return (await retrieveProjectConfigurations(root, readNxJson(root)))
.projectNodes;
}

18 changes: 4 additions & 14 deletions packages/nx/src/project-graph/utils/retrieve-workspace-files.ts
Original file line number Diff line number Diff line change
@@ -100,12 +100,10 @@ export async function retrieveWorkspaceFiles(
*
* @param workspaceRoot
* @param nxJson
* @param resetWorkspaceContext - If true, the workspace context will be reset before retrieving the project configurations. This should only be set during e2e's if creating multiple workspaces from the same node process
*/
export async function retrieveProjectConfigurations(
workspaceRoot: string,
nxJson: NxJsonConfiguration,
resetWorkspaceContext = false
nxJson: NxJsonConfiguration
): Promise<{
externalNodes: Record<string, ProjectGraphExternalNode>;
projectNodes: Record<string, ProjectConfiguration>;
@@ -117,13 +115,7 @@ export async function retrieveProjectConfigurations(
);

const globs = configurationGlobs(workspaceRoot, plugins);
return _retrieveProjectConfigurations(
workspaceRoot,
nxJson,
plugins,
globs,
resetWorkspaceContext
);
return _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins, globs);
}

export async function retrieveProjectConfigurationsWithAngularProjects(
@@ -174,8 +166,7 @@ function _retrieveProjectConfigurations(
workspaceRoot: string,
nxJson: NxJsonConfiguration,
plugins: NxPluginV2[],
globs: string[],
resetWorkspaceContext = false
globs: string[]
): {
externalNodes: Record<string, ProjectGraphExternalNode>;
projectNodes: Record<string, ProjectConfiguration>;
@@ -195,8 +186,7 @@ function _retrieveProjectConfigurations(
projectNodes: projectConfigurations.projects,
externalNodes: projectConfigurations.externalNodes,
};
},
resetWorkspaceContext
}
) as {
externalNodes: Record<string, ProjectGraphExternalNode>;
projectNodes: Record<string, ProjectConfiguration>;
12 changes: 4 additions & 8 deletions packages/nx/src/utils/workspace-context.ts
Original file line number Diff line number Diff line change
@@ -36,18 +36,14 @@ export function getProjectConfigurationFilesFromContext(
export function getProjectConfigurationsFromContext(
workspaceRoot: string,
globs: string[],
parseConfigurations: (files: string[]) => ConfigurationParserResult,
resetWorkspaceContext: boolean = false
parseConfigurations: (files: string[]) => ConfigurationParserResult
) {
ensureContextAvailable(workspaceRoot, resetWorkspaceContext);
ensureContextAvailable(workspaceRoot);
return workspaceContext.getProjectConfigurations(globs, parseConfigurations);
}

function ensureContextAvailable(
workspaceRoot: string,
resetWorkspaceContext = false
) {
if (!workspaceContext || resetWorkspaceContext) {
function ensureContextAvailable(workspaceRoot: string) {
if (!workspaceContext && workspaceContext?.workspaceRoot !== workspaceRoot) {
setupWorkspaceContext(workspaceRoot);
}
}

0 comments on commit 6ae0d3f

Please sign in to comment.