knip 1.7.1 → 1.9.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
@@ -19,29 +19,29 @@ The dots don't connect themselves. This is where Knip comes in:
19
19
  - [x] Finds used dependencies not listed in `package.json`
20
20
  - [x] Finds duplicate exports
21
21
  - [x] Finds unused members of classes and enums
22
- - [x] Built-in support for monorepos/workspaces
23
- - [x] Growing list of [built-in plugins][1]
22
+ - [x] Built-in support for [monorepos/workspaces][1]
23
+ - [x] Growing list of [built-in plugins][2]
24
24
  - [x] Checks npm scripts for used and unlisted dependencies
25
25
  - [x] Supports JavaScript (without `tsconfig.json`, or TypeScript `allowJs: true`)
26
- - [x] Features multiple [reporters][2] and supports [custom reporters][3]
26
+ - [x] Features multiple [reporters][3] and supports [custom reporters][4]
27
27
  - [x] Run Knip as part of your CI environment to detect issues and prevent regressions
28
28
 
29
29
  Knip shines in both small and large projects. It's a fresh take on keeping your projects clean & tidy!
30
30
 
31
- [![An orange cow with scissors, Van Gogh style][5]][4] <sup>_“An orange cow with scissors, Van Gogh style” - generated
31
+ [![An orange cow with scissors, Van Gogh style][6]][5] <sup>_“An orange cow with scissors, Van Gogh style” - generated
32
32
  with OpenAI_</sup>
33
33
 
34
34
  ## Migrating to v1.0.0
35
35
 
36
- When coming from version v0.13.3 or before, please see [migration to v1][6].
36
+ When coming from version v0.13.3 or before, please see [migration to v1][7].
37
37
 
38
38
  ## Issues
39
39
 
40
- Are you seeing false positives? Please report them by [opening an issue in this repo][7]. Bonus points for linking to a
40
+ Are you seeing false positives? Please report them by [opening an issue in this repo][8]. Bonus points for linking to a
41
41
  public repository using Knip, or even opening a pull request with a directory and example files in `test/fixtures`.
42
42
  Correctness and bug fixes have priority over performance and new features.
43
43
 
44
- Also see the [FAQ][8].
44
+ Also see the [FAQ][9].
45
45
 
46
46
  ## Installation
47
47
 
@@ -66,6 +66,21 @@ with a configuration file (or a `knip` property in `package.json`). Let's name t
66
66
  The `entry` files target the starting point(s) to resolve the rest of the imported code. The `project` files should
67
67
  contain all files to match against the files resolved from the entry files, including potentially unused files.
68
68
 
69
+ Use `knip.ts` with TypeScript if you prefer:
70
+
71
+ ```ts
72
+ import type { KnipConfig } from 'knip';
73
+
74
+ const config: KnipConfig = {
75
+ entry: ['src/index.ts'],
76
+ project: ['src/**/*.ts'],
77
+ };
78
+
79
+ export default config;
80
+ ```
81
+
82
+ If you have, please see [workspaces & monorepos][1].
83
+
69
84
  Then run the checks with `npx knip`. Or first add this script to `package.json`:
70
85
 
71
86
  ```json
@@ -82,11 +97,13 @@ Use `npm run knip` to analyze the project and output unused files, dependencies
82
97
  ## Command-line options
83
98
 
84
99
  $ npx knip --help
85
- knip [options]
100
+ ✂️ Find unused files, dependencies and exports in your JavaScript and TypeScript projects
101
+
102
+ Usage: knip [options]
86
103
 
87
104
  Options:
88
- -c/--config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)
89
- -t/--tsConfig [file] TypeScript configuration path (default: tsconfig.json)
105
+ -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)
106
+ -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)
90
107
  --production Analyze only production source files (e.g. no tests, devDependencies, exported types)
91
108
  --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)
92
109
  --workspace Analyze a single workspace (default: analyze all configured workspaces)
@@ -105,6 +122,8 @@ Use `npm run knip` to analyze the project and output unused files, dependencies
105
122
  --debug Show debug output
106
123
  --debug-file-filter Filter for files in debug output (regex as string)
107
124
  --performance Measure running time of expensive functions and display stats table
125
+ --h, --help Print this help text
126
+ --V, version Print version
108
127
 
109
128
  (1) Issue types: files, dependencies, unlisted, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates
110
129
 
@@ -117,7 +136,7 @@ Use `npm run knip` to analyze the project and output unused files, dependencies
117
136
  $ knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'
118
137
  $ knip --debug --debug-file-filter '(specific|particular)-module'
119
138
 
120
- More info: https://github.com/webpro/knip
139
+ More documentation and bug reports: https://github.com/webpro/knip
121
140
 
122
141
  ## Screenshots
123
142
 
@@ -221,8 +240,13 @@ be part of the analysis. Here's an example:
221
240
  }
222
241
  ```
