knip 2.19.8 → 2.19.10

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/README.md CHANGED
@@ -746,6 +746,7 @@ Many thanks to some of the early adopters of Knip:
746
746
  - Ask your questions in the [Knip knowledge base][65] (powered by OpenAI and [7-docs][66], experimental!)
747
747
  - Smashing Magazine: [Knip: An Automated Tool For Finding Unused Files, Exports, And Dependencies][67]
748
748
  - Effective TypeScript: [Recommendation Update: ✂️ Use knip to detect dead code and types][68]
749
+ - Josh Goldberg: [Speeding Up Centered Part 4: Unused Code Bloat][69]
749
750
 
750
751
  ## Why "Knip"?
751
752
 
@@ -763,7 +764,7 @@ each file, and traversing all of this, why not collect the various issues in one
763
764
 
764
765
  Special thanks to the wonderful people who have contributed to this project:
765
766
 
766
- [![Contributors][70]][69]
767
+ [![Contributors][71]][70]
767
768
 
768
769
  [1]: #workspaces
769
770
  [2]: #plugins
@@ -833,8 +834,9 @@ Special thanks to the wonderful people who have contributed to this project:
833
834
  [66]: https://github.com/7-docs/7-docs
834
835
  [67]: https://www.smashingmagazine.com/2023/08/knip-automated-tool-find-unused-files-exports-dependencies/
835
836
  [68]: https://effectivetypescript.com/2023/07/29/knip/
836
- [69]: https://github.com/webpro/knip/graphs/contributors
837
- [70]: https://contrib.rocks/image?repo=webpro/knip
837
+ [69]: https://www.joshuakgoldberg.com/blog/speeding-up-centered-part-4-unused-code-bloat/
838
+ [70]: https://github.com/webpro/knip/graphs/contributors
839
+ [71]: https://contrib.rocks/image?repo=webpro/knip
838
840
  [plugin-ava]: ./src/plugins/ava
839
841
  [plugin-babel]: ./src/plugins/babel
840
842
  [plugin-capacitor]: ./src/plugins/capacitor
