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): improve touched projects locator performance #16682

Merged
merged 1 commit into from
May 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import {
DeletedFileChange,
isDeletedFileChange,
WholeFileChange,
} from '../../file-utils';
import { JsonChange } from '../../../utils/json-diff';
import { TouchedProjectLocator } from '../affected-project-graph-models';
import minimatch = require('minimatch');
import {
Expand All @@ -12,40 +6,42 @@ import {
} from '../../../config/workspaces';
import { workspaceRoot } from '../../../utils/workspace-root';
import { getNxRequirePaths } from '../../../utils/installation-directory';
import { join } from 'path';
import { existsSync } from 'fs';

export const getTouchedProjectsFromProjectGlobChanges: TouchedProjectLocator<
WholeFileChange | JsonChange | DeletedFileChange
> = async (touchedFiles, projectGraphNodes, nxJson): Promise<string[]> => {
const pluginGlobPatterns = await getGlobPatternsFromPluginsAsync(
nxJson,
getNxRequirePaths(),
workspaceRoot
);
const workspacesGlobPatterns =
getGlobPatternsFromPackageManagerWorkspaces(workspaceRoot) || [];
export const getTouchedProjectsFromProjectGlobChanges: TouchedProjectLocator =
async (touchedFiles, projectGraphNodes, nxJson): Promise<string[]> => {
const pluginGlobPatterns = await getGlobPatternsFromPluginsAsync(
nxJson,
getNxRequirePaths(),
workspaceRoot
);
const workspacesGlobPatterns =
getGlobPatternsFromPackageManagerWorkspaces(workspaceRoot) || [];

const patterns = [
'**/project.json',
...pluginGlobPatterns,
...workspacesGlobPatterns,
];
const combinedGlobPattern =
patterns.length === 1 ? '**/project.json' : '{' + patterns.join(',') + '}';
const touchedProjects = new Set<string>();
for (const touchedFile of touchedFiles) {
const isProjectFile = minimatch(touchedFile.file, combinedGlobPattern);
if (isProjectFile) {
if (
touchedFile.getChanges().some((change) => isDeletedFileChange(change))
) {
// If any project has been deleted, we must assume all projects were affected
return Object.keys(projectGraphNodes);
}
const patterns = [
'**/project.json',
...pluginGlobPatterns,
...workspacesGlobPatterns,
];
const combinedGlobPattern =
patterns.length === 1
? '**/project.json'
: '{' + patterns.join(',') + '}';
const touchedProjects = new Set<string>();
for (const touchedFile of touchedFiles) {
const isProjectFile = minimatch(touchedFile.file, combinedGlobPattern);
if (isProjectFile) {
// If the file no longer exists on disk, then it was deleted
if (!existsSync(join(workspaceRoot, touchedFile.file))) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the new line

// If any project has been deleted, we must assume all projects were affected
return Object.keys(projectGraphNodes);
}

// Modified project config files are under a project's root, and implicitly
// mark it as affected. Thus, we don't need to handle it here.
// Modified project config files are under a project's root, and implicitly
// mark it as affected. Thus, we don't need to handle it here.
}
}
}

return Array.from(touchedProjects);
};
return Array.from(touchedProjects);
};