mobx-tanstack-query-api 0.0.81 → 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":"
|
|
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,75 +1,76 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable no-constant-condition */
|
|
2
|
+
import { Project, SyntaxKind } from 'ts-morph';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
const removeUnusedTypesItteration = async ({ dir }) => {
|
|
4
|
-
// Создаем проект в памяти
|
|
5
5
|
const project = new Project();
|
|
6
|
-
// Добавляем все TS/TSX файлы из указанной директории
|
|
7
6
|
project.addSourceFilesAtPaths([
|
|
8
7
|
path.join(dir, '**/*.ts'),
|
|
9
8
|
path.join(dir, '**/*.tsx'),
|
|
10
9
|
]);
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
for (const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
for (const intf of file.getInterfaces()) {
|
|
22
|
-
const name = intf.getName();
|
|
23
|
-
typeDeclarations.set(name, {
|
|
24
|
-
node: intf,
|
|
25
|
-
file: file.getFilePath(),
|
|
26
|
-
line: intf.getStartLineNumber(),
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
// Type-алиасы
|
|
30
|
-
for (const typeAlias of file.getTypeAliases()) {
|
|
31
|
-
const name = typeAlias.getName();
|
|
32
|
-
typeDeclarations.set(name, {
|
|
33
|
-
node: typeAlias,
|
|
34
|
-
file: file.getFilePath(),
|
|
35
|
-
line: typeAlias.getStartLineNumber(),
|
|
36
|
-
});
|
|
10
|
+
const dataContractsSourceFile = project.getSourceFile((sourceFile) => sourceFile.getFilePath().includes(`${dir}/data-contracts.ts`));
|
|
11
|
+
if (!dataContractsSourceFile)
|
|
12
|
+
return;
|
|
13
|
+
const exportedDeclarations = dataContractsSourceFile.getExportedDeclarations();
|
|
14
|
+
const candidateTypes = new Map();
|
|
15
|
+
for (const [name, declarations] of exportedDeclarations) {
|
|
16
|
+
const validDeclarations = declarations.filter((decl) => decl.getKind() === SyntaxKind.InterfaceDeclaration ||
|
|
17
|
+
decl.getKind() === SyntaxKind.TypeAliasDeclaration);
|
|
18
|
+
if (validDeclarations.length > 0) {
|
|
19
|
+
candidateTypes.set(name, validDeclarations);
|
|
37
20
|
}
|
|
38
21
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
22
|
+
if (candidateTypes.size === 0)
|
|
23
|
+
return;
|
|
24
|
+
const usedTypes = new Set();
|
|
25
|
+
const externalFiles = project
|
|
26
|
+
.getSourceFiles()
|
|
27
|
+
.filter((sf) => sf !== dataContractsSourceFile);
|
|
28
|
+
for (const file of externalFiles) {
|
|
42
29
|
const identifiers = file.getDescendantsOfKind(SyntaxKind.Identifier);
|
|
43
30
|
for (const identifier of identifiers) {
|
|
44
31
|
const name = identifier.getText();
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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);
|
|
54
46
|
}
|
|
55
47
|
}
|
|
56
48
|
}
|
|
49
|
+
dependencyGraph.set(name, dependencies);
|
|
57
50
|
}
|
|
58
|
-
|
|
59
|
-
|
|
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
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
60
64
|
}
|
|
61
65
|
let removedCount = 0;
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
removedCount++;
|
|
71
|
-
}
|
|
72
|
-
});
|
|
66
|
+
for (const [name, declarations] of candidateTypes) {
|
|
67
|
+
if (usedTypes.has(name))
|
|
68
|
+
continue;
|
|
69
|
+
for (const decl of declarations) {
|
|
70
|
+
if ('remove' in decl) {
|
|
71
|
+
decl.remove();
|
|
72
|
+
removedCount++;
|
|
73
|
+
}
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
if (removedCount > 0) {
|
|
@@ -78,9 +79,9 @@ const removeUnusedTypesItteration = async ({ dir }) => {
|
|
|
78
79
|
return removedCount;
|
|
79
80
|
};
|
|
80
81
|
export const removeUnusedTypes = async ({ dir }) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
while (true) {
|
|
83
|
+
const removedCount = (await removeUnusedTypesItteration({ dir })) ?? 0;
|
|
84
|
+
if (removedCount === 0)
|
|
85
|
+
break;
|
|
85
86
|
}
|
|
86
87
|
};
|