knip 1.6.1 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -171,7 +171,20 @@ Use `--exclude` to ignore reports you're not interested in:
171
171
  Use `--dependencies` or `--exports` as shortcuts to combine groups of related types.
172
172
 
173
173
  Still not happy with the results? Getting too much output/false positives? The [FAQ][9] may be useful. Feel free to open
174
- an issue and I'm happy to look into it.
174
+ an issue and I'm happy to look into it. Also see the next section on how to [ignore][10] certain false positives:
175
+
176
+ ## Ignore
177
+
178
+ There are a few ways to tell Knip to ignore certain packages, binaries, dependencies and workspaces. Some examples:
179
+
180
+ ```json
181
+ {
182
+ "ignore": ["**/*.d.ts", "**/fixtures"],
183
+ "ignoreBinaries": ["zip", "docker-compose"],
184
+ "ignoreDependencies": ["hidden-package"],
185
+ "ignoreWorkspaces": ["packages/deno-lib"]
186
+ }
187
+ ```
175
188
 
176
189
  ## Now what?
177
190
 
@@ -223,35 +236,35 @@ Here's some example output when running Knip in a workspace:
223
236
  Knip contains a growing list of plugins:
224
237
 
225
238
  - [Babel][9]
226
- - [Capacitor][10]
227
- - [Changesets][11]
228
- - [commitlint][12]
229
- - [Cypress][13]
230
- - [ESLint][14]
231
- - [Gatsby][15]
232
- - [GitHub Actions][16]
233
- - [husky][17]
234
- - [Jest][18]
235
- - [lint-staged][19]
236
- - [markdownlint][20]
237
- - [Mocha][21]
238
- - [Next.js][22]
239
- - [npm-package-json-lint][23]
240
- - [Nx][24]
241
- - [nyc][25]
242
- - [Playwright][26]
243
- - [PostCSS][27]
244
- - [Prettier][28]
245
- - [Release It][29]
246
- - [Remark][30]
247
- - [Remix][31]
248
- - [Rollup][32]
249
- - [Sentry][33]
250
- - [Storybook][34]
251
- - [Stryker][35]
252
- - [TypeScript][36]
253
- - [Vitest][37]
254
- - [Webpack][38]
239
+ - [Capacitor][11]
240
+ - [Changesets][12]
241
+ - [commitlint][13]
242
+ - [Cypress][14]
243
+ - [ESLint][15]
244
+ - [Gatsby][16]
245
+ - [GitHub Actions][17]
246
+ - [husky][18]
247
+ - [Jest][19]
248
+ - [lint-staged][20]
249
+ - [markdownlint][21]
250
+ - [Mocha][22]
251
+ - [Next.js][23]
252
+ - [npm-package-json-lint][24]
253
+ - [Nx][25]
254
+ - [nyc][26]
255
+ - [Playwright][27]
256
+ - [PostCSS][28]
257
+ - [Prettier][29]
258
+ - [Release It][30]
259
+ - [Remark][31]
260
+ - [Remix][32]
261
+ - [Rollup][33]
262
+ - [Sentry][34]
263
+ - [Storybook][35]
264
+ - [Stryker][36]
265
+ - [TypeScript][37]
266
+ - [Vitest][38]
267
+ - [Webpack][39]
255
268
 
256
269
  Plugins are automatically activated. Each plugin is automatically enabled based on simple heuristics. Most of them check
257
270
  whether one or one of a few (dev) dependencies are listed in `package.json`. Once enabled, they add a set of
@@ -259,7 +272,7 @@ configuration and/or entry files for Knip to analyze. These defaults can be over
259
272
 
260
273
  Most plugins use one or both of the following file types:
261
274
 
262
- - `config` - custom dependency resolvers are applied to the [config files][39]
275
+ - `config` - custom dependency resolvers are applied to the [config files][40]
263
276
  - `entry` - files to include with the analysis of the rest of the source code
264
277
 
265
278
  See each plugin's documentation for its default values.
