knip 6.42.1 → 6.44.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 (187) hide show
  1. package/dist/CacheConsultant.d.ts +1 -0
  2. package/dist/CacheConsultant.js +2 -0
  3. package/dist/CatalogCounselor.d.ts +1 -3
  4. package/dist/CatalogCounselor.js +18 -15
  5. package/dist/ConfigurationChief.d.ts +42 -0
  6. package/dist/DependencyDeputy.d.ts +2 -1
  7. package/dist/DependencyDeputy.js +9 -4
  8. package/dist/IssueCollector.js +1 -0
  9. package/dist/IssueFixer.js +10 -5
  10. package/dist/ProjectPrincipal.d.ts +3 -2
  11. package/dist/ProjectPrincipal.js +32 -10
  12. package/dist/WorkspaceWorker.d.ts +5 -2
  13. package/dist/WorkspaceWorker.js +35 -17
  14. package/dist/binaries/resolvers/bun.js +1 -0
  15. package/dist/binaries/resolvers/npm.js +12 -2
  16. package/dist/binaries/resolvers/pnpm.js +5 -3
  17. package/dist/binaries/util.js +2 -1
  18. package/dist/cli.js +6 -1
  19. package/dist/compilers/compilers.js +2 -2
  20. package/dist/compilers/index.d.ts +5 -0
  21. package/dist/compilers/index.js +1 -1
  22. package/dist/constants.d.ts +1 -0
  23. package/dist/constants.js +2 -0
  24. package/dist/graph/analyze.js +3 -2
  25. package/dist/graph/build.d.ts +2 -0
  26. package/dist/graph/build.js +37 -22
  27. package/dist/graph-explorer/cache.d.ts +2 -1
  28. package/dist/graph-explorer/cache.js +5 -1
  29. package/dist/graph-explorer/explorer.d.ts +3 -5
  30. package/dist/graph-explorer/explorer.js +24 -3
  31. package/dist/plugins/_vue/auto-import.js +31 -1
  32. package/dist/plugins/biome/index.js +1 -1
  33. package/dist/plugins/buf/index.d.ts +3 -0
  34. package/dist/plugins/buf/index.js +33 -0
  35. package/dist/plugins/buf/types.d.ts +8 -0
  36. package/dist/plugins/buf/types.js +1 -0
  37. package/dist/plugins/cspell/index.js +1 -0
  38. package/dist/plugins/dependency-cruiser/index.js +2 -2
  39. package/dist/plugins/docusaurus/helpers.js +4 -4
  40. package/dist/plugins/electron-forge/index.d.ts +3 -0
  41. package/dist/plugins/electron-forge/index.js +94 -0
  42. package/dist/plugins/electron-vite/index.js +2 -2
  43. package/dist/plugins/eslint/helpers.d.ts +1 -0
  44. package/dist/plugins/eslint/helpers.js +1 -1
  45. package/dist/plugins/eslint/resolveFromAST.js +35 -10
  46. package/dist/plugins/expo/helpers.d.ts +1 -1
  47. package/dist/plugins/expo/helpers.js +15 -8
  48. package/dist/plugins/expo/types.d.ts +2 -1
  49. package/dist/plugins/expressive-code/index.d.ts +1 -1
  50. package/dist/plugins/expressive-code/index.js +2 -2
  51. package/dist/plugins/gatsby/index.js +6 -6
  52. package/dist/plugins/gatsby/types.d.ts +1 -1
  53. package/dist/plugins/github-actions/index.js +1 -1
  54. package/dist/plugins/i18next-parser/index.js +2 -2
  55. package/dist/plugins/index.d.ts +8 -1
  56. package/dist/plugins/index.js +14 -0
  57. package/dist/plugins/jasmine/index.js +2 -2
  58. package/dist/plugins/karma/index.js +4 -4
  59. package/dist/plugins/kysely-codegen/index.d.ts +3 -0
  60. package/dist/plugins/kysely-codegen/index.js +20 -0
  61. package/dist/plugins/lefthook/index.js +2 -2
  62. package/dist/plugins/lingui/index.d.ts +3 -0
  63. package/dist/plugins/lingui/index.js +16 -0
  64. package/dist/plugins/lockfile-lint/index.js +2 -2
  65. package/dist/plugins/lost-pixel/index.js +2 -2
  66. package/dist/plugins/lunaria/index.js +2 -2
  67. package/dist/plugins/marko/index.js +5 -6
  68. package/dist/plugins/mastra/index.d.ts +3 -0
  69. package/dist/plugins/mastra/index.js +57 -0
  70. package/dist/plugins/mcp/index.d.ts +3 -0
  71. package/dist/plugins/mcp/index.js +33 -0
  72. package/dist/plugins/mcp/types.d.ts +11 -0
  73. package/dist/plugins/mcp/types.js +1 -0
  74. package/dist/plugins/mise/index.js +0 -3
  75. package/dist/plugins/mocha/index.js +42 -3
  76. package/dist/plugins/mocha/types.d.ts +1 -0
  77. package/dist/plugins/next/index.d.ts +3 -0
  78. package/dist/plugins/next/index.js +57 -9
  79. package/dist/plugins/next/types.d.ts +11 -0
  80. package/dist/plugins/next/types.js +1 -0
  81. package/dist/plugins/nx/index.js +3 -8
  82. package/dist/plugins/nyc/index.js +1 -1
  83. package/dist/plugins/openapi-ts/index.js +2 -2
  84. package/dist/plugins/oxfmt/index.js +2 -2
  85. package/dist/plugins/playwright/index.js +6 -11
  86. package/dist/plugins/pnpm/index.js +2 -4
  87. package/dist/plugins/purgecss/index.d.ts +3 -0
  88. package/dist/plugins/purgecss/index.js +16 -0
  89. package/dist/plugins/railway/index.js +1 -4
  90. package/dist/plugins/remix/index.js +1 -1
  91. package/dist/plugins/rstest/index.js +2 -2
  92. package/dist/plugins/serverless-framework/index.js +1 -1
  93. package/dist/plugins/storybook/index.js +5 -5
  94. package/dist/plugins/sveltekit/resolveFromAST.js +1 -1
  95. package/dist/plugins/syncpack/index.js +2 -2
  96. package/dist/plugins/tailwind/compiler.js +6 -2
  97. package/dist/plugins/tanstack-router/index.js +3 -2
  98. package/dist/plugins/taskfile/index.js +4 -7
  99. package/dist/plugins/textlint/helpers.js +2 -2
  100. package/dist/plugins/travis/index.js +2 -2
  101. package/dist/plugins/typescript/index.js +9 -7
  102. package/dist/plugins/unocss/index.js +2 -2
  103. package/dist/plugins/vite-plugin-pwa/index.js +1 -4
  104. package/dist/plugins/vite-plugin-pwa/resolveFromAST.d.ts +0 -2
  105. package/dist/plugins/vite-plugin-pwa/resolveFromAST.js +2 -2
  106. package/dist/plugins/vite-pwa-assets-generator/index.js +2 -2
  107. package/dist/plugins/vitest/helpers.d.ts +1 -1
  108. package/dist/plugins/vitest/helpers.js +17 -10
  109. package/dist/plugins/vitest/index.js +53 -45
  110. package/dist/plugins/vitest/types.d.ts +11 -7
  111. package/dist/plugins/webpack/index.js +4 -2
  112. package/dist/plugins/yarn/index.js +2 -4
  113. package/dist/reporters/codeclimate.d.ts +2 -2
  114. package/dist/reporters/codeclimate.js +2 -4
  115. package/dist/reporters/codeowners.d.ts +2 -2
  116. package/dist/reporters/codeowners.js +9 -9
  117. package/dist/reporters/compact.d.ts +2 -2
  118. package/dist/reporters/compact.js +8 -7
  119. package/dist/reporters/cycles.d.ts +2 -2
  120. package/dist/reporters/cycles.js +7 -6
  121. package/dist/reporters/disclosure.d.ts +2 -2
  122. package/dist/reporters/disclosure.js +6 -4
  123. package/dist/reporters/github-actions.d.ts +2 -2
  124. package/dist/reporters/github-actions.js +7 -5
  125. package/dist/reporters/index.d.ts +10 -10
  126. package/dist/reporters/json.d.ts +2 -2
  127. package/dist/reporters/json.js +2 -4
  128. package/dist/reporters/markdown.d.ts +2 -2
  129. package/dist/reporters/markdown.js +11 -9
  130. package/dist/reporters/sarif.d.ts +2 -2
  131. package/dist/reporters/sarif.js +2 -3
  132. package/dist/reporters/symbols.d.ts +2 -2
  133. package/dist/reporters/symbols.js +6 -4
  134. package/dist/run.d.ts +1 -1
  135. package/dist/run.js +3 -10
  136. package/dist/schema/configuration.d.ts +105 -0
  137. package/dist/schema/plugins.d.ts +35 -0
  138. package/dist/schema/plugins.js +7 -0
  139. package/dist/session/configuration.d.ts +12 -0
  140. package/dist/session/configuration.js +43 -0
  141. package/dist/session/incremental.d.ts +54 -0
  142. package/dist/session/incremental.js +49 -0
  143. package/dist/session/session.d.ts +1 -1
  144. package/dist/session/session.js +62 -27
  145. package/dist/session/watch.d.ts +2 -0
  146. package/dist/session/watch.js +41 -0
  147. package/dist/types/PluginNames.d.ts +2 -2
  148. package/dist/types/PluginNames.js +7 -0
  149. package/dist/types/config.d.ts +2 -0
  150. package/dist/types/issues.d.ts +4 -0
  151. package/dist/types/package-json.d.ts +0 -3
  152. package/dist/typescript/ast-nodes.js +3 -3
  153. package/dist/typescript/get-imports-and-exports.js +2 -0
  154. package/dist/typescript/visitors/calls.js +15 -11
  155. package/dist/typescript/visitors/exports.js +5 -4
  156. package/dist/typescript/visitors/imports.d.ts +2 -1
  157. package/dist/typescript/visitors/imports.js +25 -19
  158. package/dist/typescript/visitors/members.js +23 -26
  159. package/dist/typescript/visitors/walk.d.ts +3 -0
  160. package/dist/typescript/visitors/walk.js +55 -3
  161. package/dist/util/cli-arguments.d.ts +2 -1
  162. package/dist/util/cli-arguments.js +3 -0
  163. package/dist/util/create-input-handler.js +1 -1
  164. package/dist/util/create-options.d.ts +72 -1
  165. package/dist/util/create-options.js +13 -2
  166. package/dist/util/file-entry-cache.d.ts +2 -0
  167. package/dist/util/file-entry-cache.js +19 -1
  168. package/dist/util/gitignore-cache.d.ts +1 -0
  169. package/dist/util/gitignore-cache.js +1 -0
  170. package/dist/util/glob-core.js +4 -2
  171. package/dist/util/glob.d.ts +1 -0
  172. package/dist/util/glob.js +6 -0
  173. package/dist/util/input.d.ts +2 -0
  174. package/dist/util/loader.d.ts +1 -0
  175. package/dist/util/loader.js +38 -2
  176. package/dist/util/modules.js +5 -2
  177. package/dist/util/path.d.ts +1 -0
  178. package/dist/util/path.js +1 -0
  179. package/dist/util/remove-export.js +3 -1
  180. package/dist/util/reporter.d.ts +1 -1
  181. package/dist/util/reporter.js +53 -9
  182. package/dist/util/watch.d.ts +5 -11
  183. package/dist/util/watch.js +84 -68
  184. package/dist/version.d.ts +1 -1
  185. package/dist/version.js +1 -1
  186. package/package.json +4 -4
  187. package/schema.json +28 -0
