knip 6.22.0 → 6.24.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 (69) hide show
  1. package/LICENSE +1 -1
  2. package/dist/ConfigurationChief.d.ts +6 -0
  3. package/dist/ProjectPrincipal.js +3 -5
  4. package/dist/WorkspaceWorker.d.ts +3 -1
  5. package/dist/WorkspaceWorker.js +5 -2
  6. package/dist/binaries/resolvers/index.d.ts +2 -0
  7. package/dist/binaries/resolvers/index.js +3 -0
  8. package/dist/binaries/resolvers/nub.d.ts +2 -0
  9. package/dist/binaries/resolvers/nub.js +46 -0
  10. package/dist/binaries/resolvers/yarn.js +4 -3
  11. package/dist/compilers/compilers.d.ts +2 -0
  12. package/dist/compilers/compilers.js +15 -4
  13. package/dist/compilers/index.d.ts +11 -1
  14. package/dist/compilers/index.js +25 -10
  15. package/dist/compilers/less.d.ts +7 -0
  16. package/dist/compilers/less.js +37 -0
  17. package/dist/compilers/mdx.d.ts +1 -2
  18. package/dist/compilers/mdx.js +14 -8
  19. package/dist/compilers/scss.d.ts +3 -2
  20. package/dist/compilers/scss.js +17 -14
  21. package/dist/compilers/shared.d.ts +6 -0
  22. package/dist/compilers/shared.js +9 -0
  23. package/dist/compilers/style-preprocessors.d.ts +2 -0
  24. package/dist/compilers/style-preprocessors.js +41 -0
  25. package/dist/compilers/stylus.d.ts +7 -0
  26. package/dist/compilers/stylus.js +36 -0
  27. package/dist/constants.js +4 -0
  28. package/dist/graph/build.js +14 -1
  29. package/dist/plugins/astro/compiler-mdx.js +11 -2
  30. package/dist/plugins/astro/compiler.js +8 -4
  31. package/dist/plugins/astro-markdoc/index.d.ts +3 -0
  32. package/dist/plugins/astro-markdoc/index.js +34 -0
  33. package/dist/plugins/astro-markdoc/types.d.ts +12 -0
  34. package/dist/plugins/astro-markdoc/types.js +1 -0
  35. package/dist/plugins/github-actions/index.js +3 -2
  36. package/dist/plugins/index.d.ts +1 -0
  37. package/dist/plugins/index.js +2 -0
  38. package/dist/plugins/node/index.js +1 -1
  39. package/dist/plugins/nuxt/index.js +4 -2
  40. package/dist/plugins/prisma/compiler.js +3 -0
  41. package/dist/plugins/starlight/index.js +14 -1
  42. package/dist/plugins/stencil/index.js +59 -1
  43. package/dist/plugins/svelte/compiler.d.ts +2 -1
  44. package/dist/plugins/svelte/compiler.js +8 -1
  45. package/dist/plugins/tailwind/compiler.js +3 -0
  46. package/dist/plugins/tailwind/index.js +5 -1
  47. package/dist/plugins/vite/index.js +1 -1
  48. package/dist/plugins/vitest/index.js +3 -3
  49. package/dist/plugins/vue/compiler.d.ts +2 -1
  50. package/dist/plugins/vue/compiler.js +8 -1
  51. package/dist/reporters/compact.js +1 -2
  52. package/dist/reporters/symbols.js +1 -2
  53. package/dist/schema/configuration.d.ts +15 -0
  54. package/dist/schema/plugins.d.ts +5 -0
  55. package/dist/schema/plugins.js +1 -0
  56. package/dist/types/PluginNames.d.ts +2 -2
  57. package/dist/types/PluginNames.js +1 -0
  58. package/dist/types/config.d.ts +1 -0
  59. package/dist/types.d.ts +1 -1
  60. package/dist/typescript/SourceFileManager.js +3 -2
  61. package/dist/typescript/ast-nodes.d.ts +1 -0
  62. package/dist/typescript/ast-nodes.js +51 -1
  63. package/dist/typescript/comments.js +22 -3
  64. package/dist/typescript/visitors/walk.js +7 -1
  65. package/dist/util/create-options.d.ts +10 -0
  66. package/dist/version.d.ts +1 -1
  67. package/dist/version.js +1 -1
  68. package/package.json +1 -1
  69. package/schema.json +4 -0
@@ -1,4 +1,4 @@
1
- import { parseSync, rawTransferSupported, } from 'oxc-parser';
1
+ import { parseSync, rawTransferSupported, visitorKeys, } from 'oxc-parser';
2
2
  import { DEFAULT_EXTENSIONS, FIX_FLAGS, SYMBOL_TYPE } from '../constants.js';
3
3
  import { extname } from '../util/path.js';
4
4
  import { timerify } from '../util/Performance.js';
@@ -131,6 +131,56 @@ export function extractNamespaceMembers(decl, options, lineStarts, getJSDocTags,
131
131
  }
132
132
  return members;
133
133
  }
134
+ export const collectAugmentationRefs = (node) => {
135
+ if (!node.body || node.body.type !== 'TSModuleBlock')
136
+ return [];
137
+ const body = node.body.body;
138
+ const declared = new Set();
139
+ for (const stmt of body) {
140
+ const decl = stmt.type === 'ExportNamedDeclaration' && stmt.declaration ? stmt.declaration : stmt;
141
+ if ('id' in decl && decl.id?.type === 'Identifier')
142
+ declared.add(decl.id.name);
143
+ else if (decl.type === 'VariableDeclaration')
144
+ for (const d of decl.declarations)
145
+ if (d.id.type === 'Identifier')
146
+ declared.add(d.id.name);
147
+ }
148
+ const refs = [];
149
+ const seen = new Set();
150
+ const add = (ref) => {
151
+ if (ref?.type === 'Identifier' && !declared.has(ref.name) && !seen.has(ref.name)) {
152
+ seen.add(ref.name);
153
+ refs.push(ref.name);
154
+ }
155
+ };
156
+ const visit = (n) => {
157
+ const type = n?.type;
158
+ if (!type)
159
+ return;
160
+ if (type === 'TSTypeReference')
161
+ add(n.typeName);
162
+ else if (type === 'TSInterfaceHeritage')
163
+ add(n.expression);
164
+ const keys = visitorKeys[type];
165
+ if (!keys)
166
+ return;
167
+ for (const key of keys) {
168
+ const val = n[key];
169
+ if (!val)
170
+ continue;
171
+ if (Array.isArray(val)) {
172
+ for (const item of val)
173
+ if (item)
174
+ visit(item);
175
+ }
176
+ else
177
+ visit(val);
178
+ }
179
+ };
180
+ for (const stmt of body)
181
+ visit(stmt);
182
+ return refs;
183
+ };
134
184
  export function extractEnumMembers(decl, options, lineStarts, getJSDocTags) {
135
185
  if (!decl.body?.members)
136
186
  return [];
@@ -1,6 +1,7 @@
1
1
  import { IMPORT_FLAGS } from '../constants.js';
2
2
  const jsDocImportRe = /import\(\s*['"]([^'"]+)['"]\s*\)(?:\.(\w+))?/g;
3
3
  const jsDocImportTagRe = /@import\s+(?:\{[^}]*\}|\*\s+as\s+\w+)\s+from\s+['"]([^'"]+)['"]/g;
4
+ const jsDocTypeTagRe = /@(?:type|typedef|callback|param|arg|argument|property|prop|returns?|yields?|throws?|exception|this|extends|augments|implements|enum|template|satisfies|const|constant|member|var|namespace|module)\b/;
4
5
  const jsxImportSourceRe = /@jsxImportSource\s+(\S+)/;
5
6
  const referenceRe = /\s*<reference\s+(types|path)\s*=\s*"([^"]+)"[^/]*\/>/;
6
7
  const envPragmaRe = /@(vitest|jest)-environment\s+([@\w./-]+)/g;
@@ -18,6 +19,26 @@ const resolveEnvironmentPragma = (tool, value) => {
18
19
  return '@edge-runtime/vm';
19
20
  return value;
20
21
  };
22
+ const isInJsDocTypeExpression = (text, index) => {
23
+ let depth = 0;
24
+ for (let pos = index - 1; pos >= 0; pos--) {
25
+ const char = text.charCodeAt(pos);
26
+ if (char === 125) {
27
+ depth++;
28
+ }
29
+ else if (char === 123) {
30
+ if (depth > 0) {
31
+ depth--;
32
+ }
33
+ else {
34
+ const line = text.slice(text.lastIndexOf('\n', pos - 1) + 1, pos);
35
+ if (jsDocTypeTagRe.test(line))
36
+ return true;
37
+ }
38
+ }
39
+ }
40
+ return false;
41
+ };
21
42
  export const extractImportsFromComments = (comments, firstStmtStart, addImport) => {
22
43
  for (const comment of comments) {
23
44
  const text = comment.value;
@@ -25,9 +46,7 @@ export const extractImportsFromComments = (comments, firstStmtStart, addImport)
25
46
  if (comment.type === 'Block') {
26
47
  jsDocImportRe.lastIndex = 0;
27
48
  while ((results = jsDocImportRe.exec(text)) !== null) {
28
- const before = text.slice(0, results.index);
29
- const lastOpen = before.lastIndexOf('{');
30
- if (lastOpen === -1 || before.indexOf('}', lastOpen) !== -1)
49
+ if (!isInJsDocTypeExpression(text, results.index))
31
50
  continue;
32
51
  const specifier = results[1];
33
52
  const member = results[2];
@@ -3,7 +3,7 @@ import { FIX_FLAGS, IMPORT_FLAGS, OPAQUE, SYMBOL_TYPE } from '../../constants.js
3
3
  import { addValue } from '../../util/module-graph.js';
4
4
  import { isInNodeModules } from '../../util/path.js';
5
5
  import { timerify } from '../../util/Performance.js';
6
- import { getLineAndCol, getStringValue, isStringLiteral } from '../ast-nodes.js';
6
+ import { collectAugmentationRefs, getLineAndCol, getStringValue, isStringLiteral, } from '../ast-nodes.js';
7
7
  import { EMPTY_TAGS } from './jsdoc.js';
8
8
  import { handleCallExpression, handleNewExpression, trackCustomElementRegistry } from './calls.js';
9
9
  import { handleExportAssignment, handleExportDefault, handleExportNamed, handleExpressionStatement, } from './exports.js';
@@ -211,6 +211,12 @@ const coreVisitorObject = {
211
211
  },
212
212
  TSModuleDeclaration(node) {
213
213
  state.nsRanges.push([node.start, node.end]);
214
+ if (node.kind !== 'global' && isStringLiteral(node.id)) {
215
+ const specifier = getStringValue(node.id);
216
+ if (specifier.startsWith('.'))
217
+ for (const name of collectAugmentationRefs(node))
218
+ state.addImport(specifier, name, undefined, undefined, node.id.start, IMPORT_FLAGS.TYPE_ONLY);
219
+ }
214
220
  },
215
221
  ClassDeclaration(node) {
216
222
  state.classNameStack.push(node.id?.name ?? '');
@@ -58,6 +58,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
58
58
  entry?: string | string[] | undefined;
59
59
  project?: string | string[] | undefined;
60
60
  } | undefined;
61
+ 'astro-markdoc'?: string | boolean | string[] | {
62
+ config?: string | string[] | undefined;
63
+ entry?: string | string[] | undefined;
64
+ project?: string | string[] | undefined;
65
+ } | undefined;
61
66
  'astro-og-canvas'?: string | boolean | string[] | {
62
67
  config?: string | string[] | undefined;
63
68
  entry?: string | string[] | undefined;
@@ -862,6 +867,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
862
867
  entry?: string | string[] | undefined;
863
868
  project?: string | string[] | undefined;
864
869
  } | undefined;
870
+ 'astro-markdoc'?: string | boolean | string[] | {
871
+ config?: string | string[] | undefined;
872
+ entry?: string | string[] | undefined;
873
+ project?: string | string[] | undefined;
874
+ } | undefined;
865
875
  'astro-og-canvas'?: string | boolean | string[] | {
866
876
  config?: string | string[] | undefined;
867
877
  entry?: string | string[] | undefined;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "6.22.0";
1
+ export declare const version = "6.24.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '6.22.0';
1
+ export const version = '6.24.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "6.22.0",
3
+ "version": "6.24.0",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "keywords": [
6
6
  "analysis",
package/schema.json CHANGED
@@ -379,6 +379,10 @@
379
379
  "title": "astro-db plugin configuration (https://knip.dev/reference/plugins/astro-db)",
380
380
  "$ref": "#/definitions/plugin"
381
381
  },
382
+ "astro-markdoc": {
383
+ "title": "astro-markdoc plugin configuration (https://knip.dev/reference/plugins/astro-markdoc)",
384
+ "$ref": "#/definitions/plugin"
385
+ },
382
386
  "ava": {
383
387
  "title": "ava plugin configuration (https://knip.dev/reference/plugins/ava)",
384
388
  "$ref": "#/definitions/plugin"