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,5 +1,5 @@
1
1
  import { toDeferResolve, toProductionEntry } from '../../util/input.js';
2
- import { join, relative } from '../../util/path.js';
2
+ import { join } from '../../util/path.js';
3
3
  import { hasDependency } from '../../util/plugin.js';
4
4
  import { createCompiler } from './compiler.js';
5
5
  import { getTaglibDependencies } from './taglibs.js';
@@ -29,18 +29,17 @@ const tagDefFields = [
29
29
  'translate',
30
30
  ];
31
31
  const resolveConfig = (localConfig, options) => {
32
- const { configFileName, configFileDir, cwd } = options;
33
- const inputs = [];
32
+ const { configFileName, configFileDir } = options;
33
+ const inputs = production.map(pattern => toProductionEntry(pattern));
34
34
  if (!localConfig)
35
35
  return inputs;
36
36
  if (configFileName === 'marko.json') {
37
- const dir = relative(cwd, configFileDir);
38
- return tagProduction.map(pattern => toProductionEntry(join(dir, pattern)));
37
+ return tagProduction.map(pattern => toProductionEntry(join(configFileDir, pattern)));
39
38
  }
40
39
  for (const field of tagDefFields) {
41
40
  for (const id of [localConfig[field]].flat()) {
42
41
  if (typeof id === 'string')
43
- inputs.push(toDeferResolve(join(configFileDir, id)));
42
+ inputs.push(toDeferResolve(id));
44
43
  }
45
44
  }
46
45
  return inputs;
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '../../types/config.ts';
2
+ declare const plugin: Plugin;
3
+ export default plugin;
@@ -0,0 +1,57 @@
1
+ import { join } from '../../util/path.js';
2
+ import { isDirectory } from '../../util/fs.js';
3
+ import { toProductionEntry } from '../../util/input.js';
4
+ import { hasDependency } from '../../util/plugin.js';
5
+ const title = 'Mastra';
6
+ const enablers = ['mastra'];
7
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
8
+ const extensions = '{js,ts}';
9
+ const defaultDir = 'src/mastra';
10
+ const discoveryCommands = new Set(['dev', 'build']);
11
+ const getProductionPatterns = (dir) => {
12
+ const agentRoots = `${dir}/agents/*/*(subagents/*/)`;
13
+ return [
14
+ `${dir}/index.${extensions}`,
15
+ `${dir}/{storage,observability,logger,server,studio}.{js,ts,mjs,mts}`,
16
+ `${dir}/workflows/*.${extensions}`,
17
+ `${dir}/{,agents/*/}tools/**/*.${extensions}`,
18
+ `${agentRoots}{config,instructions,memory,workspace}.${extensions}`,
19
+ `${agentRoots}{tools,scorers,skills,processors/input,processors/output}/*.${extensions}`,
20
+ `${agentRoots}schedules/**/*.${extensions}`,
21
+ `!${dir}/**/*.{test,spec}.${extensions}`,
22
+ `!${dir}/**/__tests__/**`,
23
+ ];
24
+ };
25
+ const production = getProductionPatterns(defaultDir);
26
+ const args = {
27
+ binaries: ['mastra'],
28
+ string: ['dir', 'tools'],
29
+ alias: { dir: ['d'], tools: ['t'] },
30
+ resolveInputs: (parsed, { cwd }) => {
31
+ if (!discoveryCommands.has(parsed._[0]))
32
+ return [];
33
+ const inputs = [];
34
+ if (parsed.dir) {
35
+ for (const pattern of getProductionPatterns(parsed.dir))
36
+ inputs.push(toProductionEntry(pattern));
37
+ }
38
+ if (parsed.tools) {
39
+ for (const tool of String(parsed.tools).split(',')) {
40
+ const specifier = tool.trim();
41
+ if (!specifier)
42
+ continue;
43
+ const pattern = isDirectory(join(cwd, specifier)) ? `${specifier}/index.${extensions}` : specifier;
44
+ inputs.push(toProductionEntry(pattern));
45
+ }
46
+ }
47
+ return inputs;
48
+ },
49
+ };
50
+ const plugin = {
51
+ title,
52
+ enablers,
53
+ isEnabled,
54
+ production,
55
+ args,
56
+ };
57
+ export default plugin;
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '../../types/config.ts';
2
+ declare const plugin: Plugin;
3
+ export default plugin;
@@ -0,0 +1,33 @@
1
+ import { isFile } from '../../util/fs.js';
2
+ import { toAbsolute } from '../../util/path.js';
3
+ const title = 'MCP';
4
+ const enablers = 'This plugin is enabled when `.mcp.json`, `.cursor/mcp.json`, `.vscode/mcp.json` or `.codex/config.toml` is found.';
5
+ const isRootOnly = true;
6
+ const config = ['.mcp.json', '.cursor/mcp.json', '.vscode/mcp.json', '.codex/config.toml'];
7
+ const isEnabled = ({ cwd }) => config.some(file => isFile(cwd, file));
8
+ const PROJECT_DIR_VAR = /\$\{(?:workspaceFolder|CLAUDE_PROJECT_DIR(?::-[^}]*)?)\}/g;
9
+ const resolveConfig = async (localConfig, options) => {
10
+ const { cwd, getInputsFromScripts } = options;
11
+ const servers = { ...localConfig.mcpServers, ...localConfig.servers, ...localConfig.mcp_servers };
12
+ const inputs = [];
13
+ for (const server of Object.values(servers)) {
14
+ if (typeof server?.command !== 'string')
15
+ continue;
16
+ const script = [server.command, ...(server.args ?? [])].join(' ').replace(PROJECT_DIR_VAR, '.');
17
+ const dir = server.cwd ? toAbsolute(server.cwd.replace(PROJECT_DIR_VAR, '.'), cwd) : cwd;
18
+ for (const input of getInputsFromScripts(script, { optionalBinaries: true, cwd: dir })) {
19
+ input.dir = dir;
20
+ inputs.push(input);
21
+ }
22
+ }
23
+ return inputs;
24
+ };
25
+ const plugin = {
26
+ title,
27
+ enablers,
28
+ isEnabled,
29
+ isRootOnly,
30
+ config,
31
+ resolveConfig,
32
+ };
33
+ export default plugin;
@@ -0,0 +1,11 @@
1
+ type MCPServer = {
2
+ command?: string;
3
+ args?: string[];
4
+ cwd?: string;
5
+ };
6
+ export type MCPConfig = {
7
+ mcpServers?: Record<string, MCPServer>;
8
+ servers?: Record<string, MCPServer>;
9
+ mcp_servers?: Record<string, MCPServer>;
10
+ };
11
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,4 @@
1
1
  import { isFile } from '../../util/fs.js';
