Skip to content

Commit 08920c5

Browse files
authored
chore: QA tool to detect missing dependencies (#1409)
use `knip` to test for missing dependencies. since the `import/no-extraneous-dependencies` eslint rule is not working. TODO / DONE - [x] add tool - [x] configure tool - [x] add GH workflow --------- Signed-off-by: Jan Kowalleck <[email protected]>
1 parent a51e241 commit 08920c5

File tree

7 files changed

+69
-3
lines changed

7 files changed

+69
-3
lines changed

.github/workflows/nodejs.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
- name: setup tools
7575
run: |
7676
echo "::group::install code-style deps"
77-
npm run -- dev-setup:code-style --ignore-scripts --loglevel=silly
77+
npm run -- dev-setup:tools:code-style --ignore-scripts --loglevel=silly
7878
echo "::endgroup::"
7979
- name: make reports dir
8080
run: mkdir -p "$REPORTS_DIR"
@@ -98,6 +98,28 @@ jobs:
9898
path: ${{ env.REPORTS_DIR }}
9999
if-no-files-found: error
100100

101+
test-dependencies:
102+
name: test dependencies
103+
runs-on: ubuntu-latest
104+
timeout-minutes: 10
105+
steps:
106+
- name: Checkout
107+
# see https://github.com/actions/checkout
108+
uses: actions/checkout@v4
109+
- name: Setup Node.js ${{ env.NODE_ACTIVE_LTS }}
110+
# see https://github.com/actions/setup-node
111+
uses: actions/setup-node@v4
112+
with:
113+
node-version: ${{ env.NODE_ACTIVE_LTS }}
114+
# cache: "npm"
115+
# cache-dependency-path: "**/package-lock.json"
116+
- name: setup project
117+
run: npm install --ignore-scripts --loglevel=silly
118+
- name: setup tool
119+
run: npm run -- dev-setup:tools:test-dependencies --ignore-scripts --loglevel=silly
120+
- name: test
121+
run: npm run -- test:dependencies -d
122+
101123
test-jest:
102124
needs: [ 'build' ]
103125
name: test:Jest (node${{ matrix.node-version }}, ${{ matrix.os }})

.github/workflows/release.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ jobs:
117117
- name: setup tools
118118
run: |
119119
echo "::group::install code-style deps"
120-
npm run -- dev-setup:code-style --ignore-scripts --loglevel=silly
120+
npm run -- dev-setup:tools:code-style --ignore-scripts --loglevel=silly
121+
echo "::endgroup::"
122+
echo "::group::install test-dependencies deps"
123+
npm run -- dev-setup:tools:test-dependencies --ignore-scripts --loglevel=silly
121124
echo "::endgroup::"
122125
# no explicit npm build. if a build is required, it should be configured as prepublish/prepublishOnly script of npm.
123126
- name: login to registries

knip.jsonc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"$schema": "https://unpkg.com/knip@5/schema-jsonc.json",
3+
"entry": [
4+
"src/plugin.ts!",
5+
"bin/**!"
6+
],
7+
"project": [
8+
"src/**!",
9+
"tests/*.js"
10+
],
11+
"ignore": [
12+
"tools/**"
13+
],
14+
"ignoreDependencies": [
15+
// needed to force the installation of the optional dependency of a 3rd party package:
16+
"xmlbuilder2"
17+
]
18+
}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@
9393
"exports": "./dist/plugin.js",
9494
"scripts": {
9595
"dev-setup": "npm i && run-p --aggregate-output -lc dev-setup:\\*",
96-
"dev-setup:code-style": "npm --prefix tools/code-style install",
96+
"dev-setup:tools": "run-p --aggregate-output -lc dev-setup:tools:\\*",
97+
"dev-setup:tools:code-style": "npm --prefix tools/code-style install",
98+
"dev-setup:tools:test-dependencies": "npm --prefix tools/test-dependencies install",
9799
"prepublish": "npm run build",
98100
"prepublishOnly": "run-s -lc build setup-tests test",
99101
"prebuild": "node -r fs -e 'fs.rmSync(\"dist\",{recursive:true,force:true})'",
@@ -104,6 +106,7 @@
104106
"test:jest": "c8 jest",
105107
"test:lint": "tsc --noEmit",
106108
"test:standard": "npm --prefix tools/code-style exec -- eslint .",
109+
"test:dependencies": "npm --prefix tools/test-dependencies exec -- knip --include dependencies,unlisted,unresolved --production",
107110
"cs-fix": "npm --prefix tools/code-style exec -- eslint --fix ."
108111
},
109112
"jest-junit": {

tools/test-dependencies/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*
2+
!/.gitignore
3+
!/package.json
4+
!/.npmrc

tools/test-dependencies/.npmrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
; see the docs: https://docs.npmjs.com/cli/v9/using-npm/config
2+
3+
package-lock=false
4+
engine-strict=true
5+
omit=peer # don't install them automatically; we take cate of them!
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"private": true,
3+
"name": "@cyclonedx/cyclonedx-webpack-plugin/tools/test-dependencies",
4+
"license": "Apache-2.0",
5+
"engines": {
6+
"node": ">=20.18"
7+
},
8+
"dependencies": {
9+
"knip": "5.61.3"
10+
}
11+
}

0 commit comments

Comments
 (0)