knip 6.44.2 → 6.45.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 (218) hide show
  1. package/dist/ConfigurationChief.d.ts +23 -1033
  2. package/dist/ConfigurationChief.js +71 -15
  3. package/dist/DependencyDeputy.d.ts +10 -6
  4. package/dist/DependencyDeputy.js +51 -27
  5. package/dist/IssueCollector.d.ts +14 -11
  6. package/dist/IssueCollector.js +25 -20
  7. package/dist/IssueFixer.js +1 -1
  8. package/dist/PackagePeeker.d.ts +6 -0
  9. package/dist/PackagePeeker.js +43 -14
  10. package/dist/ProjectPrincipal.d.ts +6 -3
  11. package/dist/ProjectPrincipal.js +83 -32
  12. package/dist/WorkspaceWorker.d.ts +5 -1
  13. package/dist/WorkspaceWorker.js +39 -22
  14. package/dist/binaries/bash-parser.js +1 -7
  15. package/dist/binaries/command.d.ts +3 -3
  16. package/dist/binaries/command.js +6 -2
  17. package/dist/binaries/fallback.js +1 -1
  18. package/dist/binaries/plugins.d.ts +4 -1
  19. package/dist/binaries/plugins.js +66 -18
  20. package/dist/binaries/resolvers/npm.js +7 -5
  21. package/dist/binaries/resolvers/npx.js +8 -40
  22. package/dist/binaries/util.d.ts +13 -1
  23. package/dist/binaries/util.js +35 -1
  24. package/dist/cli.js +10 -84
  25. package/dist/configuration-hints.d.ts +16 -0
  26. package/dist/configuration-hints.js +64 -0
  27. package/dist/constants.d.ts +2 -1
  28. package/dist/constants.js +2 -0
  29. package/dist/graph/SubpathReferences.d.ts +33 -0
  30. package/dist/graph/SubpathReferences.js +114 -0
  31. package/dist/graph/analyze.d.ts +4 -1
  32. package/dist/graph/analyze.js +16 -5
  33. package/dist/graph/build.d.ts +3 -1
  34. package/dist/graph/build.js +47 -23
  35. package/dist/graph-explorer/operations/resolve-export-origins.js +1 -1
  36. package/dist/plugins/angular/index.js +10 -17
  37. package/dist/plugins/aws-cdk/index.d.ts +3 -0
  38. package/dist/plugins/aws-cdk/index.js +32 -0
  39. package/dist/plugins/aws-cdk/types.d.ts +5 -0
  40. package/dist/plugins/aws-cdk/types.js +1 -0
  41. package/dist/plugins/babel/index.d.ts +1 -1
  42. package/dist/plugins/babel/index.js +19 -5
  43. package/dist/plugins/bun/index.js +8 -7
  44. package/dist/plugins/c8/index.js +17 -4
  45. package/dist/plugins/changesets/index.js +3 -2
  46. package/dist/plugins/commitizen/index.js +6 -3
  47. package/dist/plugins/commitlint/index.js +10 -11
  48. package/dist/plugins/cypress/index.js +4 -2
  49. package/dist/plugins/danger/index.js +1 -1
  50. package/dist/plugins/docusaurus/helpers.js +6 -6
  51. package/dist/plugins/docusaurus/index.js +2 -2
  52. package/dist/plugins/electron-forge/index.js +2 -2
  53. package/dist/plugins/electron-vite/index.js +2 -2
  54. package/dist/plugins/eleventy/index.js +3 -2
  55. package/dist/plugins/eslint/helpers.js +4 -3
  56. package/dist/plugins/eslint/resolveFromAST.js +2 -2
  57. package/dist/plugins/evalite/index.d.ts +3 -0
  58. package/dist/plugins/evalite/index.js +26 -0
  59. package/dist/plugins/flue/index.js +2 -2
  60. package/dist/plugins/github-action/index.js +2 -2
  61. package/dist/plugins/github-actions/index.js +2 -2
  62. package/dist/plugins/graphql-codegen/index.js +13 -9
  63. package/dist/plugins/index.d.ts +5 -0
  64. package/dist/plugins/index.js +10 -0
  65. package/dist/plugins/jest/index.js +5 -5
  66. package/dist/plugins/knex/index.js +2 -2
  67. package/dist/plugins/laravel-vite-plugin/resolveFromAST.js +2 -2
  68. package/dist/plugins/lunaria/index.js +5 -2
  69. package/dist/plugins/markdownlint/index.js +8 -2
  70. package/dist/plugins/marko/index.js +2 -2
  71. package/dist/plugins/marko/taglibs.d.ts +1 -1
  72. package/dist/plugins/marko/taglibs.js +4 -28
  73. package/dist/plugins/mdx/index.d.ts +2 -1
  74. package/dist/plugins/mdx/index.js +7 -4
  75. package/dist/plugins/mdxlint/index.js +18 -15
  76. package/dist/plugins/mikro-orm/index.d.ts +3 -0
  77. package/dist/plugins/mikro-orm/index.js +77 -0
  78. package/dist/plugins/mikro-orm/types.d.ts +21 -0
  79. package/dist/plugins/mikro-orm/types.js +1 -0
  80. package/dist/plugins/msw/index.js +6 -3
  81. package/dist/plugins/msw/types.d.ts +1 -1
  82. package/dist/plugins/netlify/index.js +7 -3
  83. package/dist/plugins/next/index.js +63 -9
  84. package/dist/plugins/next/types.d.ts +5 -0
  85. package/dist/plugins/next-mdx/resolveFromAST.js +15 -10
  86. package/dist/plugins/nitro/index.js +5 -6
  87. package/dist/plugins/node/index.js +4 -4
  88. package/dist/plugins/npm-package-json-lint/index.js +10 -3
  89. package/dist/plugins/nuxt/index.js +18 -10
  90. package/dist/plugins/nuxt/types.d.ts +4 -0
  91. package/dist/plugins/nx/index.js +6 -3
  92. package/dist/plugins/openclaw/index.js +11 -11
  93. package/dist/plugins/oxlint/index.js +2 -2
  94. package/dist/plugins/payload/index.js +1 -1
  95. package/dist/plugins/playwright/index.js +3 -3
  96. package/dist/plugins/pm2/index.js +7 -7
  97. package/dist/plugins/prettier/index.js +2 -1
  98. package/dist/plugins/prisma/index.js +2 -2
  99. package/dist/plugins/quasar/resolveFromAST.js +14 -9
  100. package/dist/plugins/react-router/index.js +2 -2
  101. package/dist/plugins/release-it/index.js +6 -2
  102. package/dist/plugins/remix/index.js +3 -3
  103. package/dist/plugins/retry-cli/index.d.ts +3 -0
  104. package/dist/plugins/retry-cli/index.js +14 -0
  105. package/dist/plugins/rollup/index.js +1 -4
  106. package/dist/plugins/rstest/index.js +3 -3
  107. package/dist/plugins/semantic-release/index.js +3 -3
  108. package/dist/plugins/serverless-framework/index.js +10 -8
  109. package/dist/plugins/solidjs-vite-plugin/resolveFromAST.js +2 -2
  110. package/dist/plugins/stencil/resolveFromAST.js +5 -5
  111. package/dist/plugins/stryker/index.js +2 -2
  112. package/dist/plugins/swc/index.js +4 -3
  113. package/dist/plugins/tailwind/index.js +2 -2
  114. package/dist/plugins/tanstack-router/index.js +2 -2
  115. package/dist/plugins/ts-node/index.js +6 -1
  116. package/dist/plugins/turbo/index.js +3 -3
  117. package/dist/plugins/typedoc/index.js +2 -2
  118. package/dist/plugins/typescript/content-mappers.d.ts +1 -1
  119. package/dist/plugins/typescript/index.js +6 -9
  120. package/dist/plugins/varlock/scan.js +1 -1
  121. package/dist/plugins/vite/helpers.d.ts +1 -0
  122. package/dist/plugins/vite/helpers.js +13 -3
  123. package/dist/plugins/vite/index.js +5 -2
  124. package/dist/plugins/vite-plugin-pwa/resolveFromAST.js +2 -2
  125. package/dist/plugins/vitest/index.js +14 -16
  126. package/dist/plugins/vue/index.js +1 -1
  127. package/dist/plugins/web-test-runner/index.d.ts +3 -0
  128. package/dist/plugins/web-test-runner/index.js +86 -0
  129. package/dist/plugins/wrangler/index.js +3 -3
  130. package/dist/plugins/yarn/index.js +5 -5
  131. package/dist/plugins.js +2 -5
  132. package/dist/reporters/github-actions.js +3 -7
  133. package/dist/reporters/json.d.ts +1 -0
  134. package/dist/reporters/json.js +1 -0
  135. package/dist/reporters/util/configuration-hints.d.ts +3 -1
  136. package/dist/reporters/util/configuration-hints.js +40 -21
  137. package/dist/reporters/util/util.d.ts +1 -1
  138. package/dist/run-cli.d.ts +2 -0
  139. package/dist/run-cli.js +82 -0
  140. package/dist/run.js +12 -0
  141. package/dist/session/incremental.d.ts +1 -0
  142. package/dist/session/incremental.js +1 -0
  143. package/dist/session/watch.js +2 -1
  144. package/dist/types/PluginNames.d.ts +2 -2
  145. package/dist/types/PluginNames.js +5 -0
  146. package/dist/types/args.d.ts +3 -1
  147. package/dist/types/config.d.ts +17 -10
  148. package/dist/types/configuration.d.ts +45 -0
  149. package/dist/types/configuration.js +1 -0
  150. package/dist/types/issues.d.ts +4 -0
  151. package/dist/types/module-graph.d.ts +1 -0
  152. package/dist/types/options.d.ts +1 -0
  153. package/dist/types/package-json.d.ts +3 -8
  154. package/dist/types/workspace.d.ts +1 -0
  155. package/dist/typescript/get-imports-and-exports.js +18 -6
  156. package/dist/typescript/resolve-module-names.js +7 -45
  157. package/dist/typescript/visitors/calls.d.ts +1 -1
  158. package/dist/typescript/visitors/calls.js +14 -10
  159. package/dist/typescript/visitors/exports.js +16 -26
  160. package/dist/typescript/visitors/imports.d.ts +2 -1
  161. package/dist/typescript/visitors/imports.js +41 -24
  162. package/dist/typescript/visitors/members.d.ts +1 -1
  163. package/dist/typescript/visitors/members.js +38 -24
  164. package/dist/typescript/visitors/shadow.d.ts +2 -0
  165. package/dist/typescript/visitors/shadow.js +25 -0
  166. package/dist/typescript/visitors/walk.d.ts +20 -12
  167. package/dist/typescript/visitors/walk.js +78 -48
  168. package/dist/util/Performance.d.ts +25 -3
  169. package/dist/util/Performance.js +51 -27
  170. package/dist/util/cli-arguments.d.ts +2 -1
  171. package/dist/util/cli-arguments.js +4 -2
  172. package/dist/util/create-input-handler.js +138 -119
  173. package/dist/util/create-options.d.ts +4 -2071
  174. package/dist/util/create-options.js +6 -4
  175. package/dist/util/create-workspace-graph.js +2 -1
  176. package/dist/util/errors.d.ts +5 -2
  177. package/dist/util/errors.js +11 -18
  178. package/dist/util/fs.js +4 -2
  179. package/dist/util/input.d.ts +2 -2
  180. package/dist/util/input.js +2 -2
  181. package/dist/util/is-plugin-name.d.ts +2 -0
  182. package/dist/util/is-plugin-name.js +3 -0
  183. package/dist/util/jiti.d.ts +2 -1
  184. package/dist/util/jiti.js +10 -3
  185. package/dist/util/load-config.d.ts +1 -1
  186. package/dist/util/load-config.js +3 -2
  187. package/dist/util/loader.js +3 -2
  188. package/dist/util/map-workspaces.js +23 -1
  189. package/dist/util/module-graph.js +1 -0
  190. package/dist/util/modules.d.ts +2 -0
  191. package/dist/util/modules.js +78 -0
  192. package/dist/util/package-json.d.ts +12 -5
  193. package/dist/util/package-json.js +54 -26
  194. package/dist/util/parse-and-convert-gitignores.d.ts +2 -2
  195. package/dist/util/parse-and-convert-gitignores.js +5 -5
  196. package/dist/util/parse-configuration.d.ts +2 -0
  197. package/dist/util/parse-configuration.js +66 -0
  198. package/dist/util/plugin.js +8 -12
  199. package/dist/util/resolve.d.ts +1 -0
  200. package/dist/util/resolve.js +3 -2
  201. package/dist/util/scripts.d.ts +0 -5
  202. package/dist/util/scripts.js +1 -32
  203. package/dist/util/to-source-path.d.ts +4 -1
  204. package/dist/util/to-source-path.js +2 -2
  205. package/dist/util/unhandled-rejection.d.ts +8 -0
  206. package/dist/util/unhandled-rejection.js +29 -0
  207. package/dist/util/validation.d.ts +11 -0
  208. package/dist/util/validation.js +68 -0
  209. package/dist/util/watch.d.ts +3 -1
  210. package/dist/util/watch.js +5 -2
  211. package/dist/version.d.ts +1 -1
  212. package/dist/version.js +1 -1
  213. package/package.json +6 -7
  214. package/schema.json +34 -0
  215. package/dist/schema/configuration.d.ts +0 -3103
  216. package/dist/schema/configuration.js +0 -94
  217. package/dist/schema/plugins.d.ts +0 -1019
  218. package/dist/schema/plugins.js +0 -215
