Skip to content

Commit 8d206a0

Browse files
filipw01webpro
andauthoredJan 15, 2025··
feat: add dependency-cruiser plugin (#911)
Co-authored-by: Lars Kappert <lars@webpro.nl>
1 parent 5a3177f commit 8d206a0

File tree

13 files changed

+81
-0
lines changed

13 files changed

+81
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {}

‎packages/knip/fixtures/plugins/dependency-cruiser/node_modules/dependency-cruiser/index.js

Whitespace-only changes.

‎packages/knip/fixtures/plugins/dependency-cruiser/node_modules/dependency-cruiser/package.json

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "@fixtures/dependency-cruiser",
3+
"version": "*",
4+
"devDependencies": {
5+
"dependency-cruiser": "*"
6+
},
7+
"scripts": {
8+
"test": "dependency-cruiser",
9+
"test:custom": "depcruise --config custom-depcruise-config.js",
10+
"test:baseline": "depcruise-baseline -c baseline.config.js",
11+
"test:dependency-cruise": "dependency-cruise -c dependency-cruise.config.js"
12+
}
13+
}

‎packages/knip/schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@
328328
"title": "Cypress plugin configuration (https://knip.dev/reference/plugins/cypress)",
329329
"$ref": "#/definitions/plugin"
330330
},
331+
"dependency-cruiser": {
332+
"title": "dependency-cruiser plugin configuration (https://knip.dev/reference/plugins/dependency-cruiser)",
333+
"$ref": "#/definitions/plugin"
334+
},
331335
"dotenv": {
332336
"title": "dotenv plugin configuration (https://knip.dev/reference/plugins/dotenv)",
333337
"$ref": "#/definitions/plugin"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { IsPluginEnabled, Plugin } from '../../types/config.js';
2+
import { hasDependency } from '../../util/plugin.js';
3+
4+
// https://github.com/sverweij/dependency-cruiser
5+
6+
const title = 'dependency-cruiser';
7+
8+
const enablers = ['dependency-cruiser'];
9+
10+
const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
11+
12+
const config = ['.dependency-cruiser.{js,cjs,mjs,json}'];
13+
14+
const args = {
15+
binaries: ['depcruise', 'dependency-cruise', 'dependency-cruiser', 'depcruise-baseline'],
16+
config: true,
17+
};
18+
19+
export default {
20+
title,
21+
enablers,
22+
isEnabled,
23+
config,
24+
args,
25+
} satisfies Plugin;

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

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { default as commitlint } from './commitlint/index.js';
1111
import { default as cspell } from './cspell/index.js';
1212
import { default as cucumber } from './cucumber/index.js';
1313
import { default as cypress } from './cypress/index.js';
14+
import { default as dependencyCruiser } from './dependency-cruiser/index.js';
1415
import { default as dotenv } from './dotenv/index.js';
1516
import { default as drizzle } from './drizzle/index.js';
1617
import { default as eleventy } from './eleventy/index.js';
@@ -103,6 +104,7 @@ export const Plugins = {
103104
cspell,
104105
cucumber,
105106
cypress,
107+
'dependency-cruiser': dependencyCruiser,
106108
dotenv,
107109
drizzle,
108110
eleventy,

‎packages/knip/src/schema/plugins.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const pluginsSchema = z.object({
2525
cspell: pluginSchema,
2626
cucumber: pluginSchema,
2727
cypress: pluginSchema,
28+
'dependency-cruiser': pluginSchema,
2829
dotenv: pluginSchema,
2930
drizzle: pluginSchema,
3031
eleventy: pluginSchema,

‎packages/knip/src/types/PluginNames.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type PluginName =
1212
| 'cspell'
1313
| 'cucumber'
1414
| 'cypress'
15+
| 'dependency-cruiser'
1516
| 'dotenv'
1617
| 'drizzle'
1718
| 'eleventy'
@@ -104,6 +105,7 @@ export const pluginNames = [
104105
'cspell',
105106
'cucumber',
106107
'cypress',
108+
'dependency-cruiser',
107109
'dotenv',
108110
'drizzle',
109111
'eleventy',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { test } from 'bun:test';
2+
import assert from 'node:assert/strict';
3+
import { main } from '../../src/index.js';
4+
import { resolve } from '../../src/util/path.js';
5+
import baseArguments from '../helpers/baseArguments.js';
6+
import baseCounters from '../helpers/baseCounters.js';
7+
8+
const cwd = resolve('fixtures/plugins/dependency-cruiser');
9+
10+
test('Find dependencies with the dependency-cruiser plugin', async () => {
11+
const { counters } = await main({
12+
...baseArguments,
13+
cwd,
14+
});
15+
16+
assert.deepEqual(counters, {
17+
...baseCounters,
18+
processed: 4,
19+
total: 4,
20+
});
21+
});

0 commit comments

Comments
 (0)
Please sign in to comment.