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