Skip to content

Commit a59d3f1

Browse files
committed
refactor(examples-plugins): make tests and lint build-independant
1 parent a35ace8 commit a59d3f1

13 files changed

Lines changed: 96 additions & 70 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ jobs:
180180
- name: Install dependencies
181181
run: npm ci
182182
- name: Build CLI and ESLint plugin
183-
run: npx nx run-many -t build -p cli,plugin-eslint --parallel=2
183+
run: npx nx run-many -t build -p cli,plugin-eslint,examples-plugins --parallel=3
184184
- name: Collect Code PushUp report
185185
run: npx dist/packages/cli --config code-pushup.config.ts collect
186186
- name: Upload Code PushUp report to portal

code-pushup.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import 'dotenv/config';
22
import { z } from 'zod';
3-
import eslintPlugin, {
4-
eslintConfigFromNxProjects,
5-
} from './dist/packages/plugin-eslint';
63
import {
74
fileSizePlugin,
85
fileSizeRecommendedRefs,
96
packageJsonDocumentationGroupRef,
107
packageJsonPerformanceGroupRef,
118
packageJsonPlugin,
129
packageJsonVersionControlGroupRef,
13-
} from './examples/plugins/src';
10+
} from './dist/examples/plugins';
11+
import eslintPlugin, {
12+
eslintConfigFromNxProjects,
13+
} from './dist/packages/plugin-eslint';
1414
import type { CoreConfig } from './packages/models/src';
1515

1616
// load upload configuration from environment

esbuild.config.js

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
const esbuild = require('esbuild');
22
const { execSync } = require('child_process');
3-
const { readFileSync, writeFileSync } = require('fs');
3+
const { readFileSync, writeFileSync, existsSync } = require('fs');
44

55
const project = process.env.NX_TASK_TARGET_PROJECT;
6-
const isPublishable = project !== 'testing-utils';
7-
const projectPath = isPublishable ? `packages/${project}` : project;
6+
const projectPath =
7+
project === 'testing-utils'
8+
? 'testing-utils'
9+
: project === 'examples-plugins'
10+
? 'examples/plugins'
11+
: `packages/${project}`;
812

913
esbuild.build({
1014
plugins: [
@@ -24,44 +28,56 @@ esbuild.build({
2428
});
2529
},
2630
},
27-
...(isPublishable
28-
? [
29-
{
30-
name: 'PackageJSON',
31-
setup(build) {
32-
build.onEnd(result => {
33-
if (result.errors.length > 0) return;
31+
{
32+
name: 'PackageJSON',
33+
setup(build) {
34+
build.onEnd(result => {
35+
if (result.errors.length > 0) return;
36+
37+
if (!existsSync(`${projectPath}/package.json`)) {
38+
/** @type {import('type-fest').PackageJson} */
39+
const newPackageJson = {
40+
name: `@code-pushup/${project}`,
41+
private: true,
42+
type: 'module',
43+
main: 'index.js',
44+
types: 'src/index.d.ts',
45+
};
46+
writeFileSync(
47+
`dist/${projectPath}/package.json`,
48+
JSON.stringify(newPackageJson, null, 2),
49+
);
50+
return;
51+
}
3452

35-
/** @type {import('type-fest').PackageJson} */
36-
const rootPackageJson = JSON.parse(
37-
readFileSync(`${__dirname}/package.json`).toString(),
38-
);
53+
/** @type {import('type-fest').PackageJson} */
54+
const packageJson = JSON.parse(
55+
readFileSync(`${projectPath}/package.json`).toString(),
56+
);
3957

40-
/** @type {import('type-fest').PackageJson} */
41-
const packageJson = JSON.parse(
42-
readFileSync(`${projectPath}/package.json`).toString(),
43-
);
58+
/** @type {import('type-fest').PackageJson} */
59+
const rootPackageJson = JSON.parse(
60+
readFileSync('package.json').toString(),
61+
);
4462

45-
packageJson.license = rootPackageJson.license;
46-
packageJson.homepage = rootPackageJson.homepage;
47-
packageJson.bugs = rootPackageJson.bugs;
48-
packageJson.repository = {
49-
...rootPackageJson.repository,
50-
directory: projectPath,
51-
};
52-
packageJson.contributors = rootPackageJson.contributors;
53-
packageJson.type = 'module';
54-
packageJson.main = './index.js';
55-
packageJson.types = './src/index.d.ts';
63+
packageJson.license = rootPackageJson.license;
64+
packageJson.homepage = rootPackageJson.homepage;
65+
packageJson.bugs = rootPackageJson.bugs;
66+
packageJson.repository = {
67+
...rootPackageJson.repository,
68+
directory: projectPath,
69+
};
70+
packageJson.contributors = rootPackageJson.contributors;
71+
packageJson.type = 'module';
72+
packageJson.main = './index.js';
73+
packageJson.types = './src/index.d.ts';
5674

57-
writeFileSync(
58-
`dist/${projectPath}/package.json`,
59-
JSON.stringify(packageJson, null, 2),
60-
);
61-
});
62-
},
63-
},
64-
]
65-
: []),
75+
writeFileSync(
76+
`dist/${projectPath}/package.json`,
77+
JSON.stringify(packageJson, null, 2),
78+
);
79+
});
80+
},
81+
},
6682
],
6783
});