@@ -1,8 +1,12 @@
1
1
  import { getUrlSpecifier } from '../../compilers/shared.js';
2
2
  import { hasUrlScheme } from '../../util/url.js';
3
- const directiveMatcher = /"(?:\\(?:\r\n|[\s\S]|$)|[^"\\\r\n\f])*(?:"|[\r\n\f]|$)|'(?:\\(?:\r\n|[\s\S]|$)|[^'\\\r\n\f])*(?:'|[\r\n\f]|$)|\/\*[\s\S]*?(?:\*\/|$)|@(?:(?:import|config|plugin)\s+['"]([^'"]+)['"]|import\s+url\(\s*(?:['"]([^'"]+)['"]|([^'")\s]+))\s*\))[^;]*;|url\(\s*(?:["']([^"'\r\n]*)["']|([^'")\s]+))\s*\)/g;
3
+ const directiveMatcher = /"(?:\\(?:\r\n|[\s\S]|$)|[^"\\\r\n\f])*(?:"|[\r\n\f]|$)|'(?:\\(?:\r\n|[\s\S]|$)|[^'\\\r\n\f])*(?:'|[\r\n\f]|$)|\/\*[\s\S]*?(?:\*\/|$)|@(?:(?:import|config|plugin|reference)\s+['"]([^'"]+)['"]|import\s+url\(\s*(?:['"]([^'"]+)['"]|([^'")\s]+))\s*\))(?:\s*\{|[^;]*;)|url\(\s*(?:["']([^"'\r\n]*)["']|([^'")\s]+))\s*\)/g;
4
4
  const compiler = (text) => {
5
- if (!text.includes('@import') && !text.includes('@config') && !text.includes('@plugin') && !text.includes('url('))
5
+ if (!text.includes('@import') &&
6
+ !text.includes('@config') &&
7
+ !text.includes('@plugin') &&
8
+ !text.includes('@reference') &&
9
+ !text.includes('url('))
6
10
  return '';
7
11
  const imports = [];
8
12
  let match;
@@ -14,12 +14,13 @@ const enablers = [
14
14
  ];
15
15
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
16
16
  const config = ['tsr.config.json'];
17
- const production = ['src/routeTree.gen.{ts,js}', 'src/{router,start,client,server}.{js,jsx,ts,tsx}'];
17
+ const routerEntries = ['src/{router,start,client,server}.{js,jsx,ts,tsx}'];
18
+ const production = ['src/routeTree.gen.{ts,js}', ...routerEntries];
18
19
  const resolveConfig = async (localConfig, options) => {
19
20
  const { configFileDir } = options;
20
21
  const generatedRouteTree = localConfig.generatedRouteTree ?? './src/routeTree.gen.ts';
21
22
  const routeTreePath = toAbsolute(generatedRouteTree, configFileDir);
22
- return [toProductionEntry(routeTreePath)];
23
+ return [toProductionEntry(routeTreePath), ...routerEntries.map(id => toProductionEntry(id))];
23
24
  };
24
25
  const plugin = {
25
26
  title,
@@ -1,6 +1,5 @@
1
1
  import { isFile } from '../../util/fs.js';
2
2
  import { toConfig } from '../../util/input.js';
3
- import { join, relative } from '../../util/path.js';
4
3
  const title = 'Taskfile';
5
4
  const enablers = 'This plugin is enabled when a Taskfile is found (Taskfile.yml, taskfile.yml, Taskfile.yaml, taskfile.yaml, etc.).';
6
5
  const isRootOnly = true;
@@ -78,7 +77,7 @@ const extractScriptsFromTask = (task) => {
78
77
  const resolveConfig = async (localConfig, options) => {
79
78
  if (!localConfig || !options.configFilePath)
80
79
  return [];
81
- const { getInputsFromScripts, isProduction, configFileDir } = options;
80
+ const { getInputsFromScripts, isProduction, configFileDir, cwd } = options;
82
81
  const inputs = [];
83
82
  if (localConfig.includes && typeof localConfig.includes === 'object') {
84
83
  for (const includeValue of Object.values(localConfig.includes)) {
@@ -87,10 +86,8 @@ const resolveConfig = async (localConfig, options) => {
87
86
  : includeValue && typeof includeValue === 'object' && 'taskfile' in includeValue
88
87
  ? includeValue.taskfile
89
88
  : undefined;
90
- if (includePath) {
91
- const resolvedPath = join(configFileDir, includePath);
92
- inputs.push(toConfig('taskfile', relative(configFileDir, resolvedPath)));
93
- }
89
+ if (includePath)
90
+ inputs.push(toConfig('taskfile', includePath));
94
91
  }
95
92
  }
96
93
  if (localConfig.tasks && typeof localConfig.tasks === 'object') {
@@ -99,7 +96,7 @@ const resolveConfig = async (localConfig, options) => {
99
96
  for (const input of getInputsFromScripts([script], { optionalBinaries: true })) {
100
97
  if (isProduction)
101
98
  Object.assign(input, { optional: true });
102
- inputs.push({ ...input, dir: configFileDir });
99
+ inputs.push({ ...input, dir: input.type === 'entry' ? cwd : configFileDir });
103
100
  }
104
101
  }
105
102
  }
@@ -1,5 +1,5 @@
1
1
  import { toDependency, toDeferResolveEntry } from '../../util/input.js';
2
- import { isInternal, toAbsolute } from '../../util/path.js';
2
+ import { isInternal } from '../../util/path.js';
3
3
  const RULE_PREFIX = 'textlint-rule-';
4
4
  const PRESET_PREFIX = 'textlint-rule-preset-';
5
5
  const FILTER_RULE_PREFIX = 'textlint-filter-rule-';
@@ -29,7 +29,7 @@ const toPresetDependency = (key, manifest) => {
29
29
  return toPackageDependency(PRESET_PREFIX, name, candidates, manifest);
30
30
  };
31
31
  const toModuleDependency = (prefix, key, manifest) => toPackageDependency(prefix, key, [createFullPackageName(prefix, key), key], manifest);
32
- const toLocalEntry = (key, cwd) => toDeferResolveEntry(toAbsolute(key, cwd));
32
+ const toLocalEntry = (key, cwd) => toDeferResolveEntry(key, { dir: cwd });
33
33
  export const toRuleDependency = (key, manifest, cwd) => {
34
34
  if (isInternal(key))
35
35
  return toLocalEntry(key, cwd);
@@ -1,7 +1,7 @@
1
- import { _glob } from '../../util/glob.js';
1
+ import { isFile } from '../../util/fs.js';
2
2
  const title = 'Travis CI';
3
3
  const enablers = 'This plugin is enabled when a `.travis.yml` file is found in the root folder.';
4
- const isEnabled = async ({ cwd }) => (await _glob({ cwd, patterns: ['.travis.yml'] })).length > 0;
4
+ const isEnabled = ({ cwd }) => isFile(cwd, '.travis.yml');
5
5
  const isRootOnly = true;
6
6
  const config = ['.travis.yml'];
7
7
  const resolveConfig = async (config, options) => {
@@ -1,6 +1,6 @@
1
1
  import { compact } from '../../util/array.js';
2
2
  import { toConfig, toDeferResolve, toDependency, toProductionDependency } from '../../util/input.js';
3
- import { join } from '../../util/path.js';
3
+ import { join, toAbsolute } from '../../util/path.js';
4
4
  import { hasDependency } from '../../util/plugin.js';
5
5
  import { contentMapperResolvers } from './content-mappers.js';
6
6
  const title = 'TypeScript';
@@ -22,13 +22,15 @@ export const resolveConfig = (localConfig, options) => {
22
22
  const extend = localConfig.extends
23
23
  ? [localConfig.extends].flat().map(specifier => toConfig(options.pluginName, specifier))
24
24
  : [];
25
- const references = localConfig.references
26
- ?.filter(reference => reference.path.endsWith('.json'))
27
- .map(reference => toConfig(options.pluginName, reference.path)) ?? [];
25
+ const references = localConfig.references?.map(({ path }) => toConfig(options.pluginName, path.endsWith('.json') ? path : toAbsolute(join(path, 'tsconfig.json'), options.configFileDir))) ?? [];
28
26
  const contentMappers = resolveContentMappers(localConfig);
29
27
  if (!(compilerOptions && localConfig))
30
28
  return compact([...contentMappers, ...extend, ...references]);
31
- const jsx = (compilerOptions?.jsxImportSource ? [compilerOptions.jsxImportSource] : []).map(toProductionDependency);
29
+ const jsx = (compilerOptions?.jsxImportSource ? [compilerOptions.jsxImportSource] : []).map(id => ({
30
+ ...toProductionDependency(id),
31
+ dir: options.cwd,
32
+ alsoReferenceOwner: true,
33
+ }));
32
34
  const types = compilerOptions.types ?? [];
33
35
  const plugins = Array.isArray(compilerOptions?.plugins)
34
36
  ? compilerOptions.plugins.map(plugin => (typeof plugin === 'object' && 'name' in plugin ? plugin.name : ''))
@@ -38,8 +40,8 @@ export const resolveConfig = (localConfig, options) => {
38
40
  ...contentMappers,
39
41
  ...extend,
40
42
  ...references,
41
- ...types.map(id => toDeferResolve(id, { isTypeOnly: true, dir: options.cwd })),
42
- ...[...plugins, ...importHelpers].map(id => toDeferResolve(id)),
43
+ ...types.map(id => toDeferResolve(id, { isTypeOnly: true, dir: options.cwd, alsoReferenceOwner: true })),
44
+ ...[...plugins, ...importHelpers].map(id => toDeferResolve(id, { dir: options.cwd, alsoReferenceOwner: true })),
43
45
  ...jsx,
44
46
  ]);
45
47
  };
@@ -3,11 +3,11 @@ import { toUnconfig } from '../../util/plugin-config.js';
3
3
  const title = 'UnoCSS';
4
4
  const enablers = ['unocss'];
5
5
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
- const config = [...toUnconfig('uno.config'), ...toUnconfig('unocss.config')];
6
+ const entry = [...toUnconfig('uno.config'), ...toUnconfig('unocss.config')];
7
7
  const plugin = {
8
8
  title,
9
9
  enablers,
10
10
  isEnabled,
11
- config,
11
+ entry,
12
12
  };
13
13
  export default plugin;
@@ -1,17 +1,14 @@
1
- import { join } from '../../util/path.js';
2
1
  import { hasDependency } from '../../util/plugin.js';
3
- import { defaultFilename, defaultSrcDir, resolveFromAST } from './resolveFromAST.js';
2
+ import { resolveFromAST } from './resolveFromAST.js';
4
3
  const title = 'vite-plugin-pwa';
5
4
  const enablers = ['vite-plugin-pwa', '@vite-pwa/nuxt'];
6
5
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
7
6
  const config = ['vite.config.{js,mjs,ts,cjs,mts,cts}', 'nuxt.config.{js,cjs,mjs,ts,cts,mts}'];
8
- const production = [join(defaultSrcDir, defaultFilename)];
9
7
  const plugin = {
10
8
  title,
11
9
  enablers,
12
10
  isEnabled,
13
11
  config,
14
- production,
15
12
  resolveFromAST,
16
13
  };
17
14
  export default plugin;
@@ -1,4 +1,2 @@
1
1
  import type { ResolveFromAST } from '../../types/config.ts';
2
- export declare const defaultSrcDir = "public";
3
- export declare const defaultFilename = "sw.js";
4
2
  export declare const resolveFromAST: ResolveFromAST;
@@ -2,8 +2,8 @@ import { Visitor } from 'oxc-parser';
2
2
  import { findImportedCalls, findProperty, getFirstPropertyValue, getPropertyValues, } from '../../typescript/ast-helpers.js';
3
3
  import { toProductionEntry } from '../../util/input.js';
4
4
  import { join } from '../../util/path.js';
5
- export const defaultSrcDir = 'public';
6
- export const defaultFilename = 'sw.js';
5
+ const defaultSrcDir = 'public';
6
+ const defaultFilename = 'sw.js';
7
7
  const isNuxtConfig = (configFileName) => configFileName.startsWith('nuxt.config.');
8
8
  const getInjectManifestEntry = (options, configFileDir) => {
9
9
  if (!getPropertyValues(options, 'strategies').has('injectManifest'))
@@ -2,11 +2,11 @@ import { hasDependency } from '../../util/plugin.js';
2
2
  const title = '@vite-pwa/assets-generator';
3
3
  const enablers = ['@vite-pwa/assets-generator'];
4
4
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
5
- const config = ['pwa-assets.config.{js,cjs,mjs,ts,cts,mts}'];
5
+ const entry = ['pwa-assets.config.{js,cjs,mjs,ts,cts,mts}'];
6
6
  const plugin = {
7
7
  title,
8
8
  enablers,
9
9
  isEnabled,
10
- config,
10
+ entry,
11
11
  };
12
12
  export default plugin;
@@ -1,5 +1,5 @@
1
1
  import { type Input } from '../../util/input.ts';
2
2
  import type { AliasOptions, ViteConfig } from './types.ts';
3
- export declare const getEnvSpecifier: (env: string) => string;
3
+ export declare const toEnvDependency: (env: string) => Input;
4
4
  export declare const getAliasInputs: (aliasOptions: AliasOptions, cwd: string) => Input[];
5
5
  export declare const getExternalReporters: (reporters?: ViteConfig['test']['reporters']) => string[];
@@ -1,5 +1,5 @@
1
- import { toAlias } from '../../util/input.js';
2
- import { join, toPosix } from '../../util/path.js';
1
+ import { toAlias, toDependency } from '../../util/input.js';
2
+ import { join } from '../../util/path.js';
3
3
  const environments = {
4
4
  node: null,
5
5
  jsdom: null,
@@ -11,11 +11,12 @@ const envPackageNames = {
11
11
  'happy-dom': 'happy-dom',
12
12
  'edge-runtime': '@edge-runtime/vm',
13
13
  };
14
- export const getEnvSpecifier = (env) => {
14
+ const getEnvSpecifier = (env) => {
15
15
  if (env in envPackageNames)
16
16
  return envPackageNames[env];
17
17
  return `vitest-environment-${env}`;
18
18
  };
19
+ export const toEnvDependency = (env) => toDependency(getEnvSpecifier(env), env === 'nuxt' ? { optional: true } : undefined);
19
20
  const builtInReporters = [
20
21
  'agent',
21
22
  'basic',
@@ -34,18 +35,24 @@ const builtInReporters = [
34
35
  'verbose',
35
36
  ];
36
37
  const addStar = (value) => (value.endsWith('*') ? value : join(value, '*').replace(/\/\*\*$/, '/*'));
38
+ const getAliasEntries = (aliasOptions) => {
39
+ if (!Array.isArray(aliasOptions))
40
+ return Object.entries(aliasOptions);
41
+ const entries = [];
42
+ for (const { find, replacement } of aliasOptions)
43
+ if (typeof find === 'string')
44
+ entries.push([find, replacement]);
45
+ return entries;
46
+ };
37
47
  export const getAliasInputs = (aliasOptions, cwd) => {
38
48
  const inputs = [];
39
- for (const [alias, value] of Object.entries(aliasOptions)) {
49
+ for (const [alias, value] of getAliasEntries(aliasOptions)) {
40
50
  if (!value)
41
51
  continue;
42
- const prefixes = [value]
43
- .flat()
44
- .filter((value) => typeof value === 'string')
45
- .map(prefix => (toPosix(prefix).startsWith(cwd) ? prefix : join(cwd, prefix)));
52
+ const prefixes = [value].flat().filter((value) => typeof value === 'string');
46
53
  if (alias.length > 1)
47
- inputs.push(toAlias(alias, prefixes));
48
- inputs.push(toAlias(addStar(alias), prefixes.map(addStar)));
54
+ inputs.push(toAlias(alias, prefixes, { dir: cwd }));
55
+ inputs.push(toAlias(addStar(alias), prefixes.map(addStar), { dir: cwd }));
49
56
  }
50
57
  return inputs;
51
58
  };
@@ -1,32 +1,32 @@
1
1
  import { DEFAULT_EXTENSIONS } from '../../constants.js';
2
2
  import { filterTransitiveDependencies } from '../../util/filter-transitive-dependencies.js';
3
- import { _glob } from '../../util/glob.js';
3
+ import { findFileWithExtensions } from '../../util/fs.js';
4
+ import { _dirGlob, _glob } from '../../util/glob.js';
4
5
  import { toConfig, toDeferResolve, toDependency, toEntry, toProductionEntry } from '../../util/input.js';
5
6
  import { getPackageNameFromModuleSpecifier } from '../../util/modules.js';
6
- import { isAbsolute, isInternal, join, toAbsolute, toPosix } from '../../util/path.js';
7
+ import { basename, isAbsolute, isInternal, join, toAbsolute, toPosix } from '../../util/path.js';
7
8
  import { hasDependency } from '../../util/plugin.js';
8
9
  import { resolveExtendedConfig } from '../oxlint/index.js';
9
10
  import { getHtmlScriptEntries, getIndexHtmlEntries } from '../vite/helpers.js';
10
- import { getAliasInputs, getEnvSpecifier, getExternalReporters } from './helpers.js';
11
+ import { getAliasInputs, getExternalReporters, toEnvDependency } from './helpers.js';
11
12
  import { createVitestMockVisitor } from './visitors/mock.js';
12
13
  const title = 'Vitest';
13
14
  const enablers = ['vitest', 'vite-plus'];
14
15
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
16
+ const configExtensions = ['.ts', '.mts', '.cts', '.js', '.mjs', '.cjs'];
17
+ const projectConfigFile = /^vite(?:st)?(?:\.[\w-]+)?\.config\./;
15
18
  const config = ['vitest.config.{js,mjs,ts,cjs,mts,cts}', 'vitest.{workspace,projects}.{js,mjs,ts,cjs,mts,cts,json}'];
16
19
  const mocks = ['**/__mocks__/**/*.?(c|m)[jt]s?(x)'];
17
20
  const testEntry = ['**/*.{bench,test,test-d,spec,spec-d}.?(c|m)[jt]s?(x)'];
18
21
  const entry = [...testEntry, ...mocks];
19
22
  const benchmark = ['**/*.bench.?(c|m)[jt]s?(x)'];
23
+ const isProjectConfig = (project) => typeof project === 'object' && !(project instanceof Promise);
20
24
  const findConfigDependencies = (localConfig, options, vitestRoot) => {
21
25
  const testConfig = localConfig.test;
22
26
  if (!testConfig)
23
27
  return [];
24
28
  const env = testConfig.environment;
25
- const environments = env && env !== 'node'
26
- ? isInternal(env) || isAbsolute(env)
27
- ? [toDeferResolve(env)]
28
- : [toDependency(getEnvSpecifier(env))]
29
- : [];
29
+ const environments = env && env !== 'node' ? (isInternal(env) || isAbsolute(env) ? [toDeferResolve(env)] : [toEnvDependency(env)]) : [];
30
30
  const reporters = getExternalReporters(testConfig.reporters).map(specifier => isInternal(specifier) || isAbsolute(specifier)
31
31
  ? { ...toDeferResolve(specifier), dir: vitestRoot }
32
32
  : toDependency(specifier));
@@ -51,7 +51,7 @@ const findConfigDependencies = (localConfig, options, vitestRoot) => {
51
51
  const projectsDependencies = [];
52
52
  if (testConfig.projects !== undefined) {
53
53
  for (const projectConfig of testConfig.projects) {
54
- if (typeof projectConfig !== 'string') {
54
+ if (isProjectConfig(projectConfig)) {
55
55
  projectsDependencies.push(...findConfigDependencies(projectConfig, options, vitestRoot));
56
56
  }
57
57
  }
@@ -79,30 +79,31 @@ const getConfigs = async (localConfig) => {
79
79
  if (typeof config === 'function') {
80
80
  for (const command of ['serve', 'build']) {
81
81
  for (const mode of ['development', 'production']) {
82
- for (const ssrBuild of command === 'build' ? [undefined, false, true] : [undefined]) {
83
- const cfg = await config({ command, mode, ssrBuild });
84
- configs.push(cfg);
85
- if (cfg.test?.projects) {
86
- for (const project of cfg.test.projects) {
87
- if (typeof project !== 'string') {
88
- configs.push(project);
89
- }
90
- }
91
- }
82
+ for (const isSsrBuild of command === 'build' ? [undefined, false, true] : [undefined]) {
83
+ const cfg = await config({ command, mode, isSsrBuild, ssrBuild: isSsrBuild });
84
+ configs.push(cfg, ...(await getProjectConfigs(cfg, command === 'serve' && mode === 'development')));
92
85
  }
93
86
  }
94
87
  }
95
88
  }
96
89
  else {
97
- configs.push(config);
98
- if (config.test?.projects) {
99
- for (const project of config.test.projects) {
100
- if (typeof project !== 'string') {
101
- configs.push(project);
102
- }
103
- }
104
- }
90
+ configs.push(config, ...(await getProjectConfigs(config)));
91
+ }
92
+ }
93
+ }
94
+ return configs;
95
+ };
96
+ const projectEnv = { command: 'serve', mode: 'test', isPreview: false, isSsrBuild: false };
97
+ const getProjectConfigs = async (config, isCallFunctions = true) => {
98
+ const configs = [];
99
+ if (config.test?.projects) {
100
+ for (const project of config.test.projects) {
101
+ if (typeof project === 'function') {
102
+ if (isCallFunctions)
103
+ configs.push(await project(projectEnv));
105
104
  }
105
+ else if (typeof project !== 'string')
106
+ configs.push(await project);
106
107
  }
107
108
  }
108
109
  return configs;
@@ -112,23 +113,30 @@ export const resolveConfig = async (localConfig, options) => {
112
113
  const lintInputs = [];
113
114
  inputs.add(toEntry(join(options.cwd, 'src/vite-env.d.ts')));
114
115
  const configs = await getConfigs(localConfig);
116
+ const patterns = new Set();
115
117
  for (const cfg of configs) {
116
- if (cfg.test?.projects) {
117
- for (const project of cfg.test.projects) {
118
- if (typeof project === 'string') {
119
- const projectFiles = await _glob({
120
- cwd: options.cwd,
121
- patterns: [project],
122
- gitignore: false,
123
- });
124
- for (const projectFile of projectFiles) {
125
- inputs.add(toConfig('vitest', projectFile));
126
- }
127
- }
128
- else if (typeof project.extends === 'string') {
129
- inputs.add(toConfig('vitest', project.extends));
130
- }
131
- }
118
+ for (const project of cfg.test?.projects ?? []) {
119
+ if (typeof project === 'string')
120
+ patterns.add(project);
121
+ else if (isProjectConfig(project) && typeof project.extends === 'string')
122
+ inputs.add(toConfig('vitest', project.extends));
123
+ }
124
+ }
125
+ if (patterns.size > 0) {
126
+ const [files, dirs] = await Promise.all([
127
+ _glob({ cwd: options.cwd, patterns: [...patterns], gitignore: false }),
128
+ _dirGlob({ cwd: options.cwd, patterns: [...patterns], gitignore: false }),
129
+ ]);
130
+ for (const file of files) {
131
+ if (projectConfigFile.test(basename(file)))
132
+ inputs.add(toConfig('vitest', file));
133
+ }
134
+ for (const dir of dirs) {
135
+ const projectRoot = toAbsolute(dir, options.cwd);
136
+ const configFile = findFileWithExtensions(join(projectRoot, 'vitest.config'), configExtensions) ??
137
+ findFileWithExtensions(join(projectRoot, 'vite.config'), configExtensions);
138
+ if (configFile)
139
+ inputs.add(toConfig('vitest', configFile));
132
140
  }
133
141
  }
134
142
  const addAliases = (aliasOptions) => {
@@ -210,7 +218,7 @@ export const resolveConfig = async (localConfig, options) => {
210
218
  }
211
219
  const _entry = cfg.build?.lib?.entry ?? [];
212
220
  const entries = typeof _entry === 'string' ? [_entry] : Array.isArray(_entry) ? _entry : Object.values(_entry).flat();
213
- const deps = entries.map(specifier => join(viteRoot, specifier)).map(id => toEntry(id));
221
+ const deps = entries.map(specifier => toAbsolute(specifier, viteRoot)).map(id => toEntry(id));
214
222
  for (const dependency of deps)
215
223
  inputs.add(dependency);
216
224
  }
@@ -239,7 +247,7 @@ const args = {
239
247
  }
240
248
  }
241
249
  if (parsed['environment'] && parsed['environment'] !== 'node') {
242
- inputs.push(toDependency(getEnvSpecifier(parsed['environment'])));
250
+ inputs.push(toEnvDependency(parsed['environment']));
243
251
  }
244
252
  if (typeof parsed['typecheck'] === 'object' && parsed['typecheck'].checker) {
245
253
  inputs.push(toDependency(parsed['typecheck'].checker === 'tsc' ? 'typescript' : parsed['typecheck'].checker));
@@ -29,11 +29,7 @@ interface VitestConfig {
29
29
  workspace: never;
30
30
  };
31
31
  })[];
32
- projects?: (string | (ViteConfig & {
33
- test: VitestConfig['test'] & {
34
- projects: never;
35
- };
36
- }))[];
32
+ projects?: (string | VitestProject)[];
37
33
  alias?: AliasOptions;
38
34
  };
39
35
  }
@@ -73,12 +69,20 @@ export interface ViteConfig extends VitestConfig {
73
69
  };
74
70
  }
75
71
  export type COMMAND = 'serve' | 'build';
76
- export type MODE = 'development' | 'production';
77
- interface Options {
72
+ export type MODE = 'development' | 'production' | 'test';
73
+ export interface Options {
78
74
  command: COMMAND;
79
75
  mode: MODE;
76
+ isSsrBuild?: boolean | undefined;
80
77
  ssrBuild?: boolean | undefined;
78
+ isPreview?: boolean | undefined;
81
79
  }
82
80
  export type ViteConfigOrFn = ViteConfig | ((options: Options) => ViteConfig) | ((options: Options) => Promise<ViteConfig>);
81
+ export type VitestProjectConfig = ViteConfig & {
82
+ test: VitestConfig['test'] & {
83
+ projects: never;
84
+ };
85
+ };
86
+ export type VitestProject = VitestProjectConfig | Promise<VitestProjectConfig> | ((options: Options) => VitestProjectConfig | Promise<VitestProjectConfig>);
83
87
  export type VitestWorkspaceConfig = (string | ViteConfig)[];
84
88
  export {};
@@ -1,5 +1,5 @@
1
1
  import { toAlias, toDeferResolve, toDeferResolveEntry, toDeferResolveProductionEntry, toDependency, } from '../../util/input.js';
2
- import { extname, isInternal, join, toAbsolute } from '../../util/path.js';
2
+ import { extname, isInternal, join } from '../../util/path.js';
3
3
  import { hasDependency } from '../../util/plugin.js';
4
4
  import { getDependenciesFromConfig } from '../babel/index.js';
5
5
  import { createRequireContextVisitor } from './visitors/requireContext.js';
@@ -44,6 +44,8 @@ const resolveRuleSetDependencies = (rule) => {
44
44
  const d = getDependenciesFromConfig(rule.options).map(d => d.specifier);
45
45
  return [useItem, ...d];
46
46
  }
47
+ if (typeof useItem === 'string' && useItem && rule.options && rule.use == null)
48
+ useItem = { loader: useItem, options: rule.options };
47
49
  return [useItem].flat().flatMap((item) => {
48
50
  if (!item)
49
51
  return [];
@@ -149,7 +151,7 @@ export const findWebpackDependenciesFromConfig = async (config, options) => {
149
151
  if (alias.length > 1)
150
152
  inputs.add(toAlias(alias, prefixes));
151
153
  for (const prefix of prefixes) {
152
- inputs.add(toAlias(addStar(alias), [addStar(toAbsolute(prefix, options.configFileDir))]));
154
+ inputs.add(toAlias(addStar(alias), [addStar(prefix)], { dir: options.configFileDir }));
153
155
  }
154
156
  }
155
157
  }
@@ -22,10 +22,8 @@ const resolveConfig = config => {
22
22
  if (config.packageExtensions) {
23
23
  for (const extension of Object.values(config.packageExtensions)) {
24
24
  if (extension.peerDependencies) {
25
- for (const dep of Object.keys(extension.peerDependencies)) {
26
- const optional = extension.peerDependenciesMeta?.[dep]?.optional === true;
27
- inputs.push(optional ? toDependency(dep, { optional: true }) : toDependency(dep));
28
- }
25
+ for (const dep of Object.keys(extension.peerDependencies))
26
+ inputs.push(toDependency(dep, { optional: true }));
29
27
  }
30
28
  }
31
29
  }
@@ -1,3 +1,3 @@
1
- import type { ReporterOptions } from '../types/issues.ts';
1
+ import type { InternalReporterOptions } from '../types/issues.ts';
2
2
  export default _default;
3
- declare function _default({ report, issues, cwd }: ReporterOptions): Promise<void>;
3
+ declare function _default({ report, issues, cwd, write }: InternalReporterOptions): Promise<void>;
@@ -1,7 +1,7 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { toRelative } from '../util/path.js';
3
3
  import { flattenIssues, getIssueDescription, getIssuePrefix, getIssueTypeTitle } from './util/util.js';
4
- export default async ({ report, issues, cwd }) => {
4
+ export default async ({ report, issues, cwd, write }) => {
5
5
  const entries = [];
6
6
  for (const [type, isReportType] of Object.entries(report)) {
7
7
  if (!isReportType) {
@@ -33,9 +33,7 @@ export default async ({ report, issues, cwd }) => {
33
33
  }
34
34
  }
35
35
  }
36
- const output = JSON.stringify(entries);
37
- process.stdout._handle?.setBlocking?.(true);
38
- process.stdout.write(`${output}\n`);
36
+ write(JSON.stringify(entries));
39
37
  };
40
38
  function convertSeverity(severity) {
41
39
  switch (severity) {
@@ -1,3 +1,3 @@
1
- import type { ReporterOptions } from '../types/issues.ts';
1
+ import type { InternalReporterOptions } from '../types/issues.ts';
2
2
  export default _default;
3
- declare function _default({ report, issues, isShowProgress, options, cwd }: ReporterOptions): void;
3
+ declare function _default({ report, issues, isShowProgress, options, cwd, write }: InternalReporterOptions): void;
@@ -1,13 +1,12 @@
1
1
  import { createOwnershipEngine } from '../util/codeowners.js';
2
2
  import { relative, resolve } from '../util/path.js';
3
3
  import { getColoredTitle, getIssueLine, getIssueTypeTitle } from './util/util.js';
4
- const logIssueRecord = (issues, cwd) => {
4
+ const getIssueRecordLines = (issues, cwd) => {
5
5
  const sortedByFilePath = issues.sort((a, b) => (a.owner < b.owner ? -1 : 1));
6
- for (const { filePath, symbols, owner, parentSymbol } of sortedByFilePath) {
7
- console.log(getIssueLine({ owner, filePath, symbols, parentSymbol }, cwd));
8
- }
6
+ return sortedByFilePath.map(({ filePath, symbols, owner, parentSymbol }) => getIssueLine({ owner, filePath, symbols, parentSymbol }, cwd));
9
7
  };
10
- export default ({ report, issues, isShowProgress, options, cwd }) => {
8
+ export default ({ report, issues, isShowProgress, options, cwd, write }) => {
9
+ const lines = [];
11
10
  let opts = {};
12
11
  try {
13
12
  opts = options ? JSON.parse(options) : opts;
@@ -36,14 +35,15 @@ export default ({ report, issues, isShowProgress, options, cwd }) => {
36
35
  });
37
36
  if (issuesForType.length > 0) {
38
37
  if (totalIssues)
39
- console.log();
40
- title && console.log(getColoredTitle(title, issuesForType.length));
41
- logIssueRecord(issuesForType, cwd);
38
+ lines.push('');
39
+ title && lines.push(getColoredTitle(title, issuesForType.length));
40
+ lines.push(...getIssueRecordLines(issuesForType, cwd));
42
41
  }
43
42
  totalIssues = totalIssues + issuesForType.length;
44
43
  }
45
44
  }
46
45
  if (totalIssues === 0 && isShowProgress) {
47
- console.log('✂️ Excellent, Knip found no issues.');
46
+ lines.push('✂️ Excellent, Knip found no issues.');
48
47
  }
48
+ write(lines.join('\n'));
49
49
  };
@@ -1,3 +1,3 @@
1
- import type { ReporterOptions } from '../types/issues.ts';
1
+ import type { InternalReporterOptions } from '../types/issues.ts';
2
2
  export default _default;
3
- declare function _default({ report, issues, isShowProgress, cwd }: ReporterOptions): void;
3
+ declare function _default({ report, issues, isShowProgress, cwd, write }: InternalReporterOptions): void;
@@ -1,10 +1,10 @@
1
1
  import { flattenIssues, getColoredTitle, getIssueLine, getIssueTypeTitle } from './util/util.js';
2
- const logIssueRecord = (issues, cwd) => {
2
+ const getIssueRecordLines = (issues, cwd) => {
3
3
  const sortedByFilePath = issues.sort((a, b) => (a.filePath > b.filePath ? 1 : -1));
4
- for (const issue of sortedByFilePath)
5
- console.log(getIssueLine(issue, cwd));
4
+ return sortedByFilePath.map(issue => getIssueLine(issue, cwd));
6
5
  };
7
- export default ({ report, issues, isShowProgress, cwd }) => {
6
+ export default ({ report, issues, isShowProgress, cwd, write }) => {
7
+ const lines = [];
8
8
  let totalIssues = 0;
9
9
  for (const [reportType, isReportType] of Object.entries(report)) {
10
10
  if (isReportType) {
@@ -18,13 +18,14 @@ export default ({ report, issues, isShowProgress, cwd }) => {
18
18
  return { ...items[0], symbols: items };
19
19
  });
20
20
  if (issuesForType.length > 0) {
21
- title && console.log(getColoredTitle(title, issuesForType.length));
22
- logIssueRecord(issuesForType, cwd);
21
+ title && lines.push(getColoredTitle(title, issuesForType.length));
22
+ lines.push(...getIssueRecordLines(issuesForType, cwd));
23
23
  }
24
24
  totalIssues = totalIssues + issuesForType.length;
25
25
  }
26
26
  }
27
27
  if (totalIssues === 0 && isShowProgress) {
28
- console.log('✂️ Excellent, Knip found no issues.');
28
+ lines.push('✂️ Excellent, Knip found no issues.');
29
29
  }
30
+ write(lines.join('\n'));
30
31
  };
@@ -1,3 +1,3 @@
1
- import type { ReporterOptions } from '../types/issues.ts';
1
+ import type { InternalReporterOptions } from '../types/issues.ts';
2
2
  export default _default;
3
- declare function _default({ cwd, issues, isShowProgress }: ReporterOptions): void;
3
+ declare function _default({ cwd, issues, isShowProgress, write }: InternalReporterOptions): void;