knip 5.30.4 → 5.30.5

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.
@@ -6,10 +6,11 @@ const enablers = ['@playwright/test'];
6
6
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
7
7
  const config = ['playwright.config.{js,ts}'];
8
8
  export const entry = ['**/*.@(spec|test).?(c|m)[jt]s?(x)'];
9
- const toEntryPatterns = (testMatch, cwd, configDir, localConfig) => {
9
+ const toEntryPatterns = (testMatch, cwd, configDir, localConfig, rootConfig) => {
10
10
  if (!testMatch)
11
11
  return [];
12
- const dir = relative(cwd, localConfig.testDir ? join(configDir, localConfig.testDir) : configDir);
12
+ const testDir = localConfig.testDir ?? rootConfig.testDir;
13
+ const dir = relative(cwd, testDir ? join(configDir, testDir) : configDir);
13
14
  const patterns = [testMatch].flat().filter((p) => typeof p === 'string');
14
15
  return patterns.map(pattern => toEntryPattern(join(dir, pattern)));
15
16
  };
@@ -17,7 +18,7 @@ const builtinReporters = ['dot', 'line', 'list', 'junit', 'html', 'blob', 'json'
17
18
  export const resolveEntryPaths = async (localConfig, options) => {
18
19
  const { cwd, configFileDir } = options;
19
20
  const projects = localConfig.projects ? [localConfig, ...localConfig.projects] : [localConfig];
20
- return projects.flatMap(config => toEntryPatterns(config.testMatch, cwd, configFileDir, config));
21
+ return projects.flatMap(config => toEntryPatterns(config.testMatch, cwd, configFileDir, config, localConfig));
21
22
  };
22
23
  export const resolveConfig = async (config) => {
23
24
  const reporters = [config.reporter].flat().flatMap(reporter => {
@@ -26,3 +26,5 @@ export declare const isImportSpecifier: (node: ts.Node) => boolean;
26
26
  export declare const isReferencedInExportedType: (node: ts.Node) => boolean;
27
27
  export declare const getExportKeywordNode: (node: ts.Node) => ts.ExportKeyword | undefined;
28
28
  export declare const getDefaultKeywordNode: (node: ts.Node) => ts.DefaultKeyword | undefined;
29
+ export declare const hasRequireCall: (node: ts.Node) => boolean;
30
+ export declare const isModuleExportsAccess: (node: ts.PropertyAccessExpression) => boolean;
@@ -170,3 +170,9 @@ export const isReferencedInExportedType = (node) => {
170
170
  };
171
171
  export const getExportKeywordNode = (node) => node.modifiers?.find(mod => mod.kind === ts.SyntaxKind.ExportKeyword);
172
172
  export const getDefaultKeywordNode = (node) => node.modifiers?.find(mod => mod.kind === ts.SyntaxKind.DefaultKeyword);
173
+ export const hasRequireCall = (node) => {
174
+ if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'require')
175
+ return true;
176
+ return node.getChildren().some(child => hasRequireCall(child));
177
+ };
178
+ export const isModuleExportsAccess = (node) => ts.isIdentifier(node.expression) && node.expression.escapedText === 'module' && node.name.escapedText === 'exports';
@@ -102,9 +102,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
102
102
  if (module.isExternalLibraryImport) {
103
103
  if (skipTypeOnly && isTypeOnly)
104
104
  return;
105
- const sanitizedSpecifier = isInNodeModules(specifier)
106
- ? getPackageNameFromFilePath(specifier)
107
- : sanitizeSpecifier(specifier);
105
+ const sanitizedSpecifier = sanitizeSpecifier(isInNodeModules(specifier) || isInNodeModules(filePath) ? getPackageNameFromFilePath(specifier) : specifier);
108
106
  if (!isStartsLikePackageName(sanitizedSpecifier)) {
109
107
  return;
110
108
  }
@@ -1,5 +1,6 @@
1
1
  import ts from 'typescript';
2
- import { findAncestor, findDescendants, isRequireCall, isTopLevel } from '../../ast-helpers.js';
2
+ import { IMPORT_STAR } from '../../../constants.js';
3
+ import { findAncestor, findDescendants, isModuleExportsAccess, isRequireCall, isTopLevel } from '../../ast-helpers.js';
3
4
  import { isNotJS } from '../helpers.js';
4
5
  import { importVisitor as visit } from '../index.js';
5
6
  export default visit(() => true, node => {
@@ -43,6 +44,11 @@ export default visit(() => true, node => {
43
44
  }
44
45
  return { identifier: 'default', specifier, pos: node.arguments[0].pos, resolve };
45
46
  }
47
+ if (ts.isBinaryExpression(node.parent) &&
48
+ ts.isPropertyAccessExpression(node.parent.left) &&
49
+ isModuleExportsAccess(node.parent.left)) {
50
+ return { identifier: IMPORT_STAR, specifier, isReExport: true, pos: node.arguments[0].pos };
51
+ }
46
52
  return { identifier: 'default', specifier, pos: node.arguments[0].pos, resolve };
47
53
  }
48
54
  }
@@ -1,9 +1,8 @@
1
1
  import ts from 'typescript';
2
2
  import { SymbolType } from '../../../types/issues.js';
3
- import { stripQuotes } from '../../ast-helpers.js';
3
+ import { hasRequireCall, isModuleExportsAccess, stripQuotes } from '../../ast-helpers.js';
4
4
  import { isJS } from '../helpers.js';
5
5
  import { exportVisitor as visit } from '../index.js';
6
- const isModuleExportsAccess = (node) => ts.isIdentifier(node.expression) && node.expression.escapedText === 'module' && node.name.escapedText === 'exports';
7
6
  export default visit(isJS, (node, { isFixExports }) => {
8
7
  if (ts.isExpressionStatement(node)) {
9
8
  if (ts.isBinaryExpression(node.expression)) {
@@ -29,6 +28,9 @@ export default visit(isJS, (node, { isFixExports }) => {
29
28
  return { node, identifier: node.getText(), type: SymbolType.UNKNOWN, pos: node.getStart(), fix };
30
29
  });
31
30
  }
31
+ if (ts.isCallExpression(node.expression.right) && hasRequireCall(node.expression.right)) {
32
+ return;
33
+ }
32
34
  return { node, identifier: 'default', type: SymbolType.UNKNOWN, pos: expr.pos + 1, fix: undefined };
33
35
  }
34
36
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.30.4";
1
+ export declare const version = "5.30.5";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.30.4';
1
+ export const version = '5.30.5';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.30.4",
3
+ "version": "5.30.5",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {