Skip to content

Commit ebc5421

Browse files
authored
chore: QA tool to detect missing dependencies (#1264)
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 c9e4dae commit ebc5421

File tree

7 files changed

+72
-7
lines changed

7 files changed

+72
-7
lines changed

.github/workflows/nodejs.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ jobs:
120120
- name: setup tools
121121
run: |
122122
echo "::group::install docs-gen deps"
123-
npm run -- dev-setup:docs-gen --ignore-scripts --loglevel=silly
123+
npm run -- dev-setup:tools:docs-gen --ignore-scripts --loglevel=silly
124124
echo "::endgroup::"
125125
echo "::group::install code-style deps"
126-
npm run -- dev-setup:code-style --ignore-scripts --loglevel=silly
126+
npm run -- dev-setup:tools:code-style --ignore-scripts --loglevel=silly
127127
echo "::endgroup::"
128128
- name: make reports dir
129129
run: mkdir -p "$REPORTS_DIR"
@@ -147,6 +147,28 @@ jobs:
147147
path: ${{ env.REPORTS_DIR }}
148148
if-no-files-found: error
149149

150+
test-dependencies:
151+
name: test dependencies
152+
runs-on: ubuntu-latest
153+
timeout-minutes: 10
154+
steps:
155+
- name: Checkout
156+
# see https://github.com/actions/checkout
157+
uses: actions/checkout@v4
158+
- name: Setup Node.js ${{ env.NODE_ACTIVE_LTS }}
159+
# see https://github.com/actions/setup-node
160+
uses: actions/setup-node@v4
161+
with:
162+
node-version: ${{ env.NODE_ACTIVE_LTS }}
163+
# cache: "npm"
164+
# cache-dependency-path: "**/package-lock.json"
165+
- name: setup project
166+
run: npm install --ignore-scripts --loglevel=silly
167+
- name: setup tool
168+
run: npm run -- dev-setup:tools:test-dependencies --ignore-scripts --loglevel=silly
169+
- name: test
170+
run: npm run -- test:dependencies -d
171+
150172
test-node:
151173
needs: [ 'build' ]
152174
name: test node (${{ matrix.node-version }}, ${{ matrix.os }})
@@ -483,7 +505,7 @@ jobs:
483505
npm install --ignore-scripts --loglevel=silly
484506
echo "::endgroup::"
485507
echo "::group::install docs-gen deps"
486-
npm run -- dev-setup:docs-gen --ignore-scripts --loglevel=silly
508+
npm run -- dev-setup:tools:docs-gen --ignore-scripts --loglevel=silly
487509
echo "::endgroup::"
488510
- name: api-doc ${{ matrix.target }}
489511
run: npm run api-doc:${{ matrix.target }}

.github/workflows/release.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,13 @@ jobs:
120120
- name: setup tools
121121
run: |
122122
echo "::group::install docs-gen deps"
123-
npm run -- dev-setup:docs-gen --ignore-scripts --loglevel=silly
123+
npm run -- dev-setup:tools:docs-gen --ignore-scripts --loglevel=silly
124124
echo "::endgroup::"
125125
echo "::group::install code-style deps"
126-
npm run -- dev-setup:code-style --ignore-scripts --loglevel=silly
126+
npm run -- dev-setup:tools:code-style --ignore-scripts --loglevel=silly
127+
echo "::endgroup::"
128+
echo "::group::install test-dependencies deps"
129+
npm run -- dev-setup:tools:test-dependencies --ignore-scripts --loglevel=silly
127130
echo "::endgroup::"
128131
# no explicit npm build. if a build is required, it should be configured as prepublish/prepublishOnly script of npm.
129132
- name: login to registries

knip.jsonc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "https://unpkg.com/knip@5/schema-jsonc.json",
3+
"entry": [
4+
"src/index.node.ts!",
5+
"src/index.web.ts!"
6+
],
7+
"project": [
8+
"src/**!",
9+
"res/**!",
10+
"tests/**",
11+
"!tests/_data/normalizeResults/**",
12+
"!tests/_data/schemaTestData/**"
13+
],
14+
"ignore": [
15+
"tools/**"
16+
]
17+
}

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,10 @@
170170
},
171171
"scripts": {
172172
"dev-setup": "npm i && run-p --aggregate-output -lc dev-setup:\\*",
173-
"dev-setup:docs-gen": "npm --prefix tools/docs-gen install",
174-
"dev-setup:code-style": "npm --prefix tools/code-style install",
173+
"dev-setup:tools": "run-p --aggregate-output -lc dev-setup:tools:\\*",
174+
"dev-setup:tools:docs-gen": "npm --prefix tools/docs-gen install",
175+
"dev-setup:tools:code-style": "npm --prefix tools/code-style install",
176+
"dev-setup:tools:test-dependencies": "npm --prefix tools/test-dependencies install",
175177
"dev-setup:examples": "run-p --aggregate-output -lc dev-setup:examples:\\*",
176178
"dev-setup:examples:js": "npm --prefix examples/node/javascript i --ignore-scripts",
177179
"dev-setup:examples:ts-cjs": "npm --prefix examples/node/typescript/example.cjs i --ignore-scripts",
@@ -190,6 +192,7 @@
190192
"test:web": "node -e 'console.log(\"TODO: write web test\")'",
191193
"test:lint": "tsc --noEmit",
192194
"test:standard": "npm --prefix tools/code-style exec -- eslint .",
195+
"test:dependencies": "npm --prefix tools/test-dependencies exec -- knip --include dependencies,unlisted,unresolved --production",
193196
"cs-fix": "npm --prefix tools/code-style exec -- eslint --fix .",
194197
"api-doc": "run-p --aggregate-output -lc api-doc:\\*",
195198
"api-doc:node": "npm --prefix tools/docs-gen exec -- typedoc --options ./typedoc.node.json",

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-javascript-library/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)