knip 6.15.0 → 6.16.1

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 (63) hide show
  1. package/dist/ConfigurationChief.d.ts +20 -0
  2. package/dist/ConfigurationChief.js +2 -1
  3. package/dist/ProjectPrincipal.d.ts +4 -1
  4. package/dist/ProjectPrincipal.js +21 -13
  5. package/dist/binaries/fallback.js +1 -1
  6. package/dist/binaries/plugins.js +1 -1
  7. package/dist/binaries/resolvers/bun.js +1 -1
  8. package/dist/binaries/resolvers/bunx.js +1 -1
  9. package/dist/binaries/resolvers/npm.js +1 -1
  10. package/dist/binaries/resolvers/npx.js +1 -1
  11. package/dist/binaries/resolvers/pnpm.js +1 -1
  12. package/dist/binaries/resolvers/pnpx.js +1 -1
  13. package/dist/binaries/resolvers/yarn.js +1 -1
  14. package/dist/binaries/util.d.ts +1 -2
  15. package/dist/binaries/util.js +1 -1
  16. package/dist/compilers/index.d.ts +31 -0
  17. package/dist/graph/analyze.js +8 -7
  18. package/dist/graph/build.js +4 -3
  19. package/dist/plugins/_custom-elements/custom-element-visitor.d.ts +7 -0
  20. package/dist/plugins/_custom-elements/custom-element-visitor.js +106 -0
  21. package/dist/plugins/bun/index.js +1 -1
  22. package/dist/plugins/catalyst/index.d.ts +3 -0
  23. package/dist/plugins/catalyst/index.js +16 -0
  24. package/dist/plugins/execa/visitors/execa.js +4 -17
  25. package/dist/plugins/fast/index.d.ts +3 -0
  26. package/dist/plugins/fast/index.js +16 -0
  27. package/dist/plugins/index.d.ts +3 -0
  28. package/dist/plugins/index.js +6 -0
  29. package/dist/plugins/lit/index.d.ts +3 -0
  30. package/dist/plugins/lit/index.js +25 -0
  31. package/dist/plugins/nano-spawn/visitors/nano-spawn.js +4 -17
  32. package/dist/plugins/relay/index.js +1 -1
  33. package/dist/plugins/stencil/index.js +17 -1
  34. package/dist/plugins/sveltejs-package/helpers.js +1 -1
  35. package/dist/schema/configuration.d.ts +51 -0
  36. package/dist/schema/configuration.js +1 -0
  37. package/dist/schema/plugins.d.ts +15 -0
  38. package/dist/schema/plugins.js +3 -0
  39. package/dist/types/PluginNames.d.ts +2 -2
  40. package/dist/types/PluginNames.js +3 -0
  41. package/dist/types/args.d.ts +1 -1
  42. package/dist/types/config.d.ts +2 -0
  43. package/dist/types/module-graph.d.ts +1 -0
  44. package/dist/types/project.d.ts +1 -0
  45. package/dist/typescript/ast-helpers.js +21 -20
  46. package/dist/typescript/ast-nodes.d.ts +1 -0
  47. package/dist/typescript/ast-nodes.js +19 -0
  48. package/dist/typescript/get-imports-and-exports.js +18 -2
  49. package/dist/typescript/resolve-module-names.d.ts +11 -1
  50. package/dist/typescript/resolve-module-names.js +49 -12
  51. package/dist/typescript/visitors/calls.d.ts +3 -2
  52. package/dist/typescript/visitors/calls.js +88 -16
  53. package/dist/typescript/visitors/exports.js +12 -0
  54. package/dist/typescript/visitors/walk.d.ts +7 -0
  55. package/dist/typescript/visitors/walk.js +36 -1
  56. package/dist/util/create-options.d.ts +31 -0
  57. package/dist/util/load-tsconfig.js +2 -0
  58. package/dist/util/parse-args.d.ts +14 -0
  59. package/dist/util/parse-args.js +112 -0
  60. package/dist/version.d.ts +1 -1
  61. package/dist/version.js +1 -1
  62. package/package.json +1 -3
  63. package/schema.json +61 -43
@@ -0,0 +1,112 @@
1
+ import { parseArgs as nodeParseArgs } from 'node:util';
2
+ const isHex = /^0x[0-9a-f]+$/i;
3
+ const isDecimal = /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/;
4
+ const coerce = (value) => (isHex.test(value) || isDecimal.test(value) ? Number(value) : value);
5
+ const setNested = (target, key, value) => {
6
+ if (!key.includes('.')) {
7
+ target[key] = value;
8
+ return;
9
+ }
10
+ const parts = key.split('.');
11
+ let obj = target;
12
+ for (let i = 0; i < parts.length - 1; i++) {
13
+ const part = parts[i];
14
+ if (typeof obj[part] !== 'object' || obj[part] === null)
15
+ obj[part] = {};
16
+ obj = obj[part];
17
+ }
18
+ obj[parts[parts.length - 1]] = value;
19
+ };
20
+ const parseArgs = (argv, opts = {}) => {
21
+ const strings = new Set(opts.string ?? []);
22
+ const booleans = new Set(opts.boolean ?? []);
23
+ const groups = new Map();
24
+ const canonicalOf = new Map();
25
+ if (opts.alias) {
26
+ for (const key in opts.alias) {
27
+ const names = [key, ...[opts.alias[key]].flat()];
28
+ const isString = names.some(name => strings.has(name));
29
+ const isBoolean = names.some(name => booleans.has(name));
30
+ groups.set(key, names);
31
+ for (const name of names) {
32
+ canonicalOf.set(name, key);
33
+ if (isString)
34
+ strings.add(name);
35
+ if (isBoolean)
36
+ booleans.add(name);
37
+ }
38
+ }
39
+ }
40
+ const canonical = (name) => canonicalOf.get(name) ?? name;
41
+ const args = [];
42
+ for (const arg of argv) {
43
+ if (typeof arg === 'string')
44
+ args.push(/^-[A-Za-z]=/.test(arg) ? `-${arg}` : arg);
45
+ }
46
+ const { tokens } = nodeParseArgs({ args, strict: false, allowPositionals: true, tokens: true });
47
+ const positionals = [];
48
+ const dd = [];
49
+ const store = new Map();
50
+ const consumed = new Set();
51
+ let terminated = false;
52
+ const set = (name, value) => {
53
+ const key = canonical(name);
54
+ const prev = store.get(key);
55
+ if (prev === undefined)
56
+ store.set(key, value);
57
+ else if (prev === true && value === true)
58
+ return;
59
+ else if (Array.isArray(prev))
60
+ prev.push(value);
61
+ else
62
+ store.set(key, [prev, value]);
63
+ };
64
+ for (let i = 0; i < tokens.length; i++) {
65
+ const token = tokens[i];
66
+ if (token.kind === 'option-terminator') {
67
+ terminated = true;
68
+ }
69
+ else if (token.kind === 'positional') {
70
+ if (terminated && opts['--'])
71
+ dd.push(token.value);
72
+ else if (!consumed.has(i))
73
+ positionals.push(coerce(token.value));
74
+ }
75
+ else if (token.value === undefined && token.rawName.startsWith('--no-')) {
76
+ set(token.name.slice(3), false);
77
+ }
78
+ else {
79
+ const name = token.name;
80
+ if (booleans.has(name)) {
81
+ set(name, token.value !== 'false');
82
+ }
83
+ else if (token.value !== undefined) {
84
+ set(name, strings.has(name) ? token.value : coerce(token.value));
85
+ }
86
+ else {
87
+ const next = tokens[i + 1];
88
+ if (next?.kind === 'positional' && !consumed.has(i + 1)) {
89
+ consumed.add(i + 1);
90
+ set(name, strings.has(name) ? next.value : coerce(next.value));
91
+ }
92
+ else {
93
+ set(name, strings.has(name) ? '' : true);
94
+ }
95
+ }
96
+ }
97
+ }
98
+ for (const name of booleans) {
99
+ const key = canonical(name);
100
+ if (!store.has(key))
101
+ store.set(key, false);
102
+ }
103
+ const result = { _: positionals };
104
+ for (const [key, value] of store) {
105
+ for (const name of groups.get(key) ?? [key])
106
+ setNested(result, name, value);
107
+ }
108
+ if (opts['--'])
109
+ result['--'] = dd;
110
+ return result;
111
+ };
112
+ export default parseArgs;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "6.15.0";
1
+ export declare const version = "6.16.1";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '6.15.0';
1
+ export const version = '6.16.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "6.15.0",
3
+ "version": "6.16.1",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "keywords": [
6
6
  "analysis",
@@ -81,7 +81,6 @@
81
81
  "formatly": "^0.3.0",
82
82
  "get-tsconfig": "4.14.0",
83
83
  "jiti": "^2.7.0",
84
- "minimist": "^1.2.8",
85
84
  "oxc-parser": "^0.133.0",
86
85
  "oxc-resolver": "^11.20.0",
87
86
  "picomatch": "^4.0.4",
@@ -95,7 +94,6 @@
95
94
  "devDependencies": {
96
95
  "@jest/types": "^29.6.3",
97
96
  "@types/bun": "^1.3.3",
98
- "@types/minimist": "^1.2.5",
99
97
  "@types/picomatch": "^4.0.1",
100
98
  "@types/webpack": "^5.28.5",
101
99
  "@typescript/native-preview": "7.0.0-dev.20260512.1",
package/schema.json CHANGED
@@ -52,49 +52,7 @@
52
52
  "$ref": "#/definitions/issueTypes"
53
53
  },
54
54
  "ignoreExportsUsedInFile": {
55
- "title": "Ignore exports used in file",
56
- "examples": [
57
- {
58
- "ignoreExportsUsedInFile": true
59
- },
60
- {
61
- "ignoreExportsUsedInFile": {
62
- "interface": true,
63
- "type": true
64
- }
65
- }
66
- ],
67
- "anyOf": [
68
- {
69
- "type": "boolean"
70
- },
71
- {
72
- "type": "object",
73
- "properties": {
74
- "class": {
75
- "type": "boolean"
76
- },
77
- "enum": {
78
- "type": "boolean"
79
- },
80
- "function": {
81
- "type": "boolean"
82
- },
83
- "interface": {
84
- "type": "boolean"
85
- },
86
- "member": {
87
- "type": "boolean"
88
- },
89
- "type": {
90
- "type": "boolean"
91
- },
92
- "variable": {
93
- "type": "boolean"
94
- }
95
- }
96
- }
97
- ]
55
+ "$ref": "#/definitions/ignoreExportsUsedInFile"
98
56
  },
99
57
  "ignoreIssues": {
100
58
  "title": " Ignore specific issue types for specific file patterns",
@@ -224,6 +182,51 @@
224
182
  "title": "Include entry files when reporting unused exports",
225
183
  "type": "boolean"
226
184
  },
185
+ "ignoreExportsUsedInFile": {
186
+ "title": "Ignore exports used in file",
187
+ "examples": [
188
+ {
189
+ "ignoreExportsUsedInFile": true
190
+ },
191
+ {
192
+ "ignoreExportsUsedInFile": {
193
+ "interface": true,
194
+ "type": true
195
+ }
196
+ }
197
+ ],
198
+ "anyOf": [
199
+ {
200
+ "type": "boolean"
201
+ },
202
+ {
203
+ "type": "object",
204
+ "properties": {
205
+ "class": {
206
+ "type": "boolean"
207
+ },
208
+ "enum": {
209
+ "type": "boolean"
210
+ },
211
+ "function": {
212
+ "type": "boolean"
213
+ },
214
+ "interface": {
215
+ "type": "boolean"
216
+ },
217
+ "member": {
218
+ "type": "boolean"
219
+ },
220
+ "type": {
221
+ "type": "boolean"
222
+ },
223
+ "variable": {
224
+ "type": "boolean"
225
+ }
226
+ }
227
+ }
228
+ ]
229
+ },
227
230
  "ignoreMembers": {
228
231
  "title": "Enum and namespace members to exclude from the report (regex allowed)",
229
232
  "examples": ["render", "on.*"],
@@ -310,6 +313,9 @@
310
313
  "ignoreUnresolved": {
311
314
  "$ref": "#/definitions/ignoreUnresolved"
312
315
  },
316
+ "ignoreExportsUsedInFile": {
317
+ "$ref": "#/definitions/ignoreExportsUsedInFile"
318
+ },
313
319
  "includeEntryExports": {
314
320
  "$ref": "#/definitions/includeEntryExports"
315
321
  }
@@ -388,6 +394,10 @@
388
394
  "title": "Capacitor plugin configuration (https://knip.dev/reference/plugins/capacitor)",
389
395
  "$ref": "#/definitions/plugin"
390
396
  },
397
+ "catalyst": {
398
+ "title": "catalyst plugin configuration (https://knip.dev/reference/plugins/catalyst)",
399
+ "$ref": "#/definitions/plugin"
400
+ },
391
401
  "changelogen": {
392
402
  "title": "changelogen plugin configuration (https://knip.dev/reference/plugins/changelogen)",
393
403
  "$ref": "#/definitions/plugin"
@@ -468,6 +478,10 @@
468
478
  "title": "expressive-code plugin configuration (https://knip.dev/reference/plugins/expressive-code)",
469
479
  "$ref": "#/definitions/plugin"
470
480
  },
481
+ "fast": {
482
+ "title": "fast plugin configuration (https://knip.dev/reference/plugins/fast)",
483
+ "$ref": "#/definitions/plugin"
484
+ },
471
485
  "gatsby": {
472
486
  "title": "Gatsby plugin configuration (https://knip.dev/reference/plugins/gatsby)",
473
487
  "$ref": "#/definitions/plugin"
@@ -524,6 +538,10 @@
524
538
  "title": "linthtml plugin configuration (https://knip.dev/reference/plugins/linthtml)",
525
539
  "$ref": "#/definitions/plugin"
526
540
  },
541
+ "lit": {
542
+ "title": "lit plugin configuration (https://knip.dev/reference/plugins/lit)",
543
+ "$ref": "#/definitions/plugin"
544
+ },
527
545
  "lockfile-lint": {
528
546
  "title": "lockfile-lint plugin configuration (https://knip.dev/reference/plugins/lockfile-lint)",
529
547
  "$ref": "#/definitions/plugin"