mobx-tanstack-query-api 0.0.82 → 0.0.83

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.
@@ -1 +1 @@
1
- {"version":3,"file":"remove-unused-types.d.ts","sourceRoot":"","sources":["../../../src/codegen/utils/remove-unused-types.ts"],"names":[],"mappings":"AAmFA,eAAO,MAAM,iBAAiB,GAAU,SAAS;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,kBAM/D,CAAC"}
1
+ {"version":3,"file":"remove-unused-types.d.ts","sourceRoot":"","sources":["../../../src/codegen/utils/remove-unused-types.ts"],"names":[],"mappings":"AA6GA,eAAO,MAAM,iBAAiB,GAAU,SAAS;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,kBAK/D,CAAC"}
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-constant-condition */
1
2
  import { Project, SyntaxKind } from 'ts-morph';
2
3
  import path from 'node:path';
3
4
  const removeUnusedTypesItteration = async ({ dir }) => {
@@ -21,22 +22,44 @@ const removeUnusedTypesItteration = async ({ dir }) => {
21
22
  if (candidateTypes.size === 0)
22
23
  return;
23
24
  const usedTypes = new Set();
24
- const sourceFiles = project.getSourceFiles();
25
- for (const file of sourceFiles) {
25
+ const externalFiles = project
26
+ .getSourceFiles()
27
+ .filter((sf) => sf !== dataContractsSourceFile);
28
+ for (const file of externalFiles) {
26
29
  const identifiers = file.getDescendantsOfKind(SyntaxKind.Identifier);
27
30
  for (const identifier of identifiers) {
28
31
  const name = identifier.getText();
29
- if (!candidateTypes.has(name))
30
- continue;
31
- if (file === dataContractsSourceFile) {
32
- const parent = identifier.getParent();
33
- const isDeclaration = parent?.getKind() === SyntaxKind.InterfaceDeclaration ||
34
- parent?.getKind() === SyntaxKind.TypeAliasDeclaration;
35
- const isExport = parent?.getKind() === SyntaxKind.ExportSpecifier;
36
- if (isDeclaration || isExport)
37
- continue;
32
+ if (candidateTypes.has(name)) {
33
+ usedTypes.add(name);
34
+ }
35
+ }
36
+ }
37
+ const dependencyGraph = new Map();
38
+ for (const [name, declarations] of candidateTypes) {
39
+ const dependencies = new Set();
40
+ for (const decl of declarations) {
41
+ const identifiers = decl.getDescendantsOfKind(SyntaxKind.Identifier);
42
+ for (const ident of identifiers) {
43
+ const refName = ident.getText();
44
+ if (candidateTypes.has(refName)) {
45
+ dependencies.add(refName);
46
+ }
47
+ }
48
+ }
49
+ dependencyGraph.set(name, dependencies);
50
+ }
51
+ const queue = Array.from(usedTypes);
52
+ const visited = new Set(usedTypes);
53
+ while (queue.length > 0) {
54
+ const current = queue.shift();
55
+ if (dependencyGraph.has(current)) {
56
+ for (const dep of dependencyGraph.get(current)) {
57
+ if (!visited.has(dep)) {
58
+ visited.add(dep);
59
+ usedTypes.add(dep);
60
+ queue.push(dep);
61
+ }
38
62
  }
39
- usedTypes.add(name);
40
63
  }
41
64
  }
42
65
  let removedCount = 0;
@@ -56,7 +79,6 @@ const removeUnusedTypesItteration = async ({ dir }) => {
56
79
  return removedCount;
57
80
  };
58
81
  export const removeUnusedTypes = async ({ dir }) => {
59
- // eslint-disable-next-line no-constant-condition
60
82
  while (true) {
61
83
  const removedCount = (await removeUnusedTypesItteration({ dir })) ?? 0;
62
84
  if (removedCount === 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobx-tanstack-query-api",
3
- "version": "0.0.82",
3
+ "version": "0.0.83",
4
4
  "keywords": [],
5
5
  "author": "js2me",
6
6
  "license": "MIT",