@comet/upgrade 1.47.0 → 1.48.0
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,19 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const format_code_util_1 = require("../util/format-code.util");
|
|
3
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
4
|
/**
|
|
6
5
|
* Replaces the old ExceptionInterceptor with the new ExceptionFilter
|
|
7
6
|
*/
|
|
8
7
|
async function replaceExceptionInterceptorWithExceptionFilter() {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
if (!
|
|
12
|
-
console.log("ExceptionInterceptor not found in main.ts. Make sure that you use the new ExceptionFilter.");
|
|
8
|
+
const project = new ts_morph_1.Project({ tsConfigFilePath: "./api/tsconfig.json" });
|
|
9
|
+
const sourceFile = project.getSourceFile("api/src/main.ts");
|
|
10
|
+
if (!sourceFile) {
|
|
13
11
|
return;
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
const cmsApiImport = sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue() === "@comet/cms-api");
|
|
14
|
+
if (!cmsApiImport) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const exceptionInterceptorImport = cmsApiImport.getNamedImports().find((namedImport) => namedImport.getName() === "ExceptionInterceptor");
|
|
18
|
+
if (!exceptionInterceptorImport) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const bootstrap = sourceFile.getFirstDescendantByKind(ts_morph_1.SyntaxKind.FunctionDeclaration);
|
|
22
|
+
if (!bootstrap) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const useGlobalInterceptors = sourceFile
|
|
26
|
+
.getDescendantsOfKind(ts_morph_1.SyntaxKind.ExpressionStatement)
|
|
27
|
+
.find((node) => node.getText().includes("useGlobalInterceptors"));
|
|
28
|
+
if (!useGlobalInterceptors) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
bootstrap.insertStatements(useGlobalInterceptors.getChildIndex() + 1, "app.useGlobalFilters(new ExceptionFilter(config.debug));");
|
|
32
|
+
const exceptionInterceptor = useGlobalInterceptors
|
|
33
|
+
.getDescendantsOfKind(ts_morph_1.SyntaxKind.NewExpression)
|
|
34
|
+
.find((node) => node.getText().includes("ExceptionInterceptor"));
|
|
35
|
+
if (exceptionInterceptor) {
|
|
36
|
+
useGlobalInterceptors.getFirstDescendantByKindOrThrow(ts_morph_1.SyntaxKind.CallExpression).removeArgument(exceptionInterceptor);
|
|
37
|
+
if (useGlobalInterceptors.getDescendantsOfKind(ts_morph_1.SyntaxKind.NewExpression).length === 0) {
|
|
38
|
+
useGlobalInterceptors.remove();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exceptionInterceptorImport.remove();
|
|
42
|
+
cmsApiImport.addNamedImport("ExceptionFilter");
|
|
43
|
+
await sourceFile.save();
|
|
18
44
|
}
|
|
19
45
|
exports.default = replaceExceptionInterceptorWithExceptionFilter;
|