2
- import { isEntry } from '../../util/input.js';
3
2
  import { basename, dirname, join, toAbsolute } from '../../util/path.js';
4
3
  const title = 'mise';
5
4
  const enablers = 'This plugin is enabled when `mise.toml` or `.mise.toml` is found.';
@@ -64,8 +63,6 @@ const resolveConfig = async (localConfig, options) => {
64
63
  if (isProduction)
65
64
  input.optional = true;
66
65
  input.dir ??= dir;
67
- if (isEntry(input))
68
- input.specifier = toAbsolute(input.specifier, input.dir);
69
66
  inputs.push(input);
70
67
  }
71
68
  }
@@ -7,14 +7,51 @@ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
7
7
  const config = ['.mocharc.{js,cjs,json,jsonc,yml,yaml}', 'package.json'];
8
8
  const entry = ['**/test/*.{js,cjs,mjs}'];
9
9
  const defaultExtensions = ['js', 'cjs', 'mjs'];
10
- const resolveConfig = localConfig => {
10
+ const builtInReporters = new Set([
11
+ 'Base',
12
+ 'base',
13
+ 'Dot',
14
+ 'dot',
15
+ 'Doc',
16
+ 'doc',
17
+ 'TAP',
18
+ 'tap',
19
+ 'JSON',
20
+ 'json',
21
+ 'HTML',
22
+ 'html',
23
+ 'List',
24
+ 'list',
25
+ 'Min',
26
+ 'min',
27
+ 'Spec',
28
+ 'spec',
29
+ 'Nyan',
30
+ 'nyan',
31
+ 'XUnit',
32
+ 'xunit',
33
+ 'Markdown',
34
+ 'markdown',
35
+ 'Progress',
36
+ 'progress',
37
+ 'Landing',
38
+ 'landing',
39
+ 'JSONStream',
40
+ 'json-stream',
41
+ 'GithubActions',
42
+ 'github-actions',
43
+ ]);
44
+ const isExternalReporter = (reporter) => typeof reporter === 'string' && !builtInReporters.has(reporter);
45
+ const resolveConfig = (localConfig, options) => {
11
46
  const entryPatterns = localConfig.spec ? [localConfig.spec].flat() : entry;
12
47
  const files = localConfig.file ? [localConfig.file].flat() : [];
13
48
  const require = localConfig.require ? [localConfig.require].flat() : [];
14
49
  const inputs = [];
15
50
  inputs.push(...entryPatterns.map(id => toEntry(id)));
16
- inputs.push(...files.map(id => toDeferResolveEntry(id)));
17
- inputs.push(...require.map(id => toDeferResolve(id)));
51
+ inputs.push(...files.map(id => toDeferResolveEntry(id, { dir: options.cwd })));
52
+ inputs.push(...require.map(id => toDeferResolve(id, { dir: options.cwd })));
53
+ if (isExternalReporter(localConfig.reporter))
54
+ inputs.push(toDeferResolve(localConfig.reporter, { dir: options.cwd }));
18
55
  return inputs;
19
56
  };
20
57
  const args = {
@@ -74,6 +111,8 @@ const args = {
74
111
  }
75
112
  for (const value of [parsed.ignore ?? []].flat())
76
113
  inputs.push(toEntry(`!${String(value)}`));
114
+ if (isExternalReporter(parsed.reporter))
115
+ inputs.push(toDeferResolve(parsed.reporter));
77
116
  return inputs;
78
117
  },
79
118
  };
@@ -1,5 +1,6 @@
1
1
  export interface MochaConfig {
2
2
  file?: string | string[];
3
+ reporter?: string;
3
4
  require?: string | string[];
4
5
  spec?: string | string[];
5
6
  }
@@ -1,3 +1,6 @@
1
1
  import type { Plugin } from '../../types/config.ts';
2
+ export declare const docs: {
3
+ note: string;
4
+ };
2
5
  declare const plugin: Plugin;
3
6
  export default plugin;
@@ -3,7 +3,7 @@ import { findProperty, getPropertyValues } from '../../typescript/ast-helpers.js
3
3
  import { getStringValue } from '../../typescript/ast-nodes.js';
4
4
  import { isDirectory } from '../../util/fs.js';
5
5
  import { toConfig, toDeferResolve, toProductionEntry } from '../../util/input.js';
6
- import { join } from '../../util/path.js';
6
+ import { isInNodeModules, join } from '../../util/path.js';
7
7
  import { hasDependency } from '../../util/plugin.js';
8
8
  const title = 'Next.js';
9
9
  const enablers = ['next'];
@@ -39,6 +39,56 @@ const getEntryFilePatterns = (pageExtensions = defaultPageExtensions, cwd) => {
39
39
  ];
40
40
  };
41
41
  const production = getEntryFilePatterns();
