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 2 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
15 changes: 7 additions & 8 deletions packages/nx/src/generators/utils/project-configuration.ts
Expand Up @@ -464,7 +464,6 @@ function findDeletedProjects(tree: Tree) {
});
}

let staticFSWorkspace: RawProjectsConfigurations;
function readRawWorkspaceJson(tree: Tree): RawProjectsConfigurations {
const path = getWorkspacePath(tree);
if (path && tree.exists(path)) {
Expand All @@ -478,13 +477,13 @@ function readRawWorkspaceJson(tree: Tree): RawProjectsConfigurations {
(file) => readJson(tree, file)
).projects;
// We already have built a cache
if (!staticFSWorkspace) {
staticFSWorkspace = buildWorkspaceConfigurationFromGlobs(
nxJson,
[...globForProjectFiles(tree.root, nxJson)],
(file) => readJson(tree, file)
);
}
// if (!staticFSWorkspace) {
const staticFSWorkspace = buildWorkspaceConfigurationFromGlobs(
nxJson,
[...globForProjectFiles(tree.root, nxJson)],
(file) => readJson(tree, file)
);
// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't just remove this imho, this function gets called frequently when a generator calls readProjectConfiguration and the glob op is .5 second each call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I revert that bunch of tests fails.

Could this mean that those tests were faulty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem occurs because the workspace gets cached between test runs.
So depending on the order of invocation projects.size has a different value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this discussion was resolved, merging it in

const projects = { ...staticFSWorkspace.projects, ...createdProjects };
findDeletedProjects(tree).forEach((file) => {
const matchingStaticProject = Object.entries(projects).find(
Expand Down