Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): readRawWorkspaceJson should keep workspace cache up to date #12528

Merged
merged 3 commits into from Oct 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/nx/src/generators/utils/project-configuration.ts
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