diff --git a/compiler/src/ark_utils.ts b/compiler/src/ark_utils.ts index 52bba5f8283c7a51b5caa02468972c8eb80017fd..3adf3e7109f860754ba940109359df31448b3e57 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 fb70f5f0654508bf6d3a613ccc9b41bffab32e4e..4b0fe6851d49f6ce0b34c13cf70bc4017e1f43bb 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;