knip 6.29.0 → 6.31.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 (119) hide show
  1. package/dist/CatalogCounselor.d.ts +5 -2
  2. package/dist/CatalogCounselor.js +26 -8
  3. package/dist/ConfigurationChief.d.ts +7 -1
  4. package/dist/ConfigurationChief.js +29 -36
  5. package/dist/DependencyDeputy.d.ts +8 -1
  6. package/dist/DependencyDeputy.js +5 -5
  7. package/dist/PackagePeeker.d.ts +5 -0
  8. package/dist/PackagePeeker.js +31 -3
  9. package/dist/WorkspaceWorker.d.ts +1 -1
  10. package/dist/WorkspaceWorker.js +11 -7
  11. package/dist/binaries/bash-parser.js +3 -3
  12. package/dist/binaries/create-script-parser-context.d.ts +7 -0
  13. package/dist/binaries/create-script-parser-context.js +17 -0
  14. package/dist/binaries/resolvers/pnpx.js +10 -5
  15. package/dist/compilers/index.d.ts +15 -5
  16. package/dist/compilers/scss.js +32 -5
  17. package/dist/compilers/shared.d.ts +1 -0
  18. package/dist/compilers/shared.js +1 -1
  19. package/dist/compilers/svelte.d.ts +2 -0
  20. package/dist/compilers/svelte.js +22 -0
  21. package/dist/constants.d.ts +4 -1
  22. package/dist/constants.js +4 -0
  23. package/dist/graph/analyze.js +5 -2
  24. package/dist/graph/build.d.ts +3 -1
  25. package/dist/graph/build.js +38 -19
  26. package/dist/graph-explorer/operations/build-exports-tree.js +2 -1
  27. package/dist/graph-explorer/operations/is-referenced.js +7 -4
  28. package/dist/graph-explorer/utils.js +2 -2
  29. package/dist/plugins/_template/index.js +1 -1
  30. package/dist/plugins/astro-markdoc/index.js +3 -2
  31. package/dist/plugins/eleventy/index.js +1 -1
  32. package/dist/plugins/esbuild/index.js +1 -1
  33. package/dist/plugins/eslint/helpers.js +2 -1
  34. package/dist/plugins/gatsby/index.js +2 -2
  35. package/dist/plugins/index.d.ts +1 -0
  36. package/dist/plugins/index.js +2 -0
  37. package/dist/plugins/jest/helpers.js +1 -1
  38. package/dist/plugins/marko/compiler.d.ts +2 -0
  39. package/dist/plugins/marko/compiler.js +85 -0
  40. package/dist/plugins/marko/index.d.ts +3 -0
  41. package/dist/plugins/marko/index.js +63 -0
  42. package/dist/plugins/marko/taglibs.d.ts +4 -0
  43. package/dist/plugins/marko/taglibs.js +111 -0
  44. package/dist/plugins/marko/types.d.ts +9 -0
  45. package/dist/plugins/marko/types.js +1 -0
  46. package/dist/plugins/metro/index.js +1 -1
  47. package/dist/plugins/nest/index.js +1 -1
  48. package/dist/plugins/node/index.js +11 -2
  49. package/dist/plugins/nx/index.js +4 -3
  50. package/dist/plugins/openclaw/index.js +1 -1
  51. package/dist/plugins/oxlint/index.js +9 -2
  52. package/dist/plugins/remark/helpers.d.ts +3 -0
  53. package/dist/plugins/remark/helpers.js +42 -0
  54. package/dist/plugins/remark/index.js +4 -5
  55. package/dist/plugins/rolldown/index.js +1 -1
  56. package/dist/plugins/rollup/index.js +1 -1
  57. package/dist/plugins/rslib/index.js +1 -1
  58. package/dist/plugins/stryker/index.js +6 -1
  59. package/dist/plugins/svelte/compiler.js +7 -5
  60. package/dist/plugins/tsdown/index.js +2 -2
  61. package/dist/plugins/tsup/index.js +1 -1
  62. package/dist/plugins/vitest/index.js +1 -1
  63. package/dist/plugins/vitest/types.d.ts +1 -1
  64. package/dist/reporters/codeclimate.js +1 -5
  65. package/dist/reporters/github-actions.js +5 -3
  66. package/dist/reporters/index.d.ts +1 -0
  67. package/dist/reporters/index.js +2 -0
  68. package/dist/reporters/json.d.ts +1 -0
  69. package/dist/reporters/json.js +1 -0
  70. package/dist/reporters/sarif.d.ts +3 -0
  71. package/dist/reporters/sarif.js +79 -0
  72. package/dist/reporters/trace.js +3 -2
  73. package/dist/reporters/util/util.d.ts +2 -1
  74. package/dist/reporters/util/util.js +6 -1
  75. package/dist/run.d.ts +1 -1
  76. package/dist/run.js +30 -0
  77. package/dist/schema/configuration.d.ts +21 -6
  78. package/dist/schema/configuration.js +1 -0
  79. package/dist/schema/plugins.d.ts +5 -0
  80. package/dist/schema/plugins.js +1 -0
  81. package/dist/session/build-maps.js +2 -1
  82. package/dist/types/PluginNames.d.ts +2 -2
  83. package/dist/types/PluginNames.js +1 -0
  84. package/dist/types/issues.d.ts +1 -0
  85. package/dist/types/package-json.d.ts +10 -0
  86. package/dist/typescript/get-imports-and-exports.js +3 -2
  87. package/dist/typescript/get-published-type-dependencies.d.ts +13 -0
  88. package/dist/typescript/get-published-type-dependencies.js +155 -0
  89. package/dist/typescript/visitors/calls.js +8 -0
  90. package/dist/util/catalog.d.ts +6 -1
  91. package/dist/util/catalog.js +16 -2
  92. package/dist/util/cli-arguments.d.ts +1 -1
  93. package/dist/util/cli-arguments.js +3 -3
  94. package/dist/util/codeowners.js +1 -1
  95. package/dist/util/create-input-handler.js +8 -2
  96. package/dist/util/create-options.d.ts +16 -5
  97. package/dist/util/disk-cache.js +1 -1
  98. package/dist/util/errors.js +3 -2
  99. package/dist/util/file-entry-cache.js +5 -1
  100. package/dist/util/fs.js +2 -2
  101. package/dist/util/get-included-issue-types.js +2 -1
  102. package/dist/util/gitignore-cache.js +4 -1
  103. package/dist/util/glob-cache.js +2 -2
  104. package/dist/util/glob-core.js +3 -1
  105. package/dist/util/input.d.ts +7 -1
  106. package/dist/util/input.js +6 -0
  107. package/dist/util/package-json.d.ts +347 -0
  108. package/dist/util/package-json.js +123 -0
  109. package/dist/util/path.d.ts +8 -7
  110. package/dist/util/resolve.d.ts +6 -0
  111. package/dist/util/resolve.js +24 -0
  112. package/dist/util/string.d.ts +2 -0
  113. package/dist/util/string.js +6 -0
  114. package/dist/util/table.js +2 -2
  115. package/dist/util/to-source-path.js +1 -1
  116. package/dist/version.d.ts +1 -1
  117. package/dist/version.js +1 -1
  118. package/package.json +5 -5
  119. package/schema.json +8 -0
@@ -5,6 +5,352 @@ interface ExtendedPackageJson extends PackageJson {
5
5
  [INDENT]?: string;
6
6
  [NEWLINE]?: string;
7
7
  }
8
+ export declare const toDeclarationSpecifier: (specifier: string) => string | undefined;
9
+ export declare const getPublishedTypeManifest: (manifest: PackageJson) => {
10
+ name?: string;
11
+ main?: string;
12
+ bin?: string | Record<string, string>;
13
+ version?: string;
14
+ private?: boolean;
15
+ workspaces?: string[] | {
16
+ packages?: string[];
17
+ catalog?: import("../types/package-json.ts").Catalog;
18
+ catalogs?: import("../types/package-json.ts").Catalogs;
19
+ };
20
+ exports?: string | string[] | {
21
+ [x: string & Record<never, never>]: string | string[] | any | {
22
+ [key: string]: string | string[] | any | any | null;
23
+ } | null;
24
+ browser: string | string[] | any | {
25
+ [key: string]: string | string[] | any | any | null;
26
+ } | null;
27
+ default: string | string[] | any | {
28
+ [key: string]: string | string[] | any | any | null;
29
+ } | null;
30
+ deno: string | string[] | any | {
31
+ [key: string]: string | string[] | any | any | null;
32
+ } | null;
33
+ electron: string | string[] | any | {
34
+ [key: string]: string | string[] | any | any | null;
35
+ } | null;
36
+ import: string | string[] | any | {
37
+ [key: string]: string | string[] | any | any | null;
38
+ } | null;
39
+ node: string | string[] | any | {
40
+ [key: string]: string | string[] | any | any | null;
41
+ } | null;
42
+ "node-addons": string | string[] | any | {
43
+ [key: string]: string | string[] | any | any | null;
44
+ } | null;
45
+ "react-native": string | string[] | any | {
46
+ [key: string]: string | string[] | any | any | null;
47
+ } | null;
48
+ require: string | string[] | any | {
49
+ [key: string]: string | string[] | any | any | null;
50
+ } | null;
51
+ } | {
52
+ [key: string]: string | string[] | any | any | null;
53
+ } | null;
54
+ imports?: {
55
+ [key: `#${string}`]: string | string[] | {
56
+ [x: string & Record<never, never>]: string | string[] | any | {
57
+ [key: string]: string | string[] | any | any | null;
58
+ } | null;
59
+ browser: string | string[] | any | {
60
+ [key: string]: string | string[] | any | any | null;
61
+ } | null;
62
+ default: string | string[] | any | {
63
+ [key: string]: string | string[] | any | any | null;
64
+ } | null;
65
+ deno: string | string[] | any | {
66
+ [key: string]: string | string[] | any | any | null;
67
+ } | null;
68
+ electron: string | string[] | any | {
69
+ [key: string]: string | string[] | any | any | null;
70
+ } | null;
71
+ import: string | string[] | any | {
72
+ [key: string]: string | string[] | any | any | null;
73
+ } | null;
74
+ node: string | string[] | any | {
75
+ [key: string]: string | string[] | any | any | null;
76
+ } | null;
77
+ "node-addons": string | string[] | any | {
78
+ [key: string]: string | string[] | any | any | null;
79
+ } | null;
80
+ "react-native": string | string[] | any | {
81
+ [key: string]: string | string[] | any | any | null;
82
+ } | null;
83
+ require: string | string[] | any | {
84
+ [key: string]: string | string[] | any | any | null;
85
+ } | null;
86
+ } | {
87
+ [key: string]: string | string[] | any | any | null;
88
+ } | null;
89
+ };
90
+ scripts?: import("../types/package-json.ts").Scripts;
91
+ dependencies?: {
92
+ [x: string]: string;
93
+ };
94
+ devDependencies?: {
95
+ [x: string]: string;
96
+ };
97
+ peerDependencies?: {
98
+ [x: string]: string;
99
+ };
100
+ optionalDependencies?: {
101
+ [x: string]: string;
102
+ };
103
+ peerDependenciesMeta?: Record<string, {
104
+ optional: true;
105
+ }>;
106
+ resolutions?: {
107
+ [x: string]: string;
108
+ };
109
+ module?: string;
110
+ browser?: string;
111
+ types?: string;
112
+ typings?: string;
113
+ typesVersions?: {
114
+ [x: string]: Record<string, string[]>;
115
+ };
116
+ publishConfig?: {
117
+ directory?: string;
118
+ main?: string;
119
+ exports?: string | string[] | {
120
+ [x: string & Record<never, never>]: string | string[] | any | {
121
+ [key: string]: string | string[] | any | any | null;
122
+ } | null;
123
+ browser: string | string[] | any | {
124
+ [key: string]: string | string[] | any | any | null;
125
+ } | null;
126
+ default: string | string[] | any | {
127
+ [key: string]: string | string[] | any | any | null;
128
+ } | null;
129
+ deno: string | string[] | any | {
130
+ [key: string]: string | string[] | any | any | null;
131
+ } | null;
132
+ electron: string | string[] | any | {
133
+ [key: string]: string | string[] | any | any | null;
134
+ } | null;
135
+ import: string | string[] | any | {
136
+ [key: string]: string | string[] | any | any | null;
137
+ } | null;
138
+ node: string | string[] | any | {
139
+ [key: string]: string | string[] | any | any | null;
140
+ } | null;
141
+ "node-addons": string | string[] | any | {
142
+ [key: string]: string | string[] | any | any | null;
143
+ } | null;
144
+ "react-native": string | string[] | any | {
145
+ [key: string]: string | string[] | any | any | null;
146
+ } | null;
147
+ require: string | string[] | any | {
148
+ [key: string]: string | string[] | any | any | null;
149
+ } | null;
150
+ } | {
151
+ [key: string]: string | string[] | any | any | null;
152
+ } | null;
153
+ types?: string;
154
+ typings?: string;
155
+ typesVersions?: {
156
+ [x: string]: Record<string, string[]>;
157
+ };
158
+ };
159
+ catalog?: import("../types/package-json.ts").Catalog;
160
+ catalogs?: import("../types/package-json.ts").Catalogs;
161
+ packageManager?: string;
162
+ engines?: Record<string, string>;
163
+ pnpm: {
164
+ overrides?: {
165
+ [x: string]: string;
166
+ };
167
+ packageExtensions?: import("../types/package-json.ts").PackageExtensions;
168
+ };
169
+ knip?: import("../types/config.ts").WorkspaceConfiguration;
170
+ angular: unknown;
171
+ astro: unknown;
172
+ "astro-db": unknown;
173
+ "astro-markdoc": unknown;
174
+ "astro-og-canvas": unknown;
175
+ ava: unknown;
176
+ babel: unknown;
177
+ biome: unknown;
178
+ bumpp: unknown;
179
+ bun: unknown;
180
+ c8: unknown;
181
+ capacitor: unknown;
182
+ catalyst: unknown;
183
+ changelogen: unknown;
184
+ changelogithub: unknown;
185
+ changesets: unknown;
186
+ commitizen: unknown;
187
+ commitlint: unknown;
188
+ convex: unknown;
189
+ "create-typescript-app": unknown;
190
+ cspell: unknown;
191
+ cucumber: unknown;
192
+ cypress: unknown;
193
+ danger: unknown;
194
+ "dependency-cruiser": unknown;
195
+ docusaurus: unknown;
196
+ dotenv: unknown;
197
+ drizzle: unknown;
198
+ "electron-vite": unknown;
199
+ eleventy: unknown;
200
+ esbuild: unknown;
201
+ eslint: unknown;
202
+ eve: unknown;
203
+ execa: unknown;
204
+ expo: unknown;
205
+ "expressive-code": unknown;
206
+ fast: unknown;
207
+ fumadocs: unknown;
208
+ gatsby: unknown;
209
+ "github-action": unknown;
210
+ "github-actions": unknown;
211
+ glob: unknown;
212
+ "graphql-codegen": unknown;
213
+ hardhat: unknown;
214
+ husky: unknown;
215
+ "i18next-parser": unknown;
216
+ jest: unknown;
217
+ karma: unknown;
218
+ knex: unknown;
219
+ ladle: unknown;
220
+ "laravel-vite-plugin": unknown;
221
+ lefthook: unknown;
222
+ "lint-staged": unknown;
223
+ linthtml: unknown;
224
+ lit: unknown;
225
+ "lockfile-lint": unknown;
226
+ "lost-pixel": unknown;
227
+ lunaria: unknown;
228
+ markdownlint: unknown;
229
+ marko: unknown;
230
+ mdx: unknown;
231
+ mdxlint: unknown;
232
+ metro: unknown;
233
+ mocha: unknown;
234
+ moonrepo: unknown;
235
+ msw: unknown;
236
+ "nano-spawn": unknown;
237
+ "nano-staged": unknown;
238
+ nest: unknown;
239
+ netlify: unknown;
240
+ next: unknown;
241
+ "next-intl": unknown;
242
+ "next-mdx": unknown;
243
+ nitro: unknown;
244
+ node: unknown;
245
+ "node-modules-inspector": unknown;
246
+ nodemon: unknown;
247
+ "npm-package-json-lint": unknown;
248
+ nuxt: unknown;
249
+ "nuxtjs-i18n": unknown;
250
+ nx: unknown;
251
+ nyc: unknown;
252
+ oclif: unknown;
253
+ "openapi-ts": unknown;
254
+ openclaw: unknown;
255
+ orval: unknown;
256
+ oxfmt: unknown;
257
+ oxlint: unknown;
258
+ "panda-css": unknown;
259
+ parcel: unknown;
260
+ payload: unknown;
261
+ pino: unknown;
262
+ playwright: unknown;
263
+ "playwright-ct": unknown;
264
+ "playwright-test": unknown;
265
+ plop: unknown;
266
+ pm2: unknown;
267
+ postcss: unknown;
268
+ preconstruct: unknown;
269
+ prettier: unknown;
270
+ prisma: unknown;
271
+ quasar: unknown;
272
+ qwik: unknown;
273
+ raycast: unknown;
274
+ "react-cosmos": unknown;
275
+ "react-email": unknown;
276
+ "react-native": unknown;
277
+ "react-router": unknown;
278
+ relay: unknown;
279
+ "release-it": unknown;
280
+ remark: unknown;
281
+ remix: unknown;
282
+ rolldown: unknown;
283
+ rollup: unknown;
284
+ rsbuild: unknown;
285
+ rslib: unknown;
286
+ rspack: unknown;
287
+ rstest: unknown;
288
+ sanity: unknown;
289
+ "semantic-release": unknown;
290
+ sentry: unknown;
291
+ "serverless-framework": unknown;
292
+ "simple-git-hooks": unknown;
293
+ "size-limit": unknown;
294
+ sst: unknown;
295
+ starlight: unknown;
296
+ stencil: unknown;
297
+ storybook: unknown;
298
+ stryker: unknown;
299
+ stylelint: unknown;
300
+ svelte: unknown;
301
+ "sveltejs-package": unknown;
302
+ sveltekit: unknown;
303
+ svgo: unknown;
304
+ svgr: unknown;
305
+ swc: unknown;
306
+ syncpack: unknown;
307
+ tailwind: unknown;
308
+ "tanstack-router": unknown;
309
+ taskfile: unknown;
310
+ tauri: unknown;
311
+ temporal: unknown;
312
+ travis: unknown;
313
+ "ts-node": unknown;
314
+ tsdown: unknown;
315
+ tsup: unknown;
316
+ tsx: unknown;
317
+ typedoc: unknown;
318
+ typescript: unknown;
319
+ unbuild: unknown;
320
+ unocss: unknown;
321
+ "unplugin-auto-import": unknown;
322
+ "unplugin-icons": unknown;
323
+ "unplugin-vue-components": unknown;
324
+ "unplugin-vue-i18n": unknown;
325
+ "unplugin-vue-markdown": unknown;
326
+ "unplugin-vue-router": unknown;
327
+ vercel: unknown;
328
+ "vercel-og": unknown;
329
+ vike: unknown;
330
+ vite: unknown;
331
+ "vite-plugin-pages": unknown;
332
+ "vite-plugin-pwa": unknown;
333
+ "vite-plugin-vue-layouts-next": unknown;
334
+ "vite-plus": unknown;
335
+ "vite-pwa-assets-generator": unknown;
336
+ vitepress: unknown;
337
+ vitest: unknown;
338
+ vue: unknown;
339
+ "webdriver-io": unknown;
340
+ webpack: unknown;
341
+ wireit: unknown;
342
+ wrangler: unknown;
343
+ wxt: unknown;
344
+ xo: unknown;
345
+ yarn: unknown;
346
+ yorkie: unknown;
347
+ zx: unknown;
348
+ };
349
+ export declare const getPublishedTypeExportSpecifiers: (exports: PackageJson['exports']) => Set<string>;
350
+ export declare const getPublishedTypeEntrySpecifiers: (manifest: PackageJson) => {
351
+ candidates: string[];
352
+ versioned: Set<string>;
353
+ };
8
354
  export declare const getPackageMapTarget: (map: unknown, key: string) => {
9
355
  target: any;
10
356
  patternMatch?: undefined;
@@ -12,6 +358,7 @@ export declare const getPackageMapTarget: (map: unknown, key: string) => {
12
358
  target: unknown;
13
359
  patternMatch: string;
14
360
  } | undefined;
361
+ export declare const isPublishedTypeExportTarget: (exports: PackageJson['exports'], candidate: string) => boolean;
15
362
  export declare const load: (filePath: string) => Promise<ExtendedPackageJson>;
16
363
  export declare const save: (filePath: string, content: ExtendedPackageJson) => Promise<void>;
17
364
  export declare const getEntrySpecifiersFromManifest: (manifest: PackageJson) => Set<string>;
@@ -1,4 +1,5 @@
1
1
  import { readFile, writeFile } from 'node:fs/promises';
2
+ import { IS_DTS } from '../constants.js';
2
3
  const INDENT = Symbol.for('indent');
3
4
  const NEWLINE = Symbol.for('newline');
4
5
  const DEFAULT_NEWLINE = '\n';
@@ -35,6 +36,88 @@ const getEntriesFromExports = (obj) => {
35
36
  }
36
37
  return values;
37
38
  };
39
+ const declarationExtensionMap = new Map([
40
+ ['.js', '.d.ts'],
41
+ ['.mjs', '.d.mts'],
42
+ ['.cjs', '.d.cts'],
43
+ ]);
44
+ export const toDeclarationSpecifier = (specifier) => {
45
+ for (const [extension, declarationExtension] of declarationExtensionMap) {
46
+ if (specifier.endsWith(extension))
47
+ return specifier.slice(0, -extension.length) + declarationExtension;
48
+ }
49
+ if (IS_DTS.test(specifier))
50
+ return specifier;
51
+ };
52
+ export const getPublishedTypeManifest = (manifest) => {
53
+ const { publishConfig } = manifest;
54
+ if (!publishConfig)
55
+ return manifest;
56
+ const publishedManifest = { ...manifest };
57
+ if (Object.hasOwn(publishConfig, 'main'))
58
+ publishedManifest.main = publishConfig.main;
59
+ if (Object.hasOwn(publishConfig, 'exports'))
60
+ publishedManifest.exports = publishConfig.exports;
61
+ if (Object.hasOwn(publishConfig, 'types'))
62
+ publishedManifest.types = publishConfig.types;
63
+ if (Object.hasOwn(publishConfig, 'typings'))
64
+ publishedManifest.typings = publishConfig.typings;
65
+ if (Object.hasOwn(publishConfig, 'typesVersions'))
66
+ publishedManifest.typesVersions = publishConfig.typesVersions;
67
+ return publishedManifest;
68
+ };
69
+ const isLocalTypeTarget = (target) => !target.startsWith('/') && !target.split('/').some(segment => segment === '..' || segment === 'node_modules');
70
+ const collectPublishedTypeTargets = (value, targets) => {
71
+ if (typeof value === 'string') {
72
+ const specifier = toDeclarationSpecifier(value);
73
+ if (specifier && isLocalTypeTarget(specifier))
74
+ targets.add(specifier);
75
+ return;
76
+ }
77
+ if (!value || typeof value !== 'object')
78
+ return;
79
+ if (Array.isArray(value)) {
80
+ for (const child of value)
81
+ collectPublishedTypeTargets(child, targets);
82
+ return;
83
+ }
84
+ const children = Object.entries(value);
85
+ const typeConditions = children.filter(([condition]) => condition === 'types' || condition.startsWith('types@'));
86
+ for (const [, child] of typeConditions.length > 0 ? typeConditions : children)
87
+ collectPublishedTypeTargets(child, targets);
88
+ };
89
+ export const getPublishedTypeExportSpecifiers = (exports) => {
90
+ const specifiers = new Set();
91
+ if (exports)
92
+ collectPublishedTypeTargets(exports, specifiers);
93
+ return specifiers;
94
+ };
95
+ export const getPublishedTypeEntrySpecifiers = (manifest) => {
96
+ const versioned = new Set();
97
+ if (manifest.typesVersions) {
98
+ for (const paths of Object.values(manifest.typesVersions)) {
99
+ for (const targets of Object.values(paths)) {
100
+ if (!Array.isArray(targets))
101
+ continue;
102
+ for (const target of targets) {
103
+ if (typeof target === 'string' && isLocalTypeTarget(target))
104
+ versioned.add(target);
105
+ }
106
+ }
107
+ }
108
+ }
109
+ const candidates = [];
110
+ for (const field of [manifest.types, manifest.typings, manifest.main]) {
111
+ if (typeof field !== 'string')
112
+ continue;
113
+ const specifier = toDeclarationSpecifier(field);
114
+ if (specifier && isLocalTypeTarget(specifier) && !candidates.includes(specifier))
115
+ candidates.push(specifier);
116
+ }
117
+ if (!candidates.includes('index.d.ts'))
118
+ candidates.push('index.d.ts');
119
+ return { candidates, versioned };
120
+ };
38
121
  export const getPackageMapTarget = (map, key) => {
39
122
  if (!map || typeof map !== 'object' || Array.isArray(map))
40
123
  return key === '.' ? { target: map } : undefined;
@@ -72,6 +155,46 @@ export const getPackageMapTarget = (map, key) => {
72
155
  if (best)
73
156
  return { target: best.target, patternMatch: best.patternMatch };
74
157
  };
158
+ const matchPublishedTypeTarget = (pattern, candidate) => {
159
+ const parts = pattern.split('*');
160
+ if (parts.length === 1)
161
+ return pattern === candidate ? { patternMatch: undefined } : undefined;
162
+ const starCount = parts.length - 1;
163
+ const matchLength = (candidate.length - pattern.length + starCount) / starCount;
164
+ if (matchLength < 0 || !Number.isInteger(matchLength))
165
+ return;
166
+ const patternMatch = candidate.slice(parts[0].length, parts[0].length + matchLength);
167
+ if (parts.join(patternMatch) === candidate)
168
+ return { patternMatch };
169
+ };
170
+ const getExportEntries = (exports) => {
171
+ if (!Array.isArray(exports) && typeof exports === 'object') {
172
+ const entries = Object.entries(exports);
173
+ if (entries.some(([key]) => key.startsWith('.')))
174
+ return entries.filter(([key]) => key.startsWith('.'));
175
+ }
176
+ return [['.', exports]];
177
+ };
178
+ export const isPublishedTypeExportTarget = (exports, candidate) => {
179
+ if (!exports)
180
+ return false;
181
+ for (const [subpath, target] of getExportEntries(exports)) {
182
+ for (const pattern of getPublishedTypeExportSpecifiers(target)) {
183
+ const match = matchPublishedTypeTarget(pattern, candidate);
184
+ if (!match)
185
+ continue;
186
+ const publicSubpath = match.patternMatch === undefined ? subpath : subpath.replaceAll('*', match.patternMatch);
187
+ const resolved = getPackageMapTarget(exports, publicSubpath);
188
+ if (!resolved)
189
+ continue;
190
+ for (const selected of getPublishedTypeExportSpecifiers(resolved.target)) {
191
+ if (matchPublishedTypeTarget(selected, candidate))
192
+ return true;
193
+ }
194
+ }
195
+ }
196
+ return false;
197
+ };
75
198
  export const load = async (filePath) => {
76
199
  const file = await readFile(filePath, 'utf8');
77
200
  return parseJson(file);
@@ -1,13 +1,14 @@
1
- export declare const isAbsolute: (path: string) => boolean;
2
- export declare const dirname: (path: string) => string;
3
- export declare const extname: (path: string) => string;
4
- export declare const basename: (path: string, suffix?: string) => string;
5
- export declare const join: (...paths: string[]) => string;
1
+ import path from 'node:path';
2
+ export declare const isAbsolute: typeof path.isAbsolute;
3
+ export declare const dirname: typeof path.dirname;
4
+ export declare const extname: typeof path.extname;
5
+ export declare const basename: typeof path.basename;
6
+ export declare const join: typeof path.join;
6
7
  export declare const toPosix: (value: string) => string;
7
- export declare const resolve: (...paths: string[]) => string;
8
+ export declare const resolve: typeof path.resolve;
8
9
  export declare const relative: (from: string, to: string) => string;
9
10
  export declare const isInNodeModules: (filePath: string) => boolean;
10
11
  export declare const toAbsolute: (id: string, base: string) => string;
11
12
  export declare const toRelative: (id: string, base: string) => string;
12
13
  export declare const isInternal: (id: string) => boolean;
13
- export declare const normalize: (path: string) => string;
14
+ export declare const normalize: typeof path.normalize;
@@ -1,5 +1,11 @@
1
1
  export declare const extensionAlias: Record<string, string[]>;
2
2
  export declare const _resolveModuleSync: (specifier: string, basePath: string) => string | undefined;
3
+ declare const resolveDeclarationSync: (specifier: string, containingFile: string) => {
4
+ path: string;
5
+ packageJsonPath: string | undefined;
6
+ } | undefined;
7
+ export declare const _resolveDeclarationSync: typeof resolveDeclarationSync;
3
8
  export declare const _createSyncModuleResolver: (extensions: string[], tsConfigFile?: string) => (specifier: string, basePath: string) => string | undefined;
4
9
  export declare function clearResolverCache(): void;
5
10
  export declare const _resolveSync: (specifier: string, baseDir: string) => string | undefined;
11
+ export {};
@@ -9,6 +9,20 @@ export const extensionAlias = {
9
9
  '.cjs': ['.cjs', '.cts', '.d.cts'],
10
10
  };
11
11
  const resolverInstances = [];
12
+ const declarationResolver = new ResolverFactory({
13
+ extensions: [...DTS_EXTENSIONS, ...DEFAULT_EXTENSIONS],
14
+ extensionAlias: {
15
+ '.ts': ['.d.ts', '.ts'],
16
+ '.mts': ['.d.mts', '.mts'],
17
+ '.cts': ['.d.cts', '.cts'],
18
+ '.js': ['.d.ts', '.js'],
19
+ '.mjs': ['.d.mts', '.mjs'],
20
+ '.cjs': ['.d.cts', '.cjs'],
21
+ },
22
+ conditionNames: ['types', 'import', 'require', 'node', 'default'],
23
+ nodePath: false,
24
+ });
25
+ resolverInstances.push(declarationResolver);
12
26
  const createSyncModuleResolver = (extensions, tsConfigFile) => {
13
27
  const baseOptions = {
14
28
  extensions,
@@ -38,6 +52,16 @@ const createSyncModuleResolver = (extensions, tsConfigFile) => {
38
52
  };
39
53
  const resolveModuleSync = createSyncModuleResolver([...DEFAULT_EXTENSIONS, ...DTS_EXTENSIONS, '.json', '.jsonc']);
40
54
  export const _resolveModuleSync = timerify(resolveModuleSync, 'resolveModuleSync');
55
+ const resolveDeclarationSync = (specifier, containingFile) => {
56
+ const result = declarationResolver.resolveFileSync(containingFile, specifier);
57
+ if (!result.path)
58
+ return;
59
+ return {
60
+ path: toPosix(result.path),
61
+ packageJsonPath: result.packageJsonPath ? toPosix(result.packageJsonPath) : undefined,
62
+ };
63
+ };
64
+ export const _resolveDeclarationSync = timerify(resolveDeclarationSync, 'resolveDeclarationSync');
41
65
  export const _createSyncModuleResolver = (extensions, tsConfigFile) => timerify(createSyncModuleResolver(extensions, tsConfigFile), 'resolveModuleSync');
42
66
  const createSyncResolver = (extensions) => {
43
67
  const resolver = new ResolverFactory({
@@ -1,4 +1,6 @@
1
1
  export declare const ELLIPSIS = "\u2026";
2
+ export declare const substringBefore: (value: string, separator: string) => string;
3
+ export declare const compareStrings: (a: string, b: string) => number;
2
4
  export declare const truncate: (text: string, width: number) => string;
3
5
  export declare const truncateStart: (text: string, width: number) => string;
4
6
  export declare const pad: (text: string, width: number, fillString?: string, align?: 'left' | 'center' | 'right') => string;
@@ -1,6 +1,12 @@
1
1
  import { stripVTControlCharacters } from 'node:util';
2
2
  const CONTROL_CHARACTERS = /\u001b\[[0-9;]+m/g;
3
3
  export const ELLIPSIS = '…';
4
+ export const substringBefore = (value, separator) => {
5
+ const index = value.indexOf(separator);
6
+ return index === -1 ? value : value.slice(0, index);
7
+ };
8
+ const collator = new Intl.Collator();
9
+ export const compareStrings = (a, b) => collator.compare(a, b);
4
10
  const getTruncatedParts = (input, limit, fromStart) => {
5
11
  const parts = [];
6
12
  let width = 0;
@@ -1,5 +1,5 @@
1
1
  import { stripVTControlCharacters } from 'node:util';
2
- import { pad, truncate, truncateStart } from './string.js';
2
+ import { compareStrings, pad, truncate, truncateStart } from './string.js';
3
3
  const MIN_TRUNCATED_WIDTH = 4;
4
4
  const COLUMN_SEPARATOR = ' ';
5
5
  const visibleLength = (text) => stripVTControlCharacters(text).length;
@@ -36,7 +36,7 @@ export class Table {
36
36
  const vA = a[column]?.value;
37
37
  const vB = b[column]?.value;
38
38
  if (typeof vA === 'string' && typeof vB === 'string')
39
- return dir * vA.localeCompare(vB);
39
+ return dir * compareStrings(vA, vB);
40
40
  if (typeof vA === 'number' && typeof vB === 'number')
41
41
  return dir * (vA - vB);
42
42
  return !isPrintable(vA) ? 1 : !isPrintable(vB) ? -1 : 0;
@@ -5,7 +5,7 @@ import { _glob, prependDirToPattern } from './glob.js';
5
5
  import { getPackageNameFromModuleSpecifier } from './modules.js';
6
6
  import { getPackageMapTarget } from './package-json.js';
7
7
  import { isAbsolute, isInternal, join, toRelative } from './path.js';
8
- const defaultExtensions = `.{${[...DEFAULT_EXTENSIONS].map(ext => ext.slice(1)).join(',')}}`;
8
+ const defaultExtensions = `.{${Array.from(DEFAULT_EXTENSIONS, ext => ext.slice(1)).join(',')}}`;
9
9
  const hasTSExt = /(?<!\.d)\.(m|c)?tsx?$/;
10
10
  const matchExt = /(\.d)?\.(m|c)?(j|t)s$/;
11
11
  const sourceExtensions = [...DEFAULT_EXTENSIONS];
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "6.29.0";
1
+ export declare const version = "6.31.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '6.29.0';
1
+ export const version = '6.31.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "6.29.0",
3
+ "version": "6.31.0",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "keywords": [
6
6
  "analysis",
@@ -81,13 +81,13 @@
81
81
  "formatly": "^0.3.0",
82
82
  "get-tsconfig": "4.14.0",
83
83
  "jiti": "^2.7.0",
84
- "oxc-parser": "^0.140.0",
84
+ "oxc-parser": "^0.142.0",
85
85
  "oxc-resolver": "11.24.2",
86
86
  "picomatch": "^4.0.5",
87
- "smol-toml": "^1.7.0",
87
+ "smol-toml": "^1.7.1",
88
88
  "strip-json-comments": "5.0.3",
89
89
  "tinyglobby": "^0.2.17",
90
- "unbash": "^4.0.3",
90
+ "unbash": "^4.0.4",
91
91
  "yaml": "^2.9.0",
92
92
  "zod": "^4.4.3"
93
93
  },
@@ -97,7 +97,7 @@
97
97
  "@types/picomatch": "^4.0.3",
98
98
  "@types/webpack": "^5.28.5",
99
99
  "codeclimate-types": "^0.3.1",
100
- "prettier": "^3.9.5",
100
+ "prettier": "^3.9.6",
101
101
  "tsx": "^4.23.1",
102
102
  "typescript": "7.0.2"
103
103
  },