forked from nrwl/nx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
project-glob-changes.ts
34 lines (30 loc) · 1.4 KB
/
project-glob-changes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { TouchedProjectLocator } from '../affected-project-graph-models';
import { minimatch } from 'minimatch';
import { workspaceRoot } from '../../../utils/workspace-root';
import { join } from 'path';
import { existsSync } from 'fs';
import { configurationGlobs } from '../../utils/retrieve-workspace-files';
import { loadNxPlugins } from '../../plugins/internal-api';
import { combineGlobPatterns } from '../../../utils/globs';
export const getTouchedProjectsFromProjectGlobChanges: TouchedProjectLocator =
async (touchedFiles, projectGraphNodes, nxJson): Promise<string[]> => {
const globPattern = combineGlobPatterns(
configurationGlobs(await loadNxPlugins(nxJson?.plugins, workspaceRoot))
);
const touchedProjects = new Set<string>();
for (const touchedFile of touchedFiles) {
const isProjectFile = minimatch(touchedFile.file, globPattern, {
dot: true,
});
if (isProjectFile) {
// If the file no longer exists on disk, then it was deleted
if (!existsSync(join(workspaceRoot, touchedFile.file))) {
// 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.
}
}
return Array.from(touchedProjects);
};