Skip to content

Commit 98c1439

Browse files
committed
refactor: wip
1 parent 6a90e80 commit 98c1439

23 files changed

Lines changed: 373 additions & 257 deletions

File tree

README_AXE_ISSUE.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

code-pushup.preset.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import coveragePlugin, {
1111
} from './packages/plugin-coverage/src/index.js';
1212
import eslintPlugin, {
1313
eslintConfigFromAllNxProjects,
14-
eslintConfigFromNxProject,
1514
} from './packages/plugin-eslint/src/index.js';
1615
import jsPackagesPlugin from './packages/plugin-js-packages/src/index.js';
1716
import jsDocsPlugin from './packages/plugin-jsdocs/src/index.js';
@@ -44,15 +43,18 @@ export async function configureEslintPlugin(
4443
return {
4544
plugins: [
4645
projectName
47-
? await eslintPlugin(await eslintConfigFromNxProject(projectName), {
48-
artifacts: {
49-
// We leverage Nx dependsOn to only run all lint targets before we run code-pushup
50-
// generateArtifactsCommand: 'npx nx run-many -t lint',
51-
artifactsPaths: [
52-
`packages/${projectName}/.eslint/eslint-report.json`,
53-
],
46+
? await eslintPlugin(
47+
{ eslintrc: `packages/${projectName}/eslint.config.js` },
48+
{
49+
artifacts: {
50+
// We leverage Nx dependsOn to only run all lint targets before we run code-pushup
51+
// generateArtifactsCommand: 'npx nx run-many -t lint',
52+
artifactsPaths: [
53+
`packages/${projectName}/.eslint/eslint-report.json`,
54+
],
55+
},
5456
},
55-
})
57+
)
5658
: await eslintPlugin(await eslintConfigFromAllNxProjects()),
5759
],
5860
categories: [

packages/cli/src/lib/implementation/core-config.middleware.int.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ describe('coreConfigMiddleware', () => {
6464
),
6565
...CLI_DEFAULTS,
6666
}),
67-
).rejects.toThrow(/Cannot find (module|package) '@example\/custom-plugin'/);
67+
).rejects.toThrow("Cannot find package '@example/custom-plugin'");
6868
});
6969
});

packages/core/src/lib/implementation/read-rc-file.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export async function readRcByPath(
2727
const result = await importModule({
2828
filepath: filePath,
2929
tsconfig,
30+
format: 'esm',
3031
});
3132
return { result, message: `Imported config from ${formattedTarget}` };
3233
},

packages/core/src/lib/implementation/read-rc-file.unit.test.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,32 @@ import { CONFIG_FILE_NAME, type CoreConfig } from '@code-pushup/models';
33
import { MEMFS_VOLUME } from '@code-pushup/test-utils';
44
import { autoloadRc } from './read-rc-file.js';
55

