From dd933bc35e44d18fe0d273c269808756dc3c4da9 Mon Sep 17 00:00:00 2001 From: lixingchi1 Date: Sat, 21 Jun 2025 06:37:21 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!4907=20?= =?UTF-8?q?:=20Modify=20the=20collection=20logic=20of=20entryFile'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- compiler/main.js | 89 ++++--------------- .../src/fast_build/ark_compiler/error_code.ts | 1 - .../ark_compiler/module/module_mode.ts | 3 + 3 files changed, 22 insertions(+), 71 deletions(-) diff --git a/compiler/main.js b/compiler/main.js index 22ad1ae7d..c272569a3 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -32,23 +32,13 @@ const { TEST_RUNNER_DIR_SET, TS2ABC, WORKERS_DIR, - ARKTS_1_2, - EXTNAME_TS + ARKTS_1_2 } = require('./lib/pre_define'); const { checkAotConfig } = require('./lib/gen_aot'); -const { - LogDataFactory -} = require('./lib/fast_build/ark_compiler/logger'); - -const { - ErrorCode, - ArkTSInternalErrorDescription -} = require('./lib/fast_build/ark_compiler/error_code'); - const { configure, getLogger @@ -83,7 +73,6 @@ let sdkConfigPrefix = 'ohos|system|kit|arkts'; let ohosSystemModulePaths = []; let ohosSystemModuleSubDirPaths = []; let allModulesPaths = []; -let entryFileLanguageInfo = new Map(); function initProjectConfig(projectConfig) { initProjectPathConfig(projectConfig); @@ -144,8 +133,6 @@ function initProjectPathConfig(projectConfig) { projectConfig.aceSoPath = projectConfig.aceSoPath || process.env.aceSoPath; projectConfig.localPropertiesPath = projectConfig.localPropertiesPath || process.env.localPropertiesPath; projectConfig.projectProfilePath = projectConfig.projectProfilePath || process.env.projectProfilePath; - // In hybrid compilation, if the entry file is a static file, the path should be convert into under bridgeCodepath one - projectConfig.entryBridgeCodePath = projectConfig.entryBridgeCodePath || process.env.entryBridgeCodePath; } function loadMemoryTrackingConfig(projectConfig) { @@ -500,30 +487,13 @@ function setBundleModuleInfo(projectConfig, moduleJson) { } } -/** - * This file collects root files [entry, ability] for Rollup to bundle. - * - * The ability paths are configured in `aceModuleJson`. - * - In version 1.1, the value is a relative path. - * - In version 1.2, the value is an OHM URL (specific to 1.2). - * - * We need to read these values and populate them into `entryObj`. - * - `entryObj` is an object where: - * - The key should be converted to the relative path format used in version 1.1. - * - The value should be the corresponding absolute file path. - * - For version 1.2 entries, the value should be converted to the corresponding glue code path. - */ - function setAbilityFile(projectConfig, abilityPages) { abilityPages.forEach(abilityPath => { - const isStatic = entryFileLanguageInfo.get(abilityPath) ?? false; - const projectAbilityPath = isStatic ? path.join(projectConfig.entryBridgeCodePath, abilityPath + EXTNAME_TS) : - path.resolve(projectConfig.projectPath, '../', abilityPath); - if (path.isAbsolute(abilityPath) && !isStatic) { + const projectAbilityPath = path.resolve(projectConfig.projectPath, '../', abilityPath); + if (path.isAbsolute(abilityPath)) { abilityPath = '.' + abilityPath.slice(projectConfig.projectPath.length); } - const entryPageKey = isStatic ? transformModuleNameToRelativePath(abilityPath) : - abilityPath.replace(/^\.\/ets\//, './').replace(/\.ts$/, '').replace(/\.ets$/, ''); + const entryPageKey = abilityPath.replace(/^\.\/ets\//, './').replace(/\.ts$/, '').replace(/\.ets$/, ''); if (fs.existsSync(projectAbilityPath)) { abilityConfig.projectAbilityPath.push(projectAbilityPath); projectConfig.entryObj[entryPageKey] = projectAbilityPath + '?entry'; @@ -541,18 +511,15 @@ function readAbilityEntrance(moduleJson) { if (moduleJson.module) { const moduleSrcEntrance = moduleJson.module.srcEntrance; const moduleSrcEntry = moduleJson.module.srcEntry; + // In a mixed compilation project, we only collect entries and abilities for version 1.1. + // When the field is missing or explicitly set to 1.1, the file is treated as a 1.1 file. const isStatic = moduleJson.module?.abilityStageCodeLanguage === ARKTS_1_2; - - if (moduleSrcEntry) { + if (moduleSrcEntry && !isStatic) { abilityPages.push(moduleSrcEntry); - // abilityPagesFullPath is only for v1.1 - v1.2 files won't be included here - !isStatic && abilityPagesFullPath.add(getAbilityFullPath(projectConfig.projectPath, moduleSrcEntry)); - entryFileLanguageInfo.set(moduleSrcEntry, isStatic); - } else if (moduleSrcEntrance) { + abilityPagesFullPath.add(getAbilityFullPath(projectConfig.projectPath, moduleSrcEntry)); + } else if (moduleSrcEntrance && !isStatic) { abilityPages.push(moduleSrcEntrance); - // abilityPagesFullPath is only for v1.1 - v1.2 files won't be included here - !isStatic && abilityPagesFullPath.add(getAbilityFullPath(projectConfig.projectPath, moduleSrcEntrance)); - entryFileLanguageInfo.set(moduleSrcEntrance, isStatic); + abilityPagesFullPath.add(getAbilityFullPath(projectConfig.projectPath, moduleSrcEntrance)); } if (moduleJson.module.abilities && moduleJson.module.abilities.length > 0) { setEntrance(moduleJson.module.abilities, abilityPages); @@ -564,21 +531,23 @@ function readAbilityEntrance(moduleJson) { } return abilityPages; } - +/** + * In a mixed compilation project, we only collect entries and abilities for version 1.1. + * When the field is missing or explicitly set to 1.1, the file is treated as a 1.1 file. + */ function setEntrance(abilityConfig, abilityPages) { if (abilityConfig && abilityConfig.length > 0) { abilityConfig.forEach(ability => { const isStatic = ability.codeLanguage === ARKTS_1_2; + if (isStatic) { + return; + } if (ability.srcEntry) { - ability.srcEntry = ability.srcEntry.replace(/:[^/]+$/, ''); abilityPages.push(ability.srcEntry); - entryFileLanguageInfo.set(ability.srcEntry, isStatic); - !isStatic && abilityPagesFullPath.add(getAbilityFullPath(projectConfig.projectPath, ability.srcEntry)); + abilityPagesFullPath.add(getAbilityFullPath(projectConfig.projectPath, ability.srcEntry)); } else if (ability.srcEntrance) { - ability.srcEntrance = ability.srcEntrance.replace(/:[^/]+$/, ''); abilityPages.push(ability.srcEntrance); - entryFileLanguageInfo.set(ability.srcEntrance, isStatic); - !isStatic && abilityPagesFullPath.add(getAbilityFullPath(projectConfig.projectPath, ability.srcEntrance)); + abilityPagesFullPath.add(getAbilityFullPath(projectConfig.projectPath, ability.srcEntrance)); } }); } @@ -1230,26 +1199,6 @@ function initMixCompileHar(projectConfig) { } } -function transformModuleNameToRelativePath(moduleName) { - let defaultSourceRoot = 'src/main'; - const normalizedModuleName = moduleName.replace(/\\/g, '/'); - const normalizedRoot = defaultSourceRoot.replace(/\\/g, '/'); - - const rootIndex = normalizedModuleName.indexOf(`/${normalizedRoot}/`); - if (rootIndex === -1) { - const errInfo = LogDataFactory.newInstance( - ErrorCode.ETS2BUNDLE_INTERNAL_WRONG_MODULE_NAME_FROM_ACEMODULEJSON, - ArkTSInternalErrorDescription, - `defaultSourceRoot '${defaultSourceRoot}' not found ` + - `when process moduleName '${moduleName}'` - ); - throw Error(errInfo.toString()); - } - - const relativePath = normalizedModuleName.slice(rootIndex + normalizedRoot.length + 1); - return './' + relativePath; -} - exports.globalProgram = globalProgram; exports.projectConfig = projectConfig; exports.loadEntryObj = loadEntryObj; diff --git a/compiler/src/fast_build/ark_compiler/error_code.ts b/compiler/src/fast_build/ark_compiler/error_code.ts index 6447221fb..ec00bd97b 100644 --- a/compiler/src/fast_build/ark_compiler/error_code.ts +++ b/compiler/src/fast_build/ark_compiler/error_code.ts @@ -46,7 +46,6 @@ export enum ErrorCode { ETS2BUNDLE_INTERNAL_ES2ABC_SUBPROCESS_START_FAILED = '10310021', ETS2BUNDLE_INTERNAL_EXECUTE_ES2ABC_WITH_ASYNC_HANDLER_FAILED = '10310022', ETS2BUNDLE_INTERNAL_FAILED_TO_FIND_GLUD_CODE = '10310023', - ETS2BUNDLE_INTERNAL_WRONG_MODULE_NAME_FROM_ACEMODULEJSON = '10310024', // EXTERNAL ERRORS ETS2BUNDLE_EXTERNAL_FORBIDDEN_IMPORT_ARKTS_FILE = '10311001', diff --git a/compiler/src/fast_build/ark_compiler/module/module_mode.ts b/compiler/src/fast_build/ark_compiler/module/module_mode.ts index 8b37d97b0..6375bcc03 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_mode.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_mode.ts @@ -316,6 +316,9 @@ export class ModuleMode extends CommonMode { prepareForCompilation(rollupObject: Object, parentEvent: Object): void { const eventPrepareForCompilation = createAndStartEvent(parentEvent, 'preparation for compilation'); this.collectModuleFileList(rollupObject, rollupObject.getModuleIds()); + if (rollupObject.share.projectConfig.dependentModuleMap) { + this.writeDeclFilesConfigJson(rollupObject.share.projectConfig.entryPackageName); + } this.removeCacheInfo(rollupObject); stopEvent(eventPrepareForCompilation); } -- Gitee