knip 2.16.1 → 2.16.2

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
@@ -181,7 +181,7 @@ export const main = async (unresolvedConfiguration) => {
181
181
  const analyzeSourceFile = (filePath) => {
182
182
  const workspace = chief.findWorkspaceByFilePath(filePath);
183
183
  if (workspace) {
184
- const { imports, exports, scripts } = principal.analyzeSourceFile(filePath, { skipTypeOnly: !isReportTypes });
184
+ const { imports, exports, scripts } = principal.analyzeSourceFile(filePath, { skipTypeOnly: isProduction });
185
185
  const { internal, external, unresolved } = imports;
186
186
  const { exported, duplicate } = exports;
187
187
  if (exported.size > 0)
@@ -1,4 +1,5 @@
1
1
  import { compact } from '../../util/array.js';
2
+ import { join } from '../../util/path.js';
2
3
  import { timerify } from '../../util/Performance.js';
3
4
  import { hasDependency, load } from '../../util/plugin.js';
4
5
  import { getDependenciesFromConfig } from '../babel/index.js';
@@ -53,13 +54,13 @@ const findWebpackDependencies = async (configFilePath, { manifest, isProduction
53
54
  const cfg = typeof config === 'function' ? config(env, argv) : config;
54
55
  return [cfg].flat().flatMap(config => {
55
56
  const dependencies = (config.module?.rules?.flatMap(resolveRuleSetDependencies) ?? []).map(loader => loader.replace(/\?.*/, ''));
56
- const entries = cfg.entry
57
+ const entries = (cfg.entry
57
58
  ? typeof cfg.entry === 'string'
58
59
  ? [cfg.entry]
59
60
  : Array.isArray(cfg.entry)
60
61
  ? cfg.entry
61
62
  : Object.values(cfg.entry).map(entry => (typeof entry === 'string' ? entry : entry.filename))
62
- : [];
63
+ : []).map(entry => (config.context ? join(config.context, entry) : entry));
63
64
  return [...dependencies, ...entries];
64
65
  });
65
66
  });
@@ -7,7 +7,6 @@ interface ValidImportTypeNode extends ts.ImportTypeNode {
7
7
  export declare function isValidImportTypeNode(node: ts.Node): node is ValidImportTypeNode;
8
8
  export declare function isPrivateMember(node: ts.MethodDeclaration | ts.PropertyDeclaration): boolean;
9
9
  export declare function isDefaultImport(node: ts.ImportDeclaration | ts.ImportEqualsDeclaration | ts.ExportDeclaration): boolean;
10
- export declare function isVariableDeclarationList(node: ts.Node): node is ts.VariableDeclarationList;
11
10
  export declare function isAccessExpression(node: ts.Node): node is ts.PropertyAccessExpression | ts.ElementAccessExpression;
12
11
  export declare function isImportCall(node: ts.Node): node is ts.ImportCall;
13
12
  export declare function isRequireCall(callExpression: ts.Node): callExpression is ts.CallExpression;
@@ -8,9 +8,6 @@ export function isPrivateMember(node) {
8
8
  export function isDefaultImport(node) {
9
9
  return node.kind === ts.SyntaxKind.ImportDeclaration && !!node.importClause && !!node.importClause.name;
10
10
  }
11
- export function isVariableDeclarationList(node) {
12
- return node.kind === ts.SyntaxKind.VariableDeclarationList;
13
- }
14
11
  export function isAccessExpression(node) {
15
12
  return ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node);
16
13
  }
@@ -1,40 +1,11 @@
1
1
  import ts from 'typescript';
2
- import { isImportCall, isAccessExpression, isVariableDeclarationList, findDescendants } from '../../ast-helpers.js';
2
+ import { isImportCall } from '../../ast-helpers.js';
3
3
  import { importVisitor as visit } from '../index.js';
4
4
  export default visit(() => true, node => {
5
5
  if (isImportCall(node)) {
6
6
  if (node.arguments[0] && ts.isStringLiteralLike(node.arguments[0])) {
7
7
  const specifier = node.arguments[0].text;
8
- if (isAccessExpression(node.parent)) {
9
- return { specifier, isDynamic: true };
10
- }
11
- let _ancestor = node.parent?.parent?.parent;
12
- if (_ancestor && isAccessExpression(_ancestor)) {
13
- return { specifier, isDynamic: true };
14
- }
15
- while (_ancestor) {
16
- if (_ancestor) {
17
- if (isVariableDeclarationList(_ancestor)) {
18
- return findDescendants(_ancestor, ts.isVariableDeclaration).flatMap(variableDeclaration => {
19
- if (ts.isIdentifier(variableDeclaration.name)) {
20
- return { identifier: 'default', specifier };
21
- }
22
- else {
23
- const binds = findDescendants(variableDeclaration, _node => ts.isBindingElement(_node) && ts.isIdentifier(_node.name));
24
- return binds.flatMap(element => {
25
- const symbol = element.propertyName?.getText() || element.name.getText();
26
- return { identifier: symbol, specifier };
27
- });
28
- }
29
- });
30
- }
31
- if (ts.isPropertyAssignment(_ancestor)) {
32
- return { identifier: 'default', specifier };
33
- }
34
- }
35
- _ancestor = _ancestor.parent;
36
- }
37
- return { specifier };
8
+ return { specifier, identifier: 'default' };
38
9
  }
39
10
  }
40
11
  });
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.16.1";
1
+ export declare const version = "2.16.2";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.16.1';
1
+ export const version = '2.16.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.16.1",
3
+ "version": "2.16.2",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://github.com/webpro/knip",
6
6
  "repository": "github:webpro/knip",
@@ -22,10 +22,11 @@
22
22
  "lint": "eslint scripts src tests",
23
23
  "lint:fix": "eslint scripts src tests --fix",
24
24
  "format": "prettier scripts src tests schema.json --with-node-modules --write --config .prettierrc",
25
- "test": "glob -c \"node --no-warnings --loader tsx --test\" \"tests/**/*.test.ts\"",
25
+ "pretest": "node rmdir.js tmp && swc src -d tmp/src && swc tests -d tmp/tests",
26
+ "test": "node --no-warnings --test tmp",
26
27
  "coverage": "c8 npm test",
27
28
  "watch": "tsc --watch",
28
- "prebuild": "node -e \"require('fs').rmSync('dist', { force: true, recursive: true })\"",
29
+ "prebuild": "node rmdir.js dist",
29
30
  "build": "tsc",
30
31
  "docs": "npm run docs:cli && npm run docs:plugins && npm run docs:format",
31
32
  "docs:cli": "tsx ./scripts/update-cli-usage-in-readme.ts",
@@ -63,6 +64,8 @@
63
64
  "@jest/types": "29.6.1",
64
65
  "@npmcli/package-json": "4.0.1",
65
66
  "@release-it/bumper": "5.0.0",
67
+ "@swc/cli": "0.1.62",
68
+ "@swc/core": "1.3.70",
66
69
  "@types/eslint": "8.44.0",
67
70
  "@types/js-yaml": "4.0.5",
68
71
  "@types/micromatch": "4.0.2",
@@ -77,7 +80,6 @@
77
80
  "eslint-import-resolver-typescript": "3.5.5",
78
81
  "eslint-plugin-import": "2.27.5",
79
82
  "eslint-plugin-n": "16.0.1",
80
- "glob": "10.3.3",
81
83
  "prettier": "3.0.0",
82
84
  "release-it": "16.1.3",
83
85
  "remark-cli": "11.0.0",