-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathfind-all-projects.ts
More file actions
65 lines (62 loc) · 2.29 KB
/
find-all-projects.ts
File metadata and controls
65 lines (62 loc) · 2.29 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
55
56
57
58
59
60
61
62
63
64
65
import { logger, stringifyError } from '@code-pushup/utils';
import type { ESLintTarget } from '../config.js';
import { filterProjectGraph } from './filter-project-graph.js';
import { nxProjectsToConfig } from './projects-to-config.js';
/**
* Resolves the cached project graph for the current Nx workspace.
* First tries to read cache and if not possible, go for the async creation.
*/
async function resolveCachedProjectGraph() {
const { readCachedProjectGraph, createProjectGraphAsync } = await import(
'@nx/devkit'
);
try {
return readCachedProjectGraph();
} catch (error) {
logger.info(
`Could not read cached project graph, falling back to async creation.\n${stringifyError(error)}`,
);
return await createProjectGraphAsync({ exitOnError: false });
}
}
/**
* Finds all Nx projects in workspace and converts their lint configurations to Code PushUp ESLint plugin parameters.
*
* Allows excluding certain projects from the configuration using the `options.exclude` parameter.
*
* Use when you wish to automatically include every Nx project in a single Code PushUp project.
* If you prefer to include only a subset of your Nx monorepo, specify projects to exclude using the `exclude` option
* or consider using {@link eslintConfigFromNxProjectAndDeps} for finer control.
*
* @example
* import eslintPlugin, {
* eslintConfigFromAllNxProjects,
* } from '@code-pushup/eslint-plugin';
*
* export default {
* plugins: [
* await eslintPlugin(
* await eslintConfigFromAllNxProjects({ exclude: ['server'] })
* )
* ]
* }
*
* @param options - Configuration options to filter projects
* @param options.exclude - Array of project names to exclude from the ESLint configuration
* @returns ESLint config and patterns, intended to be passed to {@link eslintPlugin}
*/
export async function eslintConfigFromAllNxProjects(
options: { exclude?: string[] } = {},
): Promise<ESLintTarget[]> {
const projectGraph = await resolveCachedProjectGraph();
const filteredProjectGraph = filterProjectGraph(
projectGraph,
options.exclude,
);
return nxProjectsToConfig(filteredProjectGraph);
}
/**
* @deprecated
* Helper is renamed, please use `eslintConfigFromAllNxProjects` function instead.
*/
export const eslintConfigFromNxProjects = eslintConfigFromAllNxProjects;