knip 6.41.0 → 6.42.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 (71) hide show
  1. package/README.md +1 -1
  2. package/dist/ConfigurationChief.d.ts +18 -0
  3. package/dist/WorkspaceWorker.js +1 -0
  4. package/dist/binaries/bash-parser.js +16 -39
  5. package/dist/binaries/resolvers/bun.js +1 -0
  6. package/dist/compilers/scss.js +2 -22
  7. package/dist/compilers/shared.d.ts +1 -1
  8. package/dist/compilers/shared.js +24 -1
  9. package/dist/constants.js +1 -0
  10. package/dist/graph-explorer/operations/is-referenced.js +8 -2
  11. package/dist/manifest/index.js +2 -3
  12. package/dist/plugins/_component-style-urls/component-style-urls-visitor.d.ts +2 -0
  13. package/dist/plugins/_component-style-urls/component-style-urls-visitor.js +40 -0
  14. package/dist/plugins/angular/index.js +7 -1
  15. package/dist/plugins/biome/index.js +2 -2
  16. package/dist/plugins/bun/index.js +13 -0
  17. package/dist/plugins/commitlint/index.js +2 -2
  18. package/dist/plugins/eslint/helpers.js +1 -1
  19. package/dist/plugins/filesystem-routing/index.d.ts +3 -0
  20. package/dist/plugins/filesystem-routing/index.js +57 -0
  21. package/dist/plugins/github-actions/index.js +1 -1
  22. package/dist/plugins/index.d.ts +3 -0
  23. package/dist/plugins/index.js +6 -0
  24. package/dist/plugins/jest/index.js +16 -7
  25. package/dist/plugins/jest/visitors/mock.d.ts +2 -0
  26. package/dist/plugins/jest/visitors/mock.js +91 -0
  27. package/dist/plugins/mise/scripts.js +55 -97
  28. package/dist/plugins/next/index.js +33 -1
  29. package/dist/plugins/nx/index.js +46 -8
  30. package/dist/plugins/nx/types.d.ts +8 -0
  31. package/dist/plugins/oxlint/index.js +1 -1
  32. package/dist/plugins/react-router/index.d.ts +3 -0
  33. package/dist/plugins/react-router/index.js +3 -0
  34. package/dist/plugins/rstest/index.js +1 -1
  35. package/dist/plugins/semantic-release/index.js +32 -3
  36. package/dist/plugins/semantic-release/types.d.ts +1 -0
  37. package/dist/plugins/solidjs-vite-plugin/index.d.ts +6 -0
  38. package/dist/plugins/solidjs-vite-plugin/index.js +17 -0
  39. package/dist/plugins/solidjs-vite-plugin/resolveFromAST.d.ts +3 -0
  40. package/dist/plugins/solidjs-vite-plugin/resolveFromAST.js +76 -0
  41. package/dist/plugins/sst/resolveFromAST.js +1 -1
  42. package/dist/plugins/stencil/index.js +2 -39
  43. package/dist/plugins/storybook/index.js +2 -4
  44. package/dist/plugins/sveltejs-package/helpers.js +2 -2
  45. package/dist/plugins/tailwind/compiler.js +10 -2
  46. package/dist/plugins/taskfile/index.js +3 -6
  47. package/dist/plugins/tsrs/index.d.ts +3 -0
  48. package/dist/plugins/tsrs/index.js +15 -0
  49. package/dist/plugins/typescript/index.d.ts +12 -1
  50. package/dist/plugins/typescript/index.js +5 -7
  51. package/dist/plugins/vite/helpers.d.ts +1 -0
  52. package/dist/plugins/vite/helpers.js +15 -1
  53. package/dist/plugins/vitest/index.js +4 -4
  54. package/dist/schema/configuration.d.ts +45 -0
  55. package/dist/schema/plugins.d.ts +15 -0
  56. package/dist/schema/plugins.js +3 -0
  57. package/dist/types/PluginNames.d.ts +2 -2
  58. package/dist/types/PluginNames.js +3 -0
  59. package/dist/types/config.d.ts +1 -0
  60. package/dist/typescript/visitors/imports.js +11 -0
  61. package/dist/typescript/visitors/jsdoc.js +27 -22
  62. package/dist/util/create-options.d.ts +30 -0
  63. package/dist/util/create-options.js +2 -3
  64. package/dist/util/path.d.ts +1 -0
  65. package/dist/util/path.js +1 -0
  66. package/dist/util/scripts.d.ts +3 -2
  67. package/dist/util/scripts.js +32 -72
  68. package/dist/version.d.ts +1 -1
  69. package/dist/version.js +1 -1
  70. package/package.json +5 -5
  71. package/schema.json +12 -0
@@ -1,13 +1,29 @@
1
1
  export const EMPTY_TAGS = new Set();
2
2
  export function buildJSDocTagLookup(comments, sourceText) {
3
3
  const entries = [];
4
- for (const comment of comments) {
5
- if (comment.type !== 'Block')
6
- continue;
4
+ let reach = sourceText.length;
5
+ for (let i = comments.length - 1; i >= 0; i--) {
6
+ const comment = comments[i];
7
+ let end = comment.end;
8
+ while (end < sourceText.length) {
9
+ const ch = sourceText.charCodeAt(end);
10
+ if (ch !== 32 && ch !== 9 && ch !== 10 && ch !== 13)
11
+ break;
12
+ end++;
13
+ }
14
+ if (end !== comments[i + 1]?.start)
15
+ reach = end;
7
16
  const value = comment.value;
8
17
  let index = value.indexOf('@');
9
18
  if (index === -1)
10
19
  continue;
20
+ if (comment.type === 'Line') {
21
+ let start = comment.start;
22
+ while (start > 0 && (sourceText.charCodeAt(start - 1) === 32 || sourceText.charCodeAt(start - 1) === 9))
23
+ start--;
24
+ if (start > 0 && sourceText.charCodeAt(start - 1) !== 10 && sourceText.charCodeAt(start - 1) !== 13)
25
+ continue;
26
+ }
11
27
  let tags;
12
28
  while (index !== -1) {
13
29
  let end = index + 1;
@@ -25,29 +41,18 @@ export function buildJSDocTagLookup(comments, sourceText) {
25
41
  }
26
42
  if (!tags)
27
43
  continue;
28
- let reach = comment.end;
29
- for (;;) {
30
- while (reach < sourceText.length) {
31
- const ch = sourceText.charCodeAt(reach);
32
- if (ch === 32 || ch === 9 || ch === 10 || ch === 13) {
33
- reach++;
34
- continue;
35
- }
36
- break;
37
- }
38
- if (reach + 1 < sourceText.length &&
39
- sourceText.charCodeAt(reach) === 47 &&
40
- sourceText.charCodeAt(reach + 1) === 47) {
41
- const eol = sourceText.indexOf('\n', reach + 2);
42
- reach = eol === -1 ? sourceText.length : eol + 1;
43
- continue;
44
- }
45
- break;
44
+ const entry = entries[entries.length - 1];
45
+ if (entry?.reach === reach) {
46
+ for (const tag of tags)
47
+ entry.tags.add(tag);
48
+ }
49
+ else {
50
+ entries.push({ reach, tags });
46
51
  }
47
- entries.push({ reach, tags });
48
52
  }
49
53
  if (entries.length === 0)
50
54
  return () => EMPTY_TAGS;
55
+ entries.reverse();
51
56
  return function getJSDocTags(nodeStart) {
52
57
  let lo = 0;
53
58
  let hi = entries.length - 1;
@@ -241,6 +241,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
241
241
  entry?: string | string[] | undefined;
242
242
  project?: string | string[] | undefined;
243
243
  } | undefined;
244
+ 'filesystem-routing'?: string | boolean | string[] | {
245
+ config?: string | string[] | undefined;
246
+ entry?: string | string[] | undefined;
247
+ project?: string | string[] | undefined;
248
+ } | undefined;
244
249
  flue?: string | boolean | string[] | {
245
250
  config?: string | string[] | undefined;
246
251
  entry?: string | string[] | undefined;
@@ -711,6 +716,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
711
716
  entry?: string | string[] | undefined;
712
717
  project?: string | string[] | undefined;
713
718
  } | undefined;
719
+ 'solidjs-vite-plugin'?: string | boolean | string[] | {
720
+ config?: string | string[] | undefined;
721
+ entry?: string | string[] | undefined;
722
+ project?: string | string[] | undefined;
723
+ } | undefined;
714
724
  sst?: string | boolean | string[] | {
715
725
  config?: string | string[] | undefined;
716
726
  entry?: string | string[] | undefined;
@@ -826,6 +836,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
826
836
  entry?: string | string[] | undefined;
827
837
  project?: string | string[] | undefined;
828
838
  } | undefined;
839
+ tsrs?: string | boolean | string[] | {
840
+ config?: string | string[] | undefined;
841
+ entry?: string | string[] | undefined;
842
+ project?: string | string[] | undefined;
843
+ } | undefined;
829
844
  tsup?: string | boolean | string[] | {
830
845
  config?: string | string[] | undefined;
831
846
  entry?: string | string[] | undefined;
@@ -1233,6 +1248,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1233
1248
  entry?: string | string[] | undefined;
1234
1249
  project?: string | string[] | undefined;
1235
1250
  } | undefined;
1251
+ 'filesystem-routing'?: string | boolean | string[] | {
1252
+ config?: string | string[] | undefined;
1253
+ entry?: string | string[] | undefined;
1254
+ project?: string | string[] | undefined;
1255
+ } | undefined;
1236
1256
  flue?: string | boolean | string[] | {
1237
1257
  config?: string | string[] | undefined;
1238
1258
  entry?: string | string[] | undefined;
@@ -1703,6 +1723,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1703
1723
  entry?: string | string[] | undefined;
1704
1724
  project?: string | string[] | undefined;
1705
1725
  } | undefined;
1726
+ 'solidjs-vite-plugin'?: string | boolean | string[] | {
1727
+ config?: string | string[] | undefined;
1728
+ entry?: string | string[] | undefined;
1729
+ project?: string | string[] | undefined;
1730
+ } | undefined;
1706
1731
  sst?: string | boolean | string[] | {
1707
1732
  config?: string | string[] | undefined;
1708
1733
  entry?: string | string[] | undefined;
@@ -1818,6 +1843,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1818
1843
  entry?: string | string[] | undefined;
1819
1844
  project?: string | string[] | undefined;
1820
1845
  } | undefined;
1846
+ tsrs?: string | boolean | string[] | {
1847
+ config?: string | string[] | undefined;
1848
+ entry?: string | string[] | undefined;
1849
+ project?: string | string[] | undefined;
1850
+ } | undefined;
1821
1851
  tsup?: string | boolean | string[] | {
1822
1852
  config?: string | string[] | undefined;
1823
1853
  entry?: string | string[] | undefined;
@@ -11,12 +11,11 @@ import { loadResolvedConfigFile } from './load-config.js';
11
11
  import { _load } from './loader.js';
12
12
  import { logWarning } from './log.js';
13
13
  import { getKeysByValue } from './object.js';
14
- import { isAbsolute, isInternal, join, normalize, toAbsolute, toPosix } from './path.js';
14
+ import { isAbsolute, isInternal, join, resolveCwd, toAbsolute } from './path.js';
15
15
  import { splitTags } from './tag.js';
16
16
  export const createOptions = async (options) => {
17
17
  const { args = {} } = options;
18
- const pcwd = toPosix(process.cwd());
19
- const cwd = normalize(toAbsolute(toPosix(options.cwd ?? args.directory ?? pcwd), pcwd));
18
+ const cwd = resolveCwd(options.cwd ?? args.directory ?? '.');
20
19
  const manifestPath = findFile(cwd, 'package.json');
21
20
  const manifest = manifestPath && (await loadJSON(manifestPath));
22
21
  if (!(manifestPath && manifest)) {
@@ -6,6 +6,7 @@ export declare const basename: typeof path.basename;
6
6
  export declare const join: typeof path.join;
7
7
  export declare const toPosix: (value: string) => string;
8
8
  export declare const resolve: typeof path.resolve;
9
+ export declare const resolveCwd: (dir: string) => string;
9
10
  export declare const relative: (from: string, to: string) => string;
10
11
  export declare const isInNodeModules: (filePath: string) => boolean;
11
12
  export declare const toAbsolute: (id: string, base: string) => string;
package/dist/util/path.js CHANGED
@@ -7,6 +7,7 @@ export const basename = path.posix.basename;
7
7
  export const join = path.posix.join;
8
8
  export const toPosix = isWin ? (value) => value.split(path.sep).join(path.posix.sep) : (value) => value;
9
9
  export const resolve = path.posix.resolve;
10
+ export const resolveCwd = (dir) => toPosix(path.resolve(dir));
10
11
  export const relative = (from, to) => {
11
12
  if (to.startsWith(from)) {
12
13
  const next = to[from.length];
@@ -1,9 +1,10 @@
1
- import { type Command, type SyntaxNode, type Word } from 'unbash';
1
+ import { type ArithmeticCommandExpansion, type Command, type CommandExpansionPart, type ProcessSubstitutionPart, type SyntaxNode, type Word } from 'unbash';
2
2
  export interface ScriptCommand {
3
3
  binary: string;
4
4
  args: string[];
5
5
  }
6
6
  export declare const toShellCommand: (argv: string[]) => string;
7
7
  export declare const getCommandWords: (node: Pick<Command, 'args'>) => Word[];
8
- export declare function walkCommands(node: SyntaxNode): Generator<Command>;
8
+ export declare const collectCommands: (root: SyntaxNode) => Command[];
9
+ export declare const isScriptExpansion: (node: SyntaxNode) => node is CommandExpansionPart | ProcessSubstitutionPart | ArithmeticCommandExpansion;
9
10
  export declare const getScriptCommands: (script: string) => ScriptCommand[];
@@ -1,86 +1,46 @@
1
- import { parse } from 'unbash';
1
+ import { forEachChild, parse, } from 'unbash';
2
2
  import { extractBinary } from './modules.js';
3
3
  const spawningBinaries = new Set(['c8', 'cross-env', 'retry-cli']);
4
4
  export const toShellCommand = (argv) => argv.map(arg => `'${arg.replaceAll("'", `'\\''`)}'`).join(' ');
5
5
  export const getCommandWords = (node) => node.args.filter((arg) => arg.type === 'Word');
6
- export function* walkCommands(node) {
7
- switch (node.type) {
8
- case 'Command':
9
- yield node;
10
- break;
11
- case 'AndOr':
12
- case 'Pipeline':
13
- for (const command of node.commands)
14
- yield* walkCommands(command);
15
- break;
16
- case 'If':
17
- for (const statement of node.clause.commands)
18
- yield* walkCommands(statement.command);
19
- for (const statement of node.then.commands)
20
- yield* walkCommands(statement.command);
21
- if (node.else)
22
- yield* walkCommands(node.else);
23
- break;
24
- case 'While':
25
- for (const statement of node.clause.commands)
26
- yield* walkCommands(statement.command);
27
- for (const statement of node.body.commands)
28
- yield* walkCommands(statement.command);
29
- break;
30
- case 'For':
31
- case 'Select':
32
- case 'Subshell':
33
- case 'BraceGroup':
34
- for (const statement of node.body.commands)
35
- yield* walkCommands(statement.command);
36
- break;
37
- case 'CompoundList':
38
- for (const statement of node.commands)
39
- yield* walkCommands(statement.command);
40
- break;
41
- case 'Function':
42
- case 'Coproc':
43
- yield* walkCommands(node.body);
44
- break;
45
- case 'Statement':
46
- case 'Redirected':
47
- case 'Time':
48
- case 'Negation':
49
- if (node.command)
50
- yield* walkCommands(node.command);
51
- break;
52
- }
53
- }
6
+ export const collectCommands = (root) => {
7
+ const commands = [];
8
+ const visit = (node) => {
9
+ if (node.type === 'Command')
10
+ commands.push(node);
11
+ if (!isScriptExpansion(node))
12
+ forEachChild(node, visit);
13
+ };
14
+ visit(root);
15
+ return commands;
16
+ };
17
+ export const isScriptExpansion = (node) => node.type === 'CommandExpansion' || node.type === 'ProcessSubstitution' || node.type === 'ArithmeticCommandExpansion';
54
18
  export const getScriptCommands = (script) => {
55
19
  if (!script)
56
20
  return [];
57
- let parsed;
21
+ const out = [];
58
22
  try {
59
- parsed = parse(script);
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
+ }
60
41
  }
61
42
  catch {
62
43
  return [];
63
44
  }
64
- if (!parsed.commands)
65
- return [];
66
- const out = [];
67
- for (const statement of parsed.commands) {
68
- for (const node of walkCommands(statement.command)) {
69
- const text = node.name?.value;
70
- if (!text)
71
- continue;
72
- const binary = extractBinary(text);
73
- const words = getCommandWords(node);
74
- if (spawningBinaries.has(binary)) {
75
- const rest = words
76
- .filter(word => word.text !== '--')
77
- .map(word => word.text)
78
- .join(' ');
79
- out.push(...getScriptCommands(rest));
80
- }
81
- else
82
- out.push({ binary, args: words.map(word => word.value) });
83
- }
84
- }
85
45
  return out;
86
46
  };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "6.41.0";
1
+ export declare const version = "6.42.1";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '6.41.0';
1
+ export const version = '6.42.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "6.41.0",
3
+ "version": "6.42.1",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "keywords": [
6
6
  "analysis",
@@ -84,22 +84,22 @@
84
84
  "formatly": "^0.11.4",
85
85
  "get-tsconfig": "4.14.3",
86
86
  "jiti": "^2.7.0",
87
- "oxc-parser": "^0.153.0",
87
+ "oxc-parser": "^0.154.0",
88
88
  "oxc-resolver": "11.24.2",
89
89
  "picomatch": "^4.0.7",
90
90
  "smol-toml": "^1.9.0",
91
91
  "strip-json-comments": "5.0.3",
92
92
  "tinyglobby": "^0.2.17",
93
- "unbash": "^5.0.0",
93
+ "unbash": "^6.0.0",
94
94
  "yaml": "^2.9.1",
95
95
  "zod": "^4.6.5"
96
96
  },
97
97
  "devDependencies": {
98
98
  "@jest/types": "^30.5.1",
99
- "@types/bun": "^1.4.2",
99
+ "@types/bun": "^1.4.3",
100
100
  "@types/picomatch": "^4.0.3",
101
101
  "codeclimate-types": "^0.3.1",
102
- "prettier": "^3.9.9",
102
+ "prettier": "^3.9.10",
103
103
  "tsx": "^4.23.15",
104
104
  "typescript": "7.0.2",
105
105
  "webpack": "^5.111.1"
package/schema.json CHANGED
@@ -574,6 +574,10 @@
574
574
  "title": "fast plugin configuration (https://knip.dev/reference/plugins/fast)",
575
575
  "$ref": "#/definitions/plugin"
576
576
  },
577
+ "filesystem-routing": {
578
+ "title": "filesystem-routing plugin configuration (https://knip.dev/reference/plugins/filesystem-routing)",
579
+ "$ref": "#/definitions/plugin"
580
+ },
577
581
  "flue": {
578
582
  "title": "flue plugin configuration (https://knip.dev/reference/plugins/flue)",
579
583
  "$ref": "#/definitions/plugin"
@@ -938,6 +942,10 @@
938
942
  "title": "size-limit plugin configuration (https://knip.dev/reference/plugins/size-limit)",
939
943
  "$ref": "#/definitions/plugin"
940
944
  },
945
+ "solidjs-vite-plugin": {
946
+ "title": "solidjs-vite-plugin plugin configuration (https://knip.dev/reference/plugins/solidjs-vite-plugin)",
947
+ "$ref": "#/definitions/plugin"
948
+ },
941
949
  "sst": {
942
950
  "title": "sst plugin configuration (https://knip.dev/reference/plugins/sst)",
943
951
  "$ref": "#/definitions/plugin"
@@ -1030,6 +1038,10 @@
1030
1038
  "title": "tsdown plugin configuration (https://knip.dev/reference/plugins/tsdown)",
1031
1039
  "$ref": "#/definitions/plugin"
1032
1040
  },
1041
+ "tsrs": {
1042
+ "title": "tsrs plugin configuration (https://knip.dev/reference/plugins/tsrs)",
1043
+ "$ref": "#/definitions/plugin"
1044
+ },
1033
1045
  "tsup": {
1034
1046
  "title": "tsup plugin configuration (https://knip.dev/reference/plugins/tsup)",
1035
1047
  "$ref": "#/definitions/plugin"