knip 1.5.0 → 1.6.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
@@ -254,7 +254,8 @@ Knip contains a growing list of plugins:
254
254
  - [Storybook][35]
255
255
  - [Stryker][36]
256
256
  - [TypeScript][37]
257
- - [Webpack][38]
257
+ - [Vitest][38]
258
+ - [Webpack][39]
258
259
 
259
260
  Plugins are automatically activated, no need to enable anything. Each plugin is automatically enabled based on simple
260
261
  heuristics. Most of them check whether one or one of a few (dev) dependencies are listed in `package.json`. Once
@@ -262,7 +263,7 @@ enabled, they add a set of configuration and/or entry files for Knip to analyze.
262
263
 
263
264
  Most plugins use one or both of the following file types:
264
265
 
265
- - `config` - custom dependency resolvers are applied to the [config files][39]
266
+ - `config` - custom dependency resolvers are applied to the [config files][40]
266
267
  - `entry` - files to include with the analysis of the rest of the source code
267
268
 
268
269
  See each plugin's documentation for its default values.
@@ -338,14 +339,35 @@ Plugins also have this distinction. For instance, Next.js entry files for pages
338
339
  this is handled automatically by Knip and its plugins. You only need to point Knip to additional files or custom file
339
340
  locations. The more plugins Knip will have, the more projects can be analyzed out of the box!
340
341
 
342
+ ## Paths
343
+
344
+ Tools like TypeScript, Webpack and Babel support import aliases in various ways. Knip automatically includes
345
+ `compilerOptions.paths` from the TypeScript configuration, but does not (yet) automatically find other types of import
346
+ aliases. They can be configured manually:
347
+
348
+ ```json
349
+ {
350
+ "$schema": "/Users/lars/p/knip/schema.json",
351
+ "paths": {
352
+ "@lib": ["./lib/index.ts"],
353
+ "@lib/*": ["./lib/*"]
354
+ }
355
+ }
356
+ ```
357
+
358
+ Each workspace can also have its own `paths` configured. Note that Knip `paths` follow the TypeScript semantics:
359
+
360
+ - Path values is an array of relative paths.
361
+ - Paths without an `*` are exact matches.
362
+
341
363
  ## Reporters
342
364
 
343
365
  Knip provides the following built-in reporters:
344
366
 
345
- - [`codeowners`][40]
346
- - [`compact`][41]
347
- - [`json`][42]
348
- - [`symbol`][43] (default)
367
+ - [`codeowners`][41]
368
+ - [`compact`][42]
369
+ - [`json`][43]
370
+ - [`symbol`][44] (default)
349
371
 
350
372
  The `compact` reporter shows the sorted files first, and then a list of symbols:
351
373
 
@@ -372,7 +394,7 @@ type ReporterOptions = {
372
394
 
373
395
  The data can then be used to write issues to `stdout`, a JSON or CSV file, or sent to a service.
374
396
 
375
- Find more details and ideas in [custom reporters][44].
397
+ Find more details and ideas in [custom reporters][45].
376
398
 
377
399
  ## Libraries and "unused" exports
378
400
 
@@ -429,14 +451,14 @@ When unused dependencies are related to dependencies having a Knip [plugin][1],
429
451
  for that dependency are at custom locations. The default values are at the plugin's documentation, and can be overridden
430
452
  to match the custom location(s).
431
453
 
432
- When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][45].
454
+ When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][46].
433
455
 
434
456
  #### Too many unused exports
435
457
 
436
458
  When the project is a library and the exports are meant to be used by consumers of the library, there are two options:
437
459
 
438
460
  1. By default, unused exports of `entry` files are not reported, so you can add the containing file to it.
439
- 2. The exported values or types can be marked [using the JSDoc `@public` tag][46].
461
+ 2. The exported values or types can be marked [using the JSDoc `@public` tag][47].
440
462
 
441
463
  ### How to start using Knip in CI while having too many issues to sort out?
442
464
 
@@ -453,7 +475,7 @@ All of this is hiding problems, so please make sure to plan for fixing them and/
453
475
 
454
476
  This table is an ongoing comparison. Based on their docs (please report any mistakes):
455
477
 
456
- | Feature | **knip** | [depcheck][47] | [unimported][48] | [ts-unused-exports][49] | [ts-prune][50] |
478
+ | Feature | **knip** | [depcheck][48] | [unimported][49] | [ts-unused-exports][50] | [ts-prune][51] |
457
479
  | :--------------------------------- | :------: | :------------: | :--------------: | :---------------------: | :------------: |
458
480
  | Unused files | ✅ | - | ✅ | - | - |
459
481
  | Unused dependencies | ✅ | ✅ | ✅ | - | - |
