File tree Expand file tree Collapse file tree 2 files changed +39
-4
lines changed
plugin-coverage/src/lib/nx Expand file tree Collapse file tree 2 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,24 @@ import path from 'node:path';
1111import { importModule , ui } from '@code-pushup/utils' ;
1212import type { CoverageResult } from '../config.js' ;
1313
14+ /**
15+ * Resolves the cached project graph for the current Nx workspace.
16+ * First tries to read cache and if not possible, go for the async creation.
17+ */
18+ export async function resolveCachedProjectGraph ( ) {
19+ const { readCachedProjectGraph, createProjectGraphAsync } = await import (
20+ '@nx/devkit'
21+ ) ;
22+ try {
23+ return readCachedProjectGraph ( ) ;
24+ } catch ( e ) {
25+ ui ( ) . logger . warn (
26+ 'Could not read cached project graph, falling back to async creation.' ,
27+ ) ;
28+ return await createProjectGraphAsync ( { exitOnError : false } ) ;
29+ }
30+ }
31+
1432/**
1533 * @param targets nx targets to be used for measuring coverage, test by default
1634 * @returns An array of coverage result information for the coverage plugin.
@@ -25,8 +43,7 @@ export async function getNxCoveragePaths(
2543 ) ;
2644 }
2745
28- const { readCachedProjectGraph } = await import ( '@nx/devkit' ) ;
29- const { nodes } = readCachedProjectGraph ( ) ;
46+ const { nodes } = await resolveCachedProjectGraph ( ) ;
3047
3148 const coverageResults = await Promise . all (
3249 targets . map ( async target => {
Original file line number Diff line number Diff line change 1+ import { ui } from '@code-pushup/utils' ;
12import type { ESLintTarget } from '../config.js' ;
23import { filterProjectGraph } from './filter-project-graph.js' ;
34import { nxProjectsToConfig } from './projects-to-config.js' ;
45
6+ /**
7+ * Resolves the cached project graph for the current Nx workspace.
8+ * First tries to read cache and if not possible, go for the async creation.
9+ */
10+ export async function resolveCachedProjectGraph ( ) {
11+ const { readCachedProjectGraph, createProjectGraphAsync } = await import (
12+ '@nx/devkit'
13+ ) ;
14+ try {
15+ return readCachedProjectGraph ( ) ;
16+ } catch ( e ) {
17+ ui ( ) . logger . warn (
18+ 'Could not read cached project graph, falling back to async creation.' ,
19+ ) ;
20+ return await createProjectGraphAsync ( { exitOnError : false } ) ;
21+ }
22+ }
23+
524/**
625 * Finds all Nx projects in workspace and converts their lint configurations to Code PushUp ESLint plugin parameters.
726 *
@@ -31,8 +50,7 @@ import { nxProjectsToConfig } from './projects-to-config.js';
3150export async function eslintConfigFromAllNxProjects (
3251 options : { exclude ?: string [ ] } = { } ,
3352) : Promise < ESLintTarget [ ] > {
34- const { readCachedProjectGraph } = await import ( '@nx/devkit' ) ;
35- const projectGraph = readCachedProjectGraph ( ) ;
53+ const projectGraph = await resolveCachedProjectGraph ( ) ;
3654 const filteredProjectGraph = filterProjectGraph (
3755 projectGraph ,
3856 options . exclude ,
You can’t perform that action at this time.
0 commit comments