From 61a07099ab8c12a2e5cd53e56b55a8d6344714e1 Mon Sep 17 00:00:00 2001 From: shitao Date: Fri, 6 Jun 2025 00:04:15 +0800 Subject: [PATCH] Check obj not empty Issue: ICCZQ4 Signed-off-by: shitao Change-Id: I1d5a5fa78a66f5f225aec559a9d17287fc794432 --- compiler/src/ark_utils.ts | 3 +- .../module/ohmUrl/ohmUrl.test.ts | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/compiler/src/ark_utils.ts b/compiler/src/ark_utils.ts index 52bba5f82..3adf3e710 100644 --- a/compiler/src/ark_utils.ts +++ b/compiler/src/ark_utils.ts @@ -452,7 +452,8 @@ export function getNormalizedOhmUrlByAliasName(aliasName: string, projectConfig: export function getOhmUrlByByteCodeHar(moduleRequest: string, projectConfig: Object, rollupObject: Object, logger?: Object): string | undefined { - if (projectConfig.byteCodeHarInfo) { + if (projectConfig.useNormalizedOHMUrl && + projectConfig.byteCodeHarInfo && Object.keys(projectConfig.byteCodeHarInfo).length > 0) { const moduleInfoByModuleRequest: Object = rollupObject.share?.importResolver?.(moduleRequest); if (moduleInfoByModuleRequest) { return getNormalizedOhmUrlByModuleRequest(moduleInfoByModuleRequest, projectConfig, logger); diff --git a/compiler/test/ark_compiler_ut/module/ohmUrl/ohmUrl.test.ts b/compiler/test/ark_compiler_ut/module/ohmUrl/ohmUrl.test.ts index fb70f5f06..4b0fe6851 100644 --- a/compiler/test/ark_compiler_ut/module/ohmUrl/ohmUrl.test.ts +++ b/compiler/test/ark_compiler_ut/module/ohmUrl/ohmUrl.test.ts @@ -1323,6 +1323,44 @@ mocha.describe('generate ohmUrl', function () { loggerStub.restore(); }); + mocha.it('the error message of processPackageDir when useNormalizedOHMUrl is false', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = false; + this.rollup.share.projectConfig.byteCodeHarInfo = {}; + const indexFilePath: string = 'Hsp/////'; + const importerFile: string = '/testHap/entry/src/main/ets/pages/index.ets'; + const importByPkgName = 'Hsp/////'; + for (let file of [indexFilePath]) { + const moduleInfo = { + id: file, + meta: { + hostDependencyName: 'Hsp/////', + hostModuleName: 'entry' + } + } + this.rollup.moduleInfos.push(moduleInfo); + } + + const errInfo: LogData = LogDataFactory.newInstance( + ErrorCode.ETS2BUNDLE_EXTERNAL_FAILED_TO_RESOLVE_OHM_URL, + ArkTSErrorDescription, + 'Failed to resolve OhmUrl. ' + + `Failed to get a resolved OhmUrl for "${indexFilePath}" imported by "${importerFile}".`, + '', + [`Check whether the module which ${indexFilePath} belongs to is correctly configured.`, + `Check if the corresponding file name "${indexFilePath}" is correct(including case-sensitivity).`] + ); + const logger = CommonLogger.getInstance(this.rollup); + const loggerStub = sinon.stub(logger.getLoggerFromErrorCode(errInfo.code), 'printError'); + + const moduleSourceFile: string = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); + + expect(loggerStub.getCall(0).calledWithMatch(errInfo)).to.be.true; + loggerStub.restore(); + }); + mocha.it('the error message of getNormalizedOhmUrlByAliasName', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; -- Gitee