diff --git a/compiler/main.js b/compiler/main.js index 0357558b6d1551c1f1278894cae139d792240f21..7f293dc7f5979cc7662cdf4c9b8c69e79f5e1f5d 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -699,6 +699,12 @@ function loadModuleInfo(projectConfig, envArgs) { buildJsonInfo.modulePathMap[buildJsonInfo.moduleName]) { projectConfig.moduleRootPath = buildJsonInfo.modulePathMap[buildJsonInfo.moduleName]; } + if (projectConfig.aceModuleJsonPath && fs.existsSync(projectConfig.aceModuleJsonPath)) { + const moduleJsonInfo = JSON.parse(fs.readFileSync(projectConfig.aceModuleJsonPath).toString()); + if (moduleJsonInfo.app.minAPIVersion) { + process.env.minPlatformVersion = moduleJsonInfo.app.minAPIVersion.toString(); + } + } } } diff --git a/compiler/src/fast_build/ark_compiler/common/common_mode.ts b/compiler/src/fast_build/ark_compiler/common/common_mode.ts index 037cc2bbdddc7682c06880b69025c364de291f54..81c733b622f57daa5761a6acba8b92c31c68b25a 100644 --- a/compiler/src/fast_build/ark_compiler/common/common_mode.ts +++ b/compiler/src/fast_build/ark_compiler/common/common_mode.ts @@ -94,6 +94,12 @@ export abstract class CommonMode { this.throwArkTsCompilerError('ArkTS:ERROR please set panda mode'); } + // Compatible api 8 ts2abc is archived and does not support target-api-version option + if (this.projectConfig.minPlatformVersion && this.projectConfig.minPlatformVersion !== '8') { + args.push('--target-api-version'); + args.push(this.projectConfig.minPlatformVersion); + } + return args; } diff --git a/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts b/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts index 25c657af3e537a0f1a5fa22e451239ed2d87c0c4..b8313b7a608d46cbcc0f1b5b9c5252a723680970 100644 --- a/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts +++ b/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts @@ -101,16 +101,20 @@ export function initArkProjectConfig(share: any) { projectConfig.packageDir = buildJsonInfo.packageManagerType === 'ohpm' ? OH_MODULES : NODE_MODULES; } } + + // For FA mode, minPlatformVersion is stored in manifest.json if (projectConfig.aceManifestPath && fs.existsSync(projectConfig.aceManifestPath)) { const manifestJsonInfo = JSON.parse(fs.readFileSync(projectConfig.aceManifestPath).toString()); if (manifestJsonInfo.minPlatformVersion) { - arkProjectConfig.minPlatformVersion = manifestJsonInfo.minPlatformVersion; + arkProjectConfig.minPlatformVersion = manifestJsonInfo.minPlatformVersion.toString(); } } + + // For Stage mode, minPlatformVersion is stored in module.json if (projectConfig.aceModuleJsonPath && fs.existsSync(projectConfig.aceModuleJsonPath)) { const moduleJsonInfo = JSON.parse(fs.readFileSync(projectConfig.aceModuleJsonPath).toString()); if (moduleJsonInfo.app.minAPIVersion) { - arkProjectConfig.minPlatformVersion = moduleJsonInfo.app.minAPIVersion; + arkProjectConfig.minPlatformVersion = moduleJsonInfo.app.minAPIVersion.toString(); } if (moduleJsonInfo.module) { arkProjectConfig.moduleName = moduleJsonInfo.module.name; diff --git a/compiler/src/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index fdb06737fe4c300eb1496543468fde6dea73f84c..016525d284002f9cf3956ccf52874c1d9890c72b 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -764,9 +764,14 @@ export function initAbcEnv() : string[] { if (projectConfig.compileMode === ESMODULE) { args.push('--merge-abc'); } - } else { + } else { logger.error(red, `ArkTS:ERROR please set panda module`, reset); } + if (process.env.minPlatformVersion && process.env.minPlatformVersion !== 'undefined' && + process.env.minPlatformVersion !== '8') { + args.push('--target-api-version'); + args.push(process.env.minPlatformVersion); + } return args; }