@@ -360,10 +373,10 @@ Each workspace can also have its own `paths` configured. Note that Knip `paths`
360
373
 
361
374
  Knip provides the following built-in reporters:
362
375
 
363
- - [`codeowners`][40]
364
- - [`compact`][41]
365
- - [`json`][42]
366
- - [`symbol`][43] (default)
376
+ - [`codeowners`][41]
377
+ - [`compact`][42]
378
+ - [`json`][43]
379
+ - [`symbol`][44] (default)
367
380
 
368
381
  The `compact` reporter shows the sorted files first, and then a list of symbols:
369
382
 
@@ -390,7 +403,7 @@ type ReporterOptions = {
390
403
 
391
404
  The data can then be used to write issues to `stdout`, a JSON or CSV file, or sent to a service.
392
405
 
393
- Find more details and ideas in [custom reporters][44].
406
+ Find more details and ideas in [custom reporters][45].
394
407
 
395
408
  ## Libraries and "unused" exports
396
409
 
@@ -448,7 +461,7 @@ When unused dependencies are related to dependencies having a Knip [plugin][1],
448
461
  for that dependency are at custom locations. The default values are at the plugin's documentation, and can be overridden
449
462
  to match the custom location(s).
450
463
 
451
- When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][45].
464
+ When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][46].
452
465
 
453
466
  #### Too many unused exports
454
467
 
@@ -456,7 +469,7 @@ When the project is a library and the exports are meant to be used by consumers
456
469
 
457
470
  1. By default, unused exports of `entry` files are not reported. You could re-export from an existing entry file, or
458
471
  add the containing file to the `entry` array in the configuration.
459
- 2. The exported values or types can be marked [using the JSDoc `@public` tag][46].
472
+ 2. The exported values or types can be marked [using the JSDoc `@public` tag][47].
460
473
 
461
474
  ### How to start using Knip in CI while having too many issues to sort out?
462
475
 
@@ -476,7 +489,7 @@ All of this is hiding problems, so please make sure to plan for fixing them and/
476
489
 
477
490
  This table is an ongoing comparison. Based on their docs (please report any mistakes):
478
491
 
479
- | Feature | **knip** | [depcheck][47] | [unimported][48] | [ts-unused-exports][49] | [ts-prune][50] |
492
+ | Feature | **knip** | [depcheck][48] | [unimported][49] | [ts-unused-exports][50] | [ts-prune][51] |
480
493
  | :--------------------------------- | :------: | :------------: | :--------------: | :---------------------: | :------------: |
481
494
  | Unused files | ✅ | - | ✅ | - | - |
482
495
  | Unused dependencies | ✅ | ✅ | ✅ | - | - |