223
242
 
224
- All `workspaces` or `workspaces.packages` in `package.json` with a match in `workspaces` of `Knip.json` are part of the
225
- analysis.
243
+ Knip supports workspaces as defined in three possible locations:
244
+
245
+ - In the `workspaces` array in `package.json`.
246
+ - In the `workspaces.packages` array in `package.json`.
247
+ - In the `packages` array in `pnpm-workspace.yaml`.
248
+
249
+ Every directory with a match in `workspaces` of `knip.json` is part of the analysis.
226
250
 
227
251
  Extra "workspaces" not configured as a workspace in the root `package.json` can be configured as well, Knip is happy to
228
252
  analyze unused dependencies and exports from any directory with a `package.json`.
@@ -235,36 +259,36 @@ Here's some example output when running Knip in a workspace:
235
259
 
236
260
  Knip contains a growing list of plugins:
237
261
 
238
- - [Babel][9]
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]
262
+ - [Babel][11]
263
+ - [Capacitor][12]
264
+ - [Changesets][13]
265
+ - [commitlint][14]
266
+ - [Cypress][15]
267
+ - [ESLint][16]
268
+ - [Gatsby][17]
269
+ - [GitHub Actions][18]
270
+ - [husky][19]
271
+ - [Jest][20]
272
+ - [lint-staged][21]
273
+ - [markdownlint][22]
274
+ - [Mocha][23]
275
+ - [Next.js][24]
276
+ - [npm-package-json-lint][25]
277
+ - [Nx][26]
278
+ - [nyc][27]
279
+ - [Playwright][28]
280
+ - [PostCSS][29]
281
+ - [Prettier][30]
282
+ - [Release It][31]
283
+ - [Remark][32]
284
+ - [Remix][33]
285
+ - [Rollup][34]
286
+ - [Sentry][35]
287
+ - [Storybook][36]
288
+ - [Stryker][37]
289
+ - [TypeScript][38]
290
+ - [Vitest][39]
291
+ - [Webpack][40]
268
292
 
269
293
  Plugins are automatically activated. Each plugin is automatically enabled based on simple heuristics. Most of them check
270
294
  whether one or one of a few (dev) dependencies are listed in `package.json`. Once enabled, they add a set of
@@ -272,7 +296,7 @@ configuration and/or entry files for Knip to analyze. These defaults can be over
272
296
 
273
297
  Most plugins use one or both of the following file types:
274
298
 
275
- - `config` - custom dependency resolvers are applied to the [config files][40]
299
+ - `config` - custom dependency resolvers are applied to the [config files][41]
276
300
  - `entry` - files to include with the analysis of the rest of the source code
277
301
 
278
302
  See each plugin's documentation for its default values.
@@ -356,7 +380,7 @@ aliases. They can be configured manually:
356
380
 
