-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
npm-packages.ts
50 lines (45 loc) · 1.41 KB
/
npm-packages.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { isWholeFileChange, WholeFileChange } from '../../file-utils';
import {
DiffType,
isJsonChange,
JsonChange,
} from '../../../utilities/json-diff';
import { TouchedProjectLocator } from '../affected-project-graph-models';
import { isNpmProject } from '../../project-graph/operators';
export const getTouchedNpmPackages: TouchedProjectLocator<
WholeFileChange | JsonChange
> = (
touchedFiles,
workspaceJson,
nxJson,
packageJson,
projectGraph
): string[] => {
const packageJsonChange = touchedFiles.find((f) => f.file === 'package.json');
if (!packageJsonChange) return [];
let touched = [];
const changes = packageJsonChange.getChanges();
const npmPackages = Object.values(projectGraph.nodes).filter(isNpmProject);
for (const c of changes) {
if (
isJsonChange(c) &&
(c.path[0] === 'dependencies' || c.path[0] === 'devDependencies') &&
c.path.length === 2
) {
// A package was deleted so mark all workspace projects as touched.
if (c.type === DiffType.Deleted) {
touched = Object.keys(workspaceJson.projects);
break;
} else {
touched.push(
npmPackages.find((pkg) => pkg.data.packageName === c.path[1]).name
);
}
} else if (isWholeFileChange(c)) {
// Whole file was touched, so all npm packages are touched.
touched = npmPackages.map((pkg) => pkg.name);
break;
}
}
return touched;
};