Skip to content

Commit f50eac1

Browse files
authored
ci: Replace depcheck with knip (#1294)
Due to the deprecation of depcheck we migrated to knip, which is in active development and has more features. As a first step we only activate the checking of unused dependencies except peer dependencies (See comment in config). In the future we may also activate more rules to improve code quality. For monorepos it has to be run at root package level: [Knip Monorepos](https://knip.dev/features/monorepos-and-workspaces). The reason why we replaced the `docdash` jsdoc template path lookup in the jsdoc script is that knip fails to detect that a dependency (`jsdoc`) is used when a command inside of the package.json contains JavaScript code (via sub-shell). Also removes unused local-web-server dependency. JIRA: CPOUI5FOUNDATION-1126
1 parent 042f26e commit f50eac1

File tree

13 files changed

+1634
-3719
lines changed

13 files changed

+1634
-3719
lines changed

.github/workflows/github-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
run: npm run check-licenses
5757

5858
- name: Perform dependency check
59-
run: npm run depcheck
59+
run: npm run knip
6060

6161
- name: Run unit tests
6262
run: npm run coverage

internal/benchmark/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@
1111
"ui5-cli-benchmark": "./cli.js"
1212
},
1313
"scripts": {
14-
"test": "npm run lint && npm run coverage && npm run depcheck",
14+
"test": "npm run lint && npm run coverage",
1515
"unit": "node --test 'test/e2e/**/*.js'",
1616
"unit-watch": "node --test --watch 'test/e2e/**/*.js'",
1717
"coverage": "node --test --experimental-test-coverage 'test/e2e/**/*.js'",
18-
"lint": "eslint .",
19-
"depcheck": "depcheck"
18+
"lint": "eslint ."
2019
},
2120
"dependencies": {
2221
"js-yaml": "^4.1.1"
2322
},
2423
"devDependencies": {
25-
"depcheck": "^1.4.7",
2624
"eslint": "^9.39.1"
2725
}
2826
}

internal/documentation/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,20 @@
2424
"scripts": {
2525
"start": "vitepress dev --open",
2626
"lint": "eslint .",
27-
"depcheck": "depcheck --ignores @ui5/documentation,vitepress,docdash,jsdoc,open-cli,handlebars,@types/node,@ui5/webcomponents,autoprefixer,cssnano,@theme/components",
2827
"dev": "vitepress dev",
2928
"build:vitepress": "vitepress build",
3029
"build:assets": "sh -c 'DEST_DIR=${1:-./dist}; cp -r ./docs/images \"$DEST_DIR/images\"' --",
3130
"preview": "vitepress preview --port 8080",
3231
"jsdoc": "npm run jsdoc-generate && open-cli dist/api/index.html",
33-
"jsdoc-generate": "jsdoc -c jsdoc/jsdoc-workspace.json -t $(node -p 'path.dirname(require.resolve(\"docdash\"))') ./ || (echo 'Error during JSDoc generation! Check log.' && exit 1)",
34-
"jsdoc-generate-gh-pages": "jsdoc -c jsdoc/jsdoc.json -t $(node -p 'path.dirname(require.resolve(\"docdash\"))') ./ || (echo 'Error during JSDoc generation! Check log.' && exit 1)",
32+
"jsdoc-generate": "jsdoc -c jsdoc/jsdoc-workspace.json -t $(npm ls docdash --parseable | head -1) ./ || (echo 'Error during JSDoc generation! Check log.' && exit 1)",
33+
"jsdoc-generate-gh-pages": "jsdoc -c jsdoc/jsdoc.json -t $(npm ls docdash --parseable | head -1) ./ || (echo 'Error during JSDoc generation! Check log.' && exit 1)",
3534
"generate-cli-doc": "node ./scripts/generateCliDoc.js",
3635
"schema-generate": "node ./scripts/buildSchema.js",
3736
"schema-generate-gh-pages": "node ./scripts/buildSchema.js gh-pages",
3837
"download-packages": "./scripts/downloadPackages.sh"
3938
},
4039
"dependencies": {
4140
"@types/node": "^25.2.2",
42-
"@ui5/webcomponents": "^2.1.2",
4341
"autoprefixer": "^10.4.20",
4442
"cssnano": "^7.0.5",
4543
"markdown-it-implicit-figures": "^0.12.0",

internal/shrinkwrap-extractor/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
"directory": "internal/shrinkwrap-extractor"
2020
},
2121
"scripts": {
22-
"test": "npm run lint && npm run coverage && npm run depcheck",
22+
"test": "npm run lint && npm run coverage",
2323
"unit": "node --test test/lib/convertToShrinkwrap.js",
2424
"unit-watch": "node --test --watch test/lib/convertToShrinkwrap.js",
2525
"coverage": "node --test --experimental-test-coverage 'test/lib/convertToShrinkwrap.js'",
26-
"lint": "eslint .",
27-
"depcheck": "depcheck"
26+
"lint": "eslint ."
2827
},
2928
"keywords": [
3029
"npm",
@@ -44,7 +43,6 @@
4443
"pacote": "^21.0.4"
4544
},
4645
"devDependencies": {
47-
"depcheck": "^1.4.7",
4846
"eslint": "^9.39.1"
4947
}
5048
}