357
381
  ```json
358
382
  {
359
- "$schema": "/Users/lars/p/knip/schema.json",
383
+ "$schema": "https://unpkg.com/knip@1/schema.json",
360
384
  "paths": {
361
385
  "@lib": ["./lib/index.ts"],
362
386
  "@lib/*": ["./lib/*"]
@@ -373,10 +397,10 @@ Each workspace can also have its own `paths` configured. Note that Knip `paths`
373
397
 
374
398
  Knip provides the following built-in reporters:
375
399
 
376
- - [`codeowners`][41]
377
- - [`compact`][42]
378
- - [`json`][43]
379
- - [`symbol`][44] (default)
400
+ - [`codeowners`][42]
401
+ - [`compact`][43]
402
+ - [`json`][44]
403
+ - [`symbol`][45] (default)
380
404
 
381
405
  The `compact` reporter shows the sorted files first, and then a list of symbols:
382
406
 
@@ -403,7 +427,7 @@ type ReporterOptions = {
403
427
 
404
428
  The data can then be used to write issues to `stdout`, a JSON or CSV file, or sent to a service.
405
429
 
406
- Find more details and ideas in [custom reporters][45].
430
+ Find more details and ideas in [custom reporters][46].
407
431
 
408
432
  ## Libraries and "unused" exports
409
433
 
@@ -461,7 +485,7 @@ When unused dependencies are related to dependencies having a Knip [plugin][1],
461
485
  for that dependency are at custom locations. The default values are at the plugin's documentation, and can be overridden
462
486
  to match the custom location(s).
463
487
 
464
- When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][46].
488
+ When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][47].
465
489
 
466
490
  #### Too many unused exports
467
491
 
@@ -469,7 +493,7 @@ When the project is a library and the exports are meant to be used by consumers
469
493
 
470
494
  1. By default, unused exports of `entry` files are not reported. You could re-export from an existing entry file, or
471
495
  add the containing file to the `entry` array in the configuration.
472
- 2. The exported values or types can be marked [using the JSDoc `@public` tag][47].
496
+ 2. The exported values or types can be marked [using the JSDoc `@public` tag][48].
473
497
 
474
498
  ### How to start using Knip in CI while having too many issues to sort out?
475
499
 
@@ -489,7 +513,7 @@ All of this is hiding problems, so please make sure to plan for fixing them and/
489
513
 
490
514
  This table is an ongoing comparison. Based on their docs (please report any mistakes):
491
515
 
492
- | Feature | **knip** | [depcheck][48] | [unimported][49] | [ts-unused-exports][50] | [ts-prune][51] |
516
+ | Feature | **knip** | [depcheck][49] | [unimported][50] | [ts-unused-exports][51] | [ts-prune][52] |
493
517
  | :--------------------------------- | :------: | :------------: | :--------------: | :---------------------: | :------------: |
494
518
  | Unused files | ✅ | - | ✅ | - | - |
495
519
  | Unused dependencies | ✅ | ✅ | ✅ | - | - |
@@ -554,56 +578,56 @@ userland territory, much like code linters.
554
578
  Knip is Dutch for a "cut". A Dutch expression is "to be ge**knip**t for something", which means to be perfectly suited
555
579
  for the job. I'm motivated to make knip perfectly suited for the job of cutting projects to perfection! ✂️
556
580
 
557
- [1]: #plugins
558
- [2]: #reporters
559
- [3]: #custom-reporters
560
- [4]: https://labs.openai.com/s/xZQACaLepaKya0PRUPtIN5dC
561
- [5]: ./assets/cow-with-orange-scissors-van-gogh-style.webp
562
- [6]: ./docs/migration-to-v1.md
563
- [7]: https://github.com/webpro/knip/issues
564
- [8]: #faq
565
- [9]: ./src/plugins/babel
581
+ [1]: #workspaces--monorepos
582
+ [2]: #plugins
583
+ [3]: #reporters
584
+ [4]: #custom-reporters
585
+ [5]: https://labs.openai.com/s/xZQACaLepaKya0PRUPtIN5dC
586
+ [6]: ./assets/cow-with-orange-scissors-van-gogh-style.webp
587
+ [7]: ./docs/migration-to-v1.md
588
+ [8]: https://github.com/webpro/knip/issues
589
+ [9]: #faq
566
590
  [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
591
+ [11]: ./src/plugins/babel
592
+ [12]: ./src/plugins/capacitor
593
+ [13]: ./src/plugins/changesets
594
+ [14]: ./src/plugins/commitlint
595
+ [15]: ./src/plugins/cypress
596
+ [16]: ./src/plugins/eslint
597
+ [17]: ./src/plugins/gatsby
598
+ [18]: ./src/plugins/github-actions
599
+ [19]: ./src/plugins/husky
600
+ [20]: ./src/plugins/jest
601
+ [21]: ./src/plugins/lint-staged
602
+ [22]: ./src/plugins/markdownlint
603
+ [23]: ./src/plugins/mocha
604
+ [24]: ./src/plugins/next
605
+ [25]: ./src/plugins/npm-package-json-lint
606
+ [26]: ./src/plugins/nx
607
+ [27]: ./src/plugins/nyc
608
+ [28]: ./src/plugins/playwright
609
+ [29]: ./src/plugins/postcss
610
+ [30]: ./src/plugins/prettier
611
+ [31]: ./src/plugins/release-it
612
+ [32]: ./src/plugins/remark
613
+ [33]: ./src/plugins/remix
614
+ [34]: ./src/plugins/rollup
615
+ [35]: ./src/plugins/sentry
616
+ [36]: ./src/plugins/storybook
617
+ [37]: ./src/plugins/stryker
618
+ [38]: ./src/plugins/typescript
619
+ [39]: ./src/plugins/vitest
620
+ [40]: ./src/plugins/webpack
621
+ [41]: #config
622
+ [42]: #code-owners
623
+ [43]: #compact
624
+ [44]: #json
625
+ [45]: #symbol-default
626
+ [46]: ./docs/custom-reporters.md
627
+ [47]: #create-a-new-plugin
628
+ [48]: #libraries-and-unused-exports
629
+ [49]: https://github.com/depcheck/depcheck
630
+ [50]: https://github.com/smeijer/unimported
631
+ [51]: https://github.com/pzavolinsky/ts-unused-exports
632
+ [52]: https://github.com/nadeesha/ts-prune
609
633
  [53]: #production-mode
package/dist/cli.js CHANGED
@@ -6,13 +6,18 @@ import parsedArgs, { helpText } from './util/cli-arguments.js';
6
6
  import { ConfigurationError } from './util/errors.js';
7
7
  import { _load } from './util/loader.js';
8
8
  import { measure } from './util/performance.js';
9
+ import { version } from './version.js';
9
10
  import { main } from './index.js';
10
11
  register();
11
- const { values: { debug: isDebug = false, help, 'include-entry-exports': isIncludeEntryExports = false, 'max-issues': maxIssues = '0', 'no-exit-code': noExitCode = false, 'no-gitignore': isNoGitIgnore = false, 'no-progress': isNoProgress = false, production: isProduction = false, reporter = 'symbols', 'reporter-options': reporterOptions = '', strict: isStrict = false, tsConfig, }, } = parsedArgs;
12
- if (help) {
12
+ const { values: { debug: isDebug = false, help: isHelp, 'include-entry-exports': isIncludeEntryExports = false, 'max-issues': maxIssues = '0', 'no-exit-code': noExitCode = false, 'no-gitignore': isNoGitIgnore = false, 'no-progress': isNoProgress = false, production: isProduction = false, reporter = 'symbols', 'reporter-options': reporterOptions = '', strict: isStrict = false, tsConfig, version: isVersion, }, } = parsedArgs;
13
+ if (isHelp) {
13
14
  console.log(helpText);
14
15
  process.exit(0);
15
16
  }
17
+ if (isVersion) {
18
+ console.log(version);
19
+ process.exit(0);
20
+ }
16
21
  const cwd = process.cwd();
17
22
  const isShowProgress = !isDebug && isNoProgress === false && process.stdout.isTTY && typeof process.stdout.cursorTo === 'function';
18
23
  const printReport = reporter in reporters ? reporters[reporter] : await _load(path.join(cwd, reporter));
@@ -12,6 +12,7 @@ export default class ConfigurationChief {
12
12
  manifestPath: undefined | string;
13
13
  manifest: undefined | PackageJson;
14
14
  manifestWorkspaces: undefined | string[];
15
+ resolvedConfigFilePath: undefined | string;
15
16
  constructor({ cwd, isProduction }: ConfigurationManagerOptions);
16
17
  loadLocalConfig(): Promise<void>;
17
18
  normalize(rawLocalConfig: RawConfiguration): {
@@ -34,29 +34,34 @@ export default class ConfigurationChief {
34
34
  manifestPath;
35
35
  manifest;
36
36
  manifestWorkspaces;
37
+ resolvedConfigFilePath;
37
38
  constructor({ cwd, isProduction }) {
38
39
  this.cwd = cwd;
39
40
  this.isProduction = isProduction;
40
41
  this.config = defaultConfig;
41
42
  }
42
43
  async loadLocalConfig() {
43
- const manifestPath = await findFile(this.cwd, 'package.json');
44
+ const manifestPath = findFile(this.cwd, 'package.json');
44
45
  const manifest = manifestPath && (await loadJSON(manifestPath));
45
46
  if (!manifestPath || !manifest) {
46
47
  throw new ConfigurationError('Unable to find package.json');
47
48
  }
48
49
  this.manifestPath = manifestPath;
49
50
  this.manifest = manifest;
50
- let resolvedConfigFilePath;
51
+ const pnpmWorkspacesPath = findFile(this.cwd, 'pnpm-workspace.yaml');
52
+ const pnpmWorkspaces = pnpmWorkspacesPath && (await _load(pnpmWorkspacesPath));
53
+ if (this.manifest && !this.manifest.workspaces && pnpmWorkspaces) {
54
+ this.manifest.workspaces = pnpmWorkspaces;
55
+ }
51
56
  for (const configPath of rawConfigArg ? [rawConfigArg] : KNIP_CONFIG_LOCATIONS) {
52
- resolvedConfigFilePath = await findFile(this.cwd, configPath);
53
- if (resolvedConfigFilePath)
57
+ this.resolvedConfigFilePath = findFile(this.cwd, configPath);
58
+ if (this.resolvedConfigFilePath)
54
59
  break;
55
60
  }
56
- if (rawConfigArg && !resolvedConfigFilePath && !manifest.knip) {
61
+ if (rawConfigArg && !this.resolvedConfigFilePath && !manifest.knip) {
57
62
  throw new ConfigurationError(`Unable to find ${rawConfigArg} or package.json#knip`);