6-
// mock importModule from @code-pushup/utils to bypass jiti which doesn't work with memfs
7-
vi.mock('@code-pushup/utils', async () => {
8-
const utils: object = await vi.importActual('@code-pushup/utils');
6+
// mock bundleRequire inside importEsmModule used for fetching config
7+
vi.mock('bundle-require', async () => {
98
const { CORE_CONFIG_MOCK }: Record<string, CoreConfig> =
109
await vi.importActual('@code-pushup/test-fixtures');
1110

12-
const mockImportModule = async (options: { filepath: string }) => {
13-
const extension = options.filepath.split('.').at(-1);
14-
return {
15-
...CORE_CONFIG_MOCK,
16-
upload: {
17-
...CORE_CONFIG_MOCK?.upload,
18-
project: extension, // returns loaded file extension to check format precedence
19-
},
20-
};
21-
};
22-
2311
return {
24-
...utils,
25-
importModule: mockImportModule,
12+
bundleRequire: vi
13+
.fn()
14+
.mockImplementation((options: { filepath: string }) => {
15+
const extension = options.filepath.split('.').at(-1);
16+
return {
17+
mod: {
18+
default: {
19+
...CORE_CONFIG_MOCK,
20+
upload: {
21+
...CORE_CONFIG_MOCK?.upload,
22+
project: extension, // returns loaded file extension to check format precedence
23+
},
24+
},
25+
},
26+
};
27+
}),
2628
};
2729
});
2830

29-
// Note: memfs files are only listed to satisfy a system check, value is used from the mocked importModule
31+
// Note: memfs files are only listed to satisfy a system check, value is used from bundle-require mock
3032
describe('autoloadRc', () => {
3133
it('prioritise a .ts configuration file', async () => {
3234
vol.fromJSON(

packages/nx-plugin/eslint.config.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
import tseslint from 'typescript-eslint';
2-
import baseConfig from '../../eslint.config.js';
1+
const tseslint = require('typescript-eslint');
2+
const baseConfig = require('../../eslint.config.js').default;
33

4-
if (process.env['CP_DEBUG_ESLINT_IMPORTS'] === 'true') {
5-
// eslint-disable-next-line no-console
6-
console.log('[CP_DEBUG] Loaded packages/nx-plugin/eslint.config.js', {
7-
baseConfigLength: baseConfig.length,
8-
});
9-
}
10-
11-
export default tseslint.config(
4+
module.exports = tseslint.config(
125
...baseConfig,
136
{
147
files: ['**/*.ts'],
158
languageOptions: {
169
parserOptions: {
1710
projectService: true,
18-
tsconfigRootDir: import.meta.dirname,
11+
tsconfigRootDir: __dirname,
1912
},
2013
},
2114
},

packages/nx-plugin/eslint.config.mjs

Lines changed: 0 additions & 63 deletions
This file was deleted.

packages/nx-plugin/project.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@
3838
"packages/nx-plugin/**/*.ts",
3939
"packages/nx-plugin/package.json",
4040
"packages/nx-plugin/generators.json"
41-
],
42-
"args": [
43-
"'{projectRoot}/**/*.{ts,cjs,mjs,js}'",
44-
"{projectRoot}/package.json",
45-
"--config={projectRoot}/eslint.config.mjs",
46-
"--max-warnings=0",
47-
"--no-warn-ignored",
48-
"--error-on-unmatched-pattern=false",
49-
"--format=./tools/eslint-formatter-multi/dist/src/index.js"
5041
]
5142
}
5243
},

packages/nx-plugin/src/executors/cli/utils.unit.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ describe('normalizedCreateNodesV2Context', () => {
353353
createNodesV2Context({ workspaceRoot: MEMFS_VOLUME }),
354354
projectJsonPath(projectRoot),
355355
),
356-
).rejects.toThrowError(
356+
).rejects.toThrow(
357357
`Error parsing project.json file ${projectJsonPath(projectRoot)}.`,
358358
);
359359
});
@@ -372,7 +372,7 @@ describe('normalizedCreateNodesV2Context', () => {
372372
createNodesV2Context({ workspaceRoot: MEMFS_VOLUME }),
373373
projectJsonPath(projectRoot),
374374
),
375-
).rejects.toThrowError(
375+
).rejects.toThrow(
376376
`Error parsing project.json file ${projectJsonPath(projectRoot)}.`,
377377
);
378378
});

packages/nx-plugin/src/plugin/utils.unit.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ describe('normalizedCreateNodesV2Context', () => {
107107
createNodesV2Context({ workspaceRoot: MEMFS_VOLUME }),
108108
projectJsonPath(),
109109
),
110-
).rejects.toThrowError(
111-
`Error parsing project.json file ${projectJsonPath()}.`,
112-
);
110+
).rejects.toThrow(`Error parsing project.json file ${projectJsonPath()}.`);
113111
});
114112

115113
it('should provide default targetName in createOptions', async () => {

0 commit comments

Comments
 (0)