Skip to content

Commit

Permalink
build: add knip to detect unused thingies (#1066)
Browse files Browse the repository at this point in the history
* build: add knip to detect unused thingies

* build: disable reading Cypress config
  • Loading branch information
davidlj95 authored Dec 20, 2024
1 parent 70dda0a commit fceeede
Show file tree
Hide file tree
Showing 15 changed files with 281 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/reusable-example-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:
pnpm run create-example-app ${{ matrix.cli-version-alias }}
--tmp-dir=${{ runner.temp }}
- name: Build example app
run: pnpm ci:build # includes SSR and source maps
run: pnpm run ci:build # includes SSR and source maps
working-directory: ${{ env.EXAMPLE_APP_DIR }}
# 👇 We can't do just `pnpm prune --prod` or `pnpm i --prod`
# GitHub Actions `actions/upload-artifact` doesn't like symlinks
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/reusable-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,15 @@ jobs:
--from ${{ github.event.pull_request.base.sha }} \
--to ${{ github.event.pull_request.head.sha }} \
--verbose
unused:
name: Unused
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Setup
uses: ./.github/actions/setup
- name: Run
run: pnpm run lint:unused
2 changes: 1 addition & 1 deletion .idea/prettier.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions knip.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"$schema": "node_modules/knip/schema.json",
"workspaces": {
".": {
"project": [],
"entry": ["dts-config.js"],
"ignore": [
// 👇 Can't ignore "projects" being imported when shouldn't be
"jest.config.js",
// 👇 Unresolved: referenced "types". As they need to be resolved taking into account `typeRoots`
"projects/ngx-meta/e2e/tsconfig.json",
"projects/ngx-meta/src/tsconfig.lib.json",
],
"ignoreDependencies": [
// 👇 Unused: used in post-build shell script
"dts-bundle-generator",
// 👇 Unlisted: Needed by semantic release https://github.com/semantic-release/commit-analyzer
"conventional-changelog-conventionalcommits",
// 👇 Unresolved: Not hoisted by pnpm, but they're there. Added due to Semantic Release plugin
"@semantic-release/commit-analyzer",
"@semantic-release/github",
"@semantic-release/npm",
"@semantic-release/release-notes-generator",
// 👇 Unresolved: Not hoisted by pnpm, but it's there due to `angular-esbuild` dep
"@angular-eslint/builder",
// 👇 Unlisted: Manually hoisted by pnpm, but not specified in package.json
"@eslint/js",
// 👇 Unused: added by Angular CLI by default
"@angular/compiler",
"@angular/platform-browser-dynamic",
"@angular/router",
// actually used, but mistakenly from peer dep
// 👇 Unused: will be fixed soon when Knip tracks polyfills
"zone.js",
],
},
"./projects/ngx-meta/e2e": {
"project": ["**/*.ts"],
"entry": [
//👇 Due to Cypress config not read (see below)
"cypress.config.ts",
"cypress/support/coverage.ts",
],
// 👇 Disable reading config to avoid installing Cypress when running knip in CI/CD
"cypress": {
"config": [],
},
"ignoreBinaries": [
// 👇 Unlisted in CI/CD: because Cypress not installed
"cypress",
],
"ignoreDependencies": [
// 👇 Used in homonym shell script
"start-server-and-test",
// 👇 Seems it's needed by Cypress https://github.com/davidlj95/ngx/pull/679
"tslib",
],
},
"./projects/ngx-meta/example-apps": {
"project": ["src/**/*.ts"],
"entry": ["src/create-example-app.ts"],
},
"./projects/ngx-meta/schematics": {
"project": ["**/*.ts!", "!**/testing/**/*.ts!"],
"entry": [
"ng-add/index.ts!",
"migrations/const-to-function-manager-providers/index.ts!",
],
"ignore": ["external-utils/**/*.ts"],
"ignoreBinaries": ["rsync"],
},
"./projects/ngx-meta/src": {
"project": ["**/*.ts!"],
"entry": ["all-entry-points.ts!", "index.ts!"],
"ignoreDependencies": [
// 👇 Unused: As recommended to include in Angular Package Format v10+
// https://angular.dev/tools/libraries/angular-package-format#tslib
"tslib",
// 👇 Referenced optional peerDep: If not using "router" entrypoint, it's fine
"@angular/router",
],
},
},
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"lint:code:files//": "☝️ lint-staged can't/shouldn't use 'ng lint'",
"lint:commit-message": "pnpm run commitlint-edit-msg",
"lint:gh-actions": "./actionlint.sh",
"lint:unused": "pnpm run '/^lint:unused:.*$/'",
"lint:unused:development": "knip",
"lint:unused:production": "knip --production --tags=-visibleForTesting",
"ngx-meta:api-documenter": "api-documenter markdown -i ./projects/ngx-meta/api-extractor -o ./projects/ngx-meta/docs/content/api",
"ngx-meta:api-extractor": "api-extractor run -c ./projects/ngx-meta/src/api-extractor.json",
"ngx-meta:api-extractor:local": "pnpm run ngx-meta:tsc:lib && pnpm run ngx-meta:api-extractor --local",
Expand All @@ -30,7 +33,7 @@
"ngx-meta:tsc:spec": "tsc -p ./projects/ngx-meta/src/tsconfig.spec.json --listEmittedFiles",
"prepare": "husky",
"semantic-release:local": "./semantic-release-local.sh",
"start": "ng serve",
"start:dev": "ng serve",
"test:unit": "pnpm run '/^test:unit:\\w*$/'",
"test:unit:coverage": "pnpm run '/^test:unit:\\w*:coverage$/'",
"test:unit:libs": "ng test --no-watch",
Expand All @@ -48,7 +51,6 @@
"@angular/common": "18.2.10",
"@angular/compiler": "18.2.10",
"@angular/core": "18.2.10",
"@angular/forms": "18.2.10",
"@angular/platform-browser": "18.2.10",
"@angular/platform-browser-dynamic": "18.2.10",
"@angular/router": "18.2.10",
Expand Down Expand Up @@ -91,6 +93,7 @@
"karma-coverage": "2.2.1",
"karma-jasmine": "5.1.0",
"karma-jasmine-html-reporter": "2.1.0",
"knip": "5.41.1",
"lint-staged": "15.2.10",
"ng-mocks": "14.13.1",
"ng-packagr": "18.2.1",
Expand Down
Loading

0 comments on commit fceeede

Please sign in to comment.