diff --git a/incremental/tools/panda/arkts/ui2abc b/incremental/tools/panda/arkts/ui2abc index e9c4652a40e9a132215e64f73331cea104174193..178dd72ad8e6d36efb79177315b1f142eb2ee5c5 100755 --- a/incremental/tools/panda/arkts/ui2abc +++ b/incremental/tools/panda/arkts/ui2abc @@ -14,5 +14,5 @@ # limitations under the License. SCRIPT_DIR=`dirname "${BASH_SOURCE[0]}"` -PANDA_SDK_PATH=${PANDA_SDK_PATH:=$SCRIPT_DIR/../node_modules/@panda/sdk} node $SCRIPT_DIR/../../../../ui2abc/libarkts/lib/es2panda.js "$@" +KOALA_WORKSPACE=1 PANDA_SDK_PATH=${PANDA_SDK_PATH:=$SCRIPT_DIR/../node_modules/@panda/sdk} node $SCRIPT_DIR/../../../../ui2abc/libarkts/lib/es2panda.js "$@" diff --git a/ui2abc/memo-plugin/package.json b/ui2abc/memo-plugin/package.json index c41b7290ba4b169ef73464b5c6925dad0df9d5a0..4c5b816f2abc0a5fe89e01227a3543ef93eebce4 100644 --- a/ui2abc/memo-plugin/package.json +++ b/ui2abc/memo-plugin/package.json @@ -8,7 +8,7 @@ "./lib/**/*" ], "scripts": { - "clean": "rimraf build", + "clean": "rimraf build lib .rollup.cache", "compile": "rollup -c", "runtime:clean": "npm run all:clean --prefix ../../incremental", "runtime:prepare": "npm run build:incremental:inc:ui2abc --prefix ../../incremental/runtime && npm run build:incremental:inc:ui2abc:recheck --prefix ../../incremental/runtime", diff --git a/ui2abc/memo-plugin/src/MemoFactory.ts b/ui2abc/memo-plugin/src/MemoFactory.ts index ca3b6b61347b67391b0556d7c96433e49faaa387..234d8a05aed5991035e610d1542a36143bc36d57 100644 --- a/ui2abc/memo-plugin/src/MemoFactory.ts +++ b/ui2abc/memo-plugin/src/MemoFactory.ts @@ -14,7 +14,7 @@ */ import * as arkts from "@koalaui/libarkts" -import { DebugNames, RuntimeNames, isVoidReturn } from "./utils" +import { DebugNames, RuntimeNames, getRuntimePackage, isVoidReturn } from "./utils" export class factory { // Importing @@ -40,7 +40,7 @@ export class factory { static createContextTypesImportDeclaration(debug: boolean, path?: string): arkts.ETSImportDeclaration { const mandatory = [factory.createContextTypeImportSpecifier(), factory.createIdTypeImportSpecifier()] return arkts.factory.createETSImportDeclaration( - arkts.factory.createStringLiteral(path ?? RuntimeNames.CONTEXT_TYPE_DEFAULT_IMPORT), + arkts.factory.createStringLiteral(path ?? getRuntimePackage()), debug ? [...mandatory, factory.createHashImportSpecifier()] : mandatory, arkts.Es2pandaImportKinds.IMPORT_KINDS_ALL ) diff --git a/ui2abc/memo-plugin/src/utils.ts b/ui2abc/memo-plugin/src/utils.ts index 13e494ceaaaed462b0769e62055b65f005a4f680..829efe4a61236844698de6808702424378dfc66d 100644 --- a/ui2abc/memo-plugin/src/utils.ts +++ b/ui2abc/memo-plugin/src/utils.ts @@ -41,7 +41,6 @@ export enum RuntimeNames { CONTENT = "content", CONTEXT = "__memo_context", CONTEXT_TYPE = "__memo_context_type", - CONTEXT_TYPE_DEFAULT_IMPORT = "@koalaui/runtime", GENSYM = "gensym%%_", HASH = "__hash", ID = "__memo_id", @@ -239,4 +238,16 @@ export function isMemoCall(node: arkts.AstNode): boolean { const decl = getDecl(node.callee) if (!arkts.isMethodDefinition(decl)) return false return isMemo(decl) -} \ No newline at end of file +} + +function isKoalaWorkspace() { + return process.env.KOALA_WORKSPACE == "1" +} + +export function getRuntimePackage(): string { + if (isKoalaWorkspace()) { + return '@koalaui/runtime' + } else { + return 'arkui.stateManagement.runtime' + } +} diff --git a/ui2abc/ui-plugins/package.json b/ui2abc/ui-plugins/package.json index 1650dad8c516c4fd7d4ab954c8b4ca0c9f3ba941..fefd3b386c9919a2d8a92f539904b177e7627b0b 100644 --- a/ui2abc/ui-plugins/package.json +++ b/ui2abc/ui-plugins/package.json @@ -8,7 +8,7 @@ ], "dependencies": {}, "scripts": { - "clean": "rimraf build", + "clean": "rimraf build lib .rollup.cache", "compile": "rollup -c ./rollup.config.mjs", "compile:libarkts": "npm run compile --prefix ../libarkts", "check": "npm run compile && rm -rf ../../arkoala-arkts/trivial/user/build && npm run build --prefix ../../arkoala-arkts/trivial/user", diff --git a/ui2abc/ui-plugins/src/call-transformer.ts b/ui2abc/ui-plugins/src/call-transformer.ts index b87f3aa13a8e318b16eb962be547ce37fb6e4c43..53e4b1641705a0028dafbbd339d6059f2fbcf892 100644 --- a/ui2abc/ui-plugins/src/call-transformer.ts +++ b/ui2abc/ui-plugins/src/call-transformer.ts @@ -15,7 +15,7 @@ import * as arkts from "@koalaui/libarkts" import { ApplicationInfo, ComponentTransformerOptions } from "./component-transformer" -import { Importer } from "./utils" +import { getComponentPackage, Importer } from "./utils" export class CallTransformer extends arkts.AbstractVisitor { @@ -93,7 +93,7 @@ export class CallTransformer extends arkts.AbstractVisitor { const component = this.componentsList.get(name) if (!this.seenComponents.has(name)) { this.seenComponents.add(name) - this.imports.add(component.options ?? `${name}Options`, '@ohos.arkui') + this.imports.add(component.options ?? `${name}Options`, getComponentPackage()) } node = this.visitEachChild(node) as arkts.CallExpression return arkts.factory.createCallExpression(node.callee, diff --git a/ui2abc/ui-plugins/src/class-transformer.ts b/ui2abc/ui-plugins/src/class-transformer.ts index 9338bbf3fba1ce6302467b698beb5bcec92ccf60..f5878e92c3c7ab12de1b4d676b1900a6eab1662c 100644 --- a/ui2abc/ui-plugins/src/class-transformer.ts +++ b/ui2abc/ui-plugins/src/class-transformer.ts @@ -16,7 +16,7 @@ import * as arkts from "@koalaui/libarkts" import { classProperties, mangle } from "./common/arkts-utils" -import { createETSTypeReference, CustomComponentNames, Importer } from "./utils" +import { createETSTypeReference, CustomComponentNames, getCompatPackage, getComponentPackage, Importer } from "./utils" import { DecoratorNames, hasDecorator, isDecoratorAnnotation } from "./property-translators/utils"; import { fieldOf } from "./property-transformers"; @@ -30,7 +30,7 @@ export class ClassTransformer extends arkts.AbstractVisitor { const program = (node as arkts.ETSModule).program if (program && (!program.modulePrefix - || (!program.modulePrefix.startsWith(CustomComponentNames.COMPONENT_DEFAULT_IMPORT) + || (!program.modulePrefix.startsWith(getComponentPackage()) && !program.modulePrefix.startsWith("@koalaui")))) { return this.visitEachChild(node) } @@ -49,15 +49,15 @@ export class ClassTransformer extends arkts.AbstractVisitor { ...clazz.definition?.implements ?? [], ] if (isObserved) { - this.importer.add('observableProxy', '@koalaui/compat') - this.importer.add('ObservableClass', '@koalaui/compat') + this.importer.add('observableProxy', getCompatPackage()) + this.importer.add('ObservableClass', getCompatPackage()) classImplements.push(arkts.factory.createTSClassImplements( createETSTypeReference("ObservableClass")) ) } if (properties.length > 0 || isObserved) { if (properties.find(trackPropVerifier)) { - this.importer.add('TrackableProps', '@koalaui/compat') + this.importer.add('TrackableProps', getCompatPackage()) classImplements.push(arkts.factory.createTSClassImplements( createETSTypeReference("TrackableProps")) ) diff --git a/ui2abc/ui-plugins/src/component-transformer.ts b/ui2abc/ui-plugins/src/component-transformer.ts index 4c81e5b14dfb462684f021acf532466d2d107a51..a8498871ace73febe065b237eee3e6ed5b633870 100644 --- a/ui2abc/ui-plugins/src/component-transformer.ts +++ b/ui2abc/ui-plugins/src/component-transformer.ts @@ -16,9 +16,14 @@ import * as arkts from "@koalaui/libarkts" import { CustomComponentNames, + getBuilderLambdaString, + getCustomComponentPackage, getCustomComponentOptionsName, Importer, - InternalAnnotations + InternalAnnotations, + getComponentPackage, + getRuntimeAnnotationsPackage, + getDecoratorPackage } from "./utils"; import { BuilderParamTransformer, ConsumeTransformer, LinkTransformer, LocalStorageLinkTransformer, LocalStoragePropTransformer, ObjectLinkTransformer, PropertyTransformer, PropTransformer, ProvideTransformer, StateTransformer, StorageLinkTransformer, StoragePropTransformer, PlainPropertyTransformer, fieldOf, isOptionBackedByProperty, isOptionBackedByPropertyName } from "./property-transformers"; import { annotation, isAnnotation, classMethods } from "./common/arkts-utils"; @@ -54,16 +59,16 @@ export class ComponentTransformer extends arkts.AbstractVisitor { let result: arkts.Statement[] = [] this.parseEntryParameter(statements) this.imports.add( - CustomComponentNames.COMPONENT_CLASS_NAME, - CustomComponentNames.COMPONENT_DEFAULT_IMPORT) + getCustomComponentPackage(), + getComponentPackage()) this.imports.add( InternalAnnotations.BUILDER_LAMBDA, - CustomComponentNames.COMPONENT_DEFAULT_IMPORT) + getDecoratorPackage()) this.imports.add( "CommonMethod", - CustomComponentNames.COMPONENT_DEFAULT_IMPORT) - this.imports.add(InternalAnnotations.MEMO, "@koalaui/runtime/annotations") - this.imports.add(InternalAnnotations.MEMO_STABLE, "@koalaui/runtime/annotations") + getComponentPackage()) + this.imports.add(InternalAnnotations.MEMO, getRuntimeAnnotationsPackage()) + this.imports.add(InternalAnnotations.MEMO_STABLE, getRuntimeAnnotationsPackage()) this.propertyTransformers.forEach(it => it.collectImports(this.imports)) statements.forEach(statement => { if (arkts.isETSStructDeclaration(statement)) { @@ -118,7 +123,7 @@ export class ComponentTransformer extends arkts.AbstractVisitor { undefined, arkts.factory.createETSTypeReference( arkts.factory.createETSTypeReferencePart( - arkts.factory.createIdentifier(CustomComponentNames.COMPONENT_CLASS_NAME, undefined), + arkts.factory.createIdentifier(getCustomComponentPackage(), undefined), arkts.factory.createTSTypeParameterInstantiation( [ arkts.factory.createETSTypeReference( @@ -354,7 +359,7 @@ export class ComponentTransformer extends arkts.AbstractVisitor { [ arkts.factory.createClassProperty( arkts.factory.createIdentifier("value"), - arkts.factory.createStringLiteral("StructBase.instantiateImpl"), + arkts.factory.createStringLiteral(getBuilderLambdaString()), undefined, arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_NONE, false diff --git a/ui2abc/ui-plugins/src/property-transformers.ts b/ui2abc/ui-plugins/src/property-transformers.ts index a47e27815805c9aadf62b7d58e9313f9a50e8b0f..735e59d31ff81516b93300aee79d98685596596f 100644 --- a/ui2abc/ui-plugins/src/property-transformers.ts +++ b/ui2abc/ui-plugins/src/property-transformers.ts @@ -17,7 +17,7 @@ import * as arkts from "@koalaui/libarkts" import { Es2pandaTokenType } from "@koalaui/libarkts" import { DecoratorNames, DecoratorParameters, hasDecorator } from "./property-translators/utils" -import { CustomComponentNames, Importer, ImportingTransformer, InternalAnnotations } from "./utils" +import { CustomComponentNames, getComponentPackage, getDecoratorPackage, getRuntimePackage, Importer, ImportingTransformer, InternalAnnotations } from "./utils" import { annotation, classMethods, isAnnotation } from "./common/arkts-utils" export interface PropertyTransformer extends ImportingTransformer { @@ -337,7 +337,7 @@ export abstract class PropertyTransformerBase implements PropertyTransformer { return hasDecorator(property, this.decoratorName) } collectImports(importer: Importer): void { - importer.add(this.className, "@ohos.arkui") + importer.add(this.className, getComponentPackage()) } applyOptions(property: arkts.ClassProperty, result: arkts.ClassElement[]): void { } @@ -374,7 +374,7 @@ export class PlainPropertyTransformer implements PropertyTransformer { return property.annotations.length == 0 } collectImports(imports: Importer): void { - imports.add("PlainStructProperty", "@ohos.arkui") + imports.add("PlainStructProperty", getDecoratorPackage()) } applyOptions(property: arkts.ClassProperty, result: arkts.ClassElement[]): void { result.push(createOptionalClassProperty(property.id!.name, property)) @@ -415,8 +415,8 @@ export class LinkTransformer extends PropertyTransformerBase { addPropertyRecordTo(result, property) } collectImports(imports: Importer): void { - imports.add("SubscribedAbstractProperty", "@ohos.arkui") - imports.add("LinkDecoratorProperty", "@ohos.arkui") + imports.add("SubscribedAbstractProperty", getDecoratorPackage()) + imports.add("LinkDecoratorProperty", getDecoratorPackage()) } } @@ -579,7 +579,7 @@ export class ProvideTransformer extends PropertyTransformerBase { } collectImports(imports: Importer): void { super.collectImports(imports) - imports.add("once", "@koalaui/runtime") + imports.add("once", getRuntimePackage()) } } diff --git a/ui2abc/ui-plugins/src/struct-recorder.ts b/ui2abc/ui-plugins/src/struct-recorder.ts index bbc6c9084aadc22274fee5cadde70d8a00e2d16c..fd6dcb0bc601946bca31053f74432537013a3510 100644 --- a/ui2abc/ui-plugins/src/struct-recorder.ts +++ b/ui2abc/ui-plugins/src/struct-recorder.ts @@ -67,6 +67,7 @@ export class StructsResolver { if (name.startsWith("escompat")) continue if (name.startsWith("@ohos.arkui")) continue if (name.startsWith("@koalaui")) continue + if (name.startsWith("arkui.stateManagement")) continue let program = source.programs[0] let table = this.getOrCreateTable(program.sourceFilePath, this.restart) diff --git a/ui2abc/ui-plugins/src/utils.ts b/ui2abc/ui-plugins/src/utils.ts index 3101895b58354b195ff3730bcb91ac1c0ab2d404..fa2e661b3745a62d1dc9f2386239e913b924ecd7 100644 --- a/ui2abc/ui-plugins/src/utils.ts +++ b/ui2abc/ui-plugins/src/utils.ts @@ -24,8 +24,6 @@ export function mangle(value: string): string { export enum CustomComponentNames { COMPONENT_BUILD_ORI = 'build', COMPONENT_CONSTRUCTOR_ORI = 'constructor', - COMPONENT_DEFAULT_IMPORT = '@ohos.arkui', - COMPONENT_CLASS_NAME = 'StructBase', COMPONENT_INTERFACE_PREFIX = '__Options_', COMPONENT_DISPOSE_STRUCT = '__disposeStruct', COMPONENT_INITIALIZE_STRUCT = '__initializeStruct', @@ -56,6 +54,70 @@ export enum InternalAnnotations { BUILDER_LAMBDA = 'BuilderLambda' } +function isKoalaWorkspace() { + return process.env.KOALA_WORKSPACE == "1" +} + +/** + * TODO: migrate imports to runtime + * @deprecated + */ +export function getCompatPackage(): string { + if (isKoalaWorkspace()) { + return '@koalaui/compat' + } else { + return 'arkui.stateManagement.runtime' + } +} + +export function getRuntimePackage(): string { + if (isKoalaWorkspace()) { + return '@koalaui/runtime' + } else { + return 'arkui.stateManagement.runtime' + } +} + +export function getRuntimeAnnotationsPackage(): string { + if (isKoalaWorkspace()) { + return '@koalaui/runtime/annotations' + } else { + return 'arkui.stateManagement.runtime' + } +} + +export function getDecoratorPackage(): string { + if (isKoalaWorkspace()) { + return '@ohos.arkui' + } else { + return 'arkui.stateManagement.decorator' + } +} + +export function getComponentPackage(): string { + if (isKoalaWorkspace()) { + return '@ohos.arkui' + } else { + return '@ohos.arkui.component' + } +} + +export function getCustomComponentPackage(): string { + if (isKoalaWorkspace()) { + return 'StructBase' + } else { + return 'CustomComponent' + } +} + +export function getBuilderLambdaString(): string { + if (isKoalaWorkspace()) { + return 'StructBase.instantiateImpl' + } else { + return 'CustomComponent._instantiateImpl' + } +} + export function uiAttributeName(componentName: string): string { return `${componentName}Attribute` } @@ -163,7 +225,7 @@ export class Importer { private defaultArkUIImports2 = [ 'TestComponentOptions' ] constructor() { - const withDefaultImports = true + const withDefaultImports = isKoalaWorkspace() ? true : false if (withDefaultImports) { this.defaultArkUIImports2.forEach(it => { this.add(it, '@ohos.arkui')