@@ -467,7 +489,7 @@ This table is an ongoing comparison. Based on their docs (please report any mist
467
489
  | Custom reporters | ✅ | - | - | - | - |
468
490
  | JavaScript support | ✅ | ✅ | ✅ | - | - |
469
491
  | Configure entry files | ✅ | ❌ | ✅ | ❌ | ❌ |
470
- | [Support workspaces/monorepos][51] | ✅ | ❌ | ❌ | - | - |
492
+ | [Support workspaces/monorepos][52] | ✅ | ❌ | ❌ | - | - |
471
493
  | ESLint plugin available | - | - | - | ✅ | - |
472
494
 
473
495
  ✅ = Supported, ❌ = Not supported, - = Out of scope
@@ -488,7 +510,7 @@ The following commands are similar:
488
510
  unimported
489
511
  knip --production --dependencies --include files
490
512
 
491
- Also see [production mode][52].
513
+ Also see [production mode][53].
492
514
 
493
515
  ### ts-unused-exports
494
516
 
@@ -555,18 +577,19 @@ for the job. I'm motivated to make knip perfectly suited for the job of cutting
555
577
  [35]: ./src/plugins/storybook
556
578
  [36]: ./src/plugins/stryker
557
579
  [37]: ./src/plugins/typescript
558
- [38]: ./src/plugins/webpack
559
- [39]: #config
560
- [40]: #code-owners
561
- [41]: #compact
562
- [42]: #json
563
- [43]: #symbol-default
564
- [44]: ./docs/custom-reporters.md
565
- [45]: #create-a-new-plugin
566
- [46]: #libraries-and-unused-exports
567
- [47]: https://github.com/depcheck/depcheck
568
- [48]: https://github.com/smeijer/unimported
569
- [49]: https://github.com/pzavolinsky/ts-unused-exports
570
- [50]: https://github.com/nadeesha/ts-prune
571
- [51]: #workspaces--monorepos
572
- [52]: #production-mode
580
+ [38]: ./src/plugins/vitest
581
+ [39]: ./src/plugins/webpack
582
+ [40]: #config
583
+ [41]: #code-owners
584
+ [42]: #compact
585
+ [43]: #json
586
+ [44]: #symbol-default
587
+ [45]: ./docs/custom-reporters.md
588
+ [46]: #create-a-new-plugin
589
+ [47]: #libraries-and-unused-exports
590
+ [48]: https://github.com/depcheck/depcheck
591
+ [49]: https://github.com/smeijer/unimported
592
+ [50]: https://github.com/pzavolinsky/ts-unused-exports
593
+ [51]: https://github.com/nadeesha/ts-prune
594
+ [52]: #workspaces--monorepos
595
+ [53]: #production-mode
@@ -90,23 +90,25 @@ export default class ConfigurationChief {
90
90
  : workspaceConfig.entry
91
91
  ? entry
92
92
  : defaultWorkspaceConfig.project;
93
+ const paths = workspaceConfig.paths ?? defaultWorkspaceConfig.paths;
93
94
  workspaces[workspaceName] = {
94
95
  entry,
95
96
  project,
97
+ paths,
96
98
  ignore: arrayify(workspaceConfig.ignore),
97
99
  };
98
- for (const [pluginName, pluginConfig] of Object.entries(workspaceConfig)) {
99
- const name = toCamelCase(pluginName);
100
- if (PLUGIN_NAMES.includes(name)) {
100
+ for (const [name, pluginConfig] of Object.entries(workspaceConfig)) {
101
+ const pluginName = toCamelCase(name);
102
+ if (PLUGIN_NAMES.includes(pluginName)) {
101
103
  if (pluginConfig === false) {
102
- workspaces[workspaceName][name] = false;
104
+ workspaces[workspaceName][pluginName] = false;
103
105
  }
104
106
  else {
105
107
  const isObject = typeof pluginConfig !== 'string' && !Array.isArray(pluginConfig);
106
108
  const config = isObject ? arrayify(pluginConfig.config) : pluginConfig ? arrayify(pluginConfig) : null;
107
109
  const entry = isObject && 'entry' in pluginConfig ? arrayify(pluginConfig.entry) : null;
108
110
  const project = isObject && 'project' in pluginConfig ? arrayify(pluginConfig.project) : entry;
109
- workspaces[workspaceName][name] = {
111
+ workspaces[workspaceName][pluginName] = {
110
112
  config,
111
113
  entry,
112
114
  project,
@@ -209,7 +211,7 @@ export default class ConfigurationChief {
209
211
  const key = this.getConfigKeyForWorkspace(workspaceName);
210
212
  if (key && this.config?.workspaces?.[key])
211
213
  return this.config.workspaces[key];
212
- return { entry: [], project: [], ignore: [] };
214
+ return { entry: [], project: [], paths: {}, ignore: [] };
213
215
  }
214
216
  resolveIncludedIssueTypes() {
215
217
  return resolveIncludedIssueTypes({
@@ -2,6 +2,7 @@ import { z } from 'zod';
2
2
  export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendShape<z.extendShape<{
3
3
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
4
4
  project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
5
+ paths: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
5
6
  ignore: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
6
7
  ignoreBinaries: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
7
8
  ignoreDependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
@@ -13,6 +14,7 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
13
14
  workspaces: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<z.extendShape<{
14
15
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
15
16
  project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
17
+ paths: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
16
18
  ignore: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
17
19
  }, {
18
20
  babel: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
@@ -106,7 +108,7 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
106
108
  entry?: string | string[] | undefined;
107
109
  project?: string | string[] | undefined;
108
110
  }>]>>;
109
- jest: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
111
+ 'github-actions': z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
110
112
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
111
113
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
112
114
  project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -119,7 +121,20 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
119
121
  entry?: string | string[] | undefined;
120
122
  project?: string | string[] | undefined;
121
123
  }>]>>;
122
- 'github-actions': z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
124
+ husky: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
125
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
126
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
127
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
128
+ }, "strip", z.ZodTypeAny, {
129
+ config?: string | string[] | undefined;
130
+ entry?: string | string[] | undefined;
131
+ project?: string | string[] | undefined;
132
+ }, {
133
+ config?: string | string[] | undefined;
134
+ entry?: string | string[] | undefined;
135
+ project?: string | string[] | undefined;
136
+ }>]>>;
137
+ jest: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
123
138
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
124
139
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
125
140
  project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -145,6 +160,19 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
145
160
  entry?: string | string[] | undefined;
146
161
  project?: string | string[] | undefined;
147
162
  }>]>>;
163
+ markdownlint: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
164
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
165
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
166
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
167
+ }, "strip", z.ZodTypeAny, {
168
+ config?: string | string[] | undefined;
169
+ entry?: string | string[] | undefined;
170
+ project?: string | string[] | undefined;
171
+ }, {
172
+ config?: string | string[] | undefined;
173
+ entry?: string | string[] | undefined;
174
+ project?: string | string[] | undefined;
175
+ }>]>>;
148
176
  mocha: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
149
177
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
150
178
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -353,6 +381,19 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
353
381
  entry?: string | string[] | undefined;
354
382
  project?: string | string[] | undefined;
355
383
  }>]>>;
384
+ vitest: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
385
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
386
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
387
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
388
+ }, "strip", z.ZodTypeAny, {
389
+ config?: string | string[] | undefined;
390
+ entry?: string | string[] | undefined;
391
+ project?: string | string[] | undefined;
392
+ }, {
393
+ config?: string | string[] | undefined;
394
+ entry?: string | string[] | undefined;
395
+ project?: string | string[] | undefined;
396
+ }>]>>;
356
397
  webpack: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
