Skip to content

Commit b9dc80e

Browse files
Extended the NX plugins (#1443)
1 parent d8fa043 commit b9dc80e

File tree

9 files changed

+113
-7
lines changed

9 files changed

+113
-7
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": ["../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
}
9+
]
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
displayName: 'b',
3+
preset: '../../jest.preset.js',
4+
testEnvironment: 'node',
5+
transform: {
6+
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
7+
},
8+
moduleFileExtensions: ['ts', 'js', 'html'],
9+
coverageDirectory: '../../coverage/libs/b',
10+
};

packages/knip/fixtures/plugins/nx/libs/b/project.json

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,40 @@
2121
}
2222
},
2323
"test": {
24-
"executor": "@nrwl/jest:jest"
24+
"executor": "@nrwl/jest:jest",
25+
"options": {
26+
"jestConfig": "libs/b/jest.config.ts"
27+
}
2528
},
2629
"tsc": {
27-
"executor": "./tools/executors/tsc:tsc"
30+
"executor": "./tools/executors/tsc:tsc",
31+
"options": {
32+
"tsConfig": "libs/b/tsconfig.lib.json"
33+
}
2834
},
2935
"lint": {
3036
"executor": "nx:run-commands",
3137
"options": {
3238
"commands": [{ "command": "biome lint ." }]
3339
}
40+
},
41+
"eslint": {
42+
"executor": "@nx/linter:eslint",
43+
"options": {
44+
"eslintConfig": "libs/b/.eslintrc.json"
45+
}
46+
},
47+
"test-vitest": {
48+
"executor": "@nx/vitest:test",
49+
"options": {
50+
"vitestConfig": "libs/b/vitest.config.ts"
51+
}
52+
},
53+
"build-webpack": {
54+
"executor": "@nx/webpack:webpack",
55+
"options": {
56+
"webpackConfig": "libs/b/webpack.config.js"
57+
}
3458
}
3559
}
3660
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"declaration": true,
6+
"types": ["node"]
7+
},
8+
"include": ["src/**/*.ts"],
9+
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from 'vitest/config';
2+
3+
export default defineConfig({
4+
test: {
5+
globals: true,
6+
environment: 'node',
7+
coverage: {
8+
provider: 'v8',
9+
reporter: ['text', 'json', 'html'],
10+
},
11+
},
12+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const { composePlugins, withNx } = require('@nx/webpack');
2+
3+
module.exports = composePlugins(withNx(), (config) => {
4+
return config;
5+
});

packages/knip/src/plugins/nx/index.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ParsedArgs } from 'minimist';
22
import type { IsPluginEnabled, Plugin, ResolveConfig } from '../../types/config.js';
33
import { compact } from '../../util/array.js';
4-
import { toDependency } from '../../util/input.js';
4+
import { toConfig, toDependency } from '../../util/input.js';
55
import { hasDependency } from '../../util/plugin.js';
66
import type { NxConfigRoot, NxProjectConfiguration } from './types.js';
77

@@ -68,7 +68,36 @@ const resolveConfig: ResolveConfig<NxProjectConfiguration | NxConfigRoot> = asyn
6868

6969
const inputs = options.getInputsFromScripts(scripts);
7070

71-
return compact([...executors, ...inputs]).map(id => (typeof id === 'string' ? toDependency(id) : id));
71+
const configInputs = targets.flatMap(target => {
72+
const opts = target.options;
73+
if (!opts) return [];
74+
75+
const configs = [];
76+
77+
if ('eslintConfig' in opts && typeof opts.eslintConfig === 'string') {
78+
configs.push(toConfig('eslint', opts.eslintConfig));
79+
}
80+
81+
if ('jestConfig' in opts && typeof opts.jestConfig === 'string') {
82+
configs.push(toConfig('jest', opts.jestConfig));
83+
}
84+
85+
if ('tsConfig' in opts && typeof opts.tsConfig === 'string') {
86+
configs.push(toConfig('typescript', opts.tsConfig));
87+
}
88+
89+
if ('vitestConfig' in opts && typeof opts.vitestConfig === 'string') {
90+
configs.push(toConfig('vitest', opts.vitestConfig));
91+
}
92+
93+
if ('webpackConfig' in opts && typeof opts.webpackConfig === 'string') {
94+
configs.push(toConfig('webpack', opts.webpackConfig));
95+
}
96+
97+
return configs;
98+
});
99+
100+
return compact([...executors, ...inputs, ...configInputs]).map(id => (typeof id === 'string' ? toDependency(id) : id));
72101
};
73102

74103
const args = {

packages/knip/src/plugins/nx/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ export interface NxProjectConfiguration {
66
options?: {
77
command?: string;
88
commands?: Array<string | { command: string }>;
9+
eslintConfig?: string;
10+
jestConfig?: string;
11+
tsConfig?: string;
12+
vitestConfig?: string;
13+
webpackConfig?: string;
914
};
1015
};
1116
};

packages/knip/test/plugins/nx.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ test('Find dependencies with the Nx plugin', async () => {
3030
...baseCounters,
3131
binaries: 5,
3232
devDependencies: 6,
33-
unlisted: 3,
34-
processed: 0,
35-
total: 0,
33+
unlisted: 5,
34+
files: 3,
35+
processed: 3,
36+
total: 3,
3637
});
3738
});

0 commit comments

Comments
 (0)