knip 5.41.0 → 5.42.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 (63) hide show
  1. package/README.md +2 -5
  2. package/dist/ConfigurationChief.d.ts +1 -0
  3. package/dist/ConfigurationValidator.d.ts +56 -0
  4. package/dist/ProjectPrincipal.js +2 -14
  5. package/dist/WorkspaceWorker.js +2 -3
  6. package/dist/compilers/index.d.ts +10 -0
  7. package/dist/constants.js +2 -0
  8. package/dist/index.js +21 -11
  9. package/dist/plugins/_template/index.js +1 -1
  10. package/dist/plugins/angular/index.js +59 -27
  11. package/dist/plugins/angular/types.d.ts +2 -2
  12. package/dist/plugins/expo/index.d.ts +3 -0
  13. package/dist/plugins/expo/index.js +6 -4
  14. package/dist/plugins/index.d.ts +20 -10
  15. package/dist/plugins/index.js +2 -0
  16. package/dist/plugins/jest/index.d.ts +3 -0
  17. package/dist/plugins/jest/index.js +4 -0
  18. package/dist/plugins/karma/helpers.d.ts +7 -0
  19. package/dist/plugins/karma/helpers.js +32 -0
  20. package/dist/plugins/karma/index.d.ts +1 -2
  21. package/dist/plugins/karma/index.js +10 -36
  22. package/dist/plugins/linthtml/index.d.ts +2 -2
  23. package/dist/plugins/linthtml/types.d.ts +1 -1
  24. package/dist/plugins/metro/index.d.ts +15 -0
  25. package/dist/plugins/metro/index.js +48 -0
  26. package/dist/plugins/metro/types.d.ts +13 -0
  27. package/dist/plugins/metro/types.js +1 -0
  28. package/dist/plugins/nx/index.js +10 -2
  29. package/dist/plugins/nx/types.d.ts +1 -0
  30. package/dist/plugins/release-it/index.d.ts +0 -1
  31. package/dist/plugins/release-it/index.js +0 -2
  32. package/dist/plugins/simple-git-hooks/index.d.ts +2 -3
  33. package/dist/plugins/simple-git-hooks/index.js +1 -9
  34. package/dist/plugins/simple-git-hooks/types.d.ts +1 -1
  35. package/dist/plugins/typescript/index.d.ts +0 -1
  36. package/dist/plugins/typescript/index.js +0 -2
  37. package/dist/plugins/vite/index.d.ts +0 -1
  38. package/dist/plugins/vite/index.js +0 -2
  39. package/dist/plugins/webpack/index.d.ts +4 -1
  40. package/dist/plugins/webpack/index.js +5 -2
  41. package/dist/plugins/wireit/index.d.ts +0 -1
  42. package/dist/plugins/wireit/index.js +0 -2
  43. package/dist/reporters/symbols.js +6 -2
  44. package/dist/schema/plugins.d.ts +23 -0
  45. package/dist/schema/plugins.js +1 -0
  46. package/dist/types/PluginNames.d.ts +2 -2
  47. package/dist/types/PluginNames.js +1 -0
  48. package/dist/types/dependency-graph.d.ts +2 -4
  49. package/dist/typescript/ast-helpers.d.ts +1 -0
  50. package/dist/typescript/ast-helpers.js +1 -0
  51. package/dist/typescript/get-imports-and-exports.d.ts +2 -4
  52. package/dist/typescript/get-imports-and-exports.js +18 -23
  53. package/dist/typescript/visitors/exports/exportAssignment.js +2 -1
  54. package/dist/typescript/visitors/exports/exportDeclaration.js +2 -1
  55. package/dist/typescript/visitors/exports/exportKeyword.js +3 -4
  56. package/dist/typescript/visitors/helpers.d.ts +1 -0
  57. package/dist/typescript/visitors/helpers.js +1 -0
  58. package/dist/util/dependency-graph.js +2 -4
  59. package/dist/util/file-entry-cache.js +3 -3
  60. package/dist/version.d.ts +1 -1
  61. package/dist/version.js +1 -1
  62. package/package.json +12 -12
  63. package/schema.json +4 -0
