Skip to content

Commit

Permalink
fix(core): readRawWorkspaceJson should keep workspace cache up to date (
Browse files Browse the repository at this point in the history
#12528)

(cherry picked from commit ad79453)
  • Loading branch information
meeroslav authored and FrozenPandaz committed Oct 13, 2022
1 parent bb05d80 commit acd5964
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/nx/src/generators/utils/project-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ function findDeletedProjects(tree: Tree) {
}

let staticFSWorkspace: RawProjectsConfigurations;
let cachedTree: Tree;
function readRawWorkspaceJson(tree: Tree): RawProjectsConfigurations {
const path = getWorkspacePath(tree);
if (path && tree.exists(path)) {
Expand All @@ -477,13 +478,14 @@ function readRawWorkspaceJson(tree: Tree): RawProjectsConfigurations {
findCreatedProjects(tree),
(file) => readJson(tree, file)
).projects;
// We already have built a cache
if (!staticFSWorkspace) {
// We already have built a cache but need to confirm it's the same tree
if (!staticFSWorkspace || tree !== cachedTree) {
staticFSWorkspace = buildWorkspaceConfigurationFromGlobs(
nxJson,
[...globForProjectFiles(tree.root, nxJson)],
(file) => readJson(tree, file)
);
cachedTree = tree;
}
const projects = { ...staticFSWorkspace.projects, ...createdProjects };
findDeletedProjects(tree).forEach((file) => {
Expand All @@ -498,10 +500,11 @@ function readRawWorkspaceJson(tree: Tree): RawProjectsConfigurations {
delete projects[matchingStaticProject[0]];
}
});
return {
staticFSWorkspace = {
...staticFSWorkspace,
projects,
};
return staticFSWorkspace;
}
}

Expand Down

0 comments on commit acd5964

Please sign in to comment.