mobx-tanstack-query-api 0.0.82 → 0.0.84

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":"AAqIA,eAAO,MAAM,iBAAiB,GAAU,SAAS;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,kBAK/D,CAAC"}
@@ -1,4 +1,5 @@
1
- import { Project, SyntaxKind } from 'ts-morph';
1
+ /* eslint-disable no-constant-condition */
2
+ import { Project, SyntaxKind, Node } from 'ts-morph';
2
3
  import path from 'node:path';
3
4
  const removeUnusedTypesItteration = async ({ dir }) => {
4
5
  const project = new Project();
@@ -13,7 +14,8 @@ const removeUnusedTypesItteration = async ({ dir }) => {
13
14
  const candidateTypes = new Map();
14
15
  for (const [name, declarations] of exportedDeclarations) {
15
16
  const validDeclarations = declarations.filter((decl) => decl.getKind() === SyntaxKind.InterfaceDeclaration ||
16
- decl.getKind() === SyntaxKind.TypeAliasDeclaration);
17
+ decl.getKind() === SyntaxKind.TypeAliasDeclaration ||
18
+ decl.getKind() === SyntaxKind.EnumDeclaration);
17
19
  if (validDeclarations.length > 0) {
18
20
  candidateTypes.set(name, validDeclarations);
19
21
  }
@@ -21,22 +23,63 @@ const removeUnusedTypesItteration = async ({ dir }) => {
21
23
  if (candidateTypes.size === 0)
22
24
  return;
23
25
  const usedTypes = new Set();
24
- const sourceFiles = project.getSourceFiles();
25
- for (const file of sourceFiles) {
26
+ const externalFiles = project
27
+ .getSourceFiles()
28
+ .filter((sf) => sf !== dataContractsSourceFile);
29
+ for (const file of externalFiles) {
26
30
  const identifiers = file.getDescendantsOfKind(SyntaxKind.Identifier);
27
31
  for (const identifier of identifiers) {
28
32
  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;
33
+ if (candidateTypes.has(name)) {
34
+ usedTypes.add(name);
35
+ }
36
+ }
37
+ const memberAccessExpressions = file.getDescendantsOfKind(SyntaxKind.PropertyAccessExpression);
38
+ for (const expr of memberAccessExpressions) {
39
+ const expression = expr.getExpression();
40
+ if (Node.isIdentifier(expression)) {
41
+ const name = expression.getText();
42
+ if (candidateTypes.has(name)) {
43
+ usedTypes.add(name);
44
+ }
45
+ }
46
+ }
47
+ }
48
+ const dependencyGraph = new Map();
49
+ for (const [name, declarations] of candidateTypes) {
50
+ const dependencies = new Set();
51
+ for (const decl of declarations) {
52
+ const typeReferences = decl.getDescendantsOfKind(SyntaxKind.TypeReference);
53
+ for (const ref of typeReferences) {
54
+ const typeName = ref.getTypeName().getText();
55
+ if (candidateTypes.has(typeName)) {
56
+ dependencies.add(typeName);
57
+ }
58
+ }
59
+ if (decl.getKind() === SyntaxKind.EnumDeclaration) {
60
+ const initializers = decl.getDescendantsOfKind(SyntaxKind.Identifier);
61
+ for (const init of initializers) {
62
+ const text = init.getText();
63
+ if (candidateTypes.has(text)) {
64
+ dependencies.add(text);
65
+ }
66
+ }
67
+ }
68
+ }
69
+ dependencyGraph.set(name, dependencies);
70
+ }
71
+ const queue = Array.from(usedTypes);
72
+ const visited = new Set(usedTypes);
73
+ while (queue.length > 0) {
74
+ const current = queue.shift();
75
+ if (dependencyGraph.has(current)) {
76
+ for (const dep of dependencyGraph.get(current)) {
77
+ if (!visited.has(dep)) {
78
+ visited.add(dep);
79
+ usedTypes.add(dep);
80
+ queue.push(dep);
81
+ }
38
82
  }
39
- usedTypes.add(name);
40
83
  }
41
84
  }
42
85
  let removedCount = 0;
@@ -56,7 +99,6 @@ const removeUnusedTypesItteration = async ({ dir }) => {
56
99
  return removedCount;
57
100
  };
58
101
  export const removeUnusedTypes = async ({ dir }) => {
59
- // eslint-disable-next-line no-constant-condition
60
102
  while (true) {
61
103
  const removedCount = (await removeUnusedTypesItteration({ dir })) ?? 0;
62
104
  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.84",
4
4
  "keywords": [],
5
5
  "author": "js2me",
6
6
  "license": "MIT",