File tree Expand file tree Collapse file tree
plugin-coverage/src/lib/nx
plugin-typescript/src/lib/nx Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,29 +12,11 @@ import {
1212 logger ,
1313 pluralize ,
1414 pluralizeToken ,
15- stringifyError ,
15+ resolveCachedProjectGraph ,
1616} from '@code-pushup/utils' ;
1717import type { CoverageResult } from '../config.js' ;
1818import { formatMetaLog } from '../format.js' ;
1919
20- /**
21- * Resolves the cached project graph for the current Nx workspace.
22- * First tries to read cache and if not possible, go for the async creation.
23- */
24- async function resolveCachedProjectGraph ( ) {
25- const { readCachedProjectGraph, createProjectGraphAsync } = await import (
26- '@nx/devkit'
27- ) ;
28- try {
29- return readCachedProjectGraph ( ) ;
30- } catch ( error ) {
31- logger . warn (
32- `Could not read cached project graph, falling back to async creation - ${ stringifyError ( error ) } ` ,
33- ) ;
34- return await createProjectGraphAsync ( { exitOnError : false } ) ;
35- }
36- }
37-
3820/**
3921 * @param targets nx targets to be used for measuring coverage, test by default
4022 * @returns An array of coverage result information for the coverage plugin.
Original file line number Diff line number Diff line change 1- import { logger , pluralizeToken , stringifyError } from '@code-pushup/utils' ;
1+ import {
2+ logger ,
3+ pluralizeToken ,
4+ resolveCachedProjectGraph ,
5+ } from '@code-pushup/utils' ;
26import type { ESLintTarget } from '../config.js' ;
37import { formatMetaLog } from '../meta/format.js' ;
48import { filterProjectGraph } from './filter-project-graph.js' ;
59import { nxProjectsToConfig } from './projects-to-config.js' ;
610
7- /**
8- * Resolves the cached project graph for the current Nx workspace.
9- * First tries to read cache and if not possible, go for the async creation.
10- */
11- async function resolveCachedProjectGraph ( ) {
12- const { readCachedProjectGraph, createProjectGraphAsync } = await import (
13- '@nx/devkit'
14- ) ;
15- try {
16- return readCachedProjectGraph ( ) ;
17- } catch ( error ) {
18- logger . warn (
19- `Could not read cached project graph, falling back to async creation.\n${ stringifyError ( error ) } ` ,
20- ) ;
21- return await createProjectGraphAsync ( { exitOnError : false } ) ;
22- }
23- }
24-
2511/**
2612 * Finds all Nx projects in workspace and converts their lint configurations to Code PushUp ESLint plugin parameters.
2713 *
Original file line number Diff line number Diff line change 1- import { logger , pluralizeToken } from '@code-pushup/utils' ;
1+ import { createProjectGraph , logger , pluralizeToken } from '@code-pushup/utils' ;
22import type { ESLintTarget } from '../config.js' ;
33import { formatMetaLog } from '../meta/format.js' ;
44import { nxProjectsToConfig } from './projects-to-config.js' ;
@@ -32,8 +32,7 @@ import { findAllDependencies } from './traverse-graph.js';
3232export async function eslintConfigFromNxProjectAndDeps (
3333 projectName : string ,
3434) : Promise < ESLintTarget [ ] > {
35- const { createProjectGraphAsync } = await import ( '@nx/devkit' ) ;
36- const projectGraph = await createProjectGraphAsync ( { exitOnError : false } ) ;
35+ const projectGraph = await createProjectGraph ( ) ;
3736
3837 const dependencies = findAllDependencies ( projectName , projectGraph ) ;
3938
Original file line number Diff line number Diff line change 1- import { logger } from '@code-pushup/utils' ;
1+ import { createProjectGraph , logger } from '@code-pushup/utils' ;
22import type { ESLintTarget } from '../config.js' ;
33import { formatMetaLog } from '../meta/format.js' ;
44import { nxProjectsToConfig } from './projects-to-config.js' ;
@@ -31,8 +31,7 @@ import { nxProjectsToConfig } from './projects-to-config.js';
3131export async function eslintConfigFromNxProject (
3232 projectName : string ,
3333) : Promise < ESLintTarget > {
34- const { createProjectGraphAsync } = await import ( '@nx/devkit' ) ;
35- const projectGraph = await createProjectGraphAsync ( { exitOnError : false } ) ;
34+ const projectGraph = await createProjectGraph ( ) ;
3635
3736 const [ project ] = await nxProjectsToConfig (
3837 projectGraph ,
Original file line number Diff line number Diff line change @@ -2,7 +2,11 @@ import type { ProjectConfiguration } from '@nx/devkit';
22import { readdir } from 'node:fs/promises' ;
33import path from 'node:path' ;
44import { readConfigFile , sys } from 'typescript' ;
5- import { logger , pluralizeToken , stringifyError } from '@code-pushup/utils' ;
5+ import {
6+ logger ,
7+ pluralizeToken ,
8+ resolveCachedProjectGraph ,
9+ } from '@code-pushup/utils' ;
610import { formatMetaLog } from '../format.js' ;
711
812/**
@@ -35,24 +39,6 @@ function hasFilesToCompile(tsconfigPath: string): boolean {
3539 return ! ( filesEmpty && includeEmpty ) ;
3640}
3741
38- /**
39- * Resolves the cached project graph for the current Nx workspace.
40- * Tries to read from cache first, falls back to async creation.
41- */
42- async function resolveCachedProjectGraph ( ) {
43- const { readCachedProjectGraph, createProjectGraphAsync } = await import (
44- '@nx/devkit'
45- ) ;
46- try {
47- return readCachedProjectGraph ( ) ;
48- } catch ( error ) {
49- logger . warn (
50- `Could not read cached project graph, falling back to async creation.\n${ stringifyError ( error ) } ` ,
51- ) ;
52- return await createProjectGraphAsync ( { exitOnError : false } ) ;
53- }
54- }
55-
5642function isProjectIncluded (
5743 project : ProjectConfiguration ,
5844 exclude ?: string [ ] ,
Original file line number Diff line number Diff line change 3939 "wrap-ansi" : " ^9.0.2" ,
4040 "zod" : " ^4.2.1"
4141 },
42+ "peerDependencies" : {
43+ "@nx/devkit" : " >=17.0.0"
44+ },
45+ "peerDependenciesMeta" : {
46+ "@nx/devkit" : {
47+ "optional" : true
48+ }
49+ },
4250 "files" : [
4351 " src" ,
4452 " !**/*.tsbuildinfo"
Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ export {
9494export { interpolate } from './lib/interpolate.js' ;
9595export { Logger , logger } from './lib/logger.js' ;
9696export { mergeConfigs } from './lib/merge-configs.js' ;
97+ export { createProjectGraph , resolveCachedProjectGraph } from './lib/nx.js' ;
9798export {
9899 addIndex ,
99100 expandAuditsForUrls ,
Original file line number Diff line number Diff line change 1+ import type { ProjectGraph } from '@nx/devkit' ;
2+ import { stringifyError } from './errors.js' ;
3+ import { logger } from './logger.js' ;
4+
5+ /**
6+ * Creates the project graph for the current Nx workspace.
7+ */
8+ export async function createProjectGraph ( ) : Promise < ProjectGraph > {
9+ const { createProjectGraphAsync } = await import ( '@nx/devkit' ) ;
10+ return createProjectGraphAsync ( { exitOnError : false } ) ;
11+ }
12+
13+ /**
14+ * Resolves the cached project graph for the current Nx workspace.
15+ * Tries to read from cache first, falls back to async creation.
16+ */
17+ export async function resolveCachedProjectGraph ( ) : Promise < ProjectGraph > {
18+ const { readCachedProjectGraph } = await import ( '@nx/devkit' ) ;
19+ try {
20+ return readCachedProjectGraph ( ) ;
21+ } catch ( error ) {
22+ logger . warn (
23+ `Could not read cached project graph, falling back to async creation.\n${ stringifyError ( error ) } ` ,
24+ ) ;
25+ return createProjectGraph ( ) ;
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments