-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathfind-project-without-deps.ts
More file actions
50 lines (45 loc) · 1.59 KB
/
find-project-without-deps.ts
File metadata and controls
50 lines (45 loc) · 1.59 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
import { loadNxProjectGraph, logger } from '@code-pushup/utils';
import type { ESLintTarget } from '../config.js';
import { formatMetaLog } from '../meta/format.js';
import { nxProjectsToConfig } from './projects-to-config.js';
/**
* Accepts a target Nx project, converts its lint configuration to Code PushUp ESLint plugin parameters.
*
* Use when you wish to only have a single Nx project as your Code PushUp project, without any other dependencies.
* If you prefer to include all Nx projects, refer to {@link eslintConfigFromAllNxProjects} instead.
* If you'd like to auto include all dependencies of the provided target project use {@link eslintConfigFromNxProjectAndDeps} instead.
*
* @example
* import eslintPlugin, {
* eslintConfigFromNxProject,
* } from '@code-pushup/eslint-plugin';
*
* const projectName = 'backoffice'; // <-- name from project.json
*
* export default {
* plugins: [
* await eslintPlugin(
* await eslintConfigFromNxProject(projectName)
* )
* ]
* }
*
* @param projectName Nx project name
* @returns ESLint config and patterns, intended to be passed to {@link eslintPlugin}
*/
export async function eslintConfigFromNxProject(
projectName: string,
): Promise<ESLintTarget> {
const projectGraph = await loadNxProjectGraph();
const [project] = await nxProjectsToConfig(
projectGraph,
({ name }) => !!name && name === projectName,
);
if (!project) {
throw new Error(`Couldn't find Nx project named "${projectName}"`);
}
logger.info(
formatMetaLog(`Inferred lint target for Nx project "${projectName}"`),
);
return project;
}