-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathfind-project-with-deps.ts
More file actions
54 lines (49 loc) · 1.88 KB
/
find-project-with-deps.ts
File metadata and controls
54 lines (49 loc) · 1.88 KB
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
51
52
53
54
import { logger, pluralizeToken } from '@code-pushup/utils';
import type { ESLintTarget } from '../config.js';
import { formatMetaLog } from '../meta/format.js';
import { nxProjectsToConfig } from './projects-to-config.js';
import { findAllDependencies } from './traverse-graph.js';
/**
* Accepts a target Nx projects, finds projects it depends on, and converts lint configurations to Code PushUp ESLint plugin parameters.
*
* Use when you wish to include a targeted subset of your Nx monorepo in your Code PushUp project.
* If you prefer to include all Nx projects, refer to {@link eslintConfigFromAllNxProjects} instead.
* if you'd like to skip dependencies of the provided target project use {@link eslintConfigFromNxProject} instead.
*
* @example
* import eslintPlugin, {
* eslintConfigFromNxProjectAndDeps,
* } from '@code-pushup/eslint-plugin';
*
* const projectName = 'backoffice'; // <-- name from project.json
*
* export default {
* plugins: [
* await eslintPlugin(
* await eslintConfigFromNxProjectAndDeps(projectName)
* )
* ]
* }
*
* @param projectName Nx project serving as main entry point
* @returns ESLint config and patterns, intended to be passed to {@link eslintPlugin}
*/
export async function eslintConfigFromNxProjectAndDeps(
projectName: string,
): Promise<ESLintTarget[]> {
const { createProjectGraphAsync } = await import('@nx/devkit');
const projectGraph = await createProjectGraphAsync({ exitOnError: false });
const dependencies = findAllDependencies(projectName, projectGraph);
const targets = await nxProjectsToConfig(
projectGraph,
project =>
!!project.name &&
(project.name === projectName || dependencies.has(project.name)),
);
logger.info(
formatMetaLog(
`Inferred ${pluralizeToken('lint target', targets.length)} for Nx project "${projectName}" and its dependencies`,
),
);
return targets;
}