Skip to content

Commit 961dd6b

Browse files
author
John Doe
committed
Merge branch 'main' into add-plugin-targets
# Conflicts: # code-pushup.preset.ts
2 parents d114076 + 3c522c7 commit 961dd6b

42 files changed

Lines changed: 1024 additions & 234 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ testem.log
4444
Thumbs.db
4545

4646
# generated Code PushUp reports
47-
/.code-pushup
47+
.code-pushup
4848

4949
# Nx workspace cache
5050
.nx

code-pushup.preset.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import coveragePlugin, {
99
import eslintPlugin, {
1010
eslintConfigFromAllNxProjects,
1111
} from './packages/plugin-eslint/src/index.js';
12+
import type { ESLintTarget } from './packages/plugin-eslint/src/lib/config.js';
13+
import { nxProjectsToConfig } from './packages/plugin-eslint/src/lib/nx/projects-to-config.js';
1214
import jsPackagesPlugin from './packages/plugin-js-packages/src/index.js';
1315
import jsDocsPlugin from './packages/plugin-jsdocs/src/index.js';
1416
import type { JsDocsPluginTransformedConfig } from './packages/plugin-jsdocs/src/lib/config.js';
@@ -155,6 +157,17 @@ export const jsDocsCoreConfig = (
155157
),
156158
});
157159

160+
export async function eslintConfigFromPublishableNxProjects(): Promise<
161+
ESLintTarget[]
162+
> {
163+
const { createProjectGraphAsync } = await import('@nx/devkit');
164+
const projectGraph = await createProjectGraphAsync({ exitOnError: false });
165+
return nxProjectsToConfig(
166+
projectGraph,
167+
project => project.tags?.includes('publishable') ?? false,
168+
);
169+
}
170+
158171
export const eslintCoreConfigNx = async (
159172
projectName?: string,
160173
): Promise<CoreConfig> => ({
@@ -165,6 +178,21 @@ export const eslintCoreConfigNx = async (
165178
patterns: ['.'],
166179
})
167180
: await eslintPlugin(await eslintConfigFromAllNxProjects()),
181+
{
182+
artifacts: {
183+
generateArtifactsCommand: {
184+
command: 'npx',
185+
args: [
186+
'nx',
187+
'run-many',
188+
'-t',
189+
'lint-reporter',
190+
'--projects=tag:publishable',
191+
],
192+
},
193+
artifactsPaths: 'packages/*/.code-pushup/eslint/eslint-report.json',
194+
},
195+
},
168196
],
169197
categories: eslintCategories,
170198
});

nx.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,32 @@
5656
"lint": {
5757
"inputs": ["lint-eslint-inputs"],
5858
"executor": "@nx/linter:eslint",
59-
"outputs": ["{options.outputFile}"],
6059
"cache": true,
6160
"options": {
61+
"errorOnUnmatchedPattern": false,
6262
"maxWarnings": 0,
6363
"lintFilePatterns": [
6464
"{projectRoot}/**/*.ts",
6565
"{projectRoot}/package.json"
6666
]
6767
}
6868
},
69+
"lint-reporter": {
70+
"inputs": ["default", "{workspaceRoot}/eslint.config.?(c)js"],
71+
"outputs": ["{projectRoot}/.eslint/**/*.json"],
72+
"cache": true,
73+
"executor": "nx:run-commands",
74+
"options": {
75+
"command": "nx lint {projectName}",
76+
"args": [
77+
"--format",
78+
"./packages/plugin-eslint/dist/src/lib/formatter/multiple-formats.js"
79+
],
80+
"env": {
81+
"ESLINT_FORMATTER_CONFIG": "{\"outputDir\":\"{projectRoot}/.eslint\"}"
82+
}
83+
}
84+
},
6985
"nxv-pkg-install": {
7086
"parallelism": false
7187
},

packages/ci/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"targets": {
77
"build": {},
88
"lint": {},
9+
"lint-reporter": {},
910
"unit-test": {},
1011
"int-test": {}
1112
},

packages/cli/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"targets": {
77
"build": {},
88
"lint": {},
9+
"lint-reporter": {},
910
"unit-test": {},
1011
"int-test": {},
1112
"run-help": {

packages/core/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"targets": {
77
"build": {},
88
"lint": {},
9+
"lint-reporter": {},
910
"unit-test": {},
1011
"int-test": {}
1112
},

packages/core/src/lib/implementation/execute-plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ export async function executePlugin(
6666
? // IF not null, take the result from cache
6767
((await readRunnerResults(pluginMeta.slug, outputDir)) ??
6868
// ELSE execute the plugin runner
69-
(await executePluginRunner(pluginConfig)))
70-
: await executePluginRunner(pluginConfig);
69+
(await executePluginRunner(pluginConfig, persist)))
70+
: await executePluginRunner(pluginConfig, persist);
7171

7272
if (cacheWrite) {
7373
await writeRunnerResults(pluginMeta.slug, outputDir, {

packages/core/src/lib/implementation/execute-plugin.unit.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('executePlugin', () => {
102102

103103
await expect(
104104
executePlugin(MINIMAL_PLUGIN_CONFIG_MOCK, {
105-
persist: { outputDir: 'dummy-path-result-is-mocked' },
105+
persist: { outputDir: MEMFS_VOLUME },
106106
cache: { read: true, write: false },
107107
}),
108108
).resolves.toStrictEqual({
@@ -122,6 +122,7 @@ describe('executePlugin', () => {
122122

123123
expect(executePluginRunnerSpy).toHaveBeenCalledWith(
124124
MINIMAL_PLUGIN_CONFIG_MOCK,
125+
{ outputDir: MEMFS_VOLUME },
125126
);
126127
});
127128
});
@@ -322,8 +323,8 @@ describe('executePlugins', () => {
322323
{
323324
...MINIMAL_PLUGIN_CONFIG_MOCK,
324325
runner: {
325-
command: 'node',
326-
args: ['-v'],
326+
command: 'echo',
327+
args: ['16'],
327328
outputFile: 'output.json',
328329
outputTransform: (outputs: unknown): Promise<AuditOutputs> =>
329330
Promise.resolve([
@@ -337,7 +338,7 @@ describe('executePlugins', () => {
337338
},
338339
},
339340
],
340-
persist: { outputDir: '.code-pushup' },
341+
persist: { outputDir: MEMFS_VOLUME },
341342
cache: { read: false, write: false },
342343
},
343344
{ progress: false },

packages/core/src/lib/implementation/runner.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { writeFile } from 'node:fs/promises';
33
import path from 'node:path';
44
import {
55
type AuditOutputs,
6+
type PersistConfig,
67
type PluginConfig,
78
type RunnerConfig,
89
type RunnerFunction,
@@ -14,6 +15,7 @@ import {
1415
executeProcess,
1516
fileExists,
1617
isVerbose,
18+
objectToCliArgs,
1719
readJsonFile,
1820
removeDirectoryIfExists,
1921
ui,
@@ -32,12 +34,13 @@ export type ValidatedRunnerResult = Omit<RunnerResult, 'audits'> & {
3234

3335
export async function executeRunnerConfig(
3436
cfg: RunnerConfig,
37+
config: Required<Pick<PersistConfig, 'outputDir'>>,
3538
): Promise<RunnerResult> {
3639
const { args, command, outputFile, outputTransform } = cfg;
3740

3841
const { duration, date } = await executeProcess({
3942
command,
40-
args,
43+
args: [...(args ?? []), ...objectToCliArgs(config)],
4144
observer: {
4245
onStdout: stdout => {
4346
if (isVerbose()) {
@@ -66,12 +69,13 @@ export async function executeRunnerConfig(
6669

6770
export async function executeRunnerFunction(
6871
runner: RunnerFunction,
72+
config: PersistConfig,
6973
): Promise<RunnerResult> {
7074
const date = new Date().toISOString();
7175
const start = performance.now();
7276

7377
// execute plugin runner
74-
const audits = await runner();
78+
const audits = await runner(config);
7579

7680
// create runner result
7781
return {
@@ -96,12 +100,13 @@ export class AuditOutputsMissingAuditError extends Error {
96100

97101
export async function executePluginRunner(
98102
pluginConfig: Pick<PluginConfig, 'audits' | 'runner'>,
103+
persist: Required<Pick<PersistConfig, 'outputDir'>>,
99104
): Promise<Omit<RunnerResult, 'audits'> & { audits: AuditOutputs }> {
100105
const { audits: pluginConfigAudits, runner } = pluginConfig;
101106
const runnerResult: RunnerResult =
102107
typeof runner === 'object'
103-
? await executeRunnerConfig(runner)
104-
: await executeRunnerFunction(runner);
108+
? await executeRunnerConfig(runner, persist)
109+
: await executeRunnerFunction(runner, persist);
105110
const { audits: unvalidatedAuditOutputs, ...executionMeta } = runnerResult;
106111

107112
const result = auditOutputsSchema.safeParse(unvalidatedAuditOutputs);

packages/create-cli/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"targets": {
77
"build": {},
88
"lint": {},
9+
"lint-reporter": {},
910
"unit-test": {},
1011
"exec-node": {
1112
"dependsOn": ["build"],

0 commit comments

Comments
 (0)