examples/plugins/.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": ["../../.eslintrc.json"],
3-
"ignorePatterns": ["!**/*"],
3+
"ignorePatterns": ["!**/*", "code-pushup.config.ts"],
44
"overrides": [
55
{
66
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],

examples/plugins/code-pushup.config.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import {
2+
fileSizePlugin,
3+
fileSizeRecommendedRefs,
24
packageJsonDocumentationGroupRef,
35
packageJsonPerformanceGroupRef,
46
packageJsonPlugin,
57
packageJsonVersionControlGroupRef,
6-
} from './src';
7-
import fileSizePlugin, {
8-
recommendedRefs as fileSizeRecommendedRefs,
9-
} from './src/file-size/src/file-size.plugin';
8+
} from '../../dist/examples/plugins';
109

1110
/**
1211
* Run it with:
@@ -17,8 +16,7 @@ import fileSizePlugin, {
1716
*
1817
*/
1918

20-
// eslint-disable-next-line unicorn/no-unreadable-iife
21-
const config = (() => ({
19+
const config = {
2220
plugins: [
2321
fileSizePlugin({
2422
directory: './dist/packages',
@@ -52,6 +50,6 @@ const config = (() => ({
5250
refs: [packageJsonDocumentationGroupRef],
5351
},
5452
],
55-
}))();
53+
};
5654

5755
export default config;

examples/plugins/project.json

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,56 @@
33
"$schema": "../../node_modules/nx/schemas/project-schema.json",
44
"sourceRoot": "examples/plugins/src",
55
"projectType": "library",
6-
"implicitDependencies": ["cli"],
76
"targets": {
7+
"build": {
8+
"executor": "@nx/esbuild:esbuild",
9+
"outputs": ["{options.outputPath}"],
10+
"options": {
11+
"outputPath": "dist/examples/plugins",
12+
"main": "examples/plugins/src/index.ts",
13+
"tsConfig": "examples/plugins/tsconfig.lib.json",
14+
"assets": ["examples/plugins/*.md"],
15+
"esbuildConfig": "esbuild.config.js"
16+
}
17+
},
818
"lint": {
919
"executor": "@nx/linter:eslint",
1020
"outputs": ["{options.outputFile}"],
1121
"options": {
1222
"lintFilePatterns": ["examples/plugins/**/*.ts"]
13-
},
14-
"dependsOn": ["^build"]
23+
}
1524
},
1625
"unit-test": {
1726
"executor": "@nx/vite:test",
1827
"outputs": ["{options.reportsDirectory}"],
1928
"options": {
2029
"config": "examples/plugins/vite.config.unit.ts",
2130
"reportsDirectory": "../../coverage/examples-plugins/unit-tests"
22-
},
23-
"dependsOn": ["^build"]
31+
}
2432
},
2533
"integration-test": {
2634
"executor": "@nx/vite:test",
2735
"outputs": ["{options.reportsDirectory}"],
2836
"options": {
2937
"config": "examples/plugins/vite.config.integration.ts",
3038
"reportsDirectory": "../../coverage/examples-plugins/integration-tests"
31-
},
32-
"dependsOn": ["^build"]
39+
}
3340
},
3441
"run-collect": {
3542
"command": "npx dist/packages/cli collect --config=examples/plugins/code-pushup.config.ts --persist.format=md",
36-
"dependsOn": ["^build"]
43+
"dependsOn": [
44+
"build",
45+
"^build",
46+
{ "projects": ["cli"], "target": "build" }
47+
]
3748
},
3849
"run-print-config": {
3950
"command": "npx dist/packages/cli print-config --config=examples/plugins/code-pushup.config.ts",
40-
"dependsOn": ["^build"]
51+
"dependsOn": [
52+
"build",
53+
"^build",
54+
{ "projects": ["cli"], "target": "build" }
55+
]
4156
}
4257
},
4358
"tags": []

examples/plugins/src/file-size/src/file-size.plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
formatBytes,
1414
pluralizeToken,
1515
toUnixPath,
16-
} from '../../../../../dist/packages/utils';
16+
} from '@code-pushup/utils';
1717

1818
export type PluginOptions = {
1919
directory: string;

examples/plugins/src/file-size/src/file-size.plugin.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { vol } from 'memfs';
22
import { unlink } from 'node:fs/promises';
33
import { basename, join } from 'node:path';
44
import { beforeEach, describe, expect, it } from 'vitest';
5-
import { formatBytes } from '../../../../../dist/packages/utils';
5+
import { formatBytes } from '@code-pushup/utils';
66
import {
77
PluginOptions,
88
assertFileSize,

examples/plugins/src/package-json/src/integration/dependencies.audit.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { Audit, AuditOutput, Issue } from '@code-pushup/models';
2-
import {
3-
factorOf,
4-
findLineNumberInText,
5-
} from '../../../../../../dist/packages/utils';
2+
import { factorOf, findLineNumberInText } from '@code-pushup/utils';
63
import {
74
DependencyMap,
85
DependencyType,

examples/plugins/src/package-json/src/integration/type.audit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AuditOutput, Issue } from '@code-pushup/models';
2-
import { findLineNumberInText } from '../../../../../../dist/packages/utils';
2+
import { findLineNumberInText } from '@code-pushup/utils';
33
import { PackageJson, SourceResult, SourceResults } from './types';
44
import {
55
assertPropertyEmpty,

0 commit comments

Comments
 (0)