58
63
  }
59
- const rawLocalConfig = resolvedConfigFilePath ? await _load(resolvedConfigFilePath) : manifest.knip;
64
+ const rawLocalConfig = this.resolvedConfigFilePath ? await _load(this.resolvedConfigFilePath) : manifest.knip;
60
65
  if (rawLocalConfig) {
61
66
  this.config = this.normalize(ConfigurationValidator.parse(rawLocalConfig));
62
67
  }
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ import WorkspaceWorker from './workspace-worker.js';
17
17
  export const main = async (unresolvedConfiguration) => {
18
18
  const { cwd, tsConfigFile, gitignore, isStrict, isProduction, isShowProgress, isIncludeEntryExports } = unresolvedConfiguration;
19
19
  const chief = new ConfigurationChief({ cwd, isProduction });
20
- debugLogObject('Unresolved configuration', unresolvedConfiguration);
20
+ debugLogObject('Unresolved configuration (from CLI arguments)', unresolvedConfiguration);
21
21
  const collector = new IssueCollector({ cwd, isShowProgress });
22
22
  collector.updateMessage('Reading configuration and manifest files...');
23
23
  await chief.loadLocalConfig();
@@ -34,7 +34,7 @@ export const main = async (unresolvedConfiguration) => {
34
34
  for (const { name, dir, config, ancestors } of workspaces) {
35
35
  const isRoot = name === ROOT_WORKSPACE_NAME;
36
36
  const suffix = isRoot ? '' : ` (${name})`;
37
- const manifestPath = isRoot ? chief.manifestPath : await findFile(dir, 'package.json');
37
+ const manifestPath = isRoot ? chief.manifestPath : findFile(dir, 'package.json');
38
38
  const manifest = isRoot ? chief.manifest : manifestPath && (await loadJSON(manifestPath));
39
39
  if (!manifestPath || !manifest)
40
40
  continue;
@@ -195,6 +195,9 @@ export const main = async (unresolvedConfiguration) => {
195
195
  }
196
196
  collector.setReport(report);
197
197
  collector.updateMessage('Connecting the dots...');
198
+ if (chief.resolvedConfigFilePath) {
199
+ principal.removeProjectPath(chief.resolvedConfigFilePath);
200
+ }
198
201
  principal.createProjects();
199
202
  const moduleSpecifierCache = new WeakMap();
200
203
  const resolvedFiles = principal.getResolvedFiles();
@@ -12,6 +12,7 @@ export default class ProjectPrincipal {
12
12
  addEntryPath(filePath: string): void;
13
13
  addSourceFile(filePath: string): void;
14
14
  addProjectPath(filePath: string): void;
15
+ removeProjectPath(filePath: string): void;
15
16
  addTypeScriptPaths(workspaceDir: string, compilerOptions: TsConfigJson['compilerOptions']): void;
16
17
  createProjects(): void;
17
18
  getResolvedFiles(): SourceFile[];
@@ -31,6 +31,9 @@ export default class ProjectPrincipal {
31
31
  addProjectPath(filePath) {
32
32
  this.projectPaths.add(filePath);
33
33
  }
34
+ removeProjectPath(filePath) {
35
+ this.projectPaths.delete(filePath);
36
+ }
34
37
  addTypeScriptPaths(workspaceDir, compilerOptions) {
35
38
  if (!compilerOptions || !compilerOptions.paths)
36
39
  return;
@@ -13,7 +13,7 @@ export default async ({ report, issues, options }) => {
13
13
  }
14
14
  const json = {};
15
15
  const codeownersFilePath = path.resolve(opts.codeowners ?? '.github/CODEOWNERS');
16
- const codeownersEngine = (await isFile(codeownersFilePath)) && OwnershipEngine.FromCodeownersFile(codeownersFilePath);
16
+ const codeownersEngine = isFile(codeownersFilePath) && OwnershipEngine.FromCodeownersFile(codeownersFilePath);
17
17
  const flatten = (issues) => Object.values(issues).map(Object.values).flat();
18
18
  const initRow = (filePath) => {
19
19
  const file = relative(filePath);
@@ -1,4 +1,4 @@
1
- export declare const helpText = "knip [options]\n\nOptions:\n -c/--config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)\n -t/--tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n --production Analyze only production source files (e.g. no tests, devDependencies, exported types)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n --workspace Analyze a single workspace (default: analyze all configured workspaces)\n --include-entry-exports Include unused exports in entry files (without `@public`)\n --ignore Ignore files matching this glob pattern, can be repeated\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --no-progress Don't show dynamic progress updates\n --reporter Select reporter: symbols, compact, codeowners, json (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --no-exit-code Always exit with code zero (0)\n --max-issues Maximum number of issues before non-zero exit code (default: 0)\n --debug Show debug output\n --debug-file-filter Filter for files in debug output (regex as string)\n --performance Measure running time of expensive functions and display stats table\n\n(1) Issue types: files, dependencies, unlisted, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --debug --debug-file-filter '(specific|particular)-module'\n\nMore info: https://github.com/webpro/knip";
1
+ export declare const helpText = "\u2702\uFE0F Find unused files, dependencies and exports in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n --production Analyze only production source files (e.g. no tests, devDependencies, exported types)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n --workspace Analyze a single workspace (default: analyze all configured workspaces)\n --include-entry-exports Include unused exports in entry files (without `@public`)\n --ignore Ignore files matching this glob pattern, can be repeated\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --no-progress Don't show dynamic progress updates\n --reporter Select reporter: symbols, compact, codeowners, json (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --no-exit-code Always exit with code zero (0)\n --max-issues Maximum number of issues before non-zero exit code (default: 0)\n --debug Show debug output\n --debug-file-filter Filter for files in debug output (regex as string)\n --performance Measure running time of expensive functions and display stats table\n --h, --help Print this help text\n --V, version Print version\n\n(1) Issue types: files, dependencies, unlisted, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --debug --debug-file-filter '(specific|particular)-module'\n\nMore documentation and bug reports: https://github.com/webpro/knip";
2
2
  declare const _default: {
3
3
  values: {
4
4
  config: string | undefined;
@@ -21,6 +21,7 @@ declare const _default: {
21
21
  'reporter-options': string | undefined;
22
22
  strict: boolean | undefined;
23
23
  tsConfig: string | undefined;
24
+ version: boolean | undefined;
24
25
  workspace: string | undefined;
25
26
  };
26
27
  positionals: [];
@@ -1,9 +1,11 @@
1
1
  import { parseArgs } from 'node:util';
2
- export const helpText = `knip [options]
2
+ export const helpText = `✂️ Find unused files, dependencies and exports in your JavaScript and TypeScript projects
3
+
4
+ Usage: knip [options]
3
5
 
4
6
  Options:
5
- -c/--config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)
6
- -t/--tsConfig [file] TypeScript configuration path (default: tsconfig.json)
7
+ -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)
8
+ -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)
7
9
  --production Analyze only production source files (e.g. no tests, devDependencies, exported types)
8
10
  --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)
9
11
  --workspace Analyze a single workspace (default: analyze all configured workspaces)
@@ -22,6 +24,8 @@ Options:
22
24
  --debug Show debug output
23
25
  --debug-file-filter Filter for files in debug output (regex as string)
24
26
  --performance Measure running time of expensive functions and display stats table
27
+ --h, --help Print this help text
28
+ --V, version Print version
25
29
 
26
30
  (1) Issue types: files, dependencies, unlisted, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates
27
31
 
@@ -34,7 +38,7 @@ $ knip -c ./config/knip.json --reporter compact
34
38
  $ knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'
35
39
  $ knip --debug --debug-file-filter '(specific|particular)-module'
36
40
 
37
- More info: https://github.com/webpro/knip`;
41
+ More documentation and bug reports: https://github.com/webpro/knip`;
38
42
  export default parseArgs({
39
43
  options: {
40
44
  config: { type: 'string', short: 'c' },
@@ -57,6 +61,7 @@ export default parseArgs({
57
61
  'reporter-options': { type: 'string' },
58
62
  strict: { type: 'boolean' },
59
63
  tsConfig: { type: 'string', short: 't' },
64
+ version: { type: 'boolean', short: 'V' },
60
65
  workspace: { type: 'string' },
61
66
  },
62
67
  });
@@ -3,7 +3,7 @@ import { isFile } from './fs.js';
3
3
  import { logIfDebug } from './log.js';
4
4
  export const loadTSConfig = async (tsConfigFilePath) => {
5
5
  try {
6
- if (await isFile(tsConfigFilePath)) {
6
+ if (isFile(tsConfigFilePath)) {
7
7
  return parseTsconfig(tsConfigFilePath);
8
8
  }
9
9
  }
@@ -0,0 +1 @@
1
+ export declare const version = "1.9.0";
@@ -0,0 +1 @@
1
+ export const version = '1.9.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "1.7.1",
3
+ "version": "1.9.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",
@@ -63,6 +63,7 @@
63
63
  "devDependencies": {
64
64
  "@jest/types": "29.3.1",
65
65
  "@npmcli/package-json": "3.0.0",
66
+ "@release-it/bumper": "^4.0.2",
66
67
  "@types/eslint": "8.4.10",
67
68
  "@types/js-yaml": "4.0.5",
68
69
  "@types/micromatch": "4.0.2",
@@ -98,6 +99,11 @@
98
99
  },
99
100
  "github": {
100
101
  "release": true
102
+ },
103
+ "plugins": {
104
+ "@release-it/bumper": {
105
+ "out": "{dist,src}/version.*"
106
+ }
101
107
  }
102
108
  },
103
109
  "remarkConfig": {