knip 5.43.2 → 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;
@@ -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,11 +265,17 @@ 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);
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
+ }
273
279
  }
274
280
  else if (imports.importedNs.has(id)) {
275
281
  if (isConsiderReferencedNS(node)) {
@@ -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.2";
1
+ export declare const version = "5.43.3";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.43.2';
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.2",
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": {