@@ -490,7 +503,7 @@ This table is an ongoing comparison. Based on their docs (please report any mist
490
503
  | Custom reporters | ✅ | - | - | - | - |
491
504
  | JavaScript support | ✅ | ✅ | ✅ | - | - |
492
505
  | Configure entry files | ✅ | ❌ | ✅ | ❌ | ❌ |
493
- | [Support workspaces/monorepos][51] | ✅ | ❌ | ❌ | - | - |
506
+ | [Support workspaces/monorepos][52] | ✅ | ❌ | ❌ | - | - |
494
507
  | ESLint plugin available | - | - | - | ✅ | - |
495
508
 
496
509
  ✅ = Supported, ❌ = Not supported, - = Out of scope
@@ -511,7 +524,7 @@ The following commands are similar:
511
524
  unimported
512
525
  knip --production --dependencies --include files
513
526
 
514
- Also see [production mode][52].
527
+ Also see [production mode][53].
515
528
 
516
529
  ### ts-unused-exports
517
530
 
@@ -550,46 +563,47 @@ for the job. I'm motivated to make knip perfectly suited for the job of cutting
550
563
  [7]: https://github.com/webpro/knip/issues
551
564
  [8]: #faq
552
565
  [9]: ./src/plugins/babel
553
- [10]: ./src/plugins/capacitor
554
- [11]: ./src/plugins/changesets
555
- [12]: ./src/plugins/commitlint
556
- [13]: ./src/plugins/cypress
557
- [14]: ./src/plugins/eslint
558
- [15]: ./src/plugins/gatsby
559
- [16]: ./src/plugins/github-actions
560
- [17]: ./src/plugins/husky
561
- [18]: ./src/plugins/jest
562
- [19]: ./src/plugins/lint-staged
563
- [20]: ./src/plugins/markdownlint
564
- [21]: ./src/plugins/mocha
565
- [22]: ./src/plugins/next
566
- [23]: ./src/plugins/npm-package-json-lint
567
- [24]: ./src/plugins/nx
568
- [25]: ./src/plugins/nyc
569
- [26]: ./src/plugins/playwright
570
- [27]: ./src/plugins/postcss
571
- [28]: ./src/plugins/prettier
572
- [29]: ./src/plugins/release-it
573
- [30]: ./src/plugins/remark
574
- [31]: ./src/plugins/remix
575
- [32]: ./src/plugins/rollup
576
- [33]: ./src/plugins/sentry
577
- [34]: ./src/plugins/storybook
578
- [35]: ./src/plugins/stryker
579
- [36]: ./src/plugins/typescript
580
- [37]: ./src/plugins/vitest
581
- [38]: ./src/plugins/webpack
582
- [39]: #config
583
- [40]: #code-owners
584
- [41]: #compact
585
- [42]: #json
586
- [43]: #symbol-default
587
- [44]: ./docs/custom-reporters.md
588
- [45]: #create-a-new-plugin
589
- [46]: #libraries-and-unused-exports
590
- [47]: https://github.com/depcheck/depcheck
591
- [48]: https://github.com/smeijer/unimported
592
- [49]: https://github.com/pzavolinsky/ts-unused-exports
593
- [50]: https://github.com/nadeesha/ts-prune
594
- [51]: #workspaces--monorepos
595
- [52]: #production-mode
566
+ [10]: #ignore
567
+ [11]: ./src/plugins/capacitor
568
+ [12]: ./src/plugins/changesets
569
+ [13]: ./src/plugins/commitlint
570
+ [14]: ./src/plugins/cypress
571
+ [15]: ./src/plugins/eslint
572
+ [16]: ./src/plugins/gatsby
573
+ [17]: ./src/plugins/github-actions
574
+ [18]: ./src/plugins/husky
575
+ [19]: ./src/plugins/jest
576
+ [20]: ./src/plugins/lint-staged
577
+ [21]: ./src/plugins/markdownlint
578
+ [22]: ./src/plugins/mocha
579
+ [23]: ./src/plugins/next
580
+ [24]: ./src/plugins/npm-package-json-lint
581
+ [25]: ./src/plugins/nx
582
+ [26]: ./src/plugins/nyc
583
+ [27]: ./src/plugins/playwright
584
+ [28]: ./src/plugins/postcss
585
+ [29]: ./src/plugins/prettier
586
+ [30]: ./src/plugins/release-it
587
+ [31]: ./src/plugins/remark
588
+ [32]: ./src/plugins/remix
589
+ [33]: ./src/plugins/rollup
590
+ [34]: ./src/plugins/sentry
591
+ [35]: ./src/plugins/storybook
592
+ [36]: ./src/plugins/stryker
593
+ [37]: ./src/plugins/typescript
594
+ [38]: ./src/plugins/vitest
595
+ [39]: ./src/plugins/webpack
596
+ [40]: #config
597
+ [41]: #code-owners
598
+ [42]: #compact
599
+ [43]: #json
600
+ [44]: #symbol-default
601
+ [45]: ./docs/custom-reporters.md
602
+ [46]: #create-a-new-plugin
603
+ [47]: #libraries-and-unused-exports
604
+ [48]: https://github.com/depcheck/depcheck
605
+ [49]: https://github.com/smeijer/unimported
606
+ [50]: https://github.com/pzavolinsky/ts-unused-exports
607
+ [51]: https://github.com/nadeesha/ts-prune
608
+ [52]: #workspaces--monorepos
609
+ [53]: #production-mode
package/dist/constants.js CHANGED
@@ -7,7 +7,23 @@ export const DEFAULT_WORKSPACE_CONFIG = {
7
7
  ignore: [],
8
8
  };
9
9
  export const TEST_FILE_PATTERNS = ['**/*.{test,spec}.{js,jsx,ts,tsx}', '**/__tests__/**/*.{js,jsx,ts,tsx}'];
10
- export const IGNORED_GLOBAL_BINARIES = ['npm', 'npx', 'node', 'yarn', 'pnpm', 'deno', 'git'];
10
+ export const IGNORED_GLOBAL_BINARIES = [
11
+ 'deno',
12
+ 'git',
13
+ 'node',
14
+ 'npm',
15
+ 'npx',
16
+ 'pnpm',
17
+ 'yarn',
18
+ 'cd',
19
+ 'cp',
20
+ 'echo',
21
+ 'exit',
22
+ 'mkdir',
23
+ 'mv',
24
+ 'rm',
25
+ 'sudo',
26
+ ];
11
27
  export const IGNORE_DEFINITELY_TYPED = ['node'];
12
28
  export const ISSUE_TYPES = [
13
29
  'files',
@@ -1,4 +1,5 @@
1
1
  import { compact } from '../../util/array.js';
2
+ import { getBinariesFromScripts } from '../../util/binaries/index.js';
2
3
  import { _load } from '../../util/loader.js';
3
4
  import { timerify } from '../../util/performance.js';
4
5
  import { hasDependency } from '../../util/plugin.js';
@@ -6,10 +7,19 @@ export const NAME = 'Nx';
6
7
  export const ENABLERS = [/^@nrwl\//];
7
8
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
8
9
  export const CONFIG_FILE_PATTERNS = ['{apps,libs}/**/project.json'];
9
- const findNxDependencies = async (configFilePath) => {
10
+ const findNxDependencies = async (configFilePath, { manifest }) => {
10
11
  const config = await _load(configFilePath);
11
- const { targets } = config;
12
- const executors = targets ? Object.values(targets).map(target => target?.executor) : [];
13
- return compact(executors.filter(executor => executor && !executor.startsWith('.')).map(executor => executor?.split(':')[0]));
12
+ if (!config)
13
+ return [];
14
+ const targets = config.targets ? Object.values(config.targets) : [];
15
+ const executors = compact(targets
16
+ .map(target => target?.executor)
17
+ .filter(executor => executor && !executor.startsWith('.'))
18
+ .map(executor => executor?.split(':')[0]));
19
+ const scripts = compact(targets
20
+ .filter(target => target.executor === 'nx:run-commands')
21
+ .flatMap(target => (target.options?.commands ?? target.options?.command ? [target.options.command] : [])));
22
+ const binaries = getBinariesFromScripts(scripts, { manifest, knownGlobalsOnly: true });
23
+ return [...executors, ...binaries];
14
24
  };
15
25
  export const findDependencies = timerify(findNxDependencies);
@@ -0,0 +1,11 @@
1
+ export interface NxProjectConfiguration {
2
+ targets?: {
3
+ [targetName: string]: {
4
+ executor?: string;
5
+ options?: {
6
+ command?: string;
7
+ commands?: string[];
8
+ };
9
+ };
10
+ };
11
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "1.6.1",
3
+ "version": "1.7.0",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://github.com/webpro/knip",
6
6
  "repository": "github:webpro/knip",
@@ -43,7 +43,7 @@
43
43
  "@snyk/github-codeowners": "^1.1.0",
44
44
  "chalk": "^5.2.0",
45
45
  "easy-table": "^1.2.0",
46
- "esbuild": "^0.17.2",
46
+ "esbuild": "^0.17.3",
47
47
  "esbuild-register": "3.4.2",
48
48
  "eslint": "^8.32.0",
49
49
  "fast-glob": "^3.2.12",