knip 2.30.1 → 2.32.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.
Files changed (103) hide show
  1. package/README.md +15 -24
  2. package/dist/ConfigurationChief.d.ts +2 -0
  3. package/dist/ConfigurationChief.js +57 -61
  4. package/dist/ConfigurationValidator.d.ts +377 -321
  5. package/dist/ConfigurationValidator.js +2 -1
  6. package/dist/WorkspaceWorker.d.ts +8 -6
  7. package/dist/WorkspaceWorker.js +41 -62
  8. package/dist/binaries/index.js +1 -1
  9. package/dist/binaries/resolvers/c8.js +2 -1
  10. package/dist/binaries/resolvers/dotenv.js +2 -1
  11. package/dist/binaries/resolvers/fallback.js +2 -1
  12. package/dist/binaries/resolvers/nodemon.js +2 -1
  13. package/dist/binaries/resolvers/npx.js +2 -1
  14. package/dist/binaries/resolvers/nx.js +1 -1
  15. package/dist/binaries/resolvers/pnpm.js +1 -1
  16. package/dist/binaries/resolvers/rollup.js +2 -1
  17. package/dist/binaries/resolvers/yarn.js +1 -1
  18. package/dist/binaries/util.d.ts +0 -3
  19. package/dist/binaries/util.js +1 -3
  20. package/dist/constants.d.ts +0 -1
  21. package/dist/constants.js +0 -4
  22. package/dist/index.js +27 -20
  23. package/dist/plugins/ava/index.d.ts +1 -1
  24. package/dist/plugins/ava/index.js +23 -5
  25. package/dist/plugins/ava/types.d.ts +1 -0
  26. package/dist/plugins/babel/index.js +3 -1
  27. package/dist/plugins/capacitor/index.js +3 -1
  28. package/dist/plugins/changesets/index.js +3 -1
  29. package/dist/plugins/commitizen/index.d.ts +1 -0
  30. package/dist/plugins/commitizen/index.js +4 -1
  31. package/dist/plugins/commitlint/index.js +3 -1
  32. package/dist/plugins/cspell/index.js +3 -1
  33. package/dist/plugins/cypress/index.d.ts +3 -1
  34. package/dist/plugins/cypress/index.js +14 -4
  35. package/dist/plugins/drizzle/index.js +3 -5
  36. package/dist/plugins/eslint/helpers.js +2 -1
  37. package/dist/plugins/eslint/index.d.ts +1 -0
  38. package/dist/plugins/eslint/index.js +4 -1
  39. package/dist/plugins/gatsby/index.js +10 -2
  40. package/dist/plugins/github-actions/index.js +3 -1
  41. package/dist/plugins/husky/index.js +3 -1
  42. package/dist/plugins/index.d.ts +1 -0
  43. package/dist/plugins/index.js +1 -0
  44. package/dist/plugins/jest/index.d.ts +1 -1
  45. package/dist/plugins/jest/index.js +16 -7
  46. package/dist/plugins/lefthook/index.js +4 -2
  47. package/dist/plugins/lint-staged/index.d.ts +1 -0
  48. package/dist/plugins/lint-staged/index.js +4 -1
  49. package/dist/plugins/markdownlint/index.js +3 -1
  50. package/dist/plugins/mocha/index.d.ts +1 -0
  51. package/dist/plugins/mocha/index.js +10 -6
  52. package/dist/plugins/next/index.d.ts +2 -1
  53. package/dist/plugins/next/index.js +4 -0
  54. package/dist/plugins/node-test-runner/index.d.ts +6 -0
  55. package/dist/plugins/node-test-runner/index.js +17 -0
  56. package/dist/plugins/npm-package-json-lint/index.d.ts +1 -0
  57. package/dist/plugins/npm-package-json-lint/index.js +5 -2
  58. package/dist/plugins/nx/index.js +3 -1
  59. package/dist/plugins/nyc/index.js +3 -1
  60. package/dist/plugins/playwright/index.d.ts +3 -1
  61. package/dist/plugins/playwright/index.js +22 -2
  62. package/dist/plugins/playwright-ct/index.d.ts +3 -1
  63. package/dist/plugins/playwright-ct/index.js +13 -2
  64. package/dist/plugins/postcss/index.js +8 -6
  65. package/dist/plugins/prettier/index.js +3 -1
  66. package/dist/plugins/release-it/index.d.ts +1 -0
  67. package/dist/plugins/release-it/index.js +5 -2
  68. package/dist/plugins/remark/index.d.ts +1 -0
  69. package/dist/plugins/remark/index.js +10 -3
  70. package/dist/plugins/remix/index.d.ts +2 -1
  71. package/dist/plugins/remix/index.js +10 -0
  72. package/dist/plugins/rollup/index.d.ts +2 -1
  73. package/dist/plugins/rollup/index.js +7 -0
  74. package/dist/plugins/semantic-release/index.d.ts +1 -0
  75. package/dist/plugins/semantic-release/index.js +7 -2
  76. package/dist/plugins/sentry/index.d.ts +2 -1
  77. package/dist/plugins/sentry/index.js +7 -0
  78. package/dist/plugins/storybook/index.js +6 -2
  79. package/dist/plugins/stryker/index.js +9 -8
  80. package/dist/plugins/stylelint/index.js +3 -1
  81. package/dist/plugins/svelte/index.d.ts +2 -1
  82. package/dist/plugins/svelte/index.js +6 -0
  83. package/dist/plugins/typedoc/index.d.ts +1 -0
  84. package/dist/plugins/typedoc/index.js +5 -2
  85. package/dist/plugins/typescript/index.js +3 -1
  86. package/dist/plugins/vite/index.js +2 -2
  87. package/dist/plugins/vitest/index.d.ts +3 -3
  88. package/dist/plugins/vitest/index.js +16 -23
  89. package/dist/plugins/vitest/types.d.ts +1 -0
  90. package/dist/plugins/webpack/index.js +3 -1
  91. package/dist/types/config.d.ts +5 -3
  92. package/dist/types/plugins.d.ts +3 -3
  93. package/dist/util/compilers.d.ts +90 -80
  94. package/dist/util/object.d.ts +1 -0
  95. package/dist/util/object.js +1 -0
  96. package/dist/util/plugin.d.ts +2 -2
  97. package/dist/util/plugin.js +2 -2
  98. package/dist/util/protocols.d.ts +9 -0
  99. package/dist/util/protocols.js +9 -0
  100. package/dist/version.d.ts +1 -1
  101. package/dist/version.js +1 -1
  102. package/package.json +2 -1
  103. package/schema.json +4 -0
@@ -3,6 +3,7 @@ import { timerify } from '../../util/Performance.js';
3
3
  import { hasDependency, load } from '../../util/plugin.js';
4
4
  export const NAME = 'Release It';
5
5
  export const ENABLERS = ['release-it'];
6
+ export const PACKAGE_JSON_PATH = 'release-it';
6
7
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
8
  export const CONFIG_FILE_PATTERNS = [
8
9
  '.release-it.json',
@@ -10,9 +11,11 @@ export const CONFIG_FILE_PATTERNS = [
10
11
  '.release-it.{yml,yaml}',
11
12
  'package.json',
12
13
  ];
13
- const findReleaseItDependencies = async (configFilePath, { cwd, manifest }) => {
14
+ const findReleaseItDependencies = async (configFilePath, { cwd, manifest, isProduction }) => {
15
+ if (isProduction)
16
+ return [];
14
17
  const config = configFilePath.endsWith('package.json')
15
- ? manifest['release-it']
18
+ ? manifest[PACKAGE_JSON_PATH]
16
19
  : await load(configFilePath);
17
20
  if (!config)
18
21
  return [];
@@ -1,6 +1,7 @@
1
1
  import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
2
2
  export declare const NAME = "Remark";
3
3
  export declare const ENABLERS: string[];
4
+ export declare const PACKAGE_JSON_PATH = "remarkConfig";
4
5
  export declare const isEnabled: IsPluginEnabledCallback;
5
6
  export declare const CONFIG_FILE_PATTERNS: string[];
6
7
  export declare const findDependencies: GenericPluginCallback;
@@ -2,6 +2,7 @@ import { timerify } from '../../util/Performance.js';
2
2
  import { hasDependency, load } from '../../util/plugin.js';
3
3
  export const NAME = 'Remark';
4
4
  export const ENABLERS = ['remark-cli'];
5
+ export const PACKAGE_JSON_PATH = 'remarkConfig';
5
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
6
7
  export const CONFIG_FILE_PATTERNS = [
7
8
  'package.json',
@@ -10,9 +11,15 @@ export const CONFIG_FILE_PATTERNS = [
10
11
  '.remarkrc.{js,cjs,mjs}',
11
12
  '.remarkrc.{yml,yaml}',
12
13
  ];
13
- const findRemarkDependencies = async (configFilePath, { manifest }) => {
14
- const config = configFilePath.endsWith('package.json') ? manifest.remarkConfig : await load(configFilePath);
15
- const plugins = config?.plugins?.map(plugin => `remark-${plugin}`) ?? [];
14
+ const findRemarkDependencies = async (configFilePath, { manifest, isProduction }) => {
15
+ if (isProduction)
16
+ return [];
17
+ const config = configFilePath.endsWith('package.json')
18
+ ? manifest[PACKAGE_JSON_PATH]
19
+ : await load(configFilePath);
20
+ if (!config)
21
+ return [];
22
+ const plugins = config.plugins?.map(plugin => `remark-${plugin}`) ?? [];
16
23
  return [...plugins];
17
24
  };
18
25
  export const findDependencies = timerify(findRemarkDependencies);
@@ -1,6 +1,7 @@
1
- import type { IsPluginEnabledCallback } from '../../types/plugins.js';
1
+ import type { GenericPluginCallback, IsPluginEnabledCallback } from '../../types/plugins.js';
2
2
  export declare const NAME = "Remix";
3
3
  export declare const ENABLERS: RegExp[];
4
4
  export declare const isEnabled: IsPluginEnabledCallback;
5
5
  export declare const ENTRY_FILE_PATTERNS: string[];
6
6
  export declare const PRODUCTION_ENTRY_FILE_PATTERNS: string[];
7
+ export declare const findDependencies: GenericPluginCallback;
@@ -1,4 +1,6 @@
1
+ import { timerify } from '../../util/Performance.js';
1
2
  import { hasDependency } from '../../util/plugin.js';
3
+ import { toEntryPattern, toProductionEntryPattern } from '../../util/protocols.js';
2
4
  export const NAME = 'Remix';
3
5
  export const ENABLERS = [/^@remix-run\//];
4
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
@@ -9,3 +11,11 @@ export const PRODUCTION_ENTRY_FILE_PATTERNS = [
9
11
  'app/routes/**/*.{js,ts,tsx}',
10
12
  'server.{js,ts}',
11
13
  ];
14
+ const findRemixDependencies = async () => {
15
+ const entryPatterns = [
16
+ ...ENTRY_FILE_PATTERNS.map(toEntryPattern),
17
+ ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern),
18
+ ];
19
+ return entryPatterns;
20
+ };
21
+ export const findDependencies = timerify(findRemixDependencies);
@@ -1,5 +1,6 @@
1
- import type { IsPluginEnabledCallback } from '../../types/plugins.js';
1
+ import type { GenericPluginCallback, IsPluginEnabledCallback } from '../../types/plugins.js';
2
2
  export declare const NAME = "Rollup";
3
3
  export declare const ENABLERS: string[];
4
4
  export declare const isEnabled: IsPluginEnabledCallback;
5
5
  export declare const ENTRY_FILE_PATTERNS: string[];
6
+ export declare const findDependencies: GenericPluginCallback;
@@ -1,5 +1,12 @@
1
+ import { timerify } from '../../util/Performance.js';
1
2
  import { hasDependency } from '../../util/plugin.js';
3
+ import { toEntryPattern } from '../../util/protocols.js';
2
4
  export const NAME = 'Rollup';
3
5
  export const ENABLERS = ['rollup'];
4
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
5
7
  export const ENTRY_FILE_PATTERNS = ['rollup.config.{js,mjs,ts}'];
8
+ const findRollupDependencies = async () => {
9
+ const entryPatterns = ENTRY_FILE_PATTERNS.map(toEntryPattern);
10
+ return entryPatterns;
11
+ };
12
+ export const findDependencies = timerify(findRollupDependencies);
@@ -1,6 +1,7 @@
1
1
  import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
2
2
  export declare const NAME = "Semantic Release";
3
3
  export declare const ENABLERS: string[];
4
+ export declare const PACKAGE_JSON_PATH = "release";
4
5
  export declare const isEnabled: IsPluginEnabledCallback;
5
6
  export declare const CONFIG_FILE_PATTERNS: string[];
6
7
  export declare const findDependencies: GenericPluginCallback;
@@ -2,6 +2,7 @@ import { timerify } from '../../util/Performance.js';
2
2
  import { hasDependency, load } from '../../util/plugin.js';
3
3
  export const NAME = 'Semantic Release';
4
4
  export const ENABLERS = ['semantic-release'];
5
+ export const PACKAGE_JSON_PATH = 'release';
5
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
6
7
  export const CONFIG_FILE_PATTERNS = [
7
8
  '.releaserc',
@@ -9,8 +10,12 @@ export const CONFIG_FILE_PATTERNS = [
9
10
  'release.config.{js,cjs}',
10
11
  'package.json',
11
12
  ];
12
- const findSemanticReleaseDependencies = async (configFilePath, { manifest }) => {
13
- const config = configFilePath.endsWith('package.json') ? manifest.release : await load(configFilePath);
13
+ const findSemanticReleaseDependencies = async (configFilePath, { manifest, isProduction }) => {
14
+ if (isProduction)
15
+ return [];
16
+ const config = configFilePath.endsWith('package.json')
17
+ ? manifest[PACKAGE_JSON_PATH]
18
+ : await load(configFilePath);
14
19
  const plugins = config?.plugins ?? [];
15
20
  return plugins.map(plugin => (Array.isArray(plugin) ? plugin[0] : plugin));
16
21
  };
@@ -1,5 +1,6 @@
1
- import type { IsPluginEnabledCallback } from '../../types/plugins.js';
1
+ import type { GenericPluginCallback, IsPluginEnabledCallback } from '../../types/plugins.js';
2
2
  export declare const NAME = "Sentry";
3
3
  export declare const ENABLERS: RegExp[];
4
4
  export declare const isEnabled: IsPluginEnabledCallback;
5
5
  export declare const ENTRY_FILE_PATTERNS: string[];
6
+ export declare const findDependencies: GenericPluginCallback;
@@ -1,5 +1,12 @@
1
+ import { timerify } from '../../util/Performance.js';
1
2
  import { hasDependency } from '../../util/plugin.js';
3
+ import { toEntryPattern } from '../../util/protocols.js';
2
4
  export const NAME = 'Sentry';
3
5
  export const ENABLERS = [/^@sentry\//];
4
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
5
7
  export const ENTRY_FILE_PATTERNS = ['sentry.{client,server,edge}.config.{js,ts}'];
8
+ const findSentryDependencies = async () => {
9
+ const entryPatterns = ENTRY_FILE_PATTERNS.map(toEntryPattern);
10
+ return entryPatterns;
11
+ };
12
+ export const findDependencies = timerify(findSentryDependencies);
@@ -1,12 +1,16 @@
1
1
  import { timerify } from '../../util/Performance.js';
2
2
  import { hasDependency, load } from '../../util/plugin.js';
3
+ import { toEntryPattern } from '../../util/protocols.js';
3
4
  export const NAME = 'Storybook';
4
5
  export const ENABLERS = [/^@storybook\//, '@nrwl/storybook'];
5
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
6
7
  export const CONFIG_FILE_PATTERNS = ['.storybook/{main,manager,test-runner}.{js,ts}'];
7
8
  export const ENTRY_FILE_PATTERNS = ['.storybook/preview.{js,jsx,ts,tsx}', '**/*.stories.{js,jsx,ts,tsx}'];
8
9
  export const PROJECT_FILE_PATTERNS = ['.storybook/**/*.{js,jsx,ts,tsx}'];
9
- const findStorybookDependencies = async (configFilePath) => {
10
+ const findStorybookDependencies = async (configFilePath, { isProduction }) => {
11
+ const entryPatterns = ENTRY_FILE_PATTERNS.map(toEntryPattern);
12
+ if (isProduction)
13
+ return entryPatterns;
10
14
  const config = await load(configFilePath);
11
15
  if (!config)
12
16
  return [];
@@ -14,6 +18,6 @@ const findStorybookDependencies = async (configFilePath) => {
14
18
  const builder = config?.core?.builder;
15
19
  const builderPackages = builder && /webpack/.test(builder) ? [`@storybook/builder-${builder}`, `@storybook/manager-${builder}`] : [];
16
20
  const frameworks = config.framework?.name ? [config.framework.name] : [];
17
- return [...addons, ...builderPackages, ...frameworks];
21
+ return [...entryPatterns, ...addons, ...builderPackages, ...frameworks];
18
22
  };
19
23
  export const findDependencies = timerify(findStorybookDependencies);
@@ -4,14 +4,15 @@ export const NAME = 'Stryker';
4
4
  export const ENABLERS = ['@stryker-mutator/core'];
5
5
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
6
6
  export const CONFIG_FILE_PATTERNS = ['?(.)stryker.{conf,config}.{js,mjs,cjs,json}'];
7
- const findStrykerDependencies = async (configFilePath) => {
7
+ const findStrykerDependencies = async (configFilePath, { isProduction }) => {
8
+ if (isProduction)
9
+ return [];
8
10
  const config = await load(configFilePath);
9
- if (config) {
10
- const runners = config.testRunner ? [`@stryker-mutator/${config.testRunner}-runner`] : [];
11
- const checkers = config.checkers ? config.checkers.map(checker => `@stryker-mutator/${checker}-checker`) : [];
12
- const plugins = config.plugins ?? [];
13
- return [...runners, ...checkers, ...plugins];
14
- }
15
- return [];
11
+ if (!config)
12
+ return [];
13
+ const runners = config.testRunner ? [`@stryker-mutator/${config.testRunner}-runner`] : [];
14
+ const checkers = config.checkers ? config.checkers.map(checker => `@stryker-mutator/${checker}-checker`) : [];
15
+ const plugins = config.plugins ?? [];
16
+ return [...runners, ...checkers, ...plugins];
16
17
  };
17
18
  export const findDependencies = timerify(findStrykerDependencies);
@@ -9,7 +9,9 @@ export const CONFIG_FILE_PATTERNS = [
9
9
  '.stylelintrc.{cjs,js,json,yaml,yml}',
10
10
  'stylelint.config.{cjs,mjs,js}',
11
11
  ];
12
- const findPluginDependencies = async (configFilePath, { manifest }) => {
12
+ const findPluginDependencies = async (configFilePath, { manifest, isProduction }) => {
13
+ if (isProduction)
14
+ return [];
13
15
  const config = configFilePath.endsWith('package.json')
14
16
  ? manifest.stylelint
15
17
  : await load(configFilePath);
@@ -1,7 +1,8 @@
1
- import type { IsPluginEnabledCallback } from '../../types/plugins.js';
1
+ import type { GenericPluginCallback, IsPluginEnabledCallback } from '../../types/plugins.js';
2
2
  export declare const NAME = "Svelte";
3
3
  export declare const ENABLERS: string[];
4
4
  export declare const isEnabled: IsPluginEnabledCallback;
5
5
  export declare const ENTRY_FILE_PATTERNS: string[];
6
6
  export declare const PRODUCTION_ENTRY_FILE_PATTERNS: string[];
7
7
  export declare const PROJECT_FILE_PATTERNS: string[];
8
+ export declare const findDependencies: GenericPluginCallback;
@@ -1,4 +1,6 @@
1
+ import { timerify } from '../../util/Performance.js';
1
2
  import { hasDependency } from '../../util/plugin.js';
3
+ import { toEntryPattern, toProductionEntryPattern } from '../../util/protocols.js';
2
4
  export const NAME = 'Svelte';
3
5
  export const ENABLERS = ['svelte'];
4
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
@@ -7,3 +9,7 @@ export const PRODUCTION_ENTRY_FILE_PATTERNS = [
7
9
  'src/routes/**/+{page,server,page.server,error,layout,layout.server}{,@*}.{js,ts,svelte}',
8
10
  ];
9
11
  export const PROJECT_FILE_PATTERNS = ['src/**/*.{js,ts,svelte}'];
12
+ const findSvelteDependencies = async () => {
13
+ return [...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern), ...ENTRY_FILE_PATTERNS.map(toEntryPattern)];
14
+ };
15
+ export const findDependencies = timerify(findSvelteDependencies);
@@ -1,6 +1,7 @@
1
1
  import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
2
2
  export declare const NAME = "TypeDoc";
3
3
  export declare const ENABLERS: string[];
4
+ export declare const PACKAGE_JSON_PATH = "typedocOptions";
4
5
  export declare const isEnabled: IsPluginEnabledCallback;
5
6
  export declare const CONFIG_FILE_PATTERNS: string[];
6
7
  export declare const findDependencies: GenericPluginCallback;
@@ -2,6 +2,7 @@ import { timerify } from '../../util/Performance.js';
2
2
  import { hasDependency, load } from '../../util/plugin.js';
3
3
  export const NAME = 'TypeDoc';
4
4
  export const ENABLERS = ['typedoc'];
5
+ export const PACKAGE_JSON_PATH = 'typedocOptions';
5
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
6
7
  export const CONFIG_FILE_PATTERNS = [
7
8
  'typedoc.{js,cjs,json,jsonc}',
@@ -11,9 +12,11 @@ export const CONFIG_FILE_PATTERNS = [
11
12
  'package.json',
12
13
  'tsconfig.json',
13
14
  ];
14
- const findTypeDocDependencies = async (configFilePath, { manifest }) => {
15
+ const findTypeDocDependencies = async (configFilePath, { manifest, isProduction }) => {
16
+ if (isProduction)
17
+ return [];
15
18
  const config = configFilePath.endsWith('package.json')
16
- ? manifest.typedocOptions
19
+ ? manifest[PACKAGE_JSON_PATH]
17
20
  : configFilePath.endsWith('tsconfig.json')
18
21
  ? (await load(configFilePath)).typedocOptions
19
22
  : await load(configFilePath);
@@ -21,7 +21,9 @@ const resolveExtensibleConfig = async (configFilePath) => {
21
21
  }
22
22
  return config;
23
23
  };
24
- export const findTypeScriptDependencies = async (configFilePath) => {
24
+ export const findTypeScriptDependencies = async (configFilePath, { isProduction }) => {
25
+ if (isProduction)
26
+ return [];
25
27
  const { compilerOptions } = await loadTSConfig(configFilePath);
26
28
  const config = await resolveExtensibleConfig(configFilePath);
27
29
  if (!compilerOptions || !config)
@@ -5,8 +5,8 @@ export const NAME = 'Vite';
5
5
  export const ENABLERS = ['vite'];
6
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
7
  export const CONFIG_FILE_PATTERNS = ['vite.config.{js,ts}'];
8
- const findViteDependencies = async (configFilePath) => {
8
+ const findViteDependencies = async (configFilePath, options) => {
9
9
  const config = await load(configFilePath);
10
- return findVitestDeps(config);
10
+ return findVitestDeps(config, options);
11
11
  };
12
12
  export const findDependencies = timerify(findViteDependencies);
@@ -1,9 +1,9 @@
1
1
  import type { VitestConfig } from './types.js';
2
- import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
2
+ import type { IsPluginEnabledCallback, GenericPluginCallback, GenericPluginCallbackOptions } from '../../types/plugins.js';
3
3
  export declare const NAME = "Vitest";
4
4
  export declare const ENABLERS: string[];
5
5
  export declare const isEnabled: IsPluginEnabledCallback;
6
6
  export declare const CONFIG_FILE_PATTERNS: string[];
7
- export declare const ENTRY_FILE_PATTERNS: never[];
8
- export declare const findVitestDeps: (config: VitestConfig) => any[];
7
+ export declare const ENTRY_FILE_PATTERNS: string[];
8
+ export declare const findVitestDeps: (config: VitestConfig, options: GenericPluginCallbackOptions) => any[];
9
9
  export declare const findDependencies: GenericPluginCallback;
@@ -1,37 +1,30 @@
1
1
  import { compact } from '../../util/array.js';
2
2
  import { timerify } from '../../util/Performance.js';
3
3
  import { hasDependency, load } from '../../util/plugin.js';
4
+ import { toEntryPattern } from '../../util/protocols.js';
4
5
  import { getEnvPackageName, getExternalReporters } from './helpers.js';
5
6
  export const NAME = 'Vitest';
6
7
  export const ENABLERS = ['vitest'];
7
8
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
8
9
  export const CONFIG_FILE_PATTERNS = ['vitest.config.ts', 'vitest.{workspace,projects}.{ts,js,json}'];
9
- export const ENTRY_FILE_PATTERNS = [];
10
- export const findVitestDeps = (config) => {
10
+ export const ENTRY_FILE_PATTERNS = ['**/*.{test,spec}.?(c|m)[jt]s?(x)'];
11
+ export const findVitestDeps = (config, options) => {
12
+ const { isProduction } = options;
11
13
  if (!config || !config.test)
12
14
  return [];
13
- const cfg = config.test;
14
- const environments = cfg.environment ? [getEnvPackageName(cfg.environment)] : [];
15
- const reporters = getExternalReporters(cfg.reporters);
16
- const coverage = cfg.coverage ? [`@vitest/coverage-${cfg.coverage.provider ?? 'v8'}`] : [];
17
- const setupFiles = cfg.setupFiles ? [cfg.setupFiles].flat() : [];
18
- const globalSetup = cfg.globalSetup ? [cfg.globalSetup].flat() : [];
19
- return compact([...environments, ...reporters, ...coverage, ...setupFiles, ...globalSetup]);
15
+ const testConfig = config.test;
16
+ const entryPatterns = (options.config?.entry ?? testConfig.include ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
17
+ if (isProduction)
18
+ return entryPatterns;
19
+ const environments = testConfig.environment ? [getEnvPackageName(testConfig.environment)] : [];
20
+ const reporters = getExternalReporters(testConfig.reporters);
21
+ const coverage = testConfig.coverage ? [`@vitest/coverage-${testConfig.coverage.provider ?? 'v8'}`] : [];
22
+ const setupFiles = testConfig.setupFiles ? [testConfig.setupFiles].flat() : [];
23
+ const globalSetup = testConfig.globalSetup ? [testConfig.globalSetup].flat() : [];
24
+ return [...entryPatterns, ...environments, ...reporters, ...coverage, ...setupFiles, ...globalSetup];
20
25
  };
21
- const findVitestWorkspaceDeps = (config) => {
22
- let deps = [];
23
- for (const cfg of config) {
24
- if (typeof cfg === 'string')
25
- continue;
26
- deps = [...deps, ...findVitestDeps(cfg)];
27
- }
28
- return compact(deps);
29
- };
30
- const findVitestDependencies = async (configFilePath) => {
26
+ const findVitestDependencies = async (configFilePath, options) => {
31
27
  const config = await load(configFilePath);
32
- if (Array.isArray(config)) {
33
- return findVitestWorkspaceDeps(config);
34
- }
35
- return findVitestDeps(config);
28
+ return compact([config].flat().flatMap(cfg => (!cfg || typeof cfg === 'string' ? [] : findVitestDeps(cfg, options))));
36
29
  };
37
30
  export const findDependencies = timerify(findVitestDependencies);
@@ -1,5 +1,6 @@
1
1
  export interface VitestConfig {
2
2
  test: {
3
+ include: string[];
3
4
  coverage?: {
4
5
  provider: string;
5
6
  };
@@ -44,10 +44,12 @@ const resolveUseItem = (use) => {
44
44
  return [];
45
45
  };
46
46
  const findWebpackDependencies = async (configFilePath, { manifest, isProduction }) => {
47
+ if (isProduction)
48
+ return [];
47
49
  const config = await load(configFilePath);
48
50
  if (!config)
49
51
  return [];
50
- const passes = typeof config === 'function' ? [false, true] : [isProduction];
52
+ const passes = typeof config === 'function' ? [false, true] : [false];
51
53
  const dependencies = passes.flatMap(isProduction => {
52
54
  const env = { production: isProduction };
53
55
  const argv = { mode: isProduction ? 'production' : 'development' };
@@ -7,11 +7,12 @@ export type RawConfiguration = z.infer<typeof ConfigurationValidator>;
7
7
  export type RawPluginConfiguration = z.infer<typeof pluginSchema>;
8
8
  type NormalizedGlob = string[];
9
9
  export type PluginName = keyof typeof Plugins;
10
- export type PluginConfiguration = {
10
+ export type EnsuredPluginConfiguration = {
11
11
  config: NormalizedGlob | null;
12
12
  entry: NormalizedGlob | null;
13
13
  project: NormalizedGlob | null;
14
- } | false;
14
+ };
15
+ export type PluginConfiguration = EnsuredPluginConfiguration | boolean;
15
16
  export type PluginsConfiguration = Record<PluginName, PluginConfiguration>;
16
17
  interface BaseWorkspaceConfiguration {
17
18
  entry: NormalizedGlob;
@@ -33,8 +34,9 @@ export interface Configuration {
33
34
  ignoreDependencies: string[];
34
35
  ignoreExportsUsedInFile: boolean | Partial<Record<IgnorableExport, boolean>>;
35
36
  ignoreWorkspaces: string[];
36
- workspaces: Record<string, WorkspaceConfiguration>;
37
37
  syncCompilers: SyncCompilers;
38
38
  asyncCompilers: AsyncCompilers;
39
+ defaultWorkspaceConfig: WorkspaceConfiguration;
40
+ rootPluginConfigs: Partial<PluginsConfiguration>;
39
41
  }
40
42
  export {};
@@ -1,5 +1,5 @@
1
1
  /// <reference types="npmcli__package-json" />
2
- import type { PluginConfiguration, WorkspaceConfiguration } from './config.js';
2
+ import type { EnsuredPluginConfiguration, WorkspaceConfiguration } from './config.js';
3
3
  import type { PackageJson } from '@npmcli/package-json';
4
4
  export type PackageJsonWithPlugins = PackageJson & Record<string, unknown>;
5
5
  type IsPluginEnabledCallbackOptions = {
@@ -9,10 +9,10 @@ type IsPluginEnabledCallbackOptions = {
9
9
  config: WorkspaceConfiguration;
10
10
  };
11
11
  export type IsPluginEnabledCallback = (options: IsPluginEnabledCallbackOptions) => boolean | Promise<boolean>;
12
- type GenericPluginCallbackOptions = {
12
+ export type GenericPluginCallbackOptions = {
13
13
  cwd: string;
14
14
  manifest: PackageJsonWithPlugins;
15
- config: PluginConfiguration;
15
+ config?: EnsuredPluginConfiguration;
16
16
  isProduction: boolean;
17
17
  };
18
18
  export type GenericPluginCallback = (configFilePath: string, options: GenericPluginCallbackOptions) => Promise<string[]> | string[];