357
398
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
358
399
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -370,6 +411,7 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
370
411
  ignore?: string | string[] | undefined;
371
412
  entry?: string | string[] | undefined;
372
413
  project?: string | string[] | undefined;
414
+ paths?: Record<string, string[]> | undefined;
373
415
  babel?: string | false | string[] | {
374
416
  config?: string | string[] | undefined;
375
417
  entry?: string | string[] | undefined;
@@ -405,12 +447,17 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
405
447
  entry?: string | string[] | undefined;
406
448
  project?: string | string[] | undefined;
407
449
  } | undefined;
408
- jest?: string | false | string[] | {
450
+ 'github-actions'?: string | false | string[] | {
409
451
  config?: string | string[] | undefined;
410
452
  entry?: string | string[] | undefined;
411
453
  project?: string | string[] | undefined;
412
454
  } | undefined;
413
- 'github-actions'?: string | false | string[] | {
455
+ husky?: string | false | string[] | {
456
+ config?: string | string[] | undefined;
457
+ entry?: string | string[] | undefined;
458
+ project?: string | string[] | undefined;
459
+ } | undefined;
460
+ jest?: string | false | string[] | {
414
461
  config?: string | string[] | undefined;
415
462
  entry?: string | string[] | undefined;
416
463
  project?: string | string[] | undefined;
@@ -420,6 +467,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
420
467
  entry?: string | string[] | undefined;
421
468
  project?: string | string[] | undefined;
422
469
  } | undefined;
470
+ markdownlint?: string | false | string[] | {
471
+ config?: string | string[] | undefined;
472
+ entry?: string | string[] | undefined;
473
+ project?: string | string[] | undefined;
474
+ } | undefined;
423
475
  mocha?: string | false | string[] | {
424
476
  config?: string | string[] | undefined;
425
477
  entry?: string | string[] | undefined;
@@ -500,6 +552,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
500
552
  entry?: string | string[] | undefined;
501
553
  project?: string | string[] | undefined;
502
554
  } | undefined;
555
+ vitest?: string | false | string[] | {
556
+ config?: string | string[] | undefined;
557
+ entry?: string | string[] | undefined;
558
+ project?: string | string[] | undefined;
559
+ } | undefined;
503
560
  webpack?: string | false | string[] | {
504
561
  config?: string | string[] | undefined;
505
562
  entry?: string | string[] | undefined;
@@ -509,6 +566,7 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
509
566
  ignore?: string | string[] | undefined;
510
567
  entry?: string | string[] | undefined;
511
568
  project?: string | string[] | undefined;
569
+ paths?: Record<string, string[]> | undefined;
512
570
  babel?: string | false | string[] | {
513
571
  config?: string | string[] | undefined;
514
572
  entry?: string | string[] | undefined;
@@ -544,12 +602,17 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
544
602
  entry?: string | string[] | undefined;
545
603
  project?: string | string[] | undefined;
546
604
  } | undefined;
547
- jest?: string | false | string[] | {
605
+ 'github-actions'?: string | false | string[] | {
548
606
  config?: string | string[] | undefined;
549
607
  entry?: string | string[] | undefined;
550
608
  project?: string | string[] | undefined;
551
609
  } | undefined;
552
- 'github-actions'?: string | false | string[] | {
610
+ husky?: string | false | string[] | {
611
+ config?: string | string[] | undefined;
612
+ entry?: string | string[] | undefined;
613
+ project?: string | string[] | undefined;
614
+ } | undefined;
615
+ jest?: string | false | string[] | {
553
616
  config?: string | string[] | undefined;
554
617
  entry?: string | string[] | undefined;
555
618
  project?: string | string[] | undefined;
@@ -559,6 +622,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
559
622
  entry?: string | string[] | undefined;
560
623
  project?: string | string[] | undefined;
561
624
  } | undefined;
625
+ markdownlint?: string | false | string[] | {
626
+ config?: string | string[] | undefined;
627
+ entry?: string | string[] | undefined;
628
+ project?: string | string[] | undefined;
629
+ } | undefined;
562
630
  mocha?: string | false | string[] | {
563
631
  config?: string | string[] | undefined;
564
632
  entry?: string | string[] | undefined;
@@ -639,6 +707,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
639
707
  entry?: string | string[] | undefined;
640
708
  project?: string | string[] | undefined;
641
709
  } | undefined;
710
+ vitest?: string | false | string[] | {
711
+ config?: string | string[] | undefined;
712
+ entry?: string | string[] | undefined;
713
+ project?: string | string[] | undefined;
714
+ } | undefined;
642
715
  webpack?: string | false | string[] | {
643
716
  config?: string | string[] | undefined;
644
717
  entry?: string | string[] | undefined;
@@ -737,7 +810,7 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
737
810
  entry?: string | string[] | undefined;
738
811
  project?: string | string[] | undefined;
739
812
  }>]>>;
740
- jest: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
813
+ 'github-actions': z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
741
814
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
742
815
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
743
816
  project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -750,7 +823,20 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
750
823
  entry?: string | string[] | undefined;
751
824
  project?: string | string[] | undefined;
752
825
  }>]>>;
753
- 'github-actions': z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
826
+ husky: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
827
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
828
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
829
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
830
+ }, "strip", z.ZodTypeAny, {
831
+ config?: string | string[] | undefined;
832
+ entry?: string | string[] | undefined;
833
+ project?: string | string[] | undefined;
834
+ }, {
835
+ config?: string | string[] | undefined;
836
+ entry?: string | string[] | undefined;
837
+ project?: string | string[] | undefined;
838
+ }>]>>;
839
+ jest: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
754
840
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
755
841
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
756
842
  project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -776,6 +862,19 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
