Skip to content
Open
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),
);
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),
);
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 @@
{}
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 @@
{}
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 @@
{}
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 @@
{}
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';
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { cp } from 'node:fs/promises';
import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import type { MockInstance } from 'vitest';
import {
restoreNxIgnoredFiles,
teardownTestFolder,
} from '@code-pushup/test-utils';
import { executeProcess } from '@code-pushup/utils';
import { tsconfigFromAllNxProjects } from './tsconfig-paths.js';

// Test setup adapted from packages/plugin-eslint/src/lib/nx/nx.int.test.ts
describe.skipIf(process.platform === 'win32')('Nx helpers', () => {
const thisDir = fileURLToPath(path.dirname(import.meta.url));
const fixturesDir = path.join(thisDir, '..', '..', '..', 'mocks', 'fixtures');
const tmpDir = path.join(process.cwd(), 'tmp', 'int', 'plugin-typescript');
let cwdSpy: MockInstance<[], string>;

beforeAll(async () => {
const workspaceDir = path.join(tmpDir, 'nx-monorepo');
await cp(path.join(fixturesDir, 'nx-monorepo'), workspaceDir, {
recursive: true,
});
await restoreNxIgnoredFiles(workspaceDir);
cwdSpy = vi.spyOn(process, 'cwd').mockReturnValue(workspaceDir);

await executeProcess({
command: 'npx nx graph --file=.nx/graph.json',
cwd: workspaceDir,
});
});

afterAll(async () => {
cwdSpy.mockRestore();
await teardownTestFolder(tmpDir);
});

describe('tsconfigFromAllNxProjects', () => {
it('should find tsconfig.lib.json from all Nx projects', async () => {
await expect(tsconfigFromAllNxProjects()).resolves.toEqual([
'packages/cli/tsconfig.lib.json',
'packages/core/tsconfig.lib.json',
'packages/nx-plugin/tsconfig.lib.json',
'packages/utils/tsconfig.lib.json',
]);
});

it('should exclude specified projects', async () => {
await expect(
tsconfigFromAllNxProjects({
exclude: ['cli', 'core'],
}),
).resolves.toEqual([
'packages/nx-plugin/tsconfig.lib.json',
'packages/utils/tsconfig.lib.json',
]);
});

it('should return empty array when all projects are excluded', async () => {
await expect(
tsconfigFromAllNxProjects({
exclude: ['cli', 'core', 'nx-plugin', 'utils'],
}),
).resolves.toEqual([]);
});
});
});
Loading