@@ -45,7 +45,7 @@ export declare class DependencyDeputy {
45
45
  addReferencedDependency(workspaceName: string, packageName: string): void;
46
46
  addReferencedBinary(workspaceName: string, binaryName: string): void;
47
47
  addPeerDependencies(workspaceName: string, peerDependencies: Map<string, Set<string>>): void;
48
- getPeerDependencies(workspaceName: string, dependency: string): string[];
48
+ getPeerDependenciesOf(workspaceName: string, dependency: string): string[];
49
49
  maybeAddReferencedExternalDependency(workspace: Workspace, packageName: string): boolean;
50
50
  maybeAddReferencedBinary(workspace: Workspace, binaryName: string): boolean;
51
51
  private isInDependencies;
@@ -76,7 +76,7 @@ export class DependencyDeputy {
76
76
  addPeerDependencies(workspaceName, peerDependencies) {
77
77
  this.peerDependencies.set(workspaceName, peerDependencies);
78
78
  }
79
- getPeerDependencies(workspaceName, dependency) {
79
+ getPeerDependenciesOf(workspaceName, dependency) {
80
80
  return Array.from(this.peerDependencies.get(workspaceName)?.get(dependency) ?? []);
81
81
  }
82
82
  maybeAddReferencedExternalDependency(workspace, packageName) {
@@ -150,35 +150,38 @@ export class DependencyDeputy {
150
150
  return true;
151
151
  };
152
152
  const peerDepRecs = {};
153
- const isNotReferencedDependency = (dependency, isPeerDep) => {
153
+ const isReferencedDependency = (dependency, isPeerDep) => {
154
154
  if (referencedDependencies?.has(dependency))
155
- return false;
156
- if (isPeerDep && peerDepRecs[dependency])
157
155
  return true;
156
+ if (isPeerDep && peerDepRecs[dependency])
157
+ return false;
158
158
  const [scope, typedDependency] = dependency.split('/');
159
159
  if (scope === '@types') {
160
160
  const typedPackageName = getPackageFromDefinitelyTyped(typedDependency);
161
161
  if (IGNORE_DEFINITELY_TYPED.includes(typedPackageName))
162
- return false;
163
- const peerDependencies = this.getPeerDependencies(workspaceName, typedPackageName);
162
+ return true;
163
+ const peerDependencies = this.getPeerDependenciesOf(workspaceName, typedPackageName);
164
164
  if (peerDependencies.length) {
165
- return !peerDependencies.find(peerDependency => !isNotReferencedDependency(peerDependency, true));
165
+ return !!peerDependencies.find(peerDependency => isReferencedDependency(peerDependency, true));
166
166
  }
167
- return !referencedDependencies?.has(typedPackageName);
167
+ if (!referencedDependencies)
168
+ return false;
169
+ return referencedDependencies.has(typedPackageName);
168
170
  }
169
- const peerDependencies = this.getPeerDependencies(workspaceName, dependency);
171
+ const peerDependencies = this.getPeerDependenciesOf(workspaceName, dependency);
170
172
  peerDependencies.forEach(dep => (!peerDepRecs[dep] ? (peerDepRecs[dep] = 1) : peerDepRecs[dep]++));
171
- return !peerDependencies.find(peerDependency => !isNotReferencedDependency(peerDependency, true));
173
+ return !!peerDependencies.find(peerDependency => isReferencedDependency(peerDependency, true));
172
174
  };
175
+ const isNotReferencedDependency = (dependency) => !isReferencedDependency(dependency);
173
176
  const pd = this.getProductionDependencies(workspaceName);
174
177
  const dd = this.getDevDependencies(workspaceName);
175
178
  pd.filter(isNotIgnoredDependency)
176
179
  .filter(isNotIgnoredBinary)
177
- .filter(d => isNotReferencedDependency(d))
180
+ .filter(isNotReferencedDependency)
178
181
  .forEach(symbol => dependencyIssues.push({ type: 'dependencies', filePath: manifestPath, symbol }));
179
182
  dd.filter(isNotIgnoredDependency)
180
183
  .filter(isNotIgnoredBinary)
181
- .filter(d => isNotReferencedDependency(d))
184
+ .filter(isNotReferencedDependency)
182
185
  .forEach(symbol => devDependencyIssues.push({ type: 'devDependencies', filePath: manifestPath, symbol }));
183
186
  }
184
187
  return { dependencyIssues, devDependencyIssues };
@@ -158,8 +158,7 @@ export class ProjectPrincipal {
158
158
  }
159
159
  getHasReferences(filePath, exportedItem) {
160
160
  const hasReferences = { external: false, internal: false };
161
- const node = ts.isExportAssignment(exportedItem.node) ? exportedItem.node.getChildAt(1) : exportedItem.node;
162
- const symbolReferences = this.findReferences(filePath, node).flatMap(f => f.references);
161
+ const symbolReferences = this.findReferences(filePath, exportedItem.pos).flatMap(f => f.references);
163
162
  for (const reference of symbolReferences) {
164
163
  if (reference.fileName === filePath) {
165
164
  if (!reference.isDefinition) {
@@ -180,7 +179,7 @@ export class ProjectPrincipal {
180
179
  .filter(member => {
181
180
  if (this.isPublicExport(member))
182
181
  return false;
183
- const referencedSymbols = this.findReferences(filePath, member.node);
182
+ const referencedSymbols = this.findReferences(filePath, member.pos);
184
183
  const files = referencedSymbols
185
184
  .flatMap(refs => refs.references)
186
185
  .filter(ref => !ref.isDefinition)
@@ -191,8 +190,8 @@ export class ProjectPrincipal {
191
190
  })
192
191
  .map(member => member.identifier);
193
192
  }
194
- findReferences(filePath, node) {
195
- return this.backend.lsFindReferences(filePath, node.getStart()) ?? [];
193
+ findReferences(filePath, pos) {
194
+ return this.backend.lsFindReferences(filePath, pos) ?? [];
196
195
  }
197
196
  isPublicExport(exportedItem) {
198
197
  const tags = this.getJSDocTags(exportedItem);
@@ -6,4 +6,6 @@ export const ENTRY_FILE_PATTERNS = ['next.config.{js,ts,cjs,mjs}'];
6
6
  export const PRODUCTION_ENTRY_FILE_PATTERNS = [
7
7
  '{app,pages}/**/*.{js,jsx,ts,tsx}',
8
8
  'src/{app,pages}/**/*.{js,jsx,ts,tsx}',
9
+ 'middleware.{js,ts}',
10
+ 'src/middleware.{js,ts}',
9
11
  ];
@@ -3,6 +3,7 @@ import { SymbolType } from '../../../types/issues.js';
3
3
  import { exportVisitor as visit } from '../index.js';
4
4
  export default visit(() => true, node => {
5
5
  if (ts.isExportAssignment(node)) {
6
- return { node, identifier: 'default', type: SymbolType.UNKNOWN, pos: node.expression.getStart() };
6
+ const pos = node.getChildAt(1).getStart();
7
+ return { node, identifier: 'default', type: SymbolType.UNKNOWN, pos };
7
8
  }
8
9
  });
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.19.8";
1
+ export declare const version = "2.19.10";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.19.8';
1
+ export const version = '2.19.10';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.19.8",
3
+ "version": "2.19.10",
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",
@@ -62,7 +62,7 @@
62
62
  "zod-validation-error": "^1.5.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@jest/types": "29.6.1",
65
+ "@jest/types": "29.6.3",
66
66
  "@npmcli/package-json": "5.0.0",
67
67
  "@release-it/bumper": "5.1.0",
68
68
  "@swc/cli": "0.1.62",
@@ -74,13 +74,13 @@
74
74
  "@types/node": "20.5.1",
75
75
  "@types/npmcli__map-workspaces": "3.0.1",
76
76
  "@types/webpack": "5.28.1",
77
- "@typescript-eslint/eslint-plugin": "6.4.0",
78
- "@typescript-eslint/parser": "6.4.0",
77
+ "@typescript-eslint/eslint-plugin": "6.4.1",
78
+ "@typescript-eslint/parser": "6.4.1",
79
79
  "c8": "8.0.1",
80
80
  "eslint": "8.47.0",
81
81
  "eslint-import-resolver-typescript": "3.6.0",
82
82
  "eslint-plugin-import": "2.28.1",
83
- "eslint-plugin-n": "16.0.1",
83
+ "eslint-plugin-n": "16.0.2",
84
84
  "prettier": "3.0.2",
85
85
  "release-it": "16.1.5",
86
86
  "remark-cli": "11.0.0",