diff --git a/compiler/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts b/compiler/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts index 124c4ccbb70f82349c4f3fa4751c536186c7741a..3dce63cb831d46ba20bb11c40d61b481f680aad2 100644 --- a/compiler/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts +++ b/compiler/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts @@ -23,6 +23,8 @@ import { import { ArkTSEvolutionModule, BuildType, + CodeInput, + CodeInputParams, DeclFilesConfig, DECLGEN_CACHE_FILE, Params, @@ -34,7 +36,7 @@ import path from 'path'; import * as ts from 'typescript'; import { EXTNAME_D_ETS, EXTNAME_JS } from '../common/ark_define'; import { getRealModulePath } from '../../system_api/api_check_utils'; -import { generateInteropDecls } from 'declgen/build/src/generateInteropDecls'; +import { generateInteropDecls, generateInteropDeclsFromCode } from 'declgen/build/src/generateInteropDecls'; import { calculateFileHash } from '../utils'; import { processInteropUI } from '../../../process_interop_ui'; @@ -47,7 +49,11 @@ export function run(param: Params): boolean { return; } if (task.buildTask === BuildType.DECLGEN) { - DeclfileProductor.getInstance().runDeclgen(moduleInfo); + if (task.codeInputs && task.codeInputs.length > 0) { + DeclfileProductor.getInstance().runDeclgenFromCode(moduleInfo, task.codeInputs); + } else { + DeclfileProductor.getInstance().runDeclgen(moduleInfo); + } } else if (task.buildTask === BuildType.INTEROP_CONTEXT) { DeclfileProductor.getInstance().writeDeclFileInfo(moduleInfo, task.mainModuleName); } else if (task.buildTask === BuildType.BYTE_CODE_HAR) { @@ -172,6 +178,24 @@ class DeclfileProductor { fs.writeFileSync(cachePath, JSON.stringify(newCache, null, 2)); } + runDeclgenFromCode(moduleInfo: ArkTSEvolutionModule, codeInputs: CodeInput[]): void { + const config: CodeInputParams = { + codeInputs: codeInputs, + outDir: moduleInfo.declgenV2OutPath, + rootDir: moduleInfo.modulePath, + customResolveModuleNames: resolveModuleNames, + customCompilerOptions: DeclfileProductor.compilerOptions, + includePaths: [moduleInfo.modulePath] + }; + + if (!fs.existsSync(config.outDir)) { + fs.mkdirSync(config.outDir, { recursive: true }); + } + + generateInteropDeclsFromCode(config); + processInteropUI(FileManager.arkTSModuleMap.get(moduleInfo.packageName)?.declgenV2OutPath); + } + writeDeclFileInfo(moduleInfo: ArkTSEvolutionModule, mainModuleName: string): void { moduleInfo.isNative = moduleInfo.isNative ?? moduleInfo.packageName.endsWith('.so'); moduleInfo.dynamicFiles.forEach(file => { diff --git a/compiler/src/fast_build/ark_compiler/interop/type.ts b/compiler/src/fast_build/ark_compiler/interop/type.ts index 3a3dc2a11c4c1e7e197241e5f46c4bcaa55c8624..491d709bd93787cd2abaf334c74c6519456a74a1 100644 --- a/compiler/src/fast_build/ark_compiler/interop/type.ts +++ b/compiler/src/fast_build/ark_compiler/interop/type.ts @@ -37,6 +37,11 @@ export interface Params { tasks: taskInfo[]; } +export interface CodeInput { + fileName: string; + content: string; +} + export interface ProjectConfig { cachePath: string; bundleName: string; @@ -54,6 +59,7 @@ interface taskInfo { packageName: string; buildTask: BuildType; mainModuleName?: string; + codeInputs?: CodeInput[]; } export interface AliasConfig { @@ -78,6 +84,15 @@ export interface RunnerParms { includePaths?: string[]; } +export interface CodeInputParams { + codeInputs: CodeInput[]; + outDir: string; + rootDir?: string; + customResolveModuleNames?: (moduleName: string[], containingFile: string) => ts.ResolvedModuleFull[]; + customCompilerOptions?: ts.CompilerOptions; + includePaths?: string[]; +} + export interface DeclFilesConfig { packageName: string; files: { diff --git a/compiler/src/interop/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts b/compiler/src/interop/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts index 124c4ccbb70f82349c4f3fa4751c536186c7741a..962b21b04bc778f10f4dc9ac2cb3b890214caed2 100644 --- a/compiler/src/interop/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts +++ b/compiler/src/interop/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts @@ -24,11 +24,11 @@ import { ArkTSEvolutionModule, BuildType, DeclFilesConfig, - DECLGEN_CACHE_FILE, Params, ProjectConfig, RunnerParms } from './type'; +import { DECLGEN_CACHE_FILE } from './pre_define'; import fs from 'fs'; import path from 'path'; import * as ts from 'typescript';