@@ -15,23 +15,23 @@ export const expandIgnorePatterns = (patterns, shallow = false) => {
15
15
  }
16
16
  return result;
17
17
  };
18
- export const convertGitignoreToPicomatchIgnorePatterns = (pattern) => {
18
+ export const convertGitignoreToPicomatchIgnorePatterns = (pattern, isAnchored = false) => {
19
19
  const negated = pattern[0] === '!';
20
20
  if (negated)
21
21
  pattern = pattern.slice(1);
22
22
  if (pattern.endsWith('/'))
23
23
  pattern = pattern.slice(0, -1);
24
- if (pattern.startsWith('*/**/'))
24
+ if (!isAnchored && pattern.startsWith('*/**/'))
25
25
  pattern = pattern.slice(5);
26
26
  if (pattern === '*' || pattern === '**')
27
27
  return { negated, pattern };
28
28
  if (pattern.startsWith('/'))
29
29
  pattern = pattern.slice(1);
30
- else if (!pattern.startsWith('**/'))
30
+ else if (isAnchored ? !pattern.includes('/') : !pattern.startsWith('**/'))
31
31
  pattern = `**/${pattern}`;
32
32
  return { negated, pattern };
33
33
  };
34
- export const parseAndConvertGitignorePatterns = (patterns, ancestor) => {
34
+ export const parseAndConvertGitignorePatterns = (patterns, ancestor, isAnchored = !ancestor) => {
35
35
  const matchFrom = ancestor ? new RegExp(`^(!?/?)(${ancestor})`) : undefined;
36
36
  return patterns
37
37
  .split(/\r?\n/)
@@ -50,5 +50,5 @@ export const parseAndConvertGitignorePatterns = (patterns, ancestor) => {
50
50
  }
51
51
  return [pattern];
52
52
  })
53
- .map(pattern => convertGitignoreToPicomatchIgnorePatterns(pattern));
53
+ .map(pattern => convertGitignoreToPicomatchIgnorePatterns(pattern, isAnchored));
54
54
  };
@@ -0,0 +1,2 @@
1
+ import type { RawConfiguration } from '../types/configuration.ts';
2
+ export declare const parseConfiguration: (value: unknown) => RawConfiguration;
@@ -0,0 +1,66 @@
1
+ import { ISSUE_TYPES, SYMBOL_TYPE } from '../constants.js';
2
+ import { ConfigurationValidationError } from './errors.js';
3
+ import { isPluginName } from './is-plugin-name.js';
4
+ import { timerify } from './Performance.js';
5
+ import { checkArray, checkBoolean, checkObject, checkRecord, checkString, invalid, isObject, } from './validation.js';
6
+ const checkStrings = checkArray(checkString);
7
+ const checkGlob = (value, path, errors) => typeof value === 'string' || checkStrings(value, path, errors);
8
+ const checkPattern = (value, path, errors) => typeof value === 'string' || value instanceof RegExp || invalid(path, errors);
9
+ const issueTypes = new Set(ISSUE_TYPES);
10
+ const isIssueType = (value) => typeof value === 'string' && issueTypes.has(value);
11
+ const checkIssueType = (value, path, errors) => isIssueType(value) || invalid(path, errors);
12
+ const checkSeverity = (value, path, errors) => value === 'error' || value === 'warn' || value === 'off' || invalid(path, errors);
13
+ const symbolFields = {};
14
+ for (const type of Object.values(SYMBOL_TYPE))
15
+ if (type !== 'unknown')
16
+ symbolFields[type] = checkBoolean;
17
+ const checkIgnoreExports = (value, path, errors) => typeof value === 'boolean' || checkObject(value, path, errors, symbolFields);
18
+ const pluginFields = { config: checkGlob, entry: checkGlob, project: checkGlob };
19
+ const checkPlugin = (value, path, errors) => typeof value === 'boolean' ||
20
+ (isObject(value) ? checkObject(value, path, errors, pluginFields, 'ignore') : checkGlob(value, path, errors));
21
+ const getPluginCheck = (key) => (isPluginName(key) ? checkPlugin : undefined);
22
+ const checkPatterns = checkArray(checkPattern);
23
+ const checkIssueTypes = checkArray(checkIssueType);
24
+ const workspaceFields = {
25
+ entry: checkGlob,
26
+ project: checkGlob,
27
+ paths: checkRecord(checkStrings),
28
+ ignore: checkGlob,
29
+ ignoreFiles: checkGlob,
30
+ ignoreBinaries: checkPatterns,
31
+ ignoreGlobalBinaries: checkBoolean,
32
+ ignoreDependencies: checkPatterns,
33
+ ignoreMembers: checkPatterns,
34
+ ignoreUnresolved: checkPatterns,
35
+ ignoreExportsUsedInFile: checkIgnoreExports,
36
+ ignoreIssues: checkRecord(checkIssueTypes),
37
+ includeEntryExports: checkBoolean,
38
+ includeSubpathExports: checkBoolean,
39
+ };
40
+ const checkWorkspace = (value, path, errors) => checkObject(value, path, errors, workspaceFields, getPluginCheck);
41
+ const cycleFields = { allow: checkArray(checkStrings), dynamicImports: checkBoolean };
42
+ const checkCompilers = checkRecord((_value) => true);
43
+ const rootFields = {
44
+ $schema: checkString,
45
+ rules: checkRecord(checkSeverity, isIssueType),
46
+ ...workspaceFields,
47
+ cycles: (value, path, errors) => checkObject(value, path, errors, cycleFields),
48
+ ignoreWorkspaces: checkStrings,
49
+ compilers: checkCompilers,
50
+ asyncCompilers: checkCompilers,
51
+ tags: checkStrings,
52
+ treatConfigHintsAsErrors: checkBoolean,
53
+ treatTagHintsAsErrors: checkBoolean,
54
+ preprocessor: checkGlob,
55
+ preprocessorOptions: checkRecord((_value) => true),
56
+ include: checkIssueTypes,
57
+ exclude: checkIssueTypes,
58
+ workspaces: checkRecord(checkWorkspace),
59
+ };
60
+ const checkConfiguration = (value, path, errors) => checkObject(value, path, errors, rootFields, getPluginCheck);
61
+ export const parseConfiguration = timerify((value) => {
62
+ const errors = [];
63
+ if (!checkConfiguration(value, '', errors))
64
+ throw new ConfigurationValidationError(errors);
65
+ return value;
66
+ }, 'parseConfiguration');
@@ -18,18 +18,14 @@ export const hasDependency = (dependencies, values) => values.some(value => {
18
18
  export const normalizePluginConfig = (pluginConfig) => {
19
19
  if (typeof pluginConfig === 'boolean')
20
20
  return pluginConfig;
21
- const isObject = typeof pluginConfig !== 'string' && !Array.isArray(pluginConfig);
22
- const config = isObject
23
- ? 'config' in pluginConfig
24
- ? arrayify(pluginConfig.config)
25
- : null
26
- : pluginConfig
27
- ? arrayify(pluginConfig)
28
- : null;
29
- const entry = isObject && 'entry' in pluginConfig ? arrayify(pluginConfig.entry) : null;
30
- const project = isObject && 'project' in pluginConfig
31
- ? arrayify(pluginConfig.project)
32
- : (entry ?? []).filter(pattern => !pattern.startsWith('!'));
21
+ if (typeof pluginConfig === 'string' || Array.isArray(pluginConfig)) {
22
+ return { config: pluginConfig ? arrayify(pluginConfig) : null, entry: null, project: [] };
23
+ }
24
+ const config = pluginConfig.config === undefined ? null : arrayify(pluginConfig.config);
25
+ const entry = pluginConfig.entry === undefined ? null : arrayify(pluginConfig.entry);
26
+ const project = pluginConfig.project === undefined
27
+ ? (entry ?? []).filter(pattern => !pattern.startsWith('!'))
28
+ : arrayify(pluginConfig.project);
33
29
  return { config, entry, project };
34
30
  };
35
31
  export const loadConfigForPlugin = async (configFilePath, plugin, options, pluginName) => {
@@ -1,4 +1,5 @@
1
1
  export declare const extensionAlias: Record<string, string[]>;
2
+ export declare const resolvePackageFilePath: (specifier: string, baseDir: string) => string | undefined;
2
3
  export declare const resolvePackageManifestPath: (packageName: string, baseDir: string) => string | undefined;
3
4
  export declare const _resolveModuleSync: (specifier: string, basePath: string) => string | undefined;
4
5
  declare const resolveDeclarationSync: (specifier: string, containingFile: string) => {
@@ -29,11 +29,12 @@ const packageManifestResolver = new ResolverFactory({
29
29
  nodePath: false,
30
30
  });
31
31
  resolverInstances.push(packageManifestResolver);
32
- export const resolvePackageManifestPath = (packageName, baseDir) => {
33
- const resolved = packageManifestResolver.sync(baseDir, `${packageName}/package.json`);
32
+ export const resolvePackageFilePath = (specifier, baseDir) => {
33
+ const resolved = packageManifestResolver.sync(baseDir, specifier);
34
34
  if (resolved.path)
35
35
  return toPosix(resolved.path);
36
36
  };
37
+ export const resolvePackageManifestPath = (packageName, baseDir) => resolvePackageFilePath(`${packageName}/package.json`, baseDir);
37
38
  const createSyncModuleResolver = (extensions, tsConfigFile) => {
38
39
  const baseOptions = {
39
40
  extensions,
@@ -1,10 +1,5 @@
1
1
  import { type ArithmeticCommandExpansion, type Command, type CommandExpansionPart, type ProcessSubstitutionPart, type SyntaxNode, type Word } from 'unbash';
2
- export interface ScriptCommand {
3
- binary: string;
4
- args: string[];
5
- }
6
2
  export declare const toShellCommand: (argv: string[]) => string;
7
3
  export declare const getCommandWords: (node: Pick<Command, 'args'>) => Word[];
8
4
  export declare const collectCommands: (root: SyntaxNode) => Command[];
9
5
  export declare const isScriptExpansion: (node: SyntaxNode) => node is CommandExpansionPart | ProcessSubstitutionPart | ArithmeticCommandExpansion;
10
- export declare const getScriptCommands: (script: string) => ScriptCommand[];
@@ -1,6 +1,4 @@
1
- import { forEachChild, parse, } from 'unbash';
2
- import { extractBinary } from './modules.js';
3
- const spawningBinaries = new Set(['c8', 'cross-env', 'retry-cli']);
1
+ import { forEachChild, } from 'unbash';
4
2
  export const toShellCommand = (argv) => argv.map(arg => `'${arg.replaceAll("'", `'\\''`)}'`).join(' ');
5
3
  export const getCommandWords = (node) => node.args.filter((arg) => arg.type === 'Word');
6
4
  export const collectCommands = (root) => {
@@ -15,32 +13,3 @@ export const collectCommands = (root) => {
15
13
  return commands;
16
14
  };
17
15
  export const isScriptExpansion = (node) => node.type === 'CommandExpansion' || node.type === 'ProcessSubstitution' || node.type === 'ArithmeticCommandExpansion';
18
- export const getScriptCommands = (script) => {
19
- if (!script)
20
- return [];
21
- const out = [];
22
- try {
23
- for (const statement of parse(script).commands) {
24
- for (const node of collectCommands(statement.command)) {
25
- const text = node.name?.value;
26
- if (!text)
27
- continue;
28
- const binary = extractBinary(text);
29
- const words = getCommandWords(node);
30
- if (spawningBinaries.has(binary)) {
31
- const rest = words
32
- .filter(word => word.text !== '--')
33
- .map(word => word.text)
34
- .join(' ');
35
- out.push(...getScriptCommands(rest));
36
- }
37
- else
38
- out.push({ binary, args: words.map(word => word.value) });
39
- }
40
- }
41
- }
42
- catch {
43
- return [];
44
- }
45
- return out;
46
- };
@@ -1,10 +1,13 @@
1
1
  import type { SourceMap } from '../types/config.ts';
2
2
  import type { CompilerOptions } from '../types/project.ts';
3
3
  import type { ConfigurationChief, Workspace } from '../ConfigurationChief.ts';
4
+ import type { Exports } from '../types/package-json.ts';
4
5
  export declare const augmentWorkspace: (workspace: Workspace, dir: string, compilerOptions: CompilerOptions | undefined, pluginSourceMaps?: SourceMap[]) => void;
5
6
  export type WorkspacePackageTargetHandler = (specifier: string, filePath: string) => {
7
+ name: string;
6
8
  dir: string;
7
- target: unknown;
9
+ target: Exports;
10
+ subpath: string;
8
11
  patternMatch?: string;
9
12
  } | undefined;
10
13
  export declare const getWorkspacePackageTargetHandler: (chief: ConfigurationChief) => WorkspacePackageTargetHandler;
@@ -55,7 +55,7 @@ export const getWorkspacePackageTargetHandler = (chief) => {
55
55
  const packageName = getPackageNameFromModuleSpecifier(specifier);
56
56
  if (!packageName)
57
57
  return;
58
- workspace = chief.workspacesByPkgName.get(packageName);
58
+ workspace = chief.findWorkspaceByPackageName(packageName, filePath);
59
59
  key = packageName === specifier ? '.' : `.${specifier.slice(packageName.length)}`;
60
60
  }
61
61
  if (!workspace)
@@ -66,7 +66,7 @@ export const getWorkspacePackageTargetHandler = (chief) => {
66
66
  return;
67
67
  const result = getPackageMapTarget(map, key);
68
68
  if (result)
69
- return { dir: workspace.dir, ...result };
69
+ return { name: workspace.name, dir: workspace.dir, ...result };
70
70
  };
71
71
  };
72
72
  export const getModuleSourcePathHandler = (chief) => {
@@ -0,0 +1,8 @@
1
+ type Cache = {
2
+ removeEntry: (filePath: string) => void;
3
+ reconcile: () => void;
4
+ };
5
+ export declare const hasUnhandledRejection: () => boolean;
6
+ export declare const trackConfigLoad: <T>(configFilePath: string, cache: Cache, fn: () => Promise<T>) => Promise<T>;
7
+ export declare const listenForUnhandledRejections: (getCwd: () => string) => void;
8
+ export {};
@@ -0,0 +1,29 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+ import { formatCauseMessage } from './errors.js';
3
+ import { logError } from './log.js';
4
+ import { toRelative } from './path.js';
5
+ const loading = new AsyncLocalStorage();
6
+ let loads;
7
+ let isRejected = false;
8
+ export const hasUnhandledRejection = () => isRejected;
9
+ export const trackConfigLoad = (configFilePath, cache, fn) => {
10
+ loads?.set(configFilePath, cache);
11
+ return loading.run(configFilePath, fn);
12
+ };
13
+ export const listenForUnhandledRejections = (getCwd) => {
14
+ const tracked = (loads = new Map());
15
+ process.on('unhandledRejection', reason => {
16
+ isRejected = true;
17
+ process.exitCode = 2;
18
+ const cwd = getCwd();
19
+ const likelyFrom = loading.getStore();
20
+ const error = reason instanceof Error ? reason : new Error(String(reason));
21
+ const origin = likelyFrom ? `, likely from ${toRelative(likelyFrom, cwd)}` : '';
22
+ logError(`Unhandled rejection${origin} (${formatCauseMessage(error, cwd)})`);
23
+ logError('Please fix or visit https://knip.dev/reference/known-issues');
24
+ for (const [configFilePath, cache] of tracked)
25
+ cache.removeEntry(configFilePath);
26
+ for (const cache of new Set(tracked.values()))
27
+ cache.reconcile();
28
+ });
29
+ };
@@ -0,0 +1,11 @@
1
+ export type Check<T> = (value: unknown, path: string, errors: string[]) => value is T;
2
+ export type Fields<T> = {
3
+ [K in keyof T]-?: Check<Exclude<T[K], undefined>>;
4
+ };
5
+ export declare const invalid: (path: string, errors: string[], expected?: string, key?: string) => boolean;
6
+ export declare const isObject: (value: unknown) => value is Record<string, unknown>;
7
+ export declare const checkString: Check<string>;
8
+ export declare const checkBoolean: Check<boolean>;
9
+ export declare const checkArray: <T>(check: Check<T>) => Check<T[]>;
10
+ export declare const checkRecord: <T>(check: Check<T>, isKey?: (key: string) => boolean) => Check<Record<string, T>>;
11
+ export declare const checkObject: (value: unknown, path: string, errors: string[], fields: Record<string, Check<unknown>>, extraFields?: 'reject' | 'ignore' | ((key: string) => Check<unknown> | undefined)) => boolean;
@@ -0,0 +1,68 @@
1
+ const location = (path, key) => (path ? `${path}.${key}` : String(key));
2
+ export const invalid = (path, errors, expected, key) => {
3
+ const details = [];
4
+ if (path)
5
+ details.push(`location: ${path}`);
6
+ if (expected)
7
+ details.push(`expected: ${expected}`);
8
+ if (key !== undefined)
9
+ details.push(`unrecognized_keys: ${key}`);
10
+ errors.push(`Invalid input${details.length ? ` (${details.join(', ')})` : ''}`);
11
+ return false;
12
+ };
13
+ export const isObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
14
+ const isRecord = (value) => {
15
+ if (!isObject(value))
16
+ return false;
17
+ const constructor = value.constructor;
18
+ return typeof constructor !== 'function' || Object.hasOwn(constructor.prototype ?? {}, 'isPrototypeOf');
19
+ };
20
+ export const checkString = (value, path, errors) => typeof value === 'string' || invalid(path, errors, 'string');
21
+ export const checkBoolean = (value, path, errors) => typeof value === 'boolean' || invalid(path, errors, 'boolean');
22
+ export const checkArray = (check) => (value, path, errors) => {
23
+ if (!Array.isArray(value))
24
+ return invalid(path, errors, 'array');
25
+ const count = errors.length;
26
+ for (let i = 0; i < value.length; i++)
27
+ check(value[i], location(path, i), errors);
28
+ return errors.length === count;
29
+ };
30
+ export const checkRecord = (check, isKey) => (value, path, errors) => {
31
+ if (!isRecord(value))
32
+ return invalid(path, errors, 'record');
33
+ const count = errors.length;
34
+ for (const key of Reflect.ownKeys(value)) {
35
+ if (!Object.prototype.propertyIsEnumerable.call(value, key))
36
+ continue;
37
+ if (typeof key !== 'string')
38
+ invalid(location(path, String(key)), errors);
39
+ else if (isKey && !isKey(key))
40
+ invalid(path, errors, undefined, key);
41
+ else
42
+ check(value[key], location(path, key), errors);
43
+ }
44
+ return errors.length === count;
45
+ };
46
+ export const checkObject = (value, path, errors, fields, extraFields = 'reject') => {
47
+ if (!isObject(value))
48
+ return invalid(path, errors, 'object');
49
+ const count = errors.length;
50
+ let unknownKeys;
51
+ for (const key in value) {
52
+ const check = Object.hasOwn(fields, key)
53
+ ? fields[key]
54
+ : typeof extraFields === 'function'
55
+ ? extraFields(key)
56
+ : undefined;
57
+ if (check) {
58
+ const item = value[key];
59
+ if (item !== undefined)
60
+ check(item, location(path, key), errors);
61
+ }
62
+ else if (extraFields !== 'ignore')
63
+ unknownKeys = unknownKeys === undefined ? key : `${unknownKeys}, ${key}`;
64
+ }
65
+ if (unknownKeys !== undefined)
66
+ invalid(path, errors, undefined, unknownKeys);
67
+ return errors.length === count;
68
+ };
@@ -1,4 +1,5 @@
1
1
  import type { ConfigurationChief } from '../ConfigurationChief.ts';
2
+ import type { SubpathReferences } from '../graph/SubpathReferences.ts';
2
3
  import type { IssueCollector } from '../IssueCollector.ts';
3
4
  import type { ProjectPrincipal } from '../ProjectPrincipal.ts';
4
5
  import type { ConfigurationFiles } from '../session/configuration.ts';
@@ -12,6 +13,7 @@ export type SessionHandler = Awaited<ReturnType<typeof getSessionHandler>>;
12
13
  type WatchOptions = {
13
14
  analyzedFiles: Set<string>;
14
15
  analyzeSourceFile: (filePath: string) => Promise<void>;
16
+ subpathReferences: SubpathReferences;
15
17
  chief: ConfigurationChief;
16
18
  collector: IssueCollector;
17
19
  analyze: () => Promise<void>;
@@ -22,7 +24,7 @@ type WatchOptions = {
22
24
  unreferencedFiles: Set<string>;
23
25
  entryPaths: Set<string>;
24
26
  };
25
- export declare const getSessionHandler: (options: MainOptions, { analyzedFiles, analyzeSourceFile, chief, collector, analyze, principal, graph, configurationFiles, isIgnored, unreferencedFiles, entryPaths, }: WatchOptions) => Promise<{
27
+ export declare const getSessionHandler: (options: MainOptions, { analyzedFiles, analyzeSourceFile, subpathReferences, chief, collector, analyze, principal, graph, configurationFiles, isIgnored, unreferencedFiles, entryPaths, }: WatchOptions) => Promise<{
26
28
  handleFileChanges: (changes: WatchChange[]) => Promise<{
27
29
  duration: number;
28
30
  mem: number;
@@ -11,7 +11,7 @@ const createUpdate = (options) => {
11
11
  const mem = process.memoryUsage().heapUsed;
12
12
  return { duration, mem };
13
13
  };
14
- export const getSessionHandler = async (options, { analyzedFiles, analyzeSourceFile, chief, collector, analyze, principal, graph, configurationFiles, isIgnored, unreferencedFiles, entryPaths, }) => {
14
+ export const getSessionHandler = async (options, { analyzedFiles, analyzeSourceFile, subpathReferences, chief, collector, analyze, principal, graph, configurationFiles, isIgnored, unreferencedFiles, entryPaths, }) => {
15
15
  const added = new Set();
16
16
  const deleted = new Set();
17
17
  const modified = new Set();
@@ -46,6 +46,7 @@ export const getSessionHandler = async (options, { analyzedFiles, analyzeSourceF
46
46
  deleted.add(filePath);
47
47
  added.delete(filePath);
48
48
  analyzedFiles.delete(filePath);
49
+ subpathReferences.release(filePath);
49
50
  principal.removeProjectPath(filePath);
50
51
  debugLog(workspace.name, `Watcher: - ${relativePath}`);
51
52
  break;
@@ -55,6 +56,7 @@ export const getSessionHandler = async (options, { analyzedFiles, analyzeSourceF
55
56
  continue;
56
57
  }
57
58
  modified.add(filePath);
59
+ subpathReferences.release(filePath);
58
60
  debugLog(workspace.name, `Watcher: ± ${relativePath}`);
59
61
  break;
60
62
  }
@@ -97,7 +99,8 @@ export const getSessionHandler = async (options, { analyzedFiles, analyzeSourceF
97
99
  clearModuleResolutionCaches();
98
100
  clearGlobCache();
99
101
  invalidateCache(graph);
100
- const filePaths = await principal.getUsedResolvedFiles();
102
+ subpathReferences.reset();
103
+ const filePaths = await principal.getUsedResolvedFiles((specifier, filePath) => subpathReferences.add(specifier, filePath));
101
104
  const cachedUnusedFiles = collector.purge();
102
105
  for (const filePath of added)
103
106
  cachedUnusedFiles.add(filePath);
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "6.44.2";
1
+ export declare const version = "6.45.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '6.44.2';
1
+ export const version = '6.45.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "6.44.2",
3
+ "version": "6.45.0",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "keywords": [
6
6
  "analysis",
@@ -87,12 +87,11 @@
87
87
  "oxc-parser": "^0.156.0",
88
88
  "oxc-resolver": "11.24.2",
89
89
  "picomatch": "^4.0.7",
90
- "smol-toml": "^1.9.0",
90
+ "smol-toml": "^1.9.1",
91
91
  "strip-json-comments": "5.0.3",
92
92
  "tinyglobby": "^0.2.17",
93
- "unbash": "^6.0.1",
94
- "yaml": "^2.9.1",
95
- "zod": "^4.6.5"
93
+ "unbash": "^6.0.4",
94
+ "yaml": "^2.9.1"
96
95
  },
97
96
  "devDependencies": {
98
97
  "@jest/types": "^30.5.1",
@@ -119,7 +118,7 @@
119
118
  "qa": "pnpm lint && pnpm build && pnpm knip && pnpm knip:production && pnpm test",
120
119
  "release": "NODE_OPTIONS=--no-deprecation release-it",
121
120
  "create-plugin": "node ./scripts/create-new-plugin.ts",
122
- "postcreate-plugin": "pnpm run build && (oxfmt schema.json schema-jsonc.json src/schema/plugins.ts || true)",
123
- "generate-plugin-defs": "node ./scripts/generate-plugin-defs.js && (oxfmt src/plugins/index.ts src/types/PluginNames.ts src/schema/plugins.ts || true)"
121
+ "postcreate-plugin": "pnpm run build && (oxfmt schema.json schema-jsonc.json || true)",
122
+ "generate-plugin-defs": "node ./scripts/generate-plugin-defs.js && (oxfmt src/plugins/index.ts src/types/PluginNames.ts || true)"
124
123
  }
125
124
  }
package/schema.json CHANGED
@@ -100,6 +100,9 @@
100
100
  "includeEntryExports": {
101
101
  "$ref": "#/definitions/includeEntryExports"
102
102
  },
103
+ "includeSubpathExports": {
104
+ "$ref": "#/definitions/includeSubpathExports"
105
+ },
103
106
  "tags": {
104
107
  "title": "Exclude (-) or include (+) exports with the specified JSDoc/TSDoc tags",
105
108
  "examples": ["+custom", "-lintignore", "-@internal"],
@@ -165,6 +168,9 @@
165
168
  "nsTypes": {
166
169
  "$ref": "#/definitions/ruleValue"
167
170
  },
171
+ "subpaths": {
172
+ "$ref": "#/definitions/ruleValue"
173
+ },
168
174
  "types": {
169
175
  "$ref": "#/definitions/ruleValue"
170
176
  },
@@ -232,6 +238,10 @@
232
238
  "title": "Include entry files when reporting unused exports",
233
239
  "type": "boolean"
234
240
  },
241
+ "includeSubpathExports": {
242
+ "title": "Report unused subpaths in package.json#exports",
243
+ "type": "boolean"
244
+ },
235
245
  "ignoreExportsUsedInFile": {
236
246
  "title": "Ignore exports used in file",
237
247
  "examples": [
@@ -288,6 +298,7 @@
288
298
  "type": "string",
289
299
  "enum": [
290
300
  "files",
301
+ "subpaths",
291
302
  "dependencies",
292
303
  "devDependencies",
293
304
  "optionalPeerDependencies",
@@ -386,6 +397,9 @@
386
397
  },
387
398
  "includeEntryExports": {
388
399
  "$ref": "#/definitions/includeEntryExports"
400
+ },
401
+ "includeSubpathExports": {
402
+ "$ref": "#/definitions/includeSubpathExports"
389
403
  }
390
404
  }
391
405
  },
@@ -442,6 +456,10 @@
442
456
  "title": "ava plugin configuration (https://knip.dev/reference/plugins/ava)",
443
457
  "$ref": "#/definitions/plugin"
444
458
  },
459
+ "aws-cdk": {
460
+ "title": "aws-cdk plugin configuration (https://knip.dev/reference/plugins/aws-cdk)",
461
+ "$ref": "#/definitions/plugin"
462
+ },
445
463
  "babel": {
446
464
  "title": "Babel plugin configuration (https://knip.dev/reference/plugins/babel)",
447
465
  "$ref": "#/definitions/plugin"
@@ -558,6 +576,10 @@
558
576
  "title": "ESLint plugin configuration (https://knip.dev/reference/plugins/eslint)",
559
577
  "$ref": "#/definitions/plugin"
560
578
  },
579
+ "evalite": {
580
+ "title": "evalite plugin configuration (https://knip.dev/reference/plugins/evalite)",
581
+ "$ref": "#/definitions/plugin"
582
+ },
561
583
  "eve": {
562
584
  "title": "eve plugin configuration (https://knip.dev/reference/plugins/eve)",
563
585
  "$ref": "#/definitions/plugin"
@@ -706,6 +728,10 @@
706
728
  "title": "mdxlint plugin configuration (https://knip.dev/reference/plugins/mdxlint)",
707
729
  "$ref": "#/definitions/plugin"
708
730
  },
731
+ "mikro-orm": {
732
+ "title": "mikro-orm plugin configuration (https://knip.dev/reference/plugins/mikro-orm)",
733
+ "$ref": "#/definitions/plugin"
734
+ },
709
735
  "metro": {
710
736
  "title": "metro plugin configuration (https://knip.dev/reference/plugins/metro)",
711
737
  "$ref": "#/definitions/plugin"
@@ -922,6 +948,10 @@
922
948
  "title": "Remix plugin configuration (https://knip.dev/reference/plugins/remix)",
923
949
  "$ref": "#/definitions/plugin"
924
950
  },
951
+ "retry-cli": {
952
+ "title": "retry-cli plugin configuration (https://knip.dev/reference/plugins/retry-cli)",
953
+ "$ref": "#/definitions/plugin"
954
+ },
925
955
  "rolldown": {
926
956
  "title": "rolldown plugin configuration (https://knip.dev/reference/plugins/rolldown)",
927
957
  "$ref": "#/definitions/plugin"
@@ -1178,6 +1208,10 @@
1178
1208
  "title": "vue plugin configuration (https://knip.dev/reference/plugins/vue)",
1179
1209
  "$ref": "#/definitions/plugin"
1180
1210
  },
1211
+ "web-test-runner": {
1212
+ "title": "Web Test Runner plugin configuration (https://knip.dev/reference/plugins/web-test-runner)",
1213
+ "$ref": "#/definitions/plugin"
1214
+ },
1181
1215
  "webdriver-io": {
1182
1216
  "title": "webdriver-io plugin configuration (https://knip.dev/reference/plugins/webdriver-io)",
1183
1217
  "$ref": "#/definitions/plugin"