knip 5.43.1 → 5.43.3

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.
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import { getOrCreateFileNode, updateImportMap } from './util/dependency-graph.js
13
13
  import { getReferencedInputsHandler } from './util/get-referenced-inputs.js';
14
14
  import { getGitIgnoredHandler } from './util/glob-core.js';
15
15
  import { _glob, negate } from './util/glob.js';
16
- import { getHasStrictlyNsReferences, getType } from './util/has-strictly-ns-references.js';
16
+ import { getType, hasStrictlyEnumReferences, hasStrictlyNsReferences } from './util/has-strictly-ns-references.js';
17
17
  import { isConfigPattern, isEntry, isProductionEntry, toProductionEntry } from './util/input.js';
18
18
  import { getIsIdentifierReferencedHandler } from './util/is-identifier-referenced.js';
19
19
  import { getPackageNameFromModuleSpecifier } from './util/modules.js';
@@ -358,7 +358,7 @@ export const main = async (unresolvedConfiguration) => {
358
358
  printTrace(traceNode, filePath, identifier);
359
359
  if (isReferenced) {
360
360
  if (report.enumMembers && exportedItem.type === 'enum') {
361
- if (importsForExport.refs.has(identifier))
361
+ if (hasStrictlyEnumReferences(importsForExport, identifier))
362
362
  continue;
363
363
  for (const member of exportedItem.members) {
364
364
  if (findMatch(workspace.ignoreMembers, member.identifier))
@@ -424,7 +424,7 @@ export const main = async (unresolvedConfiguration) => {
424
424
  continue;
425
425
  }
426
426
  }
427
- const [hasStrictlyNsRefs, namespace] = getHasStrictlyNsReferences(graph, importsForExport, identifier);
427
+ const [hasStrictlyNsRefs, namespace] = hasStrictlyNsReferences(graph, importsForExport, identifier);
428
428
  const isType = ['enum', 'type', 'interface'].includes(exportedItem.type);
429
429
  if (hasStrictlyNsRefs && ((!report.nsTypes && isType) || !(report.nsExports || isType)))
430
430
  continue;
@@ -11,9 +11,8 @@ export const docs = { production };
11
11
  const resolveEntryPaths = async (localConfig, { manifest }) => {
12
12
  const expoConfig = typeof localConfig === 'function' ? localConfig() : localConfig;
13
13
  const config = 'expo' in expoConfig ? expoConfig.expo : expoConfig;
14
- let patterns = [];
15
14
  if (manifest.main === 'expo-router/entry') {
16
- patterns = [...production];
15
+ let patterns = [...production];
17
16
  const normalizedPlugins = config.plugins?.map(plugin => (Array.isArray(plugin) ? plugin : [plugin])) ?? [];
18
17
  const expoRouterPlugin = normalizedPlugins.find(([plugin]) => plugin === 'expo-router');
19
18
  if (expoRouterPlugin) {
@@ -22,8 +21,9 @@ const resolveEntryPaths = async (localConfig, { manifest }) => {
22
21
  patterns = [join(options.root, '**/*.{js,jsx,ts,tsx}')];
23
22
  }
24
23
  }
24
+ return patterns.map(entry => toProductionEntry(entry));
25
25
  }
26
- return patterns.map(entry => toProductionEntry(entry));
26
+ return production.map(entry => toProductionEntry(entry));
27
27
  };
28
28
  const resolveConfig = async (expoConfig, options) => getDependencies(expoConfig, options);
29
29
  export default {
@@ -6,7 +6,7 @@ const title = 'Jest';
6
6
  const enablers = ['jest'];
7
7
  const isEnabled = ({ dependencies, manifest }) => hasDependency(dependencies, enablers) || Boolean(manifest.name?.startsWith('jest-presets'));
8
8
  const config = ['jest.config.{js,ts,mjs,cjs,json}', 'package.json'];
9
- const entry = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'];
9
+ const entry = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)', '**/__mocks__/**/*.[jt]s'];
10
10
  const resolveDependencies = async (config, options) => {
11
11
  const { configFileDir } = options;
12
12
  if (config?.preset) {
@@ -23,7 +23,7 @@ export declare const isConsiderReferencedNS: (node: ts.Identifier) => boolean;
23
23
  export declare const isObjectEnumerationCallExpressionArgument: (node: ts.Identifier) => boolean;
24
24
  export declare const isInForIteration: (node: ts.Node) => boolean;
25
25
  export declare const isTopLevel: (node: ts.Node) => boolean;
26
- export declare const getTypeName: (node: ts.Identifier) => ts.QualifiedName | undefined;
26
+ export declare const getTypeRef: (node: ts.Identifier) => ts.TypeReferenceNode | undefined;
27
27
  export declare const isImportSpecifier: (node: ts.Node) => boolean;
28
28
  export declare const isReferencedInExport: (node: ts.Node) => boolean;
29
29
  export declare const getExportKeywordNode: (node: ts.Node) => ts.ExportKeyword | undefined;
@@ -150,12 +150,10 @@ export const isObjectEnumerationCallExpressionArgument = (node) => ts.isCallExpr
150
150
  objectEnumerationMethods.has(String(node.parent.expression.name.escapedText));
151
151
  export const isInForIteration = (node) => node.parent && (ts.isForInStatement(node.parent) || ts.isForOfStatement(node.parent));
152
152
  export const isTopLevel = (node) => ts.isSourceFile(node.parent) || (node.parent && ts.isSourceFile(node.parent.parent));
153
- export const getTypeName = (node) => {
153
+ export const getTypeRef = (node) => {
154
154
  if (!node.parent?.parent)
155
155
  return;
156
- const typeRef = findAncestor(node, _node => ts.isTypeReferenceNode(_node));
157
- if (typeRef && ts.isQualifiedName(typeRef.typeName))
158
- return typeRef.typeName;
156
+ return findAncestor(node, _node => ts.isTypeReferenceNode(_node));
159
157
  };
160
158
  export const isImportSpecifier = (node) => ts.isImportSpecifier(node.parent) ||
161
159
  ts.isImportEqualsDeclaration(node.parent) ||
@@ -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, isInForIteration, isObjectEnumerationCallExpressionArgument, isReferencedInExport, } from './ast-helpers.js';
9
+ import { getAccessMembers, getDestructuredIds, getJSDocTags, getLineAndCharacterOfPosition, getTypeRef, 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';
@@ -265,20 +265,28 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
265
265
  addNsMemberRefs(imports, id, members);
266
266
  }
267
267
  else {
268
- const typeName = getTypeName(node);
269
- if (typeName) {
270
- const [ns, ...right] = [typeName.left.getText(), typeName.right.getText()].join('.').split('.');
271
- const members = right.map((_r, index) => right.slice(0, index + 1).join('.'));
272
- addNsMemberRefs(imports, ns, members);
273
- }
274
- else if (imports.importedNs.has(id) && isConsiderReferencedNS(node)) {
275
- imports.refs.add(id);
276
- }
277
- else if (isObjectEnumerationCallExpressionArgument(node)) {
278
- imports.refs.add(id);
268
+ const typeRef = getTypeRef(node);
269
+ if (typeRef) {
270
+ if (ts.isQualifiedName(typeRef.typeName)) {
271
+ const typeName = typeRef.typeName;
272
+ const [ns, ...right] = [typeName.left.getText(), typeName.right.getText()].join('.').split('.');
273
+ const members = right.map((_r, index) => right.slice(0, index + 1).join('.'));
274
+ addNsMemberRefs(imports, ns, members);
275
+ }
276
+ else {
277
+ imports.refs.add(id);
278
+ }
279
279
  }
280
- else if (isInForIteration(node)) {
281
- imports.refs.add(id);
280
+ else if (imports.importedNs.has(id)) {
281
+ if (isConsiderReferencedNS(node)) {
282
+ imports.refs.add(id);
283
+ }
284
+ else if (isObjectEnumerationCallExpressionArgument(node)) {
285
+ imports.refs.add(id);
286
+ }
287
+ else if (isInForIteration(node)) {
288
+ imports.refs.add(id);
289
+ }
282
290
  }
283
291
  }
284
292
  }
@@ -1,4 +1,4 @@
1
- export declare const helpText = "\u2702\uFE0F Find unused files, dependencies and exports in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n --production Analyze only production source files (e.g. no test files, devDependencies)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n -W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --directory [dir] Run process from a different directory (default: cwd)\n --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --watch Watch mode\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,binaries,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --files Shortcut for --include files\n --fix Fix issues\n --fix-type Fix only issues of type, can be comma-separated or repeated (2)\n --allow-remove-files Allow Knip to remove files (with --fix)\n --include-libs Include type definitions from external dependencies (default: false)\n --include-entry-exports Include entry files when reporting unused exports\n --isolate-workspaces Isolate workspaces into separate programs\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\n --reporter Select reporter: symbols, compact, codeowners, json, can be repeated (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --tags Include or exclude tagged exports\n --no-config-hints Suppress configuration hints\n --no-exit-code Always exit with code zero (0)\n --max-issues Maximum number of issues before non-zero exit code (default: 0)\n -d, --debug Show debug output\n --trace Show trace output\n --trace-export [name] Show trace output for named export(s)\n --trace-file [file] Show trace output for exports in file\n --performance Measure count and running time of expensive functions and display stats table\n -h, --help Print this help text\n -V, --version Print version\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n(2) Fixable issue types: dependencies, exports, types\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --tags=-knipignore\n\nWebsite: https://knip.dev";
1
+ export declare const helpText = "\u2702\uFE0F Find unused files, dependencies and exports in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n --production Analyze only production source files (e.g. no test files, devDependencies)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n -W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --directory [dir] Run process from a different directory (default: cwd)\n --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --watch Watch mode\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,binaries,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --files Shortcut for --include files\n --fix Fix issues\n --fix-type Fix only issues of type, can be comma-separated or repeated (2)\n --allow-remove-files Allow Knip to remove files (with --fix)\n --include-libs Include type definitions from external dependencies (default: false)\n --include-entry-exports Include entry files when reporting unused exports\n --isolate-workspaces Isolate workspaces into separate programs\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\n --reporter Select reporter: symbols, compact, codeowners, json, can be repeated (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --tags Include or exclude tagged exports\n --no-config-hints Suppress configuration hints\n --no-exit-code Always exit with code zero (0)\n --max-issues Maximum number of issues before non-zero exit code (default: 0)\n -d, --debug Show debug output\n --trace Show trace output\n --trace-export [name] Show trace output for named export(s)\n --trace-file [file] Show trace output for exports in file\n --performance Measure count and running time of expensive functions and display stats table\n -h, --help Print this help text\n -V, --version Print version\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n(2) Fixable issue types: dependencies, exports, types\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --tags=-lintignore\n\nWebsite: https://knip.dev";
2
2
  declare const _default: {
3
3
  cache?: boolean | undefined;
4
4
  'cache-location'?: string | undefined;
@@ -52,7 +52,7 @@ $ knip --production
52
52
  $ knip --workspace packages/client --include files,dependencies
53
53
  $ knip -c ./config/knip.json --reporter compact
54
54
  $ knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'
55
- $ knip --tags=-knipignore
55
+ $ knip --tags=-lintignore
56
56
 
57
57
  Website: https://knip.dev`;
58
58
  let parsedArgs;
@@ -1,10 +1,10 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
+ import { deserialize, serialize } from 'node:v8';
3
4
  import { timerify } from './Performance.js';
4
5
  import { debugLog } from './debug.js';
5
6
  import { isDirectory, isFile } from './fs.js';
6
7
  import { cwd, dirname, isAbsolute, resolve } from './path.js';
7
- import { deserialize, serialize } from './serialize.js';
8
8
  const createCache = (filePath) => {
9
9
  try {
10
10
  return deserialize(fs.readFileSync(filePath));
@@ -1,3 +1,4 @@
1
1
  import type { DependencyGraph, ImportDetails } from '../types/dependency-graph.js';
2
- export declare const getHasStrictlyNsReferences: (graph: DependencyGraph, importsForExport: ImportDetails | undefined, id: string) => [boolean, string?];
2
+ export declare const hasStrictlyEnumReferences: (importsForExport: ImportDetails | undefined, id: string) => boolean;
3
+ export declare const hasStrictlyNsReferences: (graph: DependencyGraph, importsForExport: ImportDetails | undefined, id: string) => [boolean, string?];
3
4
  export declare const getType: (hasOnlyNsReference: boolean, isType: boolean) => "exports" | "types" | "nsExports" | "nsTypes";
@@ -1,5 +1,13 @@
1
1
  import { IMPORT_STAR } from '../constants.js';
2
- export const getHasStrictlyNsReferences = (graph, importsForExport, id) => {
2
+ export const hasStrictlyEnumReferences = (importsForExport, id) => {
3
+ if (!importsForExport || !importsForExport.refs.has(id))
4
+ return false;
5
+ for (const ref of importsForExport.refs)
6
+ if (ref.startsWith(`${id}.`))
7
+ return false;
8
+ return true;
9
+ };
10
+ export const hasStrictlyNsReferences = (graph, importsForExport, id) => {
3
11
  if (!importsForExport)
4
12
  return [false];
5
13
  let namespace;
@@ -15,9 +23,9 @@ export const getHasStrictlyNsReferences = (graph, importsForExport, id) => {
15
23
  for (const filePath of byFilePaths) {
16
24
  const file = graph.get(filePath);
17
25
  if (file?.imported) {
18
- const hasStrictlyNsReferences = getHasStrictlyNsReferences(graph, file.imported, id);
19
- if (hasStrictlyNsReferences[0] === false)
20
- return hasStrictlyNsReferences;
26
+ const hasStrictlyNsRefs = hasStrictlyNsReferences(graph, file.imported, id);
27
+ if (hasStrictlyNsRefs[0] === false)
28
+ return hasStrictlyNsRefs;
21
29
  }
22
30
  }
23
31
  }
@@ -27,9 +35,9 @@ export const getHasStrictlyNsReferences = (graph, importsForExport, id) => {
27
35
  for (const filePath of byFilePaths) {
28
36
  const file = graph.get(filePath);
29
37
  if (file?.imported) {
30
- const hasStrictlyNsReferences = getHasStrictlyNsReferences(graph, file.imported, id);
31
- if (hasStrictlyNsReferences[0] === false)
32
- return hasStrictlyNsReferences;
38
+ const hasStrictlyNsRefs = hasStrictlyNsReferences(graph, file.imported, id);
39
+ if (hasStrictlyNsRefs[0] === false)
40
+ return hasStrictlyNsRefs;
33
41
  }
34
42
  }
35
43
  }
@@ -41,10 +49,10 @@ export const getHasStrictlyNsReferences = (graph, importsForExport, id) => {
41
49
  for (const filePath of byFilePaths) {
42
50
  const file = graph.get(filePath);
43
51
  if (file?.imported) {
44
- const hasStrictlyNsReferences = getHasStrictlyNsReferences(graph, file.imported, id);
45
- if (hasStrictlyNsReferences[0] === false)
46
- return hasStrictlyNsReferences;
47
- namespace = hasStrictlyNsReferences[1];
52
+ const hasStrictlyNsRefs = hasStrictlyNsReferences(graph, file.imported, id);
53
+ if (hasStrictlyNsRefs[0] === false)
54
+ return hasStrictlyNsRefs;
55
+ namespace = hasStrictlyNsRefs[1];
48
56
  }
49
57
  }
50
58
  }
@@ -54,10 +62,10 @@ export const getHasStrictlyNsReferences = (graph, importsForExport, id) => {
54
62
  for (const filePath of byFilePaths) {
55
63
  const file = graph.get(filePath);
56
64
  if (file?.imported) {
57
- const hasStrictlyNsReferences = getHasStrictlyNsReferences(graph, file.imported, id);
58
- if (hasStrictlyNsReferences[0] === false)
59
- return hasStrictlyNsReferences;
60
- namespace = hasStrictlyNsReferences[1];
65
+ const hasStrictlyNsRefs = hasStrictlyNsReferences(graph, file.imported, id);
66
+ if (hasStrictlyNsRefs[0] === false)
67
+ return hasStrictlyNsRefs;
68
+ namespace = hasStrictlyNsRefs[1];
61
69
  }
62
70
  }
63
71
  }
@@ -69,10 +77,10 @@ export const getHasStrictlyNsReferences = (graph, importsForExport, id) => {
69
77
  for (const filePath of filePaths) {
70
78
  const file = graph.get(filePath);
71
79
  if (file?.imported) {
72
- const hasStrictlyNsReferences = getHasStrictlyNsReferences(graph, file.imported, [alias, ...rest].join('.'));
73
- if (hasStrictlyNsReferences[0] === false)
74
- return hasStrictlyNsReferences;
75
- namespace = hasStrictlyNsReferences[1];
80
+ const hasStrictlyNsRefs = hasStrictlyNsReferences(graph, file.imported, [alias, ...rest].join('.'));
81
+ if (hasStrictlyNsRefs[0] === false)
82
+ return hasStrictlyNsRefs;
83
+ namespace = hasStrictlyNsRefs[1];
76
84
  }
77
85
  }
78
86
  }
@@ -81,10 +89,10 @@ export const getHasStrictlyNsReferences = (graph, importsForExport, id) => {
81
89
  for (const filePath of filePaths) {
82
90
  const file = graph.get(filePath);
83
91
  if (file?.imported) {
84
- const hasStrictlyNsReferences = getHasStrictlyNsReferences(graph, file.imported, `${ns}.${id}`);
85
- if (hasStrictlyNsReferences[0] === false)
86
- return hasStrictlyNsReferences;
87
- namespace = hasStrictlyNsReferences[1];
92
+ const hasStrictlyNsRefs = hasStrictlyNsReferences(graph, file.imported, `${ns}.${id}`);
93
+ if (hasStrictlyNsRefs[0] === false)
94
+ return hasStrictlyNsRefs;
95
+ namespace = hasStrictlyNsRefs[1];
88
96
  }
89
97
  }
90
98
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.43.1";
1
+ export declare const version = "5.43.3";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.43.1';
1
+ export const version = '5.43.3';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.43.1",
3
+ "version": "5.43.3",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {
@@ -83,14 +83,14 @@
83
83
  "devDependencies": {
84
84
  "@jest/types": "^29.6.3",
85
85
  "@release-it/bumper": "^7.0.0",
86
- "@types/bun": "^1.1.16",
86
+ "@types/bun": "^1.2.0",
87
87
  "@types/js-yaml": "^4.0.9",
88
88
  "@types/minimist": "^1.2.5",
89
89
  "@types/picomatch": "3.0.1",
90
90
  "@types/webpack": "^5.28.5",
91
91
  "@wdio/types": "^9.5.0",
92
92
  "glob": "^10.4.2",
93
- "release-it": "^18.1.1",
93
+ "release-it": "^18.1.2",
94
94
  "type-fest": "^4.31.0",
95
95
  "typescript": "^5.5.2"
96
96
  },
@@ -1,2 +0,0 @@
1
- declare let s: (data: any) => Buffer, d: (buffer: Buffer) => any;
2
- export { s as serialize, d as deserialize };
@@ -1,12 +0,0 @@
1
- let s, d;
2
- if (typeof Bun !== 'undefined') {
3
- const { serialize, deserialize } = await import('bun:jsc');
4
- s = serialize;
5
- d = deserialize;
6
- }
7
- else {
8
- const { serialize, deserialize } = await import('node:v8');
9
- s = serialize;
10
- d = deserialize;
11
- }
12
- export { s as serialize, d as deserialize };