knip.config.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/**
2+
* @type {import('knip').KnipConfig}
3+
*/
4+
const config = {
5+
/**
6+
* We only need dependency checking at the moment,
7+
* so all checks except for dependencies are turned off.
8+
*/
9+
rules: {
10+
files: "off",
11+
duplicates: "off",
12+
classMembers: "off",
13+
unlisted: "off",
14+
binaries: "off",
15+
unresolved: "off",
16+
catalog: "off",
17+
exports: "off",
18+
types: "off",
19+
enumMembers: "off",
20+
/**
21+
* We also ignore peer dependencies because @ui5/project
22+
* defines an optional peer dependency to @ui5/builder
23+
* which is needed and not an issue in our point of view.
24+
*/
25+
optionalPeerDependencies: "off"
26+
},
27+
28+
ignoreDependencies: [
29+
/**
30+
* Used via nyc ava --node-arguments="--experimental-loader=@istanbuljs/esm-loader-hook"
31+
* which is not detected by knip as a usage of this package
32+
*/
33+
"@istanbuljs/esm-loader-hook"
34+
],
35+
36+
workspaces: {
37+
".": {
38+
ignoreDependencies: [
39+
/**
40+
* Invoked manually via "npx husky" to install git hooks
41+
*/
42+
"husky"
43+
]
44+
},
45+
"packages/cli": {
46+
ignoreDependencies: [
47+
/**
48+
* The package.json files of all @ui5/* packages are dynamically required for the "version" command
49+
* (See packages/cli/lib/cli/commands/versions.js)
50+
* Only @ui5/fs is not used anywhere else in the CLI package, so we need to ignore it here
51+
*/
52+
"@ui5/fs"
53+
],
54+
entry: [
55+
/**
56+
* Commands are dynamically loaded via readdir (see packages/cli/lib/cli/cli.js)
57+
*/
58+
"lib/cli/commands/*.js"
59+
]
60+
},
61+
"packages/server": {
62+
/**
63+
* We ignore these dependencies here because these are dynamic imports
64+
* and knip is unable to detect that these are being used
65+
* (See packages/server/lib/middleware/MiddlewareManager.js)
66+
*/
67+
ignoreDependencies: [
68+
"compression",
69+
"cors"
70+
]
71+
},
72+
"packages/*": {
73+
},
74+
"internal/documentation": {
75+
ignoreDependencies: [
76+
/**
77+
* Used in internal/documentation/postcss.config.js but can't be detected
78+
* as the plugin is dynamically applied based on NODE_ENV.
79+
*/
80+
"cssnano",
81+
/**
82+
* Used as jsdoc template in package.json script, which is not detected
83+
*/
84+
"docdash"
85+
]
86+
},
87+
"internal/*": {
88+
}
89+
}
90+
};
91+
92+
module.exports = config;

0 commit comments

Comments
 (0)