{"id":22253236,"url":"https://github.com/davidlj95/a19-knip","last_synced_at":"2025-07-28T05:32:25.406Z","repository":{"id":265784883,"uuid":"896637763","full_name":"davidlj95/a19-knip","owner":"davidlj95","description":"Angular v19 fresh app to use to improve Knip defaults for Angular","archived":true,"fork":false,"pushed_at":"2025-01-17T10:32:42.000Z","size":281,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T12:27:52.388Z","etag":null,"topics":["angular","knip","oss"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidlj95.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-30T22:30:29.000Z","updated_at":"2025-01-17T10:33:40.000Z","dependencies_parsed_at":"2024-12-20T16:31:04.993Z","dependency_job_id":"4d2a5e3a-cc61-438b-94a2-47049a46118d","html_url":"https://github.com/davidlj95/a19-knip","commit_stats":null,"previous_names":["davidlj95/a19-knip"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/davidlj95/a19-knip","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidlj95%2Fa19-knip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidlj95%2Fa19-knip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidlj95%2Fa19-knip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidlj95%2Fa19-knip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidlj95","download_url":"https://codeload.github.com/davidlj95/a19-knip/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidlj95%2Fa19-knip/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267468295,"owners_count":24092317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","knip","oss"],"created_at":"2024-12-03T07:17:31.471Z","updated_at":"2025-07-28T05:32:25.397Z","avatar_url":"https://github.com/davidlj95.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A19Knip\n\nThis project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 19.0.2.\n\nPurpose of is to improve [`knip`](https://knip.dev/) defaults for Angular projects. So that it works nicely out-of-the-box for Angular projects created with default options and server side rendering (SSR) enabled. Plus then support common use cases like [environment files](#environment-files), [scripts and polyfills](#scripts-and-polyfills), ...\n\n## Knip\n\n### Setup\n\n`knip` was added following the [getting started guide](https://knip.dev/overview/getting-started).\n\n```shell\npnpm create @knip/config\n```\n\n\u003e [`@knip/create-config`](https://www.npmjs.com/package/@knip/create-config) version `1.0.3`\n\u003e\n\u003e [`knip`](https://www.npmjs.com/package/knip) version `5.38.3`\n\n### Initial results\n\nAfter setup, installing and running `knip`, following output was given\n\n[knip-5.38.4]: https://github.com/webpro-nl/knip/releases/tag/5.38.4\n\n[knip-5.39.0]: https://github.com/webpro-nl/knip/releases/tag/5.39.0\n\n[knip-5.42.0]: https://github.com/webpro-nl/knip/releases/tag/5.42.0\n\n#### Regular mode\n\n\u003e ##### Unused files (4)\n\u003e\n\u003e * ~~src/app/app.component.spec.ts~~ [Solved in 5.42.0][knip-5.42.0]\n\u003e * ~~src/app/app.config.server.ts~~ [Solved in 5.38.4][knip-5.38.4]\n\u003e * ~~src/app/app.routes.server.ts~~ [Solved in 5.38.4][knip-5.38.4]\n\u003e * ~~src/environments/environment.development.ts~~ [Solved in 5.39.0][knip-5.39.0]\n\u003e * ~~src/main.server.ts~~ [Solved in 5.38.4][knip-5.38.4]\n\u003e\n\u003e ##### Unused dependencies (3)\n\u003e\n\u003e | Name                                                                 | Location     | Severity |\n\u003e |:---------------------------------------------------------------------| :----------- | :------- |\n\u003e | @angular/platform-browser-dynamic                                    | package.json | error    |\n\u003e | ~~@angular/compiler~~ [Unsure why but solved in 5.42.0][knip-5.42.0] | package.json | error    |\n\u003e | @angular/forms                                                       | package.json | error    |\n\u003e\n\u003e ##### Unused devDependencies (5)\n\u003e\n\u003e | Name                                                             | Location     | Severity |\n\u003e |:-----------------------------------------------------------------|:-------------|:---------|\n\u003e | ~~karma-jasmine-html-reporter~~  [Solved in 5.42.0][knip-5.42.0] | package.json | error    |\n\u003e | ~~karma-chrome-launcher~~  [Solved in 5.42.0][knip-5.42.0]       | package.json | error    |\n\u003e | ~~karma-coverage~~  [Solved in 5.42.0][knip-5.42.0]              | package.json | error    |\n\u003e | ~~karma-jasmine~~ [Solved in 5.42.0][knip-5.42.0]                | package.json | error    |\n\u003e | ~~jasmine-core~~ [Solved in 5.42.0][knip-5.42.0]                 | package.json | error    |\n\n#### Production mode\n\n\u003e ##### Unused files (4)\n\u003e\n\u003e * ~~src/app/app.component.spec.ts~~ [Solved in 5.42.0][knip-5.42.0]\n\u003e * ~~src/app/app.config.server.ts~~ [Solved in 5.38.4][knip-5.38.4]\n\u003e * ~~src/app/app.routes.server.ts~~ [Solved in 5.38.4][knip-5.38.4]\n\u003e * ~~src/environments/environment.development.ts~~ [Solved in 5.39.0][knip-5.39.0]\n\u003e * ~~src/main.server.ts~~ [Solved in 5.38.4][knip-5.38.4]\n\u003e\n\u003e ##### Unused dependencies (3)\n\u003e\n\u003e | Name                                                                  | Location     | Severity |\n\u003e |:----------------------------------------------------------------------| :----------- | :------- |\n\u003e | @angular/platform-browser-dynamic                                     | package.json | error    |\n\u003e | ~~@angular/compiler~~ [Unsure why, but solved in 5.42.0][knip-5.42.0] | package.json | error    |\n\u003e | @angular/forms                                                        | package.json | error    |\n\u003e\n\u003e ##### Unlisted binaries (1)\n\u003e\n\u003e | Name | Location     | Severity |\n\u003e | :- | :----------- | :------- |\n\u003e | ng | package.json | error    |\n\n### Improvements\n\nThere are several improvements that can be grouped by category:\n\n#### Server Side Rendering (SSR)\n\n##### Include `src/main.server.ts`\n\n✅ **UPDATE: Done. Released as part of [v5.38.4][knip-5.38.4]**\n\nAs production entry file (comes from `angular.json` `projects.*.architect.build.options.server` when using the new ESBuild-based `application` builder).\n\nThis will then use `src/app/app.config.server.ts`. Which will then use the `serverRoutes` from `src/app/app.routes.server.ts`. So those unused reported files will be gone too.\n\n#### Testing with Karma \u0026 Jasmine\n\n✅ **UPDATE: Done. Released as part of [v5.42.0][knip-5.42.0]**\n\nBy default, Angular CLI initializes a workspace with an application with unit testing provided by Karma \u0026 Jasmine. This is specified in the Angular workspace configuration file `angular.json`, under the test target for a project: `projects.*.architect.test`. The builder is [`@angular-devkit/build-angular:karma`](https://github.com/angular/angular-cli/blob/19.0.2/packages/angular_devkit/build_angular/src/builders/karma).\n\nThis is a bit more difficult to solve. As **there is no Karma plugin yet for Knip**. So maybe a Karma plugin would first be needed to pass the configuration to it.\n\nThen, the test running is configured by a mix of the builder options and Karma configuration.\n\nBuilder options configure many things as can be seen in the [options schema][karma-builder-options-schema]. Some of those are specified by default when creating the app in `angular.json`. Checkout [the `angular.json` file](./angular.json) to see which ones. Other have some defaults as can be seen in the [options schema][karma-builder-options-schema]. So to be correct, builder options in `angular.json` should be merged with defaults.\n\nOptions in there can be grouped in these main categories:\n\n##### App build options\n\nHow the app should be built for testing purposes. So it includes many options available in `build` targets. Up until v19 app was built using the traditional, Webpack-based `browser` builder. However, [in v19 there is developer preview support for building with the newer ESBuild-based `application` / `browser-esbuild` builder][v19-test-tooling-state]. Via `builderMode` option\n\nSpecifically here are those options and how they could be used for Knip:\n\n- `main`: to add as non-production entry point (as it's a testing entry point)\n- `tsConfig`: is set to `tsconfig.spec.json` by default as you can see [in  `angular.json`](./angular.json). To add to Typescript plugin config.\n- `polyfills`: to add as non-production entry if points to a local file, or as used dependency.\n- `assets`\n- `scripts`: same as `polyfills`.\n- `styles`: N/A\n- `inlineStyleLanguage`: N/A\n- `stylePreprocessorOptions`: N/A\n- `sourceMap`: N/A\n- `progress`: N/A\n- `watch`: N/A\n- `poll`: N/A\n- `preserveSymlinks`: N/A\n- `browsers`: N/A\n- `fileReplacements`: to add as non-production entry points\n- `builderMode`: N/A\n- `webWorkerTsConfig`\n\nTaking into account that entry points that are considered production ones, if added because found here, they should not change to be considered non-production ones.\n\n##### Test files to include exclude\n\nTwo options for that:\n\n- **`include`**: defines the test files to run. Defaults to `**/*.spec.ts` as can be seen in [options schema][karma-builder-options-schema]. They should be added as non-production entry files. Some quirks:\n  - If a directory is specified, it means all `.spec.@(ts|tsx)` inside it will be included. More details [in `findTests`](https://github.com/angular/angular-cli/blob/19.0.2/packages/angular_devkit/build_angular/src/builders/karma/find-tests.ts#L14) and [in `findMatchingTests`](https://github.com/angular/angular-cli/blob/19.0.2/packages/angular_devkit/build_angular/src/builders/karma/find-tests.ts#L47) functions of the builder's implementation.\n- **`exclude`**: files to exclude for test running. For more details, check out the functions mentioned above. They should be taken into account alongst with `include` to not add those as entry files.\n\nWith that, we'd remove the `app.component.spec.ts` unused file. In a bigger app, there will be lots of them.\n\n##### Coverage options\n\nSpecifically:\n\n- `codeCoverage`: whether to generate a code coverage report or not. N/A to knip.\n- `codeCoverageExclude`: files to exclude from coverage measure. N/A to knip AFAIK.\n\nThose options may be overridden if specified in Karma configuration. However, given they're not interesting for Knip, nothing to take into account.\n\n##### Karma configuration\n\nFinally, there's the `karmaConfig` option that allows to specify the [Karma configuration][karma-config-file] to use. By default, it's unspecified and the [default Karma configuration hardcoded in the builder][karma-builder-default-config] will be used. However, one can be specified. Which may have been generated [with `ng g config`](https://angular.dev/cli/generate/config) command[^1]\n\nWith that, we could get rid of:\n\n- **Unused dependencies**: [default Karma's builder options][karma-builder-default-config] includes many `devDependencies` listed as unused in regular mode. Specifically `karma-jasmine`, `karma-chrome-launcher`, `karma-jasmine-html-reporter` and `karma-coverage`. So the only unused dependency not tracked would be `jasmine-core`. But that one could be hardcoded.\n\n[karma-builder-options-schema]: https://github.com/angular/angular-cli/blob/19.0.2/packages/angular_devkit/build_angular/src/builders/karma/schema.json\n\n[karma-builder-default-config]: https://github.com/angular/angular-cli/blob/19.0.2/packages/angular_devkit/build_angular/src/builders/karma/index.ts#L103\n\n[v19-test-tooling-state]: https://blog.angular.dev/meet-angular-v19-7b29dfd05b84#:~:text=State%20of%20testing%20tooling\n\n[karma-config-file]: https://karma-runner.github.io/6.4/config/configuration-file.html\n\nFinally, as side note, a Jest builder is available too. But [it's still experimental][v19-test-tooling-state]. So it's not the default yet.\n\n##### Plan\n\n[knip-5.40.0]: https://github.com/webpro-nl/knip/releases/tag/5.40.0\n\nSo with all this information, the way to go with this could be:\n\n- **Karma plugin for Knip** **UPDATE: ✅ Done. Released in [`5.40.0`][knip-5.40.0]**\n  - Enable if `karma` listed as development dependency.\n  - Parse [Karma config file][karma-config-file] if exists.\n  - [Test files](https://karma-runner.github.io/6.4/config/files.html): add them as non-production entry points. No defaults for that, it's a mandatory option.\n  - [Plugins](https://karma-runner.github.io/6.4/config/configuration-file.html#plugins): add dependencies listed in `plugins` configuration as used, non-production dependencies. Default is all `karma-*` dependencies.\n- **Angular's Karma builder** **UPDATE: ✅ Done. Released as part of [v5.42.0][knip-5.42.0]**\n  - Files: from builders options and their defaults.\n  - If configuration file not specified:\n    - Frameworks/plugins: from [hardcoded default Karma configuration][karma-builder-default-config] if no `karmaConfig` is specified\n  - If configuration file specified and not one of Karma default config files:\n    - Karma configuration file [Knip's `toConfig`](https://github.com/webpro-nl/knip/blob/5.38.3/packages/knip/src/util/input.ts#49)\n- ~~**Add files used Angular build options in test builder**. Seen in the [app build options](#app-build-options) above~~. It's already done, given the plugin grabs the configuration options disregarding of the test target.\n\nPlugin will be needed first before then passing configurations to it. ~~However, using the files in Angular build options for the test target is something that could be done already. However, that could come later as it's not something required hence many users may not use those.~~\n\n#### Others\n\nTo end up with a freshly generated app having nothing unused would require also fixing:\n\n##### Unused dependencies\n\nTL;DR: they're properly being reported as unused by default. As they're actually unused.\n\n- `@angular/platform-browser-dynamic`: makes sense to report as unused, as it's not used by default when creating standalone apps ([default since v17](https://blog.angular.dev/introducing-angular-v17-4d7033312e4b#:~:text=Standalone%20APIs%20from%20the%20start)). It [is used](https://github.com/angular/angular-cli/blob/19.0.2/packages/schematics/angular/application/files/standalone-files/src/main.ts.template) for module-based apps. Though it's added there in case you need to. [Seems it allows to run apps that require the JIT compiler on the client](https://angular.dev/reference/configs/npm-packages#default-dependencies:~:text=Includes%20providers%20and%20methods%20to%20compile%20and%20run%20the%20application%20on%20the%20client%20using%20the%20JIT%20compiler.). Can't say more as haven't dealt with it much.\n  - After trying to uninstall it from a project given it was apparently unneeded, Karma tests failed because couldn't be compiled. Seems the testing entrypoint is needed: `ng-virtual-main.js!=!data:text/javascript;base64,[...]:2:0-119 - Error: Module not found: Error: Can't resolve '@angular/platform-browser-dynamic/testing' in '[...]'`. So seems if using Karma testing, this is needed.\n- `@angular/compiler`: same as above. Seems if not using JIT on the client, not needed, could be a development dependency. Can't say much, haven't dealt with it. **UPDATE: no longer appearing after upgrading to 5.42.0**\n- `@angular/forms`: if not using forms, it's correctly to appear as unused, as it's not used. But Angular CLI adds it there by default so you have it there when you want to use it. Users could choose to ignore that one or uninstall it if unused.\n\n##### Unlisted binaries\n\n`ng` appears as unlisted binary in production mode. This is because `start` run script uses `ng serve`. However, Angular CLI is not listed as a production dependency. Maybe that could be ignored by default for Angular projects?\n\n##### Environment files\n\n✅ **UPDATE: Done. Released as part of [v5.39.0][knip-5.39.0]**\n\nAs seen in [app build options](#app-build-options), when an app has environment files (see [docs](https://angular.dev/tools/cli/environments#configure-environment-specific-defaults)) they should be included too. They aren't included when specified as `build` options either.\n\n##### Scripts and polyfills\n\n[knip-5.42.2]: https://github.com/webpro-nl/knip/releases/tag/5.42.2\n\n✅ **UPDATE: Done. Scripts released as part of [v5.42.0][knip-5.42.0]. Polyfills as part of [v5.42.2][knip-5.42.2]**\n\nAs seen in [app build options](#app-build-options), scripts and polyfill files to use in the app can be specified in there. They should be taken into account. Both the ones in `build` and `test` target. Those in `build` as production entries. Those in `test` as non-production entries.\n\n### Tasks\n\nSorted by high impact, low complexity first\n\n|      Status       |                        PR                        | Name                                                | Complexity | Impact |\n|:-----------------:|:------------------------------------------------:|:----------------------------------------------------|:----------:|:------:|\n| [🚀][knip-5.38.4] | [🔗](https://github.com/webpro-nl/knip/pull/865) | [SSR fixes](#server-side-rendering-ssr)             |     🟢     |   ⏫    |\n| [🚀][knip-5.39.0] | [🔗](https://github.com/webpro-nl/knip/pull/868) | [Environment files](#environment-files)             |     🟡     |   ⬆️   |\n| [🚀][knip-5.40.0] | [🔗](https://github.com/webpro-nl/knip/pull/871) | [Karma plugin](#plan)                               |     🔴     |   ⏫    |\n| [🚀][knip-5.42.0] | [🔗](https://github.com/webpro-nl/knip/pull/885) | (Needs 👆) [Angular options to Karma plugin](#plan) |     🟡     |   ⏫    |\n| [🚀][knip-5.42.0] | [🔗](https://github.com/webpro-nl/knip/pull/886) | [Scripts build option](#scripts-and-polyfills)      |     🟢     |   ⬆️   |\n| [🚀][knip-5.42.2] | [🔗](https://github.com/webpro-nl/knip/pull/913) | [Polyfills build option](#scripts-and-polyfills)    |     🟢     |   ⬆️   |\n\nComplexity means subjective implementation complexity / work / effort.\n\nImpact:\n\n- ⏫ **very high**: affects freshly baked apps by default\n- ⬆️ **high**: affects apps using subjectively usual custom configurations\n- ⬇️ **low**: affects apps with subjectively unusual custom configurations\n\n## Generation\n\nCommand used to generate this project:\n\n```shell\npnpm dlx @angular/cli@19.0.2 new a19-knip \\\n  --package-manager=pnpm \\\n  --style=css \\\n  --ssr --server-routing\n```\n\nLater, environment files were generated with `ng generate environments`. They are used as expected by logging contents of it.\n\n## Development server\n\nTo start a local development server, run:\n\n```bash\nng serve\n```\n\nOnce the server is running, open your browser and navigate to `http://localhost:4200/`. The application will automatically reload whenever you modify any of the source files.\n\n## Code scaffolding\n\nAngular CLI includes powerful code scaffolding tools. To generate a new component, run:\n\n```bash\nng generate component component-name\n```\n\nFor a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:\n\n```bash\nng generate --help\n```\n\n## Building\n\nTo build the project run:\n\n```bash\nng build\n```\n\nThis will compile your project and store the build artifacts in the `dist/` directory. By default, the production build optimizes your application for performance and speed.\n\n## Running unit tests\n\nTo execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:\n\n```bash\nng test\n```\n\n## Running end-to-end tests\n\nFor end-to-end (e2e) testing, run:\n\n```bash\nng e2e\n```\n\nAngular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.\n\n## Additional Resources\n\nFor more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.\n\n[^1]: [`karma.conf.js` template](https://github.com/angular/angular-cli/blob/19.0.2/packages/schematics/angular/config/files/karma.conf.js.template)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidlj95%2Fa19-knip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidlj95%2Fa19-knip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidlj95%2Fa19-knip/lists"}