@hadss/turbo-trans-json-plugin 1.0.0-rc.0 → 1.0.0-rc.2
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.
- package/README.md +1 -1
- package/dist/core/Types.d.ts +7 -0
- package/dist/core/Types.js +7 -1
- package/dist/core/analyzers/ClassAnalyzer.d.ts +15 -0
- package/dist/core/analyzers/ClassAnalyzer.js +200 -120
- package/dist/core/analyzers/CustomTypeAnalyzer.d.ts +3 -0
- package/dist/core/analyzers/CustomTypeAnalyzer.js +65 -60
- package/dist/core/constants/DecoratorConstants.d.ts +1 -0
- package/dist/core/constants/DecoratorConstants.js +3 -1
- package/dist/core/handlers/CustomClassHandler.js +0 -1
- package/dist/core/import-rewrite/services/BuildProfileUpdater.js +1 -1
- package/dist/core/import-rewrite/services/ImportRewriteService.js +1 -1
- package/dist/core/interfaces/index.d.ts +2 -2
- package/dist/core/services/CodeAnalysisService.js +2 -1
- package/dist/core/services/CodeGenerationService/CodeGenerationService.js +1 -1
- package/dist/core/services/CodeGenerationService/generators/MergedSendableClassGenerator.d.ts +0 -1
- package/dist/core/services/CodeGenerationService/generators/MergedSendableClassGenerator.js +0 -20
- package/dist/core/services/CodeGenerationService/generators/OriginalClassGenerator.d.ts +4 -4
- package/dist/core/services/CodeGenerationService/generators/OriginalClassGenerator.js +26 -45
- package/dist/core/services/CodeGenerationService/generators/SendableClassGenerator.d.ts +22 -0
- package/dist/core/services/CodeGenerationService/generators/SendableClassGenerator.js +194 -129
- package/dist/core/services/CodeGenerationService/generators/SerializerGenerator.js +20 -15
- package/dist/core/services/CodeGenerationService/generators/TempSerializerGenerator.js +2 -1
- package/dist/core/services/CodeGenerationService/shared/ImportManager.d.ts +2 -2
- package/dist/core/template/HandlebarsTemplateEngine.d.ts +2 -0
- package/dist/core/template/HandlebarsTemplateEngine.js +24 -2
- package/dist/core/utils/DeepCopyUtil.js +4 -2
- package/dist/core/utils/GenericTypeSubstitutionUtil.d.ts +1 -0
- package/dist/core/utils/GenericTypeSubstitutionUtil.js +27 -1
- package/dist/core/utils/SerializationPathUtil.d.ts +1 -1
- package/dist/core/utils/TsMorphUtil.js +6 -1
- package/dist/json-plugin/JSONExecuteController.d.ts +4 -0
- package/dist/json-plugin/JSONExecuteController.js +46 -36
- package/dist/json-plugin/interfaces/impl/TargetContext.js +4 -2
- package/dist/json-plugin/tasks/BaseTask.d.ts +2 -2
- package/dist/json-plugin/tasks/WatchTask.js +2 -1
- package/package.json +1 -1
- package/src/core/Types.ts +97 -89
- package/src/core/analyzers/ClassAnalyzer.ts +358 -197
- package/src/core/analyzers/CustomTypeAnalyzer.ts +145 -74
- package/src/core/constants/DecoratorConstants.ts +7 -5
- package/src/core/constants/PathConstants.ts +7 -7
- package/src/core/constants/StringConstants.ts +95 -97
- package/src/core/handlers/BaseTypeHandler.ts +11 -2
- package/src/core/handlers/CustomClassHandler.ts +4 -7
- package/src/core/handlers/DateHandler.ts +54 -46
- package/src/core/handlers/DecimalHandler.ts +53 -45
- package/src/core/handlers/EnumHandler.ts +2 -1
- package/src/core/handlers/GenericContainerHandler.ts +3 -1
- package/src/core/handlers/TupleHandler.ts +2 -1
- package/src/core/handlers/TypeHandlerRegistry.ts +3 -2
- package/src/core/handlers/UnionTypeHandler.ts +8 -7
- package/src/core/import-rewrite/services/BuildProfileUpdater.ts +7 -5
- package/src/core/import-rewrite/services/ImportRewriteService.ts +1 -3
- package/src/core/import-rewrite/services/ImportTransformService.ts +2 -2
- package/src/core/import-rewrite/types/ImportRewriteTypes.ts +3 -3
- package/src/core/index.ts +4 -4
- package/src/core/interfaces/ITask.ts +6 -5
- package/src/core/interfaces/ITaskContext.ts +9 -9
- package/src/core/interfaces/index.ts +2 -2
- package/src/core/logger/Logger.ts +28 -28
- package/src/core/services/CodeAnalysisService.ts +3 -2
- package/src/core/services/CodeGenerationEngine.ts +42 -42
- package/src/core/services/CodeGenerationService/CodeGenerationService.ts +1 -2
- package/src/core/services/CodeGenerationService/generators/MergedSendableClassGenerator.ts +0 -29
- package/src/core/services/CodeGenerationService/generators/OriginalClassGenerator.ts +31 -64
- package/src/core/services/CodeGenerationService/generators/SendableClassGenerator.ts +261 -170
- package/src/core/services/CodeGenerationService/generators/SerializerGenerator.ts +26 -19
- package/src/core/services/CodeGenerationService/generators/TempSerializerGenerator.ts +5 -3
- package/src/core/services/CodeGenerationService/shared/ImportManager.ts +8 -8
- package/src/core/template/HandlebarsTemplateEngine.ts +43 -10
- package/src/core/utils/ConfigManager.ts +2 -1
- package/src/core/utils/DeepCopyUtil.ts +4 -2
- package/src/core/utils/GenericTypeSubstitutionUtil.ts +45 -2
- package/src/core/utils/SerializationPathUtil.ts +7 -6
- package/src/core/utils/TsMorphUtil.ts +9 -2
- package/src/index.ts +2 -2
- package/src/json-plugin/JSONExecuteController.ts +51 -38
- package/src/json-plugin/interfaces/IModuleContext.ts +8 -8
- package/src/json-plugin/interfaces/ITargetContext.ts +6 -6
- package/src/json-plugin/interfaces/impl/ModuleContext.ts +10 -10
- package/src/json-plugin/interfaces/impl/TargetContext.ts +63 -58
- package/src/json-plugin/tasks/BaseTask.ts +5 -4
- package/src/json-plugin/tasks/CleanTask.ts +7 -7
- package/src/json-plugin/tasks/WatchTask.ts +20 -18
- package/template/SerializerPerformanceTemplate.hbs +14 -4
- package/template/SerializerStrictTemplate.hbs +9 -1
- package/template/SerializerTemplate.hbs +71 -46
|
@@ -19,57 +19,65 @@ import { BaseTypeHandler } from './BaseTypeHandler';
|
|
|
19
19
|
import { TypeContext, ConversionDirection, ITypeHandler } from './ITypeHandler';
|
|
20
20
|
|
|
21
21
|
class DateHandler extends BaseTypeHandler implements ITypeHandler {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
parse(typeNode: TypeNode, context: TypeContext): TypeStructure {
|
|
34
|
-
return {
|
|
35
|
-
kind: PropertyKind.Date,
|
|
36
|
-
depth: 0,
|
|
37
|
-
sourceText: typeNode.getText(),
|
|
38
|
-
args: [],
|
|
39
|
-
dependencies: []
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
getSerializerMetadata(structure: TypeStructure, withParam?: string): SerializerMetadata {
|
|
43
|
-
return {
|
|
44
|
-
name: 'DateSerializer',
|
|
45
|
-
typeDeclaration: 'DateSerializer',
|
|
46
|
-
instantiationTemplate: 'DateSerializer.INSTANCE',
|
|
47
|
-
encodeMethod: 'encodeSerializableElement',
|
|
48
|
-
decodeMethod: 'deserialize',
|
|
49
|
-
decoderType: 'Date | undefined',
|
|
50
|
-
needsTypeAssertion: false
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
generateInstantiation(structure: TypeStructure): string {
|
|
54
|
-
return 'DateSerializer.INSTANCE';
|
|
55
|
-
}
|
|
56
|
-
generateTypeDeclaration(structure: TypeStructure): string {
|
|
57
|
-
return 'DateSerializer';
|
|
58
|
-
}
|
|
59
|
-
generateTypeKey(structure: TypeStructure): string {
|
|
60
|
-
return structure.sourceText;
|
|
61
|
-
}
|
|
62
|
-
generateSendableTypeDeclaration(structure: TypeStructure): string {
|
|
63
|
-
return structure.sourceText;
|
|
64
|
-
}
|
|
65
|
-
generatePropertyConversion(structure: TypeStructure, sourceValue: string, direction: ConversionDirection): string {
|
|
66
|
-
return sourceValue;
|
|
22
|
+
readonly name: string = 'DateHandler';
|
|
23
|
+
kind: PropertyKind = PropertyKind.Date;
|
|
24
|
+
priority: number = 95;
|
|
25
|
+
|
|
26
|
+
matches(typeNode: TypeNode, context: TypeContext): boolean {
|
|
27
|
+
if (typeNode.getKind() === SyntaxKind.TypeReference) {
|
|
28
|
+
const typeRef = typeNode as TypeReferenceNode;
|
|
29
|
+
const refName = typeRef.getTypeName().getText();
|
|
30
|
+
return refName === 'Date';
|
|
67
31
|
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
parse(typeNode: TypeNode, context: TypeContext): TypeStructure {
|
|
36
|
+
return {
|
|
37
|
+
kind: PropertyKind.Date,
|
|
38
|
+
depth: 0,
|
|
39
|
+
sourceText: typeNode.getText(),
|
|
40
|
+
args: [],
|
|
41
|
+
dependencies: []
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getSerializerMetadata(structure: TypeStructure, withParam?: string): SerializerMetadata {
|
|
46
|
+
return {
|
|
47
|
+
name: 'DateSerializer',
|
|
48
|
+
typeDeclaration: 'DateSerializer',
|
|
49
|
+
instantiationTemplate: 'DateSerializer.INSTANCE',
|
|
50
|
+
encodeMethod: 'encodeSerializableElement',
|
|
51
|
+
decodeMethod: 'deserialize',
|
|
52
|
+
decoderType: 'Date | undefined',
|
|
53
|
+
needsTypeAssertion: false
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
generateInstantiation(structure: TypeStructure): string {
|
|
58
|
+
return 'DateSerializer.INSTANCE';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
generateTypeDeclaration(structure: TypeStructure): string {
|
|
62
|
+
return 'DateSerializer';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
generateTypeKey(structure: TypeStructure): string {
|
|
66
|
+
return structure.sourceText;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
generateSendableTypeDeclaration(structure: TypeStructure): string {
|
|
70
|
+
return structure.sourceText;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
generatePropertyConversion(structure: TypeStructure, sourceValue: string, direction: ConversionDirection): string {
|
|
74
|
+
return sourceValue;
|
|
75
|
+
}
|
|
68
76
|
}
|
|
69
77
|
|
|
70
78
|
/**
|
|
71
79
|
* 工厂函数
|
|
72
80
|
*/
|
|
73
81
|
export function createDateHandler(): ITypeHandler {
|
|
74
|
-
|
|
82
|
+
return new DateHandler();
|
|
75
83
|
}
|
|
@@ -19,52 +19,60 @@ import { BaseTypeHandler } from './BaseTypeHandler';
|
|
|
19
19
|
import { TypeContext, ConversionDirection, ITypeHandler } from './ITypeHandler';
|
|
20
20
|
|
|
21
21
|
class DecimalHandler extends BaseTypeHandler implements ITypeHandler {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
parse(typeNode: TypeNode, context: TypeContext): TypeStructure {
|
|
34
|
-
return {
|
|
35
|
-
kind: PropertyKind.Decimal,
|
|
36
|
-
depth: 0,
|
|
37
|
-
sourceText: typeNode.getText(),
|
|
38
|
-
args: [],
|
|
39
|
-
dependencies: []
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
getSerializerMetadata(structure: TypeStructure, withParam?: string): SerializerMetadata {
|
|
43
|
-
return {
|
|
44
|
-
name: 'DecimalSerializer',
|
|
45
|
-
typeDeclaration: 'DecimalSerializer',
|
|
46
|
-
instantiationTemplate: 'DecimalSerializer.INSTANCE',
|
|
47
|
-
encodeMethod: 'encodeSerializableElement',
|
|
48
|
-
decodeMethod: 'deserialize',
|
|
49
|
-
decoderType: 'Decimal | undefined',
|
|
50
|
-
needsTypeAssertion: false
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
generateInstantiation(structure: TypeStructure): string {
|
|
54
|
-
return 'DecimalSerializer.INSTANCE';
|
|
55
|
-
}
|
|
56
|
-
generateTypeDeclaration(structure: TypeStructure): string {
|
|
57
|
-
return 'DecimalSerializer';
|
|
58
|
-
}
|
|
59
|
-
generateTypeKey(structure: TypeStructure): string {
|
|
60
|
-
return structure.sourceText;
|
|
61
|
-
}
|
|
62
|
-
generateSendableTypeDeclaration(structure: TypeStructure): string {
|
|
63
|
-
return structure.sourceText;
|
|
22
|
+
readonly name: string = 'DecimalHandler';
|
|
23
|
+
kind: PropertyKind = PropertyKind.Decimal;
|
|
24
|
+
priority: number = 95;
|
|
25
|
+
|
|
26
|
+
matches(typeNode: TypeNode, context: TypeContext): boolean {
|
|
27
|
+
if (typeNode.getKind() === SyntaxKind.TypeReference) {
|
|
28
|
+
const typeRef = typeNode as TypeReferenceNode;
|
|
29
|
+
const refName = typeRef.getTypeName().getText();
|
|
30
|
+
return refName === 'Decimal';
|
|
64
31
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
parse(typeNode: TypeNode, context: TypeContext): TypeStructure {
|
|
36
|
+
return {
|
|
37
|
+
kind: PropertyKind.Decimal,
|
|
38
|
+
depth: 0,
|
|
39
|
+
sourceText: typeNode.getText(),
|
|
40
|
+
args: [],
|
|
41
|
+
dependencies: []
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getSerializerMetadata(structure: TypeStructure, withParam?: string): SerializerMetadata {
|
|
46
|
+
return {
|
|
47
|
+
name: 'DecimalSerializer',
|
|
48
|
+
typeDeclaration: 'DecimalSerializer',
|
|
49
|
+
instantiationTemplate: 'DecimalSerializer.INSTANCE',
|
|
50
|
+
encodeMethod: 'encodeSerializableElement',
|
|
51
|
+
decodeMethod: 'deserialize',
|
|
52
|
+
decoderType: 'Decimal | undefined',
|
|
53
|
+
needsTypeAssertion: false
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
generateInstantiation(structure: TypeStructure): string {
|
|
58
|
+
return 'DecimalSerializer.INSTANCE';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
generateTypeDeclaration(structure: TypeStructure): string {
|
|
62
|
+
return 'DecimalSerializer';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
generateTypeKey(structure: TypeStructure): string {
|
|
66
|
+
return structure.sourceText;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
generateSendableTypeDeclaration(structure: TypeStructure): string {
|
|
70
|
+
return structure.sourceText;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
generatePropertyConversion(structure: TypeStructure, sourceValue: string, direction: ConversionDirection): string {
|
|
74
|
+
return sourceValue;
|
|
75
|
+
}
|
|
68
76
|
}
|
|
69
77
|
|
|
70
78
|
/**
|
|
@@ -108,7 +108,8 @@ class EnumHandler extends BaseTypeHandler implements ITypeHandler {
|
|
|
108
108
|
|
|
109
109
|
generateTypeDeclaration(structure: TypeStructure): string {
|
|
110
110
|
if (!structure.enumDetails) {
|
|
111
|
-
throw new CustomError('EnumHandler: missing enumDetails for type declaration',
|
|
111
|
+
throw new CustomError('EnumHandler: missing enumDetails for type declaration',
|
|
112
|
+
ErrorCodes.ENUM_STRUCTURE_NOT_FOUND);
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
const valueType = structure.enumDetails.valueType;
|
|
@@ -72,7 +72,8 @@ abstract class GenericContainerHandler extends BaseTypeHandler implements ITypeH
|
|
|
72
72
|
private parseArrayLiteral(typeNode: ArrayTypeNode, context: TypeContext): TypeStructure {
|
|
73
73
|
const elementTypeNode = typeNode.getElementTypeNode();
|
|
74
74
|
|
|
75
|
-
Logger.debug('GenericHandler.parseArrayLiteral', typeNode.getText(), elementTypeNode.getText(),
|
|
75
|
+
Logger.debug('GenericHandler.parseArrayLiteral', typeNode.getText(), elementTypeNode.getText(),
|
|
76
|
+
elementTypeNode.getKind());
|
|
76
77
|
|
|
77
78
|
// 递归解析元素类型
|
|
78
79
|
const { TypeHandlerRegistry } = require('./TypeHandlerRegistry');
|
|
@@ -572,6 +573,7 @@ class HashSetHandler extends GenericContainerHandler {
|
|
|
572
573
|
protected getSendableContainerName(): string {
|
|
573
574
|
throw new CustomError('toSendable HashSet type is not supported.', ErrorCodes.TYPE_NOT_SUPPORT);
|
|
574
575
|
}
|
|
576
|
+
|
|
575
577
|
protected getOriginContainerName(): string {
|
|
576
578
|
throw new CustomError('toOrgin HashSet type is not supported.', ErrorCodes.TYPE_NOT_SUPPORT);
|
|
577
579
|
}
|
|
@@ -125,7 +125,8 @@ class TupleHandler extends BaseTypeHandler implements ITypeHandler {
|
|
|
125
125
|
const sendableElementTypes = structure.args.map(element => {
|
|
126
126
|
const handler = registry.getHandlerForKind(element.kind);
|
|
127
127
|
if (!handler) {
|
|
128
|
-
throw new CustomError(`TupleHandler: no handler for element type: ${element.kind}`,
|
|
128
|
+
throw new CustomError(`TupleHandler: no handler for element type: ${element.kind}`,
|
|
129
|
+
ErrorCodes.HANDLER_NOT_FOUND);
|
|
129
130
|
}
|
|
130
131
|
return handler.generateSendableTypeDeclaration(element);
|
|
131
132
|
});
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import { TypeNode, SyntaxKind
|
|
16
|
+
import { TypeNode, SyntaxKind } from 'ts-morph';
|
|
17
17
|
import { ITypeHandler, TypeContext } from './ITypeHandler';
|
|
18
18
|
import { PropertyKind, TypeStructure, Logger } from '..';
|
|
19
19
|
import { CustomError, ErrorCodes } from '../utils/CustomError';
|
|
@@ -30,7 +30,8 @@ export class TypeHandlerRegistry {
|
|
|
30
30
|
/** 类型名称到Handler的快速查找表(支持多个候选) */
|
|
31
31
|
private nameMap: Map<string, ITypeHandler[]> = new Map();
|
|
32
32
|
|
|
33
|
-
private constructor() {
|
|
33
|
+
private constructor() {
|
|
34
|
+
}
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
37
|
* 获取单例实例
|
|
@@ -206,9 +206,9 @@ abstract class UnionTypeHandler extends BaseTypeHandler implements ITypeHandler
|
|
|
206
206
|
* 检查是否为Optional、Nullable或OptionalNullable模式
|
|
207
207
|
*/
|
|
208
208
|
protected isOptionalOrNullablePattern(): boolean {
|
|
209
|
-
return this.supportedPattern === 'optional' ||
|
|
210
|
-
|
|
211
|
-
|
|
209
|
+
return this.supportedPattern === 'optional' ||
|
|
210
|
+
this.supportedPattern === 'nullable' ||
|
|
211
|
+
this.supportedPattern === 'optionalNullable';
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
/**
|
|
@@ -221,7 +221,7 @@ abstract class UnionTypeHandler extends BaseTypeHandler implements ITypeHandler
|
|
|
221
221
|
case 'nullable':
|
|
222
222
|
return structure.unionDetails?.find(m => m.kind !== PropertyKind.NULL);
|
|
223
223
|
case 'optionalNullable':
|
|
224
|
-
return structure.unionDetails?.find(m =>
|
|
224
|
+
return structure.unionDetails?.find(m =>
|
|
225
225
|
m.kind !== PropertyKind.NULL && m.kind !== PropertyKind.UNDEFINED
|
|
226
226
|
);
|
|
227
227
|
default:
|
|
@@ -236,7 +236,7 @@ abstract class UnionTypeHandler extends BaseTypeHandler implements ITypeHandler
|
|
|
236
236
|
if (this.supportedPattern === 'optionalNullable' && structure.unionDetails?.length !== 3) {
|
|
237
237
|
throw new CustomError(`${this.name}: expected 3 union members`, ErrorCodes.UNION_EXPEDTED_THREE);
|
|
238
238
|
}
|
|
239
|
-
|
|
239
|
+
|
|
240
240
|
if (this.supportedPattern !== 'optionalNullable' && structure.unionDetails?.length !== 2) {
|
|
241
241
|
throw new CustomError(`${this.name}: expected 2 union members`, ErrorCodes.UNION_EXPEDTED_TWO);
|
|
242
242
|
}
|
|
@@ -267,7 +267,7 @@ abstract class UnionTypeHandler extends BaseTypeHandler implements ITypeHandler
|
|
|
267
267
|
const { TypeHandlerRegistry } = require('./TypeHandlerRegistry');
|
|
268
268
|
const innerHandler = TypeHandlerRegistry.getInstance().getHandlerForKind(innerMember.kind);
|
|
269
269
|
const innerTypeKey = innerHandler.generateTypeKey(innerMember);
|
|
270
|
-
|
|
270
|
+
|
|
271
271
|
switch (this.supportedPattern) {
|
|
272
272
|
case 'optional':
|
|
273
273
|
return `[${innerTypeKey}, "'undefined'"]`;
|
|
@@ -303,7 +303,8 @@ abstract class UnionTypeHandler extends BaseTypeHandler implements ITypeHandler
|
|
|
303
303
|
|
|
304
304
|
generateSendableTypeDeclaration(structure: TypeStructure): string {
|
|
305
305
|
if (!structure.unionDetails || structure.unionDetails.length === 0) {
|
|
306
|
-
throw new CustomError(`${this.name}: missing unionDetails for Sendable type declaration`,
|
|
306
|
+
throw new CustomError(`${this.name}: missing unionDetails for Sendable type declaration`,
|
|
307
|
+
ErrorCodes.UNION_STRUCTURE_NOT_FOUND);
|
|
307
308
|
}
|
|
308
309
|
|
|
309
310
|
// 递归获取TypeHandlerRegistry
|
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import {
|
|
16
|
+
import { Logger } from '../..';
|
|
17
17
|
import { ITargetContext } from '../../../json-plugin/interfaces/ITargetContext';
|
|
18
18
|
import SerializationPathUtil from '../../utils/SerializationPathUtil';
|
|
19
|
+
import { ModuleBuildProfile } from '@ohos/hvigor-ohos-plugin/src/options/build/module-build-profile';
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* build-profile.json5 配置更新服务实现
|
|
@@ -83,7 +84,7 @@ export class BuildProfileUpdaterImpl {
|
|
|
83
84
|
/**
|
|
84
85
|
* 读取 build-profile.json5 配置
|
|
85
86
|
*/
|
|
86
|
-
private readBuildProfile(buildProfilePath: string):
|
|
87
|
+
private readBuildProfile(buildProfilePath: string): ModuleBuildProfile.ModuleBuildOpt {
|
|
87
88
|
try {
|
|
88
89
|
// 使用继承自 FileUtil 的方法读取 JSON5
|
|
89
90
|
return SerializationPathUtil.readJson5(buildProfilePath);
|
|
@@ -96,7 +97,8 @@ export class BuildProfileUpdaterImpl {
|
|
|
96
97
|
/**
|
|
97
98
|
* 写入 build-profile.json5 配置
|
|
98
99
|
*/
|
|
99
|
-
private writeBuildProfile(targetContext: ITargetContext, buildProfilePath: string,
|
|
100
|
+
private writeBuildProfile(targetContext: ITargetContext, buildProfilePath: string,
|
|
101
|
+
config: ModuleBuildProfile.ModuleBuildOpt): void {
|
|
100
102
|
try {
|
|
101
103
|
// 不需要修改源代码,仅重写构建过程中的buildProfile文件,修改源码方式SerializationPathUtil.writeFileSync(buildProfilePath, JSON.stringify(config, null, 2));
|
|
102
104
|
targetContext.context.moduleContext.setBuildProfileOpt(config);
|
|
@@ -111,9 +113,9 @@ export class BuildProfileUpdaterImpl {
|
|
|
111
113
|
* @param config 配置对象
|
|
112
114
|
* @returns 是否进行了更新
|
|
113
115
|
*/
|
|
114
|
-
private updateSourceRootsConfig(config:
|
|
116
|
+
private updateSourceRootsConfig(config: ModuleBuildProfile.ModuleBuildOpt): boolean {
|
|
115
117
|
let updated = false;
|
|
116
|
-
const generatedSourceRoot =
|
|
118
|
+
const generatedSourceRoot = './src/generated';
|
|
117
119
|
Logger.info(`target.source.sourceRoots start`);
|
|
118
120
|
|
|
119
121
|
// 更新 targets 中的 source.sourceRoots
|
|
@@ -17,8 +17,6 @@ import { ITaskContext, ImportRewriteOptions, Logger } from '../..';
|
|
|
17
17
|
import { GeneratedFileInfo, ImportRewriteService as IImportRewriteService } from '../types/ImportRewriteTypes';
|
|
18
18
|
import { ImportTransformServiceImpl } from './ImportTransformService';
|
|
19
19
|
import SerializationPathUtil from '../../utils/SerializationPathUtil';
|
|
20
|
-
import { BuildProfileUpdaterImpl } from './BuildProfileUpdater';
|
|
21
|
-
import { ITargetContext } from '../../../json-plugin/interfaces/ITargetContext';
|
|
22
20
|
|
|
23
21
|
/**
|
|
24
22
|
* 导入重写主服务实现
|
|
@@ -65,7 +63,7 @@ export class ImportRewriteServiceImpl implements IImportRewriteService {
|
|
|
65
63
|
options.preserveOriginalImports
|
|
66
64
|
);
|
|
67
65
|
successCount++;
|
|
68
|
-
} catch
|
|
66
|
+
} catch {
|
|
69
67
|
errorCount++;
|
|
70
68
|
}
|
|
71
69
|
}
|
|
@@ -162,7 +162,7 @@ export class ImportTransformServiceImpl implements ImportTransformService {
|
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
private replaceWithCommentedOriginal(
|
|
165
|
-
importDecl:
|
|
165
|
+
importDecl: ImportDeclaration | ExportDeclaration,
|
|
166
166
|
originalModuleSpecifier: string,
|
|
167
167
|
newModuleSpecifier: string
|
|
168
168
|
): void {
|
|
@@ -176,7 +176,7 @@ export class ImportTransformServiceImpl implements ImportTransformService {
|
|
|
176
176
|
importDecl.replaceWithText(`${commentedOriginal}\n${newImportText.trim()}`);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
private handleRewriteResult(sourceFile:
|
|
179
|
+
private handleRewriteResult(sourceFile: SourceFile, filePath: string, rewriteCount: number): void {
|
|
180
180
|
if (rewriteCount > 0) {
|
|
181
181
|
sourceFile.saveSync();
|
|
182
182
|
Logger.info(`文件 ${filePath} 重写了 ${rewriteCount} 个导入语句`);
|
|
@@ -21,9 +21,9 @@ import { ITaskContext, ImportRewriteOptions } from '../..';
|
|
|
21
21
|
* 包含源文件到生成文件的完整映射关系
|
|
22
22
|
*/
|
|
23
23
|
export interface GeneratedFileInfo {
|
|
24
|
-
sourceFilePath: string;
|
|
25
|
-
generatedFilePath: string;
|
|
26
|
-
classNames: Set<string>;
|
|
24
|
+
sourceFilePath: string; // 源文件绝对路径
|
|
25
|
+
generatedFilePath: string; // 生成文件绝对路径
|
|
26
|
+
classNames: Set<string>; // 该文件中包含的类名列表
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
package/src/core/index.ts
CHANGED
|
@@ -13,19 +13,19 @@
|
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
export * from './interfaces'
|
|
16
|
+
export * from './interfaces';
|
|
17
17
|
|
|
18
18
|
export * from './logger/Logger';
|
|
19
19
|
|
|
20
|
-
export * from './constants'
|
|
20
|
+
export * from './constants';
|
|
21
21
|
|
|
22
22
|
export * from './Types';
|
|
23
23
|
|
|
24
|
-
export * from './services/CodeGenerationEngine'
|
|
24
|
+
export * from './services/CodeGenerationEngine';
|
|
25
25
|
|
|
26
26
|
// 导入重写功能导出
|
|
27
27
|
export * from './import-rewrite/types/ImportRewriteTypes';
|
|
28
28
|
export * from './import-rewrite/services/ImportRewriteService';
|
|
29
29
|
export * from './utils/ConfigManager';
|
|
30
30
|
|
|
31
|
-
export { TempSerializerGenerator } from './services/CodeGenerationService/generators/TempSerializerGenerator'
|
|
31
|
+
export { TempSerializerGenerator } from './services/CodeGenerationService/generators/TempSerializerGenerator';
|
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import { ITaskContext } from './ITaskContext'
|
|
16
|
+
import { ITaskContext } from './ITaskContext';
|
|
17
17
|
|
|
18
18
|
export interface ITask {
|
|
19
|
-
readonly taskName: string
|
|
20
|
-
readonly dependencies: string[]
|
|
21
|
-
readonly postDependencies: string[]
|
|
22
|
-
|
|
19
|
+
readonly taskName: string;
|
|
20
|
+
readonly dependencies: string[];
|
|
21
|
+
readonly postDependencies: string[];
|
|
22
|
+
|
|
23
|
+
run(context: ITaskContext): void | Promise<void>;
|
|
23
24
|
}
|
|
@@ -21,7 +21,7 @@ export interface ITaskContext {
|
|
|
21
21
|
* @example
|
|
22
22
|
* 'module/src/main/ets/User.ets' -> '/module/src/generated/ets/User.ets'
|
|
23
23
|
*/
|
|
24
|
-
mapToOutputPath(absSourceFile: string): string
|
|
24
|
+
mapToOutputPath(absSourceFile: string): string;
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* 获取输出根目录
|
|
@@ -30,27 +30,27 @@ export interface ITaskContext {
|
|
|
30
30
|
* @example
|
|
31
31
|
* 'module/src/generated'
|
|
32
32
|
*/
|
|
33
|
-
getOutputRoot(): string
|
|
33
|
+
getOutputRoot(): string;
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* 获取模块名称
|
|
37
37
|
* 返回当前模块module.json5中配置的name字段
|
|
38
38
|
* @returns 输出当前模块module.json5中配置的name字段
|
|
39
39
|
*/
|
|
40
|
-
getModuleName(): string
|
|
40
|
+
getModuleName(): string;
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* 获取模块根路径
|
|
44
44
|
* @returns 输出当前模块根路径
|
|
45
45
|
*/
|
|
46
|
-
getModulePath(): string
|
|
46
|
+
getModulePath(): string;
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* 获取package名称
|
|
50
50
|
* 返回当前模块oh-package.json5中配置的name字段
|
|
51
51
|
* @returns 输出当前模块oh-package.json5中配置的name字段
|
|
52
52
|
*/
|
|
53
|
-
getPackageName(): string
|
|
53
|
+
getPackageName(): string;
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* 获取文件的相对路径
|
|
@@ -61,7 +61,7 @@ export interface ITaskContext {
|
|
|
61
61
|
* @example
|
|
62
62
|
* 'module/src/main/ets/User.ets' -> 'src/main/ets/User.ets'
|
|
63
63
|
*/
|
|
64
|
-
getRelativePath(absolutePath: string): string
|
|
64
|
+
getRelativePath(absolutePath: string): string;
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* 检查输出路径是否有效
|
|
@@ -70,7 +70,7 @@ export interface ITaskContext {
|
|
|
70
70
|
* @param outputPath 输出文件路径
|
|
71
71
|
* @returns 路径是否有效
|
|
72
72
|
*/
|
|
73
|
-
isValidOutputPath(outputPath: string): boolean
|
|
73
|
+
isValidOutputPath(outputPath: string): boolean;
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
76
|
* 确保输出目录存在
|
|
@@ -78,7 +78,7 @@ export interface ITaskContext {
|
|
|
78
78
|
* @param outputPath 输出文件路径
|
|
79
79
|
* @returns Promise<void>
|
|
80
80
|
*/
|
|
81
|
-
ensureOutputDirectory(outputPath: string): void
|
|
81
|
+
ensureOutputDirectory(outputPath: string): void;
|
|
82
82
|
|
|
83
83
|
|
|
84
84
|
/**
|
|
@@ -90,5 +90,5 @@ export interface ITaskContext {
|
|
|
90
90
|
* @example
|
|
91
91
|
* 'module/src/main/ets/User.ets' -> '/ets/User.ets'
|
|
92
92
|
*/
|
|
93
|
-
calculateSourceRootToModuleRoot(absolutePath: string): string
|
|
93
|
+
calculateSourceRootToModuleRoot(absolutePath: string): string;
|
|
94
94
|
}
|