42
+ const getInputs = (pageExtensions, loaders, aliasTargets, configFileDir) => {
43
+ const extensions = pageExtensions.length > 0 ? pageExtensions : defaultPageExtensions;
44
+ const patterns = [...getEntryFilePatterns(extensions, configFileDir), 'next-env.d.ts'];
45
+ const inputs = patterns.map(id => toProductionEntry(join(configFileDir, id)));
46
+ for (const loader of loaders)
47
+ inputs.push(toDeferResolve(loader));
48
+ for (const target of aliasTargets)
49
+ inputs.push({ ...toDeferResolve(target, { dir: configFileDir }), production: true });
50
+ return inputs;
51
+ };
52
+ const isObject = (value) => typeof value === 'object' && value !== null;
53
+ const addSpecifier = (specifiers, value) => {
54
+ if (typeof value === 'string' && !isInNodeModules(value))
55
+ specifiers.add(value);
56
+ };
57
+ const collectLoaderValues = (value, loaders) => {
58
+ if (Array.isArray(value))
59
+ for (const item of value)
60
+ collectLoaderValues(item, loaders);
61
+ else if (isObject(value)) {
62
+ addSpecifier(loaders, value.loader);
63
+ collectLoaderValues(value.loaders, loaders);
64
+ }
65
+ else
66
+ addSpecifier(loaders, value);
67
+ };
68
+ const collectAliasTargetValues = (value, targets) => {
69
+ if (Array.isArray(value))
70
+ for (const item of value)
71
+ collectAliasTargetValues(item, targets);
72
+ else if (isObject(value))
73
+ collectAliasTargetValues(value.browser, targets);
74
+ else
75
+ addSpecifier(targets, value);
76
+ };
77
+ const resolveConfig = async (localConfig, { configFileDir }) => {
78
+ const config = typeof localConfig === 'function'
79
+ ? await localConfig('phase-production-build', { defaultConfig: {} })
80
+ : localConfig;
81
+ const pageExtensions = Array.isArray(config?.pageExtensions)
82
+ ? config.pageExtensions.filter(extension => typeof extension === 'string')
83
+ : [];
84
+ const loaders = new Set();
85
+ for (const rule of Object.values(config?.turbopack?.rules ?? {}))
86
+ collectLoaderValues(rule, loaders);
87
+ const aliasTargets = new Set();
88
+ for (const target of Object.values(config?.turbopack?.resolveAlias ?? {}))
89
+ collectAliasTargetValues(target, aliasTargets);
90
+ return getInputs(pageExtensions, loaders, aliasTargets, configFileDir);
91
+ };
42
92
  const resolveFromAST = (program, { configFileDir }) => {
43
93
  const pageExtensions = new Set();
44
94
  const loaders = new Set();
@@ -100,14 +150,7 @@ const resolveFromAST = (program, { configFileDir }) => {
100
150
  },
101
151
  });
102
152
  visitor.visit(program);
103
- const extensions = pageExtensions.size > 0 ? [...pageExtensions] : defaultPageExtensions;
104
- const patterns = [...getEntryFilePatterns(extensions, configFileDir), 'next-env.d.ts'];
105
- const inputs = patterns.map(id => toProductionEntry(join(configFileDir, id)));
106
- for (const loader of loaders)
107
- inputs.push(toDeferResolve(loader));
108
- for (const target of aliasTargets)
109
- inputs.push({ ...toDeferResolve(target, { dir: configFileDir }), production: true });
110
- return inputs;
153
+ return getInputs([...pageExtensions], loaders, aliasTargets, configFileDir);
111
154
  };
112
155
  const commands = new Set(['dev', 'build', 'start']);
113
156
  const args = {
@@ -119,12 +162,17 @@ const args = {
119
162
  return [toConfig('next', join(dir, 'next.config'))];
120
163
  },
121
164
  };
165
+ const note = `Knip loads \`next.config.*\` to read Turbopack loaders and alias targets from the composed configuration,
166
+ including values a shared configuration factory adds. A configuration file that fails to load is analyzed statically.`;
167
+ export const docs = { note };
122
168
  const plugin = {
123
169
  title,
124
170
  enablers,
125
171
  isEnabled,
126
172
  config,
127
173
  production,
174
+ isLoadConfigOptional: true,
175
+ resolveConfig,
128
176
  resolveFromAST,
129
177
  args,
130
178
  };
