Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add TypeScript plugin #902

Draft
wants to merge 54 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
0a75f47
feat: add TypeScript plugin
BioPhoton Dec 23, 2024
63a3129
wip
BioPhoton Dec 23, 2024
1606175
wip
BioPhoton Dec 23, 2024
eead92f
wip
BioPhoton Dec 23, 2024
a92c487
wip
BioPhoton Dec 23, 2024
7abace2
fix lint
BioPhoton Dec 23, 2024
84b0bc6
fix format
BioPhoton Dec 23, 2024
01d044e
wip
BioPhoton Dec 23, 2024
e3c0d48
add category
BioPhoton Dec 23, 2024
7683533
fix: adjust plugin options
BioPhoton Dec 24, 2024
c1cff7b
fix: adjust plugin options for audits
BioPhoton Dec 24, 2024
62e4ba0
wip
BioPhoton Dec 24, 2024
0a48be4
wip
BioPhoton Dec 24, 2024
381ffbb
wip
BioPhoton Dec 24, 2024
a32f9b2
wip
BioPhoton Dec 24, 2024
c7f2d3a
wip
BioPhoton Dec 24, 2024
ba00774
wip
BioPhoton Dec 24, 2024
73232cd
add groups
BioPhoton Dec 25, 2024
ce4daa6
refactor static ts error data
BioPhoton Dec 25, 2024
68f56c8
feat(plugin-typescript): new tests, docs, readme, remove unused async…
aramirezj Dec 25, 2024
7c67433
merge PR
BioPhoton Dec 25, 2024
7ecb376
wip
BioPhoton Dec 25, 2024
8bd94f6
wip
BioPhoton Dec 25, 2024
e229455
wip
BioPhoton Dec 25, 2024
1b4d4bb
feat: add ts config default generator
BioPhoton Dec 26, 2024
cee894f
wip
BioPhoton Dec 26, 2024
e8ab0e4
wip
BioPhoton Dec 26, 2024
9ee6857
wip
BioPhoton Dec 26, 2024
f02dd08
wip
BioPhoton Dec 26, 2024
26c12d0
cleanup config and imports
BioPhoton Dec 26, 2024
4c71a2b
wip
BioPhoton Dec 27, 2024
233fe92
wip
BioPhoton Dec 27, 2024
039ed97
wip
BioPhoton Dec 27, 2024
bea7105
wip
BioPhoton Dec 27, 2024
05b2504
wip
BioPhoton Dec 27, 2024
1f17b67
wip
BioPhoton Dec 27, 2024
64876ed
wip
BioPhoton Dec 27, 2024
6f702d7
wip
BioPhoton Dec 27, 2024
58bb4f8
wip
BioPhoton Dec 27, 2024
d7d797c
wip
BioPhoton Dec 27, 2024
eda1681
chore(plugin-typescript): wip (#906)
aramirezj Dec 27, 2024
06b39ca
feat: add postinstall to typescript plugin
BioPhoton Dec 27, 2024
f6b8f59
wip
BioPhoton Dec 27, 2024
4ceac7f
fix lint
BioPhoton Dec 27, 2024
396b761
refactor tests
BioPhoton Dec 28, 2024
4092fa0
refactor unit tests
BioPhoton Dec 28, 2024
21ee2fe
refactor unit tests
BioPhoton Dec 28, 2024
1b0a8f3
wip
BioPhoton Dec 28, 2024
e855d6f
Update package.json
BioPhoton Dec 28, 2024
c150de0
wip
BioPhoton Dec 28, 2024
b3a38b3
test: setup basic e2e
BioPhoton Dec 28, 2024
430186e
wip
BioPhoton Dec 28, 2024
55f4e2c
wip
BioPhoton Dec 28, 2024
137fe52
wip
BioPhoton Dec 28, 2024
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
10 changes: 8 additions & 2 deletions code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
eslintCoreConfigNx,
jsPackagesCoreConfig,
lighthouseCoreConfig,
typescriptPluginConfigNx,
} from './code-pushup.preset.js';
import type { CoreConfig } from './packages/models/src/index.js';
import { mergeConfigs } from './packages/utils/src/index.js';
Expand Down Expand Up @@ -33,10 +34,15 @@ const config: CoreConfig = {

export default mergeConfigs(
config,
await coverageCoreConfigNx(),
/* await coverageCoreConfigNx(),
await jsPackagesCoreConfig(),
await lighthouseCoreConfig(
'https://github.com/code-pushup/cli?tab=readme-ov-file#code-pushup-cli/',
),
await eslintCoreConfigNx(),
await eslintCoreConfigNx(),*/
await typescriptPluginConfigNx({
tsConfigPath:
'packages/plugin-typescript/mocks/fixtures/basic-setup/tsconfig.json',
// onlyAudits: ['verbatim-module-syntax-typescript']
}),
);
23 changes: 23 additions & 0 deletions code-pushup.preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import jsPackagesPlugin from './packages/plugin-js-packages/src/index.js';
import lighthousePlugin, {
lighthouseGroupRef,
} from './packages/plugin-lighthouse/src/index.js';
import {
type TypescriptPluginOptions,
typescriptPlugin,
} from './packages/plugin-typescript/src/index.js';
import { getCategoryRefsFromGroups } from './packages/plugin-typescript/src/lib/utils.js';

export const jsPackagesCategories: CategoryConfig[] = [
{
Expand Down Expand Up @@ -129,6 +134,24 @@ export const eslintCoreConfigNx = async (
};
};

export const typescriptPluginConfigNx = async (
options?: TypescriptPluginOptions,
): Promise<CoreConfig> => {
const opt: TypescriptPluginOptions = {
...options,
};
return {
plugins: [await typescriptPlugin(opt)],
categories: [
{
slug: 'typescript',
title: 'Typescript',
refs: await getCategoryRefsFromGroups(opt),
},
],
};
};

export const coverageCoreConfigNx = async (
projectName?: string,
): Promise<CoreConfig> => {
Expand Down
12 changes: 12 additions & 0 deletions e2e/plugin-typescript-e2e/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import tseslint from 'typescript-eslint';
import baseConfig from '../../eslint.config.js';

export default tseslint.config(...baseConfig, {
files: ['**/*.ts'],
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { CoreConfig } from '@code-pushup/models';
import {getCategoryRefsFromGroups, typescriptPlugin} from "@code-pushup/typescript-plugin";

export default {
plugins: [
await typescriptPlugin({
tsConfigPath: 'tsconfig.json',
}),
],
categories: [
{
slug: 'typescript-quality',
title: 'Typescript',
refs: await getCategoryRefsFromGroups({
tsConfigPath: 'tsconfig.json',
})
}
],
} satisfies CoreConfig;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Error Code: 7006
* Compiler Option: noImplicitAny
* Description: Parameter 'param' implicitly has an 'any' type.
*/
function noImplicitAnyError(param) {
console.log(param);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"rootDir": "./src",
"target": "ES6",
"module": "CommonJS"
},
"include": ["src/**/*.ts"],
}
23 changes: 23 additions & 0 deletions e2e/plugin-typescript-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "plugin-typescript-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "e2e/plugin-typescript-e2e/src",
"projectType": "application",
"targets": {
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["e2e/plugin-typescript-e2e/**/*.ts"]
}
},
"e2e": {
"executor": "@nx/vite:test",
"options": {
"configFile": "e2e/plugin-typescript-e2e/vite.config.e2e.ts"
}
}
},
"implicitDependencies": ["cli", "plugin-typescript"],
"tags": ["scope:plugin", "type:e2e"]
}
30 changes: 30 additions & 0 deletions e2e/plugin-typescript-e2e/tests/install.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import path from 'node:path';
import { expect } from 'vitest';
import { nxTargetProject } from '@code-pushup/test-nx-utils';
import { E2E_ENVIRONMENTS_DIR, TEST_OUTPUT_DIR } from '@code-pushup/test-utils';
import { getCurrentTsVersion } from '@code-pushup/typescript-plugin';
import { readJsonFile } from '@code-pushup/utils';

describe('PLUGIN install of typescript-plugin NPM package', () => {
const testFileDir = path.join(
E2E_ENVIRONMENTS_DIR,
nxTargetProject(),
TEST_OUTPUT_DIR,
'install',
);

it('should have current TS version defaults generated after install', async () => {
await expect(
readJsonFile(
path.join(
testFileDir,
'node_modules',
'.code-pushup',
'plugin-typescript',
'default-ts-configs',
await getCurrentTsVersion(),
),
),
).resolves.not.toThrow();
});
});
20 changes: 20 additions & 0 deletions e2e/plugin-typescript-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "ESNext",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"types": ["vitest"]
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.test.json"
}
]
}
14 changes: 14 additions & 0 deletions e2e/plugin-typescript-e2e/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"],
"target": "ES2020"
},
"include": [
"vite.config.e2e.ts",
"tests/**/*.e2e.test.ts",
"tests/**/*.d.ts",
"mocks/**/*.ts"
]
}
21 changes: 21 additions & 0 deletions e2e/plugin-typescript-e2e/vite.config.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// <reference types="vitest" />
import { defineConfig } from 'vite';
import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases.js';

export default defineConfig({
cacheDir: '../../node_modules/.vite/plugin-typescript-e2e',
test: {
reporters: ['basic'],
testTimeout: 120_000,
globals: true,
alias: tsconfigPathAliases(),
pool: 'threads',
poolOptions: { threads: { singleThread: true } },
cache: {
dir: '../../node_modules/.vitest',
},
environment: 'node',
include: ['tests/**/*.e2e.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
setupFiles: ['../../testing/test-setup/src/lib/reset.mocks.ts'],
},
});
Loading
Loading