776
862
  entry?: string | string[] | undefined;
777
863
  project?: string | string[] | undefined;
778
864
  }>]>>;
865
+ markdownlint: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
866
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
867
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
868
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
869
+ }, "strip", z.ZodTypeAny, {
870
+ config?: string | string[] | undefined;
871
+ entry?: string | string[] | undefined;
872
+ project?: string | string[] | undefined;
873
+ }, {
874
+ config?: string | string[] | undefined;
875
+ entry?: string | string[] | undefined;
876
+ project?: string | string[] | undefined;
877
+ }>]>>;
779
878
  mocha: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
780
879
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
781
880
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -984,6 +1083,19 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
984
1083
  entry?: string | string[] | undefined;
985
1084
  project?: string | string[] | undefined;
986
1085
  }>]>>;
1086
+ vitest: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
1087
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
1088
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
1089
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
1090
+ }, "strip", z.ZodTypeAny, {
1091
+ config?: string | string[] | undefined;
1092
+ entry?: string | string[] | undefined;
1093
+ project?: string | string[] | undefined;
1094
+ }, {
1095
+ config?: string | string[] | undefined;
1096
+ entry?: string | string[] | undefined;
1097
+ project?: string | string[] | undefined;
1098
+ }>]>>;
987
1099
  webpack: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
988
1100
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
989
1101
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -1003,6 +1115,7 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
1003
1115
  include?: string[] | undefined;
1004
1116
  entry?: string | string[] | undefined;
1005
1117
  project?: string | string[] | undefined;
1118
+ paths?: Record<string, string[]> | undefined;
1006
1119
  ignoreBinaries?: string[] | undefined;
1007
1120
  ignoreDependencies?: string[] | undefined;
1008
1121
  ignoreWorkspaces?: string[] | undefined;
@@ -1041,12 +1154,17 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
1041
1154
  entry?: string | string[] | undefined;
1042
1155
  project?: string | string[] | undefined;
1043
1156
  } | undefined;
1044
- jest?: string | false | string[] | {
1157
+ 'github-actions'?: string | false | string[] | {
1045
1158
  config?: string | string[] | undefined;
1046
1159
  entry?: string | string[] | undefined;
1047
1160
  project?: string | string[] | undefined;
1048
1161
  } | undefined;
1049
- 'github-actions'?: string | false | string[] | {
1162
+ husky?: string | false | string[] | {
1163
+ config?: string | string[] | undefined;
1164
+ entry?: string | string[] | undefined;
1165
+ project?: string | string[] | undefined;
1166
+ } | undefined;
1167
+ jest?: string | false | string[] | {
1050
1168
  config?: string | string[] | undefined;
1051
1169
  entry?: string | string[] | undefined;
1052
1170
  project?: string | string[] | undefined;
@@ -1056,6 +1174,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
1056
1174
  entry?: string | string[] | undefined;
1057
1175
  project?: string | string[] | undefined;
1058
1176
  } | undefined;
1177
+ markdownlint?: string | false | string[] | {
1178
+ config?: string | string[] | undefined;
1179
+ entry?: string | string[] | undefined;
1180
+ project?: string | string[] | undefined;
1181
+ } | undefined;
1059
1182
  mocha?: string | false | string[] | {
1060
1183
  config?: string | string[] | undefined;
1061
1184
  entry?: string | string[] | undefined;
@@ -1136,6 +1259,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
1136
1259
  entry?: string | string[] | undefined;
1137
1260
  project?: string | string[] | undefined;
1138
1261
  } | undefined;
1262
+ vitest?: string | false | string[] | {
1263
+ config?: string | string[] | undefined;
1264
+ entry?: string | string[] | undefined;
1265
+ project?: string | string[] | undefined;
1266
+ } | undefined;
1139
1267
  webpack?: string | false | string[] | {
1140
1268
  config?: string | string[] | undefined;
1141
1269
  entry?: string | string[] | undefined;
@@ -1145,6 +1273,7 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
1145
1273
  ignore?: string | string[] | undefined;
1146
1274
  entry?: string | string[] | undefined;
1147
1275
  project?: string | string[] | undefined;
1276
+ paths?: Record<string, string[]> | undefined;
1148
1277
  babel?: string | false | string[] | {
1149
1278
  config?: string | string[] | undefined;
1150
1279
  entry?: string | string[] | undefined;
@@ -1180,12 +1309,17 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
1180
1309
  entry?: string | string[] | undefined;
1181
1310
  project?: string | string[] | undefined;
1182
1311
  } | undefined;
1183
- jest?: string | false | string[] | {
1312
+ 'github-actions'?: string | false | string[] | {
1184
1313
  config?: string | string[] | undefined;
1185
1314
  entry?: string | string[] | undefined;
1186
1315
  project?: string | string[] | undefined;
1187
1316
  } | undefined;
1188
- 'github-actions'?: string | false | string[] | {
1317
+ husky?: string | false | string[] | {
1318
+ config?: string | string[] | undefined;
1319
+ entry?: string | string[] | undefined;
1320
+ project?: string | string[] | undefined;
1321
+ } | undefined;
1322
+ jest?: string | false | string[] | {
1189
1323
  config?: string | string[] | undefined;
1190
1324
  entry?: string | string[] | undefined;
1191
1325
  project?: string | string[] | undefined;
@@ -1195,6 +1329,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
1195
1329
  entry?: string | string[] | undefined;
1196
1330
  project?: string | string[] | undefined;
1197
1331
  } | undefined;
1332
+ markdownlint?: string | false | string[] | {
1333
+ config?: string | string[] | undefined;
1334
+ entry?: string | string[] | undefined;
1335
+ project?: string | string[] | undefined;
1336
+ } | undefined;
1198
1337
  mocha?: string | false | string[] | {
1199
1338
  config?: string | string[] | undefined;
1200
1339
  entry?: string | string[] | undefined;
@@ -1275,6 +1414,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
1275
1414
  entry?: string | string[] | undefined;
1276
1415
  project?: string | string[] | undefined;
1277
1416
  } | undefined;
1417
+ vitest?: string | false | string[] | {
1418
+ config?: string | string[] | undefined;
1419
+ entry?: string | string[] | undefined;
1420
+ project?: string | string[] | undefined;
1421
+ } | undefined;
1278
1422
  webpack?: string | false | string[] | {
1279
1423
  config?: string | string[] | undefined;
1280
1424
  entry?: string | string[] | undefined;
@@ -1287,6 +1431,7 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
1287
1431
  include?: string[] | undefined;
1288
1432
  entry?: string | string[] | undefined;
1289
1433
  project?: string | string[] | undefined;
1434
+ paths?: Record<string, string[]> | undefined;
1290
1435
  ignoreBinaries?: string[] | undefined;
1291
1436
  ignoreDependencies?: string[] | undefined;
1292
1437
  ignoreWorkspaces?: string[] | undefined;
@@ -1325,12 +1470,17 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
1325
1470
  entry?: string | string[] | undefined;
1326
1471
  project?: string | string[] | undefined;
1327
1472
  } | undefined;
1328
- jest?: string | false | string[] | {
1473
+ 'github-actions'?: string | false | string[] | {
1329
1474
  config?: string | string[] | undefined;
1330
1475
  entry?: string | string[] | undefined;
1331
1476
  project?: string | string[] | undefined;
1332
1477
  } | undefined;
1333
- 'github-actions'?: string | false | string[] | {
1478
+ husky?: string | false | string[] | {
1479
+ config?: string | string[] | undefined;
1480
+ entry?: string | string[] | undefined;
1481
+ project?: string | string[] | undefined;
1482
+ } | undefined;
1483
+ jest?: string | false | string[] | {
1334
1484
  config?: string | string[] | undefined;
1335
1485
  entry?: string | string[] | undefined;
1336
1486
  project?: string | string[] | undefined;
@@ -1340,6 +1490,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
1340
1490
  entry?: string | string[] | undefined;
1341
1491
  project?: string | string[] | undefined;
1342
1492
  } | undefined;
1493
+ markdownlint?: string | false | string[] | {
1494
+ config?: string | string[] | undefined;
1495
+ entry?: string | string[] | undefined;
1496
+ project?: string | string[] | undefined;
1497
+ } | undefined;
1343
1498
  mocha?: string | false | string[] | {
1344
1499
  config?: string | string[] | undefined;
1345
1500
  entry?: string | string[] | undefined;
@@ -1420,6 +1575,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
1420
1575
  entry?: string | string[] | undefined;
1421
1576
  project?: string | string[] | undefined;
1422
1577
  } | undefined;
1578
+ vitest?: string | false | string[] | {
1579
+ config?: string | string[] | undefined;
1580
+ entry?: string | string[] | undefined;
1581
+ project?: string | string[] | undefined;
1582
+ } | undefined;
1423
1583
  webpack?: string | false | string[] | {
1424
1584
  config?: string | string[] | undefined;
1425
1585
  entry?: string | string[] | undefined;
@@ -1429,6 +1589,7 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
1429
1589
  ignore?: string | string[] | undefined;
1430
1590
  entry?: string | string[] | undefined;
1431
1591
  project?: string | string[] | undefined;
1592
+ paths?: Record<string, string[]> | undefined;
1432
1593
  babel?: string | false | string[] | {
1433
1594
  config?: string | string[] | undefined;
1434
1595
  entry?: string | string[] | undefined;
@@ -1464,12 +1625,17 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
1464
1625
  entry?: string | string[] | undefined;
1465
1626
  project?: string | string[] | undefined;
1466
1627
  } | undefined;
1467
- jest?: string | false | string[] | {
1628
+ 'github-actions'?: string | false | string[] | {
1468
1629
  config?: string | string[] | undefined;
1469
1630
  entry?: string | string[] | undefined;
1470
1631
  project?: string | string[] | undefined;
1471
1632
  } | undefined;
1472
- 'github-actions'?: string | false | string[] | {
1633
+ husky?: string | false | string[] | {
1634
+ config?: string | string[] | undefined;
1635
+ entry?: string | string[] | undefined;
1636
+ project?: string | string[] | undefined;
1637
+ } | undefined;
1638
+ jest?: string | false | string[] | {
1473
1639
  config?: string | string[] | undefined;
1474
1640
  entry?: string | string[] | undefined;
1475
1641
  project?: string | string[] | undefined;
@@ -1479,6 +1645,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
1479
1645
  entry?: string | string[] | undefined;
1480
1646
  project?: string | string[] | undefined;
1481
1647
  } | undefined;
1648
+ markdownlint?: string | false | string[] | {
1649
+ config?: string | string[] | undefined;
1650
+ entry?: string | string[] | undefined;
1651
+ project?: string | string[] | undefined;
1652
+ } | undefined;
1482
1653
  mocha?: string | false | string[] | {
1483
1654
  config?: string | string[] | undefined;
1484
1655
  entry?: string | string[] | undefined;
@@ -1559,6 +1730,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.extendShape<z.extendS
1559
1730
  entry?: string | string[] | undefined;
1560
1731
  project?: string | string[] | undefined;
1561
1732
  } | undefined;
1733
+ vitest?: string | false | string[] | {
1734
+ config?: string | string[] | undefined;
1735
+ entry?: string | string[] | undefined;
1736
+ project?: string | string[] | undefined;
1737
+ } | undefined;
1562
1738
  webpack?: string | false | string[] | {
1563
1739
  config?: string | string[] | undefined;
1564
1740
  entry?: string | string[] | undefined;
@@ -1,8 +1,10 @@
1
1
  import { z } from 'zod';
2
2
  const globSchema = z.union([z.string(), z.array(z.string())]);
3
+ const pathsSchema = z.record(z.string(), z.array(z.string()));
3
4
  const rootConfigurationSchema = z.object({
4
5
  entry: globSchema.optional(),
5
6
  project: globSchema.optional(),
7
+ paths: pathsSchema.optional(),
6
8
  ignore: globSchema.optional(),
7
9
  ignoreBinaries: z.array(z.string()).optional(),
8
10
  ignoreDependencies: z.array(z.string()).optional(),
@@ -29,9 +31,11 @@ const pluginsSchema = z.object({
29
31
  cypress: pluginSchema,
30
32
  eslint: pluginSchema,
31
33
  gatsby: pluginSchema,
32
- jest: pluginSchema,
33
34
  'github-actions': pluginSchema,
35
+ husky: pluginSchema,
36
+ jest: pluginSchema,
34
37
  'lint-staged': pluginSchema,
38
+ markdownlint: pluginSchema,
35
39
  mocha: pluginSchema,
36
40
  next: pluginSchema,
37
41
  'npm-package-json-lint': pluginSchema,
@@ -48,11 +52,13 @@ const pluginsSchema = z.object({
48
52
  storybook: pluginSchema,
49
53
  stryker: pluginSchema,
50
54
  typescript: pluginSchema,
55
+ vitest: pluginSchema,
51
56
  webpack: pluginSchema,
52
57
  });
53
58
  const baseWorkspaceConfigurationSchema = z.object({
54
59
  entry: globSchema.optional(),
55
60
  project: globSchema.optional(),
61
+ paths: pathsSchema.optional(),
56
62
  ignore: globSchema.optional(),
57
63
  });
58
64
  const workspaceConfigurationSchema = baseWorkspaceConfigurationSchema.merge(pluginsSchema.partial());
@@ -4,6 +4,7 @@ export declare const KNIP_CONFIG_LOCATIONS: string[];
4
4
  export declare const DEFAULT_WORKSPACE_CONFIG: {
5
5
  entry: string[];
6
6
  project: string[];
7
+ paths: {};
7
8
  ignore: never[];
8
9
  };
9
10
  export declare const TEST_FILE_PATTERNS: string[];
package/dist/constants.js CHANGED
@@ -3,6 +3,7 @@ export const KNIP_CONFIG_LOCATIONS = ['knip.json', 'knip.jsonc', '.knip.json', '
3
3
  export const DEFAULT_WORKSPACE_CONFIG = {
4
4
  entry: ['index.{js,ts,tsx}!', 'src/index.{js,ts,tsx}!'],
5
5
  project: ['**/*.{js,ts,tsx}!'],
6
+ paths: {},
6
7
  ignore: [],
7
8
  };
8
9
  export const TEST_FILE_PATTERNS = ['**/*.{test,spec}.{js,jsx,ts,tsx}', '**/__tests__/**/*.{js,jsx,ts,tsx}'];
@@ -56,7 +56,9 @@ export default class DependencyDeputy {
56
56
  return this.installedBinaries.get(workspaceName);
57
57
  }
58
58
  addTypeScriptConfigPathGlobs(workspaceName, paths) {
59
- this.tsConfigPathGlobs.set(workspaceName, paths ? Object.keys(paths).map(p => p.replace(/\*/g, '**')) : []);
59
+ const wsPaths = this.tsConfigPathGlobs.get(workspaceName) ?? [];
60
+ const addPaths = Object.keys(paths).map(value => value.replace(/\*/g, '**'));
61
+ this.tsConfigPathGlobs.set(workspaceName, [...wsPaths, ...addPaths]);
60
62
  }
61
63
  addReferencedDependency(workspaceName, packageName) {
62
64
  if (!this.referencedDependencies.has(workspaceName)) {
package/dist/index.js CHANGED
@@ -48,6 +48,10 @@ export const main = async (unresolvedConfiguration) => {
48
48
  deputy.addTypeScriptConfigPathGlobs(name, tsConfig.compilerOptions.paths);
49
49
  principal.addTypeScriptPaths(dir, tsConfig.compilerOptions);
50
50
  }
51
+ if (Object.keys(config.paths).length > 0) {
52
+ deputy.addTypeScriptConfigPathGlobs(name, config.paths);
53
+ principal.addTypeScriptPaths(dir, { paths: config.paths });
54
+ }
51
55
  collector.updateMessage(`Resolving custom dependencies...${suffix}`);
52
56
  const workspaceManifest = deputy.getWorkspaceManifest(name);
53
57
  if (!workspaceManifest)
@@ -5,7 +5,7 @@ import { getValuesByKeyDeep } from '../../util/object.js';
5
5
  import { timerify } from '../../util/performance.js';
6
6
  export const NAME = 'GitHub Actions';
7
7
  export const ENABLERS = 'This plugin is enabled when a `.yml` file is found in the `.github/workflows` folder.';
8
- export const isEnabled = () => Boolean(_firstGlob({ cwd: process.cwd(), patterns: ['.github/workflows/*.yml'] }));
8
+ export const isEnabled = async ({ cwd }) => Boolean(await _firstGlob({ cwd, patterns: ['.github/workflows/*.yml'] }));
9
9
  export const CONFIG_FILE_PATTERNS = ['.github/workflows/*.yml'];
10
10
  const findGithubActionsDependencies = async (configFilePath, { manifest, rootConfig }) => {
11
11
  const config = await _load(configFilePath);
@@ -26,4 +26,5 @@ export * as sentry from './sentry/index.js';
26
26
  export * as storybook from './storybook/index.js';
27
27
  export * as stryker from './stryker/index.js';
28
28
  export * as typescript from './typescript/index.js';
29
+ export * as vitest from './vitest/index.js';
29
30
  export * as webpack from './webpack/index.js';
@@ -26,4 +26,5 @@ export * as sentry from './sentry/index.js';
26
26
  export * as storybook from './storybook/index.js';
27
27
  export * as stryker from './stryker/index.js';
28
28
  export * as typescript from './typescript/index.js';
29
+ export * as vitest from './vitest/index.js';
29
30
  export * as webpack from './webpack/index.js';
@@ -0,0 +1,5 @@
1
+ type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime';
2
+ type VitestEnvironment = BuiltinEnvironment | (string & Record<never, never>);
3
+ export declare const getEnvPackageName: (env: VitestEnvironment) => any;
4
+ export declare const getExternalReporters: (reporters?: string[]) => string[];
5
+ export {};
@@ -0,0 +1,20 @@
1
+ const environments = {
2
+ node: null,
3
+ jsdom: null,
4
+ 'happy-dom': null,
5
+ 'edge-runtime': null,
6
+ };
7
+ const envPackageNames = {
8
+ jsdom: 'jsdom',
9
+ 'happy-dom': 'happy-dom',
10
+ 'edge-runtime': '@edge-runtime/vm',
11
+ };
12
+ export const getEnvPackageName = (env) => {
13
+ if (env === 'node')
14
+ return null;
15
+ if (env in envPackageNames)
16
+ return envPackageNames[env];
17
+ return `vitest-environment-${env}`;
18
+ };
19
+ const builtInReporters = ['default', 'verbose', 'dot', 'json', 'tap', 'tap-flat', 'junit', 'hanging-process'];
20
+ export const getExternalReporters = (reporters) => reporters ? reporters.filter(reporter => !builtInReporters.includes(reporter)) : [];
@@ -0,0 +1,7 @@
1
+ import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
2
+ export declare const NAME = "Vitest";
3
+ export declare const ENABLERS: string[];
4
+ export declare const isEnabled: IsPluginEnabledCallback;
5
+ export declare const CONFIG_FILE_PATTERNS: string[];
6
+ export declare const ENTRY_FILE_PATTERNS: string[];
7
+ export declare const findDependencies: GenericPluginCallback;
@@ -0,0 +1,20 @@
1
+ import { _load } from '../../util/loader.js';
2
+ import { timerify } from '../../util/performance.js';
3
+ import { hasDependency } from '../../util/plugin.js';
4
+ import { getEnvPackageName, getExternalReporters } from './helpers.js';
5
+ export const NAME = 'Vitest';
6
+ export const ENABLERS = ['vitest'];
7
+ export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
8
+ export const CONFIG_FILE_PATTERNS = ['vitest.config.ts', 'vite.config.ts'];
9
+ export const ENTRY_FILE_PATTERNS = ['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'];
10
+ const findVitestDependencies = async (configFilePath) => {
11
+ const config = await _load(configFilePath);
12
+ if (!config || !config.test)
13
+ return [];
14
+ const cfg = config.test;
15
+ const environments = cfg.environment ? [getEnvPackageName(cfg.environment)] : [];
16
+ const reporters = getExternalReporters(cfg.reporters);
17
+ const coverage = cfg.coverage?.provider ? [`@vitest/coverage-${cfg.coverage.provider}`] : [];
18
+ return [...environments, ...reporters, ...coverage];
19
+ };
20
+ export const findDependencies = timerify(findVitestDependencies);
@@ -0,0 +1,9 @@
1
+ export type VitestConfig = {
2
+ test: {
3
+ environment?: string;
4
+ reporters?: string[];
5
+ coverage?: {
6
+ provider: string;
7
+ };
8
+ };
9
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -34,15 +34,15 @@ export default class ProjectPrincipal {
34
34
  addTypeScriptPaths(workspaceDir, compilerOptions) {
35
35
  if (!compilerOptions || !compilerOptions.paths)
36
36
  return;
37
+ if (!this.projectOptions)
38
+ this.projectOptions = {};
39
+ if (!this.projectOptions.compilerOptions)
40
+ this.projectOptions.compilerOptions = {};
41
+ if (!this.projectOptions.compilerOptions.paths)
42
+ this.projectOptions.compilerOptions.paths = {};
37
43
  const { baseUrl, paths } = compilerOptions;
38
44
  for (const [key, entries] of Object.entries(paths)) {
39
45
  const workspacePaths = entries.map(entry => baseUrl ? path.join(workspaceDir, baseUrl, entry) : path.join(workspaceDir, entry));
40
- if (!this.projectOptions)
41
- this.projectOptions = {};
42
- if (!this.projectOptions.compilerOptions)
43
- this.projectOptions.compilerOptions = {};
44
- if (!this.projectOptions.compilerOptions.paths)
45
- this.projectOptions.compilerOptions.paths = {};
46
46
  if (this.projectOptions.compilerOptions.paths[key]) {
47
47
  this.projectOptions.compilerOptions.paths[key].push(...workspacePaths);
48
48
  }
@@ -13,6 +13,7 @@ type PluginsConfiguration = Record<PluginName, PluginConfiguration>;
13
13
  interface BaseWorkspaceConfiguration {
14
14
  entry: NormalizedGlob;
15
15
  project: NormalizedGlob;
16
+ paths: Record<string, string[]>;
16
17
  ignore: NormalizedGlob;
17
18
  }
18
19
  export interface WorkspaceConfiguration extends BaseWorkspaceConfiguration, Partial<PluginsConfiguration> {
@@ -1,10 +1,11 @@
1
1
  import { Configuration, PluginConfiguration, WorkspaceConfiguration } from './config.js';
2
2
  import type { PackageJson } from 'type-fest';
3
3
  type IsPluginEnabledCallbackOptions = {
4
+ cwd: string;
4
5
  manifest: PackageJson;
5
6
  dependencies: Set<string>;
6
7
  };
7
- export type IsPluginEnabledCallback = (options: IsPluginEnabledCallbackOptions) => boolean;
8
+ export type IsPluginEnabledCallback = (options: IsPluginEnabledCallbackOptions) => boolean | Promise<boolean>;
8
9
  type GenericPluginCallbackOptions = {
9
10
  cwd: string;
10
11
  manifest: PackageJson;
@@ -36,7 +36,7 @@ export default class WorkspaceWorker {
36
36
  constructor({ name, dir, config, ancestorManifests, rootWorkspaceConfig, rootConfig, negatedWorkspacePatterns, manifest, rootWorkspaceDir, isProduction, }: WorkspaceManagerOptions);
37
37
  getConfigForPlugin(pluginName: PluginName): PluginConfiguration;
38
38
  init(): Promise<void>;
39
- setEnabledPlugins(): void;
39
+ setEnabledPlugins(): Promise<void>;
40
40
  initReferencedDependencies(): Promise<void>;
41
41
  getEntryFilePatterns(): string[];
42
42
  getProjectFilePatterns(): string[];
@@ -40,10 +40,10 @@ export default class WorkspaceWorker {
40
40
  return this.config[pluginName] ?? { config: null, entry: null, project: null };
41
41
  }
42
42
  async init() {
43
- this.setEnabledPlugins();
43
+ await this.setEnabledPlugins();
44
44
  await this.initReferencedDependencies();
45
45
  }
46
- setEnabledPlugins() {
46
+ async setEnabledPlugins() {
47
47
  const dependencies = new Set([this.manifest, ...this.ancestorManifests]
48
48
  .flatMap(manifest => [Object.keys(manifest?.dependencies ?? {}), Object.keys(manifest?.devDependencies ?? {})])
49
49
  .flat());
@@ -53,7 +53,7 @@ export default class WorkspaceWorker {
53
53
  this.enabled[pluginName] =
54
54
  this.config[pluginName] !== false &&
55
55
  hasIsEnabled &&
56
- plugin.isEnabled({ manifest: this.manifest, dependencies });
56
+ (await plugin.isEnabled({ cwd: this.dir, manifest: this.manifest, dependencies }));
57
57
  }
58
58
  const enabledPlugins = pluginEntries.filter(([name]) => this.enabled[name]).map(([, plugin]) => plugin.NAME);
59
59
  debugLogObject(`Enabled plugins (${this.name})`, enabledPlugins);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "1.5.0",
3
+ "version": "1.6.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",
package/schema.json CHANGED
@@ -117,6 +117,14 @@
117
117
  "default": ["**/*.{js,ts,tsx}"],
118
118
  "$ref": "#/definitions/globPatterns"
119
119
  },
120
+ "paths": {
121
+ "title": "",
122
+ "example": {
123
+ "~": ["."]
124
+ },
125
+ "default": {},
126
+ "$ref": "#/definitions/paths"
127
+ },
120
128
  "ignore": {
121
129
  "title": "Files to ignore in the analysis.",
122
130
  "example": ["**/fixtures", "mocks"],
@@ -268,11 +276,24 @@
268
276
  "title": "TypeScript plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/typescript/README.md)",
269
277
  "$ref": "#/definitions/plugin"
270
278
  },
279
+ "vitest": {
280
+ "title": "vitest plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/vitest/README.md)",
281
+ "$ref": "#/definitions/plugin"
282
+ },
271
283
  "webpack": {
272
284
  "title": "Webpack plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/webpack/README.md)",
273
285
  "$ref": "#/definitions/plugin"
274
286
  }
275
287
  }
288
+ },
289
+ "paths": {
290
+ "type": "object",
291
+ "additionalProperty": {
292
+ "type": "array",
293
+ "items": {
294
+ "type": "string"
295
+ }
296
+ }
276
297
  }
277
298
  }
278
299
  }