@@ -0,0 +1,11 @@
1
+ type NextConfig = {
2
+ pageExtensions?: string[];
3
+ turbopack?: {
4
+ rules?: Record<string, unknown>;
5
+ resolveAlias?: Record<string, unknown>;
6
+ };
7
+ };
8
+ export type NextConfigModule = NextConfig | ((phase: string, context: {
9
+ defaultConfig: NextConfig;
10
+ }) => NextConfig | Promise<NextConfig>);
11
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -2,7 +2,7 @@ import { compact } from '../../util/array.js';
2
2
  import { isFile, loadJSON } from '../../util/fs.js';
3
3
  import { toConfig, toDeferResolveEntry, toDependency } from '../../util/input.js';
4
4
  import { get } from '../../util/object.js';
5
- import { dirname, join, relative } from '../../util/path.js';
5
+ import { dirname, join, relative, toAbsolute } from '../../util/path.js';
6
6
  import { hasDependency } from '../../util/plugin.js';
7
7
  import { substringBefore } from '../../util/string.js';
8
8
  const title = 'Nx';
@@ -39,12 +39,7 @@ const resolveConfig = async (localConfig, options) => {
39
39
  .filter(executor => executor && !executor.startsWith('.'))
40
40
  .map(executor => executor && substringBefore(executor, ':'));
41
41
  const expand = (value) => value.replaceAll('{projectRoot}', options.configFileDir).replaceAll('{workspaceRoot}', options.rootCwd);
42
- const resolveTargetCwd = (targetCwd) => {
43
- if (!targetCwd)
44
- return options.cwd;
45
- const expanded = expand(targetCwd);
46
- return expanded === targetCwd ? join(options.cwd, targetCwd) : expanded;
47
- };
42
+ const resolveTargetCwd = (targetCwd) => targetCwd ? toAbsolute(expand(targetCwd), options.rootCwd) : options.cwd;
48
43
  const inputs = targets
49
44
  .filter(target => target.executor === 'nx:run-commands' || target.command)
50
45
  .flatMap(target => {
@@ -112,7 +107,7 @@ const resolve = async (options) => {
112
107
  continue;
113
108
  for (const id of [entry.implementation || entry.factory, entry.batchImplementation]) {
114
109
  if (typeof id === 'string' && id.length > 0) {
115
- inputs.push(toDeferResolveEntry(join(dirname(filePath), substringBefore(id, '#'))));
110
+ inputs.push(toDeferResolveEntry(substringBefore(id, '#'), { dir: dirname(filePath) }));
116
111
  }
117
112
  }
118
113
  }
@@ -3,7 +3,7 @@ import { hasDependency } from '../../util/plugin.js';
3
3
  const title = 'nyc';
4
4
  const enablers = ['nyc'];
5
5
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
- const config = ['.nycrc', '.nycrc.{json,yml,yaml}', 'nyc.config.js', 'package.json'];
6
+ const config = ['.nycrc', '.nycrc.{json,yml,yaml}', 'nyc.config.{js,cjs,mjs}', 'package.json'];
7
7
  const resolveConfig = config => {
8
8
  const extend = config?.extends ?? [];
9
9
  const requires = config?.require ?? [];
@@ -3,11 +3,11 @@ import { toC12config } from '../../util/plugin-config.js';
3
3
  const title = 'openapi-ts';
4
4
  const enablers = ['@hey-api/openapi-ts'];
5
5
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
- const config = ['package.json', ...toC12config('openapi-ts')];
6
+ const entry = ['package.json', ...toC12config('openapi-ts')];
7
7
  const plugin = {
8
8
  title,
9
9
  enablers,
10
10
  isEnabled,
11
- config,
11
+ entry,
12
12
  };
13
13
  export default plugin;
@@ -2,7 +2,7 @@ import { hasDependency } from '../../util/plugin.js';
2
2
  const title = 'Oxfmt';
3
3
  const enablers = ['oxfmt'];
4
4
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
5
- const config = ['.oxfmtrc.json', '.oxfmtrc.jsonc', 'oxfmt.config.{ts,mts}'];
5
+ const entry = ['.oxfmtrc.json', '.oxfmtrc.jsonc', 'oxfmt.config.{ts,mts}'];
6
6
  const args = {
7
7
  config: true,
8
8
  };
@@ -10,7 +10,7 @@ const plugin = {
10
10
  title,
11
11
  enablers,
12
12
  isEnabled,
13
- config,
13
+ entry,
14
14
  args,
15
15
  };
16
16
  export default plugin;
@@ -1,21 +1,21 @@
1
1
  import { arrayify } from '../../util/array.js';
2
2
  import { toDeferResolve, toEntry } from '../../util/input.js';
3
- import { join, relative, toAbsolute } from '../../util/path.js';
3
+ import { join, toAbsolute } from '../../util/path.js';
4
4
  import { hasDependency } from '../../util/plugin.js';
5
5
  const title = 'Playwright';
6
6
  const enablers = ['@playwright/test'];
7
7
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
8
8
  const config = ['playwright.config.{js,cjs,mjs,ts,cts,mts}'];
9
9
  export const entry = ['**/*.@(spec|test).?(c|m)[jt]s?(x)'];
10
- const toEntryPatterns = (testMatch, cwd, configDir, localConfig, rootConfig) => {
10
+ const toEntryPatterns = (testMatch, configDir, localConfig, rootConfig) => {
11
11
  const testDir = localConfig.testDir ?? rootConfig.testDir;
12
- const dir = relative(cwd, testDir ? join(configDir, testDir) : configDir);
12
+ const dir = testDir ? toAbsolute(testDir, configDir) : configDir;
13
13
  const patterns = [testMatch].flat().filter((p) => typeof p === 'string');
14
14
  return patterns.map(pattern => toEntry(join(dir, pattern)));
15
15
  };
16
16
  const builtinReporters = ['dot', 'line', 'list', 'junit', 'html', 'blob', 'json', 'github', 'null'];
17
17
  export const resolveConfig = async (localConfig, options) => {
18
- const { cwd, configFileDir } = options;
18
+ const { configFileDir } = options;
19
19
  const inputs = [];
20
20
  for (const id of arrayify(localConfig.globalSetup))
21
21
  inputs.push(toEntry(toAbsolute(id, configFileDir)));
@@ -30,12 +30,7 @@ export const resolveConfig = async (localConfig, options) => {
30
30
  cwd: dir,
31
31
  manifest: options.getManifest(dir) ?? options.manifest,
32
32
  })) {
33
- const inputDir = input.dir ?? dir;
34
- inputs.push({
35
- ...input,
36
- ...(input.type === 'entry' ? { specifier: toAbsolute(input.specifier, inputDir) } : {}),
37
- dir: inputDir,
38
- });
33
+ inputs.push({ ...input, dir: input.dir ?? dir });
39
34
  }
40
35
  }
41
36
  const projects = localConfig.projects ? [localConfig, ...localConfig.projects] : [localConfig];
@@ -46,7 +41,7 @@ export const resolveConfig = async (localConfig, options) => {
46
41
  return [name];
47
42
  });
48
43
  return projects
49
- .flatMap(config => toEntryPatterns(config.testMatch ?? entry, cwd, configFileDir, config, localConfig))
44
+ .flatMap(config => toEntryPatterns(config.testMatch ?? entry, configFileDir, config, localConfig))
50
45
  .concat(reporters.map(id => toDeferResolve(id)))
51
46
  .concat(inputs);
52
47
  };
@@ -12,10 +12,8 @@ const resolveConfig = config => {
12
12
  if (packageExtensions) {
13
13
  for (const extension of Object.values(packageExtensions)) {
14
14
  if (extension.peerDependencies) {
15
- for (const dep of Object.keys(extension.peerDependencies)) {
16
- const optional = extension.peerDependenciesMeta?.[dep]?.optional === true;
17
- inputs.push(optional ? toDependency(dep, { optional: true }) : toDependency(dep));
18
- }
15
+ for (const dep of Object.keys(extension.peerDependencies))
16
+ inputs.push(toDependency(dep, { optional: true }));
19
17
  }
20
18
  }
21
19
  }
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '../../types/config.ts';
2
+ declare const plugin: Plugin;
3
+ export default plugin;
@@ -0,0 +1,16 @@
1
+ import { hasDependency } from '../../util/plugin.js';
2
+ const title = 'PurgeCSS';
3
+ const enablers = ['purgecss', '@fullhuman/postcss-purgecss'];
4
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
5
+ const entry = ['purgecss.config.js'];
6
+ const args = {
7
+ config: true,
8
+ };
9
+ const plugin = {
10
+ title,
11
+ enablers,
12
+ isEnabled,
13
+ entry,
14
+ args,
15
+ };
16
+ export default plugin;
@@ -2,8 +2,7 @@ import { Visitor } from 'oxc-parser';
2
2
  import { findProperty, getFirstPropertyValue, getStringValues } from '../../typescript/ast-helpers.js';
3
3
  import { getStringValue } from '../../typescript/ast-nodes.js';
4
4
  import { getGitRemoteUrls } from '../../util/git.js';
5
- import { isEntry } from '../../util/input.js';
6
- import { join, toAbsolute } from '../../util/path.js';
5
+ import { join } from '../../util/path.js';
7
6
  import { hasDependency } from '../../util/plugin.js';
8
7
  const title = 'Railway';
9
8
  const enablers = ['railway'];
@@ -109,8 +108,6 @@ const resolveFromAST = (program, options) => {
109
108
  ...getCommands(findProperty(findProperty(serviceConfig, 'deploy'), 'preDeployCommand')),
110
109
  ];
111
110
  for (const input of options.getInputsFromScripts(commands, { optionalBinaries: true, cwd, manifest })) {
112
- if (isEntry(input))
113
- input.specifier = toAbsolute(input.specifier, cwd);
114
111
  inputs.push({ ...input, dir: cwd });
115
112
  }
116
113
  },
@@ -1,6 +1,6 @@
1
1
  import { hasDependency } from '../../util/plugin.js';
2
2
  const title = 'Remix';
3
- const enablers = [/^@remix-run\//];
3
+ const enablers = ['@remix-run/dev'];
4
4
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
5
5
  const entry = ['remix.config.js', 'remix.init/index.js'];
6
6
  const production = [
@@ -2,7 +2,7 @@ import { arrayify } from '../../util/array.js';
2
2
  import { findFileWithExtensions } from '../../util/fs.js';
3
3
  import { _dirGlob, _glob, negate } from '../../util/glob.js';
4
4
  import { toAlias, toConfig, toDeferResolve, toDependency, toEntry } from '../../util/input.js';
5
- import { dirname, join, relative, toAbsolute } from '../../util/path.js';
5
+ import { dirname, join, toAbsolute } from '../../util/path.js';
6
6
  import { hasDependency, load } from '../../util/plugin.js';
7
7
  import { createRstestMockVisitor } from './visitors/mock.js';
8
8
  const title = 'Rstest';
@@ -25,7 +25,7 @@ const resolveConfig = async (localConfig, options) => {
25
25
  const seen = new Set([configFilePath]);
26
26
  const inputs = [];
27
27
  const addProject = async (project, projectRoot) => {
28
- const toPattern = (pattern) => relative(cwd, toAbsolute(replaceRootDir(pattern, projectRoot), projectRoot));
28
+ const toPattern = (pattern) => toAbsolute(replaceRootDir(pattern, projectRoot), projectRoot);
29
29
  if (!options.config.entry) {
30
30
  const include = [];
31
31
  const exclude = [...(Array.isArray(project.exclude) ? project.exclude : (project.exclude?.patterns ?? []))];
@@ -27,7 +27,7 @@ const handlerToEntry = (handler) => {
27
27
  const file = handler.slice(0, dot);
28
28
  return toProductionEntry(/\.(?:[cm]?[jt]s|[jt]sx)$/.test(file) ? file : `${file}.{js,ts}`);
29
29
  };
30
- const pluginToInput = (plugin, dir) => isInternal(plugin) ? toProductionEntry(join(dir, plugin)) : toDependency(plugin);
30
+ const pluginToInput = (plugin, dir) => isInternal(plugin) ? toProductionEntry(toAbsolute(plugin, dir)) : toDependency(plugin);
31
31
  const getFunctionEntries = async (functions, dir) => {
32
32
  const entries = [];
33
33
  const resolved = await resolveFileVariable(functions, dir);
@@ -1,6 +1,6 @@
1
1
  import MDX from '../../compilers/mdx.js';
2
2
  import { toConfig, toDeferResolve, toDependency, toEntry } from '../../util/input.js';
3
- import { join, relative } from '../../util/path.js';
3
+ import { join, toAbsolute } from '../../util/path.js';
4
4
  import { hasDependency } from '../../util/plugin.js';
5
5
  import { getBabelInputs } from '../vite/helpers.js';
6
6
  const title = 'Storybook';
@@ -14,14 +14,14 @@ const project = ['.{storybook,rnstorybook}/**/*.{js,jsx,ts,tsx,mts}'];
14
14
  const resolveConfig = async (localConfig, options) => {
15
15
  const { cwd, configFileDir } = options;
16
16
  const strs = typeof localConfig?.stories === 'function' ? await localConfig.stories(stories) : localConfig?.stories;
17
- const relativePatterns = strs?.map(pattern => {
17
+ const storyPatterns = strs?.map(pattern => {
18
18
  if (typeof pattern === 'string')
19
- return relative(cwd, join(configFileDir, pattern));
20
- return relative(cwd, join(configFileDir, pattern.directory, pattern.files ?? stories[0]));
19
+ return toAbsolute(pattern, configFileDir);
20
+ return join(toAbsolute(pattern.directory, configFileDir), pattern.files ?? stories[0]);
21
21
  });
22
22
  const patterns = [
23
23
  ...(options.config.entry ?? restEntry),
24
- ...(relativePatterns && relativePatterns.length > 0 ? relativePatterns : stories),
24
+ ...(storyPatterns && storyPatterns.length > 0 ? storyPatterns : stories),
25
25
  ];
26
26
  const addons = localConfig.addons?.map(addon => (typeof addon === 'string' ? addon : addon.name)) ?? [];
27
27
  const builder = localConfig?.core?.builder &&
@@ -5,7 +5,7 @@ import { toAlias, toIgnore, toProductionEntry } from '../../util/input.js';
5
5
  import { config as viteConfig } from '../vite/index.js';
6
6
  const production = [
7
7
  'src/routes/**/+{page,server,page.server,error,layout,layout.server}{,@*}.{js,ts,svelte}',
8
- 'src/hooks.{server,client}.{js,ts}',
8
+ 'src/hooks{,.server,.client}.{js,ts}',
9
9
  'src/params/*.{js,ts}',
10
10
  'src/service-worker.{js,ts}',
11
11
  'src/service-worker/index.{js,ts}',
@@ -3,11 +3,11 @@ import { toCosmiconfig } from '../../util/plugin-config.js';
3
3
  const title = 'Syncpack';
4
4
  const enablers = ['syncpack'];
5
5
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
- const config = ['package.json', ...toCosmiconfig('syncpack')];
6
+ const entry = ['package.json', ...toCosmiconfig('syncpack')];
7
7
  const plugin = {
8
8
  title,
9
9
  enablers,
10
10
  isEnabled,
11
- config,
11
+ entry,
12
12
  };
13
13
  export default plugin;