Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default mergeConfigs(
await configureEslintPlugin(),
await configureCoveragePlugin(),
await configureJsPackagesPlugin(),
configureTypescriptPlugin(),
await configureTypescriptPlugin(),
configureJsDocsPlugin(),
await configureLighthousePlugin(TARGET_URL),
configureAxePlugin(TARGET_URL),
Expand Down
12 changes: 10 additions & 2 deletions code-pushup.preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from './packages/plugin-lighthouse/src/index.js';
import typescriptPlugin, {
getCategories,
tsconfigFromAllNxProjects,
} from './packages/plugin-typescript/src/index.js';

export function configureUpload(projectName: string = 'workspace'): CoreConfig {
Expand Down Expand Up @@ -150,10 +151,17 @@ export async function configureJsPackagesPlugin(): Promise<CoreConfig> {
};
}

export function configureTypescriptPlugin(projectName?: string): CoreConfig {
export async function configureTypescriptPlugin(
projectName?: string,
): Promise<CoreConfig> {
const tsconfig = projectName
? `packages/${projectName}/tsconfig.lib.json`
: 'tsconfig.code-pushup.json';
: await tsconfigFromAllNxProjects({
exclude: [
'test-fixtures', // Intentionally incomplete tsconfigs
'models', // Uses ts-patch transformer plugin
],
});
return {
plugins: [typescriptPlugin({ tsconfig })],
categories: getCategories(),
Expand Down
2 changes: 1 addition & 1 deletion packages/ci/code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export default mergeConfigs(
configureUpload(projectName),
await configureEslintPlugin(projectName),
await configureCoveragePlugin(projectName),
configureTypescriptPlugin(projectName),
await configureTypescriptPlugin(projectName),
configureJsDocsPlugin(projectName),
);
2 changes: 1 addition & 1 deletion packages/cli/code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export default mergeConfigs(
configureUpload(projectName),
await configureEslintPlugin(projectName),
await configureCoveragePlugin(projectName),
configureTypescriptPlugin(projectName),
await configureTypescriptPlugin(projectName),
configureJsDocsPlugin(projectName),
);
2 changes: 1 addition & 1 deletion packages/core/code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export default mergeConfigs(
configureUpload(projectName),
await configureEslintPlugin(projectName),
await configureCoveragePlugin(projectName),
configureTypescriptPlugin(projectName),
await configureTypescriptPlugin(projectName),
configureJsDocsPlugin(projectName),
);
2 changes: 1 addition & 1 deletion packages/create-cli/code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export default mergeConfigs(
configureUpload(projectName),
await configureEslintPlugin(projectName),
await configureCoveragePlugin(projectName),
configureTypescriptPlugin(projectName),
await configureTypescriptPlugin(projectName),
configureJsDocsPlugin(projectName),
);
2 changes: 1 addition & 1 deletion packages/nx-plugin/code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export default mergeConfigs(
configureUpload(projectName),
await configureEslintPlugin(projectName),
await configureCoveragePlugin(projectName),
configureTypescriptPlugin(projectName),
await configureTypescriptPlugin(projectName),
configureJsDocsPlugin(projectName),
);
2 changes: 1 addition & 1 deletion packages/plugin-axe/code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export default mergeConfigs(
configureUpload(projectName),
await configureEslintPlugin(projectName),
await configureCoveragePlugin(projectName),
configureTypescriptPlugin(projectName),
await configureTypescriptPlugin(projectName),
configureJsDocsPlugin(projectName),
);
2 changes: 1 addition & 1 deletion packages/plugin-coverage/code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export default mergeConfigs(
configureUpload(projectName),
await configureEslintPlugin(projectName),
await configureCoveragePlugin(projectName),
configureTypescriptPlugin(projectName),
await configureTypescriptPlugin(projectName),
configureJsDocsPlugin(projectName),
);
22 changes: 2 additions & 20 deletions packages/plugin-coverage/src/lib/nx/coverage-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,22 @@ import type { VitestExecutorOptions } from '@nx/vite/executors';
import path from 'node:path';
import {
importModule,
loadNxProjectGraph,
logger,
pluralize,
pluralizeToken,
stringifyError,
} from '@code-pushup/utils';
import type { CoverageResult } from '../config.js';
import { formatMetaLog } from '../format.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.warn(
`Could not read cached project graph, falling back to async creation - ${stringifyError(error)}`,
);
return await createProjectGraphAsync({ exitOnError: false });
}
}

/**
* @param targets nx targets to be used for measuring coverage, test by default
* @returns An array of coverage result information for the coverage plugin.
*/
export async function getNxCoveragePaths(
targets: string[] = ['test'],
): Promise<CoverageResult[]> {
const { nodes } = await resolveCachedProjectGraph();
const { nodes } = await loadNxProjectGraph();

const coverageResultsPerTarget = Object.fromEntries(
await Promise.all(
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-eslint/code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export default mergeConfigs(
configureUpload(projectName),
await configureEslintPlugin(projectName),
await configureCoveragePlugin(projectName),
configureTypescriptPlugin(projectName),
await configureTypescriptPlugin(projectName),
configureJsDocsPlugin(projectName),
);
22 changes: 2 additions & 20 deletions packages/plugin-eslint/src/lib/nx/find-all-projects.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
import { logger, pluralizeToken, stringifyError } from '@code-pushup/utils';
import { loadNxProjectGraph, logger, pluralizeToken } from '@code-pushup/utils';
import type { ESLintTarget } from '../config.js';
import { formatMetaLog } from '../meta/format.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.warn(
`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.
*
Expand Down Expand Up @@ -51,7 +33,7 @@ async function resolveCachedProjectGraph() {
export async function eslintConfigFromAllNxProjects(
options: { exclude?: string[] } = {},
): Promise<ESLintTarget[]> {
const projectGraph = await resolveCachedProjectGraph();
const projectGraph = await loadNxProjectGraph();
const filteredProjectGraph = filterProjectGraph(
projectGraph,
options.exclude,
Expand Down
5 changes: 2 additions & 3 deletions packages/plugin-eslint/src/lib/nx/find-project-with-deps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logger, pluralizeToken } from '@code-pushup/utils';
import { loadNxProjectGraph, 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';
Expand Down Expand Up @@ -32,8 +32,7 @@ import { findAllDependencies } from './traverse-graph.js';
export async function eslintConfigFromNxProjectAndDeps(
projectName: string,
): Promise<ESLintTarget[]> {
const { createProjectGraphAsync } = await import('@nx/devkit');
const projectGraph = await createProjectGraphAsync({ exitOnError: false });
const projectGraph = await loadNxProjectGraph();

const dependencies = findAllDependencies(projectName, projectGraph);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logger } from '@code-pushup/utils';
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';
Expand Down Expand Up @@ -31,8 +31,7 @@ import { nxProjectsToConfig } from './projects-to-config.js';
export async function eslintConfigFromNxProject(
projectName: string,
): Promise<ESLintTarget> {
const { createProjectGraphAsync } = await import('@nx/devkit');
const projectGraph = await createProjectGraphAsync({ exitOnError: false });
const projectGraph = await loadNxProjectGraph();

const [project] = await nxProjectsToConfig(
projectGraph,
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-js-packages/code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export default mergeConfigs(
configureUpload(projectName),
await configureEslintPlugin(projectName),
await configureCoveragePlugin(projectName),
configureTypescriptPlugin(projectName),
await configureTypescriptPlugin(projectName),
configureJsDocsPlugin(projectName),
);
2 changes: 1 addition & 1 deletion packages/plugin-jsdocs/code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export default mergeConfigs(
configureUpload(projectName),
await configureEslintPlugin(projectName),
await configureCoveragePlugin(projectName),
configureTypescriptPlugin(projectName),
await configureTypescriptPlugin(projectName),
configureJsDocsPlugin(projectName),
);
2 changes: 1 addition & 1 deletion packages/plugin-lighthouse/code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export default mergeConfigs(
configureUpload(projectName),
await configureEslintPlugin(projectName),
await configureCoveragePlugin(projectName),
configureTypescriptPlugin(projectName),
await configureTypescriptPlugin(projectName),
configureJsDocsPlugin(projectName),
);
38 changes: 33 additions & 5 deletions packages/plugin-typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,49 @@ Each set is also available as group in the plugin. See more under [Audits and Gr

The plugin accepts the following parameters:

| Option | Type | Default | Description |
| ---------- | -------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| tsconfig | string | `tsconfig.json` | A string that defines the path to your `tsconfig.json` file |
| onlyAudits | string[] | undefined | An array of audit slugs to specify which documentation types you want to measure. Only the specified audits will be included in the results |
| Option | Type | Default | Description |
| ---------- | ------------------ | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| tsconfig | string \| string[] | `tsconfig.json` | Path(s) to your `tsconfig.json` file(s) |
| onlyAudits | string[] | undefined | An array of audit slugs to specify which documentation types you want to measure. Only the specified audits will be included in the results |

#### `tsconfig`

Optional parameter. The `tsconfig` option accepts a string that defines the path to your config file and defaults to `tsconfig.json`.
Optional parameter. The `tsconfig` option accepts a path or an array of paths to your config files. Defaults to `tsconfig.json`.

```js
typescriptPlugin({
tsconfig: './tsconfig.json',
});
```

You can also provide multiple tsconfigs to combine results from different configurations (e.g., separate configs for source and test files):

```js
typescriptPlugin({
tsconfig: ['./tsconfig.lib.json', './tsconfig.spec.json'],
});
```

If you're using an Nx monorepo, a helper function is provided to auto-discover tsconfigs from all projects:

```js
import typescriptPlugin, { tsconfigFromAllNxProjects } from '@code-pushup/typescript-plugin';

export default {
plugins: [
await typescriptPlugin({
tsconfig: await tsconfigFromAllNxProjects(),
}),
],
};
```

You can exclude specific projects by name:

```js
await tsconfigFromAllNxProjects({ exclude: ['my-app-e2e'] });
```

#### `onlyAudits`

The `onlyAudits` option allows you to specify which documentation types you want to measure. Only the specified audits will be included in the results. All audits are included by default. Example:
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-typescript/code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export default mergeConfigs(
configureUpload(projectName),
await configureEslintPlugin(projectName),
await configureCoveragePlugin(projectName),
configureTypescriptPlugin(projectName),
await configureTypescriptPlugin(projectName),
configureJsDocsPlugin(projectName),
);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.nx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "cli",
"sourceRoot": "packages/cli/src",
"projectType": "library"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"compilerOptions": { "strict": true }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files": [],
"include": [],
"references": [{ "path": "./tsconfig.lib.json" }]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"include": ["src/**/*.ts"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "core",
"sourceRoot": "packages/core/src",
"projectType": "library"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"include": ["src/**/*.ts"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "nx-plugin",
"sourceRoot": "packages/nx-plugin/src",
"projectType": "library"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"include": ["src/**/*.ts"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "utils",
"sourceRoot": "packages/utils/src",
"projectType": "library"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"include": ["src/**/*.ts"]
}
6 changes: 6 additions & 0 deletions packages/plugin-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@
"zod": "^4.2.1"
},
"peerDependencies": {
"@nx/devkit": ">=17.0.0",
"typescript": ">=4.0.0"
},
"peerDependenciesMeta": {
"@nx/devkit": {
"optional": true
}
},
"scripts": {},
"files": [
"src",
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export {
type TypescriptPluginOptions,
} from './lib/schema.js';
export { getCategories, getCategoryRefsFromGroups } from './lib/utils.js';
export { tsconfigFromAllNxProjects } from './lib/nx/tsconfig-paths.js';
Loading