Skip to content

Commit 650d300

Browse files
author
John Doe
committed
fix: fix lint issues
1 parent 5f438c5 commit 650d300

42 files changed

Lines changed: 308 additions & 74 deletions

Some content is hidden

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

code-pushup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import {
33
jsPackagesCoreConfig,
44
lighthouseCoreConfig,
55
loadEnv,
6+
mergeConfigs,
67
} from './code-pushup.preset.js';
78
import type { CoreConfig } from './packages/models/src/index.js';
8-
import { mergeConfigs } from './packages/utils/src/index.js';
99

1010
const projectName = 'cli';
1111

code-pushup.preset.ts

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { z } from 'zod';
44
import type {
55
CategoryConfig,
66
CoreConfig,
7+
PersistConfig,
8+
PluginConfig,
9+
UploadConfig,
710
} from './packages/models/src/index.js';
811
import coveragePlugin, {
912
getNxCoveragePaths,
@@ -265,3 +268,148 @@ export const coverageCoreConfigNx = async (
265268
categories: coverageCategories,
266269
};
267270
};
271+
272+
export function mergeConfigs(
273+
config: CoreConfig,
274+
...configs: Partial<CoreConfig>[]
275+
): CoreConfig {
276+
return configs.reduce<CoreConfig>(
277+
(acc, obj) => ({
278+
...acc,
279+
...mergeCategories(acc.categories, obj.categories),
280+
...mergePlugins(acc.plugins, obj.plugins),
281+
...mergePersist(acc.persist, obj.persist),
282+
...mergeUpload(acc.upload, obj.upload),
283+
}),
284+
config,
285+
);
286+
}
287+
288+
function mergeCategories(
289+
a: CategoryConfig[] | undefined,
290+
b: CategoryConfig[] | undefined,
291+
): Pick<CoreConfig, 'categories'> {
292+
if (!a && !b) {
293+
return {};
294+
}
295+
296+
const mergedMap = new Map<string, CategoryConfig>();
297+
298+
const addToMap = (categories: CategoryConfig[]) => {
299+
categories.forEach(newObject => {
300+
if (mergedMap.has(newObject.slug)) {
301+
const existingObject: CategoryConfig | undefined = mergedMap.get(
302+
newObject.slug,
303+
);
304+
305+
mergedMap.set(newObject.slug, {
306+
...existingObject,
307+
...newObject,
308+
309+
refs: mergeByUniqueCategoryRefCombination(
310+
existingObject?.refs,
311+
newObject.refs,
312+
),
313+
});
314+
} else {
315+
mergedMap.set(newObject.slug, newObject);
316+
}
317+
});
318+
};
319+
320+
if (a) {
321+
addToMap(a);
322+
}
323+
if (b) {
324+
addToMap(b);
325+
}
326+
327+
// Convert the map back to an array
328+
return { categories: [...mergedMap.values()] };
329+
}
330+
331+
function mergePlugins(
332+
a: PluginConfig[] | undefined,
333+
b: PluginConfig[] | undefined,
334+
): Pick<CoreConfig, 'plugins'> {
335+
if (!a && !b) {
336+
return { plugins: [] };
337+
}
338+
339+
const mergedMap = new Map<string, PluginConfig>();
340+
341+
const addToMap = (plugins: PluginConfig[]) => {
342+
plugins.forEach(newObject => {
343+
mergedMap.set(newObject.slug, newObject);
344+
});
345+
};
346+
347+
if (a) {
348+
addToMap(a);
349+
}
350+
if (b) {
351+
addToMap(b);
352+
}
353+
354+
return { plugins: [...mergedMap.values()] };
355+
}
356+
357+
function mergePersist(
358+
a: PersistConfig | undefined,
359+
b: PersistConfig | undefined,
360+
): Pick<CoreConfig, 'persist'> {
361+
if (!a && !b) {
362+
return {};
363+
}
364+
365+
if (a) {
366+
return b ? { persist: { ...a, ...b } } : {};
367+
} else {
368+
return { persist: b };
369+
}
370+
}
371+
372+
function mergeByUniqueCategoryRefCombination<
373+
T extends { slug: string; type: string; plugin: string },
374+
>(a: T[] | undefined, b: T[] | undefined) {
375+
const map = new Map<string, T>();
376+
377+
const addToMap = (refs: T[]) => {
378+
refs.forEach(ref => {
379+
const uniqueIdentification = `${ref.type}:${ref.plugin}:${ref.slug}`;
380+
if (map.has(uniqueIdentification)) {
381+
map.set(uniqueIdentification, {
382+
...map.get(uniqueIdentification),
383+
...ref,
384+
});
385+
} else {
386+
map.set(uniqueIdentification, ref);
387+
}
388+
});
389+
};
390+
391+
// Add objects from both arrays to the map
392+
if (a) {
393+
addToMap(a);
394+
}
395+
if (b) {
396+
addToMap(b);
397+
}
398+
399+
return [...map.values()];
400+
}
401+
402+
function mergeUpload(
403+
a: UploadConfig | undefined,
404+
b: UploadConfig | undefined,
405+
): Pick<CoreConfig, 'upload'> {
406+
if (!a && !b) {
407+
return {};
408+
}
409+
410+
if (a) {
411+
return b ? { upload: { ...a, ...b } } : {};
412+
} else {
413+
return { upload: b };
414+
}
415+
}

eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export default tseslint.config(
2727
String.raw`^.*/eslint(\.base)?\.config\.[cm]?js$`,
2828
String.raw`^.*/code-pushup\.(config|preset)(\.m?[jt]s)?$`,
2929
'^[./]+/tools/.*$',
30+
'^@code-pushup/test-utils(|/.*)$',
31+
'^@code-pushup/test-nx-utils(|/.*)$',
3032
],
3133
depConstraints: [
3234
{

examples/plugins/tsconfig.lib.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"vitest.int.config.ts",
1212
"src/**/*.test.ts",
1313
"src/**/*.mock.ts",
14-
"mocks/**/*.ts"
14+
"mocks/**/*.ts",
15+
"code-pushup.config.ts"
1516
]
1617
}

packages/ci/tsconfig.lib.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"vitest.int.config.ts",
1212
"src/**/*.test.ts",
1313
"src/**/*.mock.ts",
14-
"mocks/**/*.ts"
14+
"mocks/**/*.ts",
15+
"code-pushup.config.ts"
1516
]
1617
}

packages/ci/tsconfig.tools.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc-tools",
5+
"types": ["node"]
6+
},
7+
"include": ["code-pushup.config.ts"]
8+
}

packages/cli/code-pushup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import {
66
jsDocsExclusionPatterns,
77
jsPackagesCoreConfig,
88
loadEnv,
9+
mergeConfigs,
910
typescriptPluginConfig,
1011
} from '../../code-pushup.preset.js';
1112
import type { CoreConfig } from '../../packages/models/src/index.js';
12-
import { mergeConfigs } from '../../packages/utils/src/index.js';
1313

1414
const projectName = process.env.NX_TASK_TARGET_PROJECT;
1515

packages/cli/tsconfig.lib.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"vitest.int.config.ts",
1212
"src/**/*.test.ts",
1313
"src/**/*.mock.ts",
14-
"mocks/**/*.ts"
14+
"mocks/**/*.ts",
15+
"code-pushup.config.ts"
1516
]
1617
}

packages/cli/tsconfig.tools.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc-tools",
5+
"types": ["node"]
6+
},
7+
"include": ["code-pushup.config.ts"]
8+
}
Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +0,0 @@
1-
import 'dotenv/config';
2-
import {
3-
coverageCoreConfigNx,
4-
eslintCoreConfigNx,
5-
jsDocsCoreConfig,
6-
jsDocsExclusionPatterns,
7-
jsPackagesCoreConfig,
8-
loadEnv,
9-
typescriptPluginConfig,
10-
} from '../../code-pushup.preset.js';
11-
import type { CoreConfig } from '../../packages/models/src/index.js';
12-
import { mergeConfigs } from '../../packages/utils/src/index.js';
13-
14-
const projectName = process.env.NX_TASK_TARGET_PROJECT;
15-
16-
const config: CoreConfig = {
17-
...(await loadEnv()),
18-
plugins: [],
19-
};
20-
21-
export default mergeConfigs(
22-
config,
23-
await coverageCoreConfigNx(projectName),
24-
await jsPackagesCoreConfig('package.json'), // Use workspace root package.json
25-
await typescriptPluginConfig({
26-
tsconfig: `packages/${projectName}/tsconfig.lib.json`,
27-
}),
28-
await eslintCoreConfigNx(projectName),
29-
jsDocsCoreConfig([
30-
`packages/${projectName}/src/**/*.ts`,
31-
...jsDocsExclusionPatterns,
32-
]),
33-
);

0 commit comments

Comments
 (0)