@@ -6,7 +6,7 @@ import { addNsValue, addValue, createImports } from '../util/dependency-graph.js
6
6
  import { getPackageNameFromFilePath, isStartsLikePackageName, sanitizeSpecifier } from '../util/modules.js';
7
7
  import { isInNodeModules } from '../util/path.js';
8
8
  import { shouldIgnore } from '../util/tag.js';
9
- import { getAccessMembers, getDestructuredIds, getJSDocTags, getLineAndCharacterOfPosition, getTypeName, isAccessExpression, isConsiderReferencedNS, isDestructuring, isImportSpecifier, isObjectEnumerationCallExpressionArgument, isReferencedInExport, } from './ast-helpers.js';
9
+ import { getAccessMembers, getDestructuredIds, getJSDocTags, getLineAndCharacterOfPosition, getTypeName, isAccessExpression, isConsiderReferencedNS, isDestructuring, isImportSpecifier, isInForIteration, isObjectEnumerationCallExpressionArgument, isReferencedInExport, } from './ast-helpers.js';
10
10
  import { findInternalReferences, isType } from './find-internal-references.js';
11
11
  import getDynamicImportVisitors from './visitors/dynamic-imports/index.js';
12
12
  import getExportVisitors from './visitors/exports/index.js';
@@ -35,9 +35,9 @@ const createMember = (node, member, pos) => {
35
35
  };
36
36
  const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) => {
37
37
  const { skipTypeOnly, tags, ignoreExportsUsedInFile } = options;
38
- const internalImports = new Map();
39
- const externalImports = new Set();
40
- const unresolvedImports = new Set();
38
+ const internal = new Map();
39
+ const external = new Set();
40
+ const unresolved = new Set();
41
41
  const resolved = new Set();
42
42
  const specifiers = new Set();
43
43
  const exports = new Map();
@@ -80,10 +80,10 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
80
80
  const { identifier, symbol, filePath, namespace, alias, specifier, isReExport } = options;
81
81
  const isStar = identifier === IMPORT_STAR;
82
82
  specifiers.add([specifier, filePath]);
83
- const file = internalImports.get(filePath);
83
+ const file = internal.get(filePath);
84
84
  const imports = file ?? createImports();
85
85
  if (!file)
86
- internalImports.set(filePath, imports);
86
+ internal.set(filePath, imports);
87
87
  const nsOrAlias = symbol ? String(symbol.escapedName) : alias;
88
88
  if (isReExport) {
89
89
  if (isStar && namespace) {
@@ -134,7 +134,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
134
134
  if (!isStartsLikePackageName(sanitizedSpecifier)) {
135
135
  return;
136
136
  }
137
- externalImports.add(sanitizedSpecifier);
137
+ external.add(sanitizedSpecifier);
138
138
  }
139
139
  }
140
140
  }
@@ -147,10 +147,10 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
147
147
  return;
148
148
  if (typeof pos === 'number') {
149
149
  const { line, character } = sourceFile.getLineAndCharacterOfPosition(pos);
150
- unresolvedImports.add({ specifier, pos, line: line + 1, col: character + 1 });
150
+ unresolved.add({ specifier, pos, line: line + 1, col: character + 1 });
151
151
  }
152
152
  else {
153
- unresolvedImports.add({ specifier });
153
+ unresolved.add({ specifier });
154
154
  }
155
155
  }
156
156
  };
@@ -161,7 +161,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
161
161
  const importedSymbolFilePath = importedInternalSymbols.get(symbol);
162
162
  if (importedSymbolFilePath) {
163
163
  const importId = String(symbol.escapedName);
164
- const internalImport = internalImports.get(importedSymbolFilePath);
164
+ const internalImport = internal.get(importedSymbolFilePath);
165
165
  if (internalImport) {
166
166
  if (importId !== identifier) {
167
167
  addNsValue(internalImport.reExportedAs, importId, identifier, sourceFile.fileName);
@@ -242,7 +242,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
242
242
  if (symbol) {
243
243
  if (filePath) {
244
244
  if (!isImportSpecifier(node)) {
245
- const imports = internalImports.get(filePath);
245
+ const imports = internal.get(filePath);
246
246
  if (imports) {
247
247
  traceRefs.add(id);
248
248
  if (isAccessExpression(node.parent)) {
@@ -277,6 +277,9 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
277
277
  else if (isObjectEnumerationCallExpressionArgument(node)) {
278
278
  imports.refs.add(id);
279
279
  }
280
+ else if (isInForIteration(node)) {
281
+ imports.refs.add(id);
282
+ }
280
283
  }
281
284
  }
282
285
  }
@@ -294,7 +297,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
294
297
  const namespace = left.text;
295
298
  const { filePath } = getImport(namespace, node);
296
299
  if (filePath) {
297
- const internalImport = internalImports.get(filePath);
300
+ const internalImport = internal.get(filePath);
298
301
  if (internalImport)
299
302
  addNsMemberRefs(internalImport, namespace, right.text);
300
303
  }
@@ -327,17 +330,9 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
327
330
  item.symbol = undefined;
328
331
  }
329
332
  return {
330
- imports: {
331
- internal: internalImports,
332
- external: externalImports,
333
- resolved,
334
- specifiers,
335
- unresolved: unresolvedImports,
336
- },
337
- exports: {
338
- exported: exports,
339
- duplicate: [...aliasedExports.values()],
340
- },
333
+ imports: { internal, external, resolved, specifiers, unresolved },
334
+ exports,
335
+ duplicates: [...aliasedExports.values()],
341
336
  scripts,
342
337
  traceRefs,
343
338
  };
@@ -1,8 +1,9 @@
1
1
  import ts from 'typescript';
2
2
  import { FIX_FLAGS } from '../../../constants.js';
3
3
  import { SymbolType } from '../../../types/issues.js';
4
+ import { isModule } from '../helpers.js';
4
5
  import { exportVisitor as visit } from '../index.js';
5
- export default visit(() => true, (node, { isFixExports }) => {
6
+ export default visit(isModule, (node, { isFixExports }) => {
6
7
  if (ts.isExportAssignment(node)) {
7
8
  const pos = node.getChildAt(1).getStart();
8
9
  const fix = isFixExports ? [node.getStart(), node.getEnd() + 1, FIX_FLAGS.NONE] : undefined;
@@ -1,8 +1,9 @@
1
1
  import ts from 'typescript';
2
2
  import { FIX_FLAGS } from '../../../constants.js';
3
3
  import { SymbolType } from '../../../types/issues.js';
4
+ import { isModule } from '../helpers.js';
4
5
  import { exportVisitor as visit } from '../index.js';
5
- export default visit(() => true, (node, { isFixExports, isFixTypes }) => {
6
+ export default visit(isModule, (node, { isFixExports, isFixTypes }) => {
6
7
  if (ts.isExportDeclaration(node)) {
7
8
  if (node.exportClause && ts.isNamedExports(node.exportClause)) {
8
9
  const nodeType = node.isTypeOnly ? SymbolType.TYPE : SymbolType.UNKNOWN;
@@ -3,8 +3,9 @@ import { FIX_FLAGS } from '../../../constants.js';
3
3
  import { SymbolType } from '../../../types/issues.js';
4
4
  import { compact } from '../../../util/array.js';
5
5
  import { getDefaultKeywordNode, getExportKeywordNode, isGetOrSetAccessorDeclaration, isPrivateMember, stripQuotes, } from '../../ast-helpers.js';
6
+ import { isModule } from '../helpers.js';
6
7
  import { exportVisitor as visit } from '../index.js';
7
- export default visit(() => true, (node, { isFixExports, isFixTypes, isReportClassMembers }) => {
8
+ export default visit(isModule, (node, { isFixExports, isFixTypes, isReportClassMembers }) => {
8
9
  const exportKeyword = getExportKeywordNode(node);
9
10
  if (exportKeyword) {
10
11
  const getFix = (node, defaultKeyword) => isFixExports ? [node.getStart(), (defaultKeyword ?? node).getEnd() + 1, FIX_FLAGS.NONE] : undefined;
@@ -14,9 +15,7 @@ export default visit(() => true, (node, { isFixExports, isFixTypes, isReportClas
14
15
  if (ts.isObjectBindingPattern(declaration.name)) {
15
16
  return compact(declaration.name.elements.map(element => {
16
17
  if (ts.isIdentifier(element.name)) {
17
- const fix = isFixExports
18
- ? [element.getStart(), element.getEnd(), FIX_FLAGS.OBJECT_BINDING]
19
- : undefined;
18
+ const fix = isFixExports ? [element.getStart(), element.getEnd(), FIX_FLAGS.OBJECT_BINDING] : undefined;
20
19
  return {
21
20
  node: element,
22
21
  symbol: element.symbol,
@@ -3,5 +3,6 @@ import type { ImportNode } from '../../types/imports.js';
3
3
  import type { BoundSourceFile } from '../SourceFile.js';
4
4
  export declare const isNotJS: (sourceFile: BoundSourceFile) => boolean;
5
5
  export declare const isJS: (sourceFile: BoundSourceFile) => boolean;
6
+ export declare const isModule: (sourceFile: BoundSourceFile) => boolean;
6
7
  export declare function getImportsFromPragmas(sourceFile: BoundSourceFile): ImportNode[];
7
8
  export declare function hasImportSpecifier(node: ts.Statement, name: string): boolean;
@@ -1,6 +1,7 @@
1
1
  import ts from 'typescript';
2
2
  export const isNotJS = (sourceFile) => !isJS(sourceFile);
3
3
  export const isJS = (sourceFile) => sourceFile.scriptKind === ts.ScriptKind.JS || sourceFile.scriptKind === ts.ScriptKind.JSX;
4
+ export const isModule = (sourceFile) => ts.isExternalModule(sourceFile);
4
5
  export function getImportsFromPragmas(sourceFile) {
5
6
  const importNodes = [];
6
7
  if (sourceFile.pragmas) {
@@ -36,10 +36,8 @@ const createFileNode = () => ({
36
36
  external: new Set(),
37
37
  unresolved: new Set(),
38
38
  },
39
- exports: {
40
- exported: new Map(),
41
- duplicate: new Set(),
42
- },
39
+ exports: new Map(),
40
+ duplicates: new Set(),
43
41
  scripts: new Set(),
44
42
  traceRefs: new Set(),
45
43
  });
@@ -1,10 +1,10 @@
1
1
  import fs from 'node:fs';
2
+ import path from 'node:path';
2
3
  import { timerify } from './Performance.js';
3
4
  import { debugLog } from './debug.js';
4
5
  import { isDirectory, isFile } from './fs.js';
5
- import { dirname, isAbsolute, resolve } from './path.js';
6
+ import { cwd, dirname, isAbsolute, resolve } from './path.js';
6
7
  import { deserialize, serialize } from './serialize.js';
7
- const cwd = process.cwd();
8
8
  const createCache = (filePath) => {
9
9
  try {
10
10
  return deserialize(fs.readFileSync(filePath));
@@ -19,7 +19,7 @@ export class FileEntryCache {
19
19
  cache = new Map();
20
20
  normalizedEntries = new Map();
21
21
  constructor(cacheId, _path) {
22
- this.filePath = isAbsolute(_path) ? resolve(_path, cacheId) : resolve(cwd, _path, cacheId);
22
+ this.filePath = isAbsolute(_path) ? path.resolve(_path, cacheId) : path.resolve(cwd, _path, cacheId);
23
23
  if (isFile(this.filePath))
24
24
  this.cache = create(this.filePath);
25
25
  this.removeNotFoundFiles();
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.41.0";
1
+ export declare const version = "5.42.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.41.0';
1
+ export const version = '5.42.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.41.0",
3
+ "version": "5.42.0",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {
@@ -48,7 +48,7 @@
48
48
  "qa": "bun lint && bun run build && bun knip && bun knip:production && bun run test",
49
49
  "release": "release-it",
50
50
  "create-plugin": "bun ./scripts/create-new-plugin.ts",
51
- "postcreate-plugin": "biome format --write schema.json schema-jsonc.json src/ConfigurationValidator.ts",
51
+ "postcreate-plugin": "bun run build && biome format --write schema.json schema-jsonc.json src/ConfigurationValidator.ts",
52
52
  "generate-plugin-defs": "node ./scripts/generate-plugin-defs.js && biome check --write src/plugins/index.ts src/types/PluginNames.ts src/schema/plugins.ts"
53
53
  },
54
54
  "files": [
@@ -58,12 +58,12 @@
58
58
  "schema-jsonc.json"
59
59
  ],
60
60
  "dependencies": {
61
- "@nodelib/fs.walk": "1.2.8",
61
+ "@nodelib/fs.walk": "3.0.1",
62
62
  "@snyk/github-codeowners": "1.1.0",
63
63
  "easy-table": "1.2.0",
64
- "enhanced-resolve": "^5.17.1",
65
- "fast-glob": "^3.3.2",
66
- "jiti": "^2.4.0",
64
+ "enhanced-resolve": "^5.18.0",
65
+ "fast-glob": "^3.3.3",
66
+ "jiti": "^2.4.2",
67
67
  "js-yaml": "^4.1.0",
68
68
  "minimist": "^1.2.8",
69
69
  "picocolors": "^1.1.0",
@@ -81,20 +81,20 @@
81
81
  },
82
82
  "devDependencies": {
83
83
  "@jest/types": "^29.6.3",
84
- "@release-it/bumper": "^6.0.1",
85
- "@types/bun": "^1.1.13",
84
+ "@release-it/bumper": "^7.0.0",
85
+ "@types/bun": "^1.1.15",
86
86
  "@types/js-yaml": "^4.0.9",
87
87
  "@types/minimist": "^1.2.5",
88
88
  "@types/picomatch": "3.0.1",
89
89
  "@types/webpack": "^5.28.5",
90
- "@wdio/types": "^9.2.2",
90
+ "@wdio/types": "^9.5.0",
91
91
  "glob": "^10.4.2",
92
- "release-it": "^17.10.0",
93
- "type-fest": "^4.26.1",
92
+ "release-it": "^18.1.1",
93
+ "type-fest": "^4.31.0",
94
94
  "typescript": "^5.5.2"
95
95
  },
96
96
  "engines": {
97
- "node": ">=18.6.0"
97
+ "node": ">=18.18.0"
98
98
  },
99
99
  "engineStrict": true,
100
100
  "keywords": [
package/schema.json CHANGED
@@ -400,6 +400,10 @@
400
400
  "title": "markdownlint plugin configuration (https://knip.dev/reference/plugins/markdownlint)",
401
401
  "$ref": "#/definitions/plugin"
402
402
  },
403
+ "metro": {
404
+ "title": "metro plugin configuration (https://knip.dev/reference/plugins/metro)",
405
+ "$ref": "#/definitions/plugin"
406
+ },
403
407
  "mocha": {
404
408
  "title": "Mocha plugin configuration (https://knip.dev/reference/plugins/mocha)",
405
409
  "$ref": "#/definitions/plugin"