From dac83e3ce522606a3b35962d2801c1c37b132421 Mon Sep 17 00:00:00 2001 From: ah Date: Tue, 20 May 2025 11:42:35 +0800 Subject: [PATCH] Fix the ohmurlbymoduleRequest Issue: https://gitee.com/openharmony/developtools_ace_ets2bundle/issues/ICB4M5 Signed-off-by: ah --- compiler/src/ark_utils.ts | 40 +++++++-- .../ark_compiler/module/module_mode.ts | 12 +-- .../ark_compiler/module/module_source_file.ts | 14 ++-- .../ark_compiler_ut/mock/rollup_mock/share.ts | 21 +++++ .../module/ohmUrl/ohmUrl.test.ts | 81 +++++++++++++++---- 5 files changed, 133 insertions(+), 35 deletions(-) diff --git a/compiler/src/ark_utils.ts b/compiler/src/ark_utils.ts index 70674432f..3c3f06155 100644 --- a/compiler/src/ark_utils.ts +++ b/compiler/src/ark_utils.ts @@ -130,7 +130,7 @@ export function getNormalizedOhmUrlByFilepath(filePath: string, projectConfig: O 'Failed to resolve OhmUrl. ' + `Failed to get a resolved OhmUrl for "${filePath}" imported by "${importerFile}".`, '', - [`Check whether the "${pkgName}" module which ${filePath} belongs to is correctly configured.`, + [`Check whether the "${pkgName}" module which ${filePath} belongs to is correctly configured.`, 'Check the corresponding file name is correct(including case-sensitivity).'] ); logger.printError(errInfo); @@ -230,7 +230,7 @@ function processPackageDir(params: Object): string { 'Failed to resolve OhmUrl. ' + `Failed to get a resolved OhmUrl for "${originalFilePath}" imported by "${importerFile}".`, '', - [`Check whether the module which ${originalFilePath} belongs to is correctly configured.`, + [`Check whether the module which ${originalFilePath} belongs to is correctly configured.`, 'Check the corresponding file name is correct(including case-sensitivity).'] ); logger.printError(errInfo); @@ -269,7 +269,7 @@ function processPackageDir(params: Object): string { 'Failed to resolve OhmUrl. ' + `Failed to get a resolved OhmUrl for "${originalFilePath}" imported by "${importerFile}".`, '', - [`Check whether the module which ${originalFilePath} belongs to is correctly configured.`, + [`Check whether the module which ${originalFilePath} belongs to is correctly configured.`, 'Check the corresponding file name is correct(including case-sensitivity).'] ); logger.printError(errInfo); @@ -306,7 +306,7 @@ export function getOhmUrlBySystemApiOrLibRequest(moduleRequest: string, config?: if (REG_LIB_SO.test(moduleRequest.trim())) { if (useNormalizedOHMUrl) { const pkgInfo = config.pkgContextInfo[moduleRequest]; - if (pkgInfo === undefined) { + if (!pkgInfo) { const errInfo: LogData = LogDataFactory.newInstance( ErrorCode.ETS2BUNDLE_INTERNAL_UNABLE_TO_GET_PKG_CONTENT_INFO, ArkTSInternalErrorDescription, @@ -314,6 +314,7 @@ export function getOhmUrlBySystemApiOrLibRequest(moduleRequest: string, config?: `which being imported by '${importerFile}'` ); logger?.printError(errInfo); + return moduleRequest; } const isSo = pkgInfo.isSO ? 'Y' : 'N'; return `@normalized:${isSo}&${pkgInfo.moduleName}&${pkgInfo.bundleName}&${moduleRequest}&${pkgInfo.version}`; @@ -392,6 +393,25 @@ function removeSuffix(filePath: string): string { return filePath.split(path.sep).join('/').replace(SUFFIX_REG, ''); } +export function getNormalizedOhmUrlByModuleRequest(moduleInfoByModuleRequest: Object, projectConfig: Object, + logger?: Object): string { + const normalizedPath = moduleInfoByModuleRequest.normalizedPath; + const pkgName = moduleInfoByModuleRequest.packageName; + const pkgInfo: Object = projectConfig.pkgContextInfo[pkgName]; + if (!normalizedPath || !pkgName || !pkgInfo) { + const errInfo: LogData = LogDataFactory.newInstance( + ErrorCode.ETS2BUNDLE_INTERNAL_PACKAGE_NOT_FOUND_IN_CONTEXT_INFO, + ArkTSInternalErrorDescription, + `Failed to find package '${pkgName}'. ` + + `Failed to obtain package '${pkgName}' from the package context information.` + ); + logger?.printError(errInfo); + return normalizedPath; + } + const isSo = pkgInfo.isSO ? 'Y' : 'N'; + return `@normalized:${isSo}&${pkgInfo.moduleName}&${pkgInfo.bundleName}&${toUnixPath(normalizedPath)}&${pkgInfo.version}`; +} + export function getNormalizedOhmUrlByAliasName(aliasName: string, projectConfig: Object, logger?: Object, filePath?: string): string { let pkgName: string = aliasName; @@ -430,9 +450,13 @@ export function getNormalizedOhmUrlByAliasName(aliasName: string, projectConfig: return `@normalized:${isSo}&${pkgInfo.moduleName}&${pkgInfo.bundleName}&${normalizedPath}&${pkgInfo.version}`; } -export function getOhmUrlByByteCodeHar(moduleRequest: string, projectConfig: Object, logger?: Object): +export function getOhmUrlByByteCodeHar(moduleRequest: string, projectConfig: Object, rollupObject: Object, logger?: Object): string | undefined { if (projectConfig.byteCodeHarInfo) { + const moduleInfoByModuleRequest: Object = rollupObject.share?.importResolver?.(moduleRequest); + if (moduleInfoByModuleRequest) { + return getNormalizedOhmUrlByModuleRequest(moduleInfoByModuleRequest, projectConfig, logger); + } let aliasName: string = getAliasNameFromPackageMap(projectConfig.byteCodeHarInfo, moduleRequest); if (aliasName) { return getNormalizedOhmUrlByAliasName(aliasName, projectConfig, logger); @@ -467,11 +491,15 @@ function getAliasNameFromPackageMap(externalPkgMap: Object, moduleRequest: strin return undefined; } -export function getOhmUrlByExternalPackage(moduleRequest: string, projectConfig: Object, logger?: Object, +export function getOhmUrlByExternalPackage(moduleRequest: string, projectConfig: Object, rollupObject?: Object, logger?: Object, useNormalizedOHMUrl: boolean = false): string | undefined { // The externalPkgMap store the ohmurl with the alias of hsp package and the hars depended on bytecode har. let externalPkgMap: Object = Object.assign({}, projectConfig.hspNameOhmMap, projectConfig.harNameOhmMap); if (Object.keys(externalPkgMap).length !== 0) { + const moduleInfoByModuleRequest: Object = rollupObject?.share?.importResolver?.(moduleRequest); + if (useNormalizedOHMUrl && moduleInfoByModuleRequest) { + return getNormalizedOhmUrlByModuleRequest(moduleInfoByModuleRequest, projectConfig, logger); + } let aliasName: string = getAliasNameFromPackageMap(externalPkgMap, moduleRequest); if (aliasName) { if (useNormalizedOHMUrl) { 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 74ad9cb65..b6b99b690 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_mode.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_mode.ts @@ -106,7 +106,7 @@ import { import { SourceMapGenerator } from '../generate_sourcemap'; import { MemoryMonitor } from '../../meomry_monitor/rollup-plugin-memory-monitor'; import { MemoryDefine } from '../../meomry_monitor/memory_define'; -import { +import { ArkTSInternalErrorDescription, ArkTSErrorDescription, ErrorCode @@ -224,7 +224,7 @@ export class ModuleMode extends CommonMode { const errInfo: LogData = LogDataFactory.newInstance( ErrorCode.ETS2BUNDLE_INTERNAL_MODULE_INFO_NOT_FOUND, ArkTSInternalErrorDescription, - 'Failed to find module info. ' + + 'Failed to find module info. ' + `Failed to find module info with '${moduleId}' from the context information.` ); this.logger.printErrorAndExit(errInfo); @@ -234,7 +234,7 @@ export class ModuleMode extends CommonMode { const errInfo: LogData = LogDataFactory.newInstance( ErrorCode.ETS2BUNDLE_INTERNAL_META_INFO_NOT_FOUND, ArkTSInternalErrorDescription, - 'Failed to find meta info. ' + + 'Failed to find meta info. ' + `Failed to find meta info with '${moduleId}' from the module info.` ); this.logger.printErrorAndExit(errInfo); @@ -347,7 +347,7 @@ export class ModuleMode extends CommonMode { this.updatePkgEntryInfos(pkgEntryInfos, pkgName, ohmurl); continue; } - let hspOhmurl: string | undefined = getOhmUrlByExternalPackage(pkgName, this.projectConfig, this.logger, + let hspOhmurl: string | undefined = getOhmUrlByExternalPackage(pkgName, this.projectConfig, undefined, this.logger, this.useNormalizedOHMUrl); if (hspOhmurl !== undefined) { hspOhmurl = hspOhmurl.replace(/^@(\w+):(.*)/, '@$1.$2'); @@ -626,7 +626,7 @@ export class ModuleMode extends CommonMode { // Generate cache file path for bytecode har private genAbcCacheFilePath(abcPath: string): string { /** - * The projectTopDir is the path of the main project, the projectRootPath is the project path to which it belongs, + * The projectTopDir is the path of the main project, the projectRootPath is the project path to which it belongs, * and the path of bytecode har is within the main project. Therefore, the projectTopDir is used to intercept the * relative path of bytecodehar. */ @@ -950,7 +950,7 @@ export class ModuleMode extends CommonMode { const errInfo: LogData = LogDataFactory.newInstance( ErrorCode.ETS2BUNDLE_INTERNAL_INVALID_COMPILE_MODE, ArkTSInternalErrorDescription, - 'Invalid compilation mode. ' + + 'Invalid compilation mode. ' + `ProjectConfig.pandaMode should be either ${TS2ABC} or ${ES2ABC}.` ); this.logger.printErrorAndExit(errInfo); diff --git a/compiler/src/fast_build/ark_compiler/module/module_source_file.ts b/compiler/src/fast_build/ark_compiler/module/module_source_file.ts index c6b75a9d6..9d57484c1 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_source_file.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_source_file.ts @@ -67,12 +67,12 @@ import { } from 'arkguard'; import { MemoryMonitor } from '../../meomry_monitor/rollup-plugin-memory-monitor'; import { MemoryDefine } from '../../meomry_monitor/memory_define'; -import { +import { CommonLogger, LogData, LogDataFactory } from '../logger'; -import { +import { ArkTSInternalErrorDescription, ErrorCode } from '../error_code'; @@ -161,7 +161,7 @@ export class ModuleSourceFile { if (!!rollupObject.share.projectConfig.useNormalizedOHMUrl) { useNormalizedOHMUrl = rollupObject.share.projectConfig.useNormalizedOHMUrl; } - let transformedMockTarget: string | undefined = getOhmUrlByExternalPackage(originKey, ModuleSourceFile.projectConfig, + let transformedMockTarget: string | undefined = getOhmUrlByExternalPackage(originKey, ModuleSourceFile.projectConfig, rollupObject, ModuleSourceFile.logger, useNormalizedOHMUrl); if (transformedMockTarget !== undefined) { ModuleSourceFile.addMockConfig(ModuleSourceFile.transformedHarOrHspMockConfigInfo, transformedMockTarget, src); @@ -332,7 +332,7 @@ export class ModuleSourceFile { } ModuleSourceFile.isEnvInitialized = true; } - + if (ModuleSourceFile.moduleIdMap.has(moduleId)) { let moduleSourceFile = ModuleSourceFile.moduleIdMap.get(moduleId); ModuleSourceFile.moduleIdMap.delete(moduleId); @@ -351,7 +351,7 @@ export class ModuleSourceFile { await moduleSourceFile.writeSourceFile(eventWriteSourceFile); stopEvent(eventWriteSourceFile); } - } + } static async processModuleSourceFiles(rollupObject: Object, parentEvent: Object): Promise { this.initPluginEnv(rollupObject); @@ -434,14 +434,14 @@ export class ModuleSourceFile { return systemOrLibOhmUrl; } const externalPkgOhmurl: string | undefined = getOhmUrlByExternalPackage(moduleRequest, - ModuleSourceFile.projectConfig, ModuleSourceFile.logger, useNormalizedOHMUrl); + ModuleSourceFile.projectConfig, rollupObject, ModuleSourceFile.logger, useNormalizedOHMUrl); if (externalPkgOhmurl !== undefined) { if (ModuleSourceFile.needProcessMock) { ModuleSourceFile.generateNewMockInfo(moduleRequest, externalPkgOhmurl, rollupObject, importerFile); } return externalPkgOhmurl; } - const byteCodeHarOhmurl: string | undefined = getOhmUrlByByteCodeHar(moduleRequest, ModuleSourceFile.projectConfig, + const byteCodeHarOhmurl: string | undefined = getOhmUrlByByteCodeHar(moduleRequest, ModuleSourceFile.projectConfig, rollupObject, ModuleSourceFile.logger); if (byteCodeHarOhmurl !== undefined) { if (ModuleSourceFile.needProcessMock) { diff --git a/compiler/test/ark_compiler_ut/mock/rollup_mock/share.ts b/compiler/test/ark_compiler_ut/mock/rollup_mock/share.ts index b46b194f9..308633119 100644 --- a/compiler/test/ark_compiler_ut/mock/rollup_mock/share.ts +++ b/compiler/test/ark_compiler_ut/mock/rollup_mock/share.ts @@ -183,6 +183,27 @@ class Share { return logger; } + public importResolver (moduleRequest: string): Object | undefined { + if (moduleRequest === "@ohos/library////\\\\/") { + return { + normalizedPath: "@ohos/library/Index", + packageName: "@ohos/library" + } + } + if (moduleRequest === "@ohos/library/src/main/ets////") { + return { + normalizedPath: "@ohos/library/src/main/ets/Index", + packageName: "@ohos/library" + } + } + if (moduleRequest === "bytecode_alias_oh///\\\/") { + return { + normalizedPath: "bytecode_alias_oh/Index", + packageName: "bytecode_alias_oh" + } + } + return undefined; + } public scan(testcase: string) { if (!testcase) { return; 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 7f09e32a6..2e6514a7e 100644 --- a/compiler/test/ark_compiler_ut/module/ohmUrl/ohmUrl.test.ts +++ b/compiler/test/ark_compiler_ut/module/ohmUrl/ohmUrl.test.ts @@ -22,7 +22,8 @@ import { getOhmUrlByExternalPackage, getOhmUrlBySystemApiOrLibRequest, getNormalizedOhmUrlByFilepath, - getNormalizedOhmUrlByAliasName + getNormalizedOhmUrlByAliasName, + getNormalizedOhmUrlByModuleRequest } from '../../../../lib/ark_utils'; import { PACKAGES } from '../../../../lib/pre_define'; import projectConfig from '../../utils/processProjectConfig'; @@ -118,22 +119,32 @@ mocha.describe('generate ohmUrl', function () { }); mocha.it('shared library', function () { + this.rollup.build(); const sharedLibraryPackageName: string = "@ohos/sharedLibrary"; const sharedLibraryPackageNameSlashes: string = "@ohos/library///"; const sharedLibraryPage: string = "@ohos/sharedLibrary/src/main/ets/pages/page1"; const errorSharedLibrary: string = "@ohos/staticLibrary"; - const sharedLibraryPackageNameOhmUrl: string = getOhmUrlByExternalPackage(sharedLibraryPackageName, projectConfig); - const sharedLibraryPackageNameSlashesOhmUrl: string = getOhmUrlByExternalPackage(sharedLibraryPackageNameSlashes, projectConfig, ModuleSourceFile.logger, true); - const sharedLibraryPageOhmUrl: string = getOhmUrlByExternalPackage(sharedLibraryPage, projectConfig); - const errorSharedLibraryOhmUrl = getOhmUrlByExternalPackage(errorSharedLibrary, projectConfig); + const sharedLibraryModuleRequest = "@ohos/library////\\\\/"; + const sharedLibraryModuleRequestByPath = "@ohos/library/src/main/ets////"; + const sharedLibraryPackageNameOhmUrl: string = getOhmUrlByExternalPackage(sharedLibraryPackageName, projectConfig, this.rollup); + const sharedLibraryPackageNameSlashesOhmUrl: string = getOhmUrlByExternalPackage(sharedLibraryPackageNameSlashes, projectConfig, this.rollup, ModuleSourceFile.logger, true); + const sharedLibraryPageOhmUrl: string = getOhmUrlByExternalPackage(sharedLibraryPage, projectConfig, this.rollup); + const errorSharedLibraryOhmUrl = getOhmUrlByExternalPackage(errorSharedLibrary, projectConfig, this.rollup); + const sharedLibraryModuleRequestOhmUrl = getOhmUrlByExternalPackage(sharedLibraryModuleRequest, projectConfig, this.rollup, ModuleSourceFile.logger, true); + const sharedLibraryModuleRequestByPathOhmUrl = getOhmUrlByExternalPackage(sharedLibraryModuleRequestByPath, projectConfig, this.rollup, ModuleSourceFile.logger, true); const expectedSharedLibraryOhmUrl: string = "@bundle:UtTestApplication/sharedLibrary/ets/index"; const expectedSharedLibrarySlashesOhmUrl: string = "@normalized:N&&&@ohos/library/Index&1.0.0"; const expectedSharedLibraryPageOhmUrl: string = "@bundle:UtTestApplication/sharedLibrary/ets/pages/page1"; const expectedErrorSharedLibraryOhmUrl = undefined; + const expectsharedLibraryModuleRequestOhmUrl = "@normalized:N&&&@ohos/library/Index&1.0.0"; + const expectsharedLibraryModuleRequestByPathOhmUrl = "@normalized:N&&&@ohos/library/src/main/ets/Index&1.0.0"; expect(sharedLibraryPackageNameOhmUrl == expectedSharedLibraryOhmUrl).to.be.true; expect(sharedLibraryPackageNameSlashesOhmUrl == expectedSharedLibrarySlashesOhmUrl).to.be.true; expect(sharedLibraryPageOhmUrl == expectedSharedLibraryPageOhmUrl).to.be.true; expect(errorSharedLibraryOhmUrl == expectedErrorSharedLibraryOhmUrl).to.be.true; + expect(sharedLibraryModuleRequestOhmUrl == expectsharedLibraryModuleRequestOhmUrl).to.be.true; + expect(sharedLibraryModuleRequestByPathOhmUrl == expectsharedLibraryModuleRequestByPathOhmUrl).to.be.true; + }); mocha.it('project module', function () { @@ -237,7 +248,7 @@ mocha.describe('generate ohmUrl', function () { 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 ' + + 'Failed to resolve OhmUrl. Failed to get a resolved OhmUrl for ' + '"/testProjectRootPath/entry/oh_modules/json5/dist/index.js" imported by "importTest.ts".', '', ['Check whether the module which /testProjectRootPath/entry/oh_modules/json5/dist/index.js belongs to is correctly configured.', @@ -261,7 +272,7 @@ mocha.describe('generate ohmUrl', function () { 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 ' + + 'Failed to resolve OhmUrl. Failed to get a resolved OhmUrl for ' + '"/testProjectRootPath/entry/oh_modules/json5/dist/index.js" imported by "importTest.ts".', '', ['Check whether the module which /testProjectRootPath/entry/oh_modules/json5/dist/index.js belongs to is correctly configured.', @@ -495,7 +506,7 @@ mocha.describe('generate ohmUrl', function () { const etsBasedAbsolutePath: string = 'ets/utils/Calc'; const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc'; const moduleSourceFile: string = new ModuleSourceFile(); - ModuleSourceFile.initPluginEnv(this.rollup); + ModuleSourceFile.initPluginEnv(this.rollup); const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, importerFile); @@ -573,7 +584,7 @@ mocha.describe('generate ohmUrl', function () { const etsBasedAbsolutePath: string = 'ets/utils/Calc'; const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc'; const moduleSourceFile: string = new ModuleSourceFile(); - ModuleSourceFile.initPluginEnv(this.rollup); + ModuleSourceFile.initPluginEnv(this.rollup); const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, importerFile); @@ -652,7 +663,7 @@ mocha.describe('generate ohmUrl', function () { const etsBasedAbsolutePath: string = 'ets/utils/Calc'; const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc'; const moduleSourceFile: string = new ModuleSourceFile(); - ModuleSourceFile.initPluginEnv(this.rollup); + ModuleSourceFile.initPluginEnv(this.rollup); const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, importerFile); @@ -730,7 +741,7 @@ mocha.describe('generate ohmUrl', function () { const etsBasedAbsolutePath: string = 'ets/utils/Calc'; const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc'; const moduleSourceFile: string = new ModuleSourceFile(); - ModuleSourceFile.initPluginEnv(this.rollup); + ModuleSourceFile.initPluginEnv(this.rollup); const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, importerFile); @@ -1113,7 +1124,7 @@ mocha.describe('generate ohmUrl', function () { mockConfigPath: `${projectConfig.projectRootPath}/entry/src/mock/mock-config.json5` } this.rollup.share.projectConfig.entryModuleName = 'entry'; - + const importerFile: string = `${projectConfig.projectRootPath}/entry/src/main/ets/pages/index.ets`; const moduleInfo = { id: importerFile, @@ -1124,7 +1135,7 @@ mocha.describe('generate ohmUrl', function () { } } this.rollup.moduleInfos.push(moduleInfo); - + for (let moduleRequest in PRVIEW_MOCK_CONFIG) { let mockPath = PRVIEW_MOCK_CONFIG[moduleRequest] let filePath: string; @@ -1197,13 +1208,14 @@ mocha.describe('generate ohmUrl', function () { } } const filePath: string = 'bytecode_alias/src/main/ets/utils/Calc'; - const indexFilePath: string = 'bytecode_alias'; + const indexFilePath: string = 'bytecode_alias'; const importerFile: string = '/testHap/entry/src/main/ets/pages/index.ets' const importByPkgName = 'bytecode_alias'; const standardImportPath: string = 'bytecode_alias/src/main/ets/utils/Calc'; const importByPkgNameSlashes = 'bytecode_alias///'; const importByPkgNameSlashesOh = 'bytecode_alias_oh///'; + const importModuleRequets = 'bytecode_alias_oh///\\\/' const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); @@ -1211,14 +1223,17 @@ mocha.describe('generate ohmUrl', function () { importerFile); const importByPkgNameOhmUrlSlashes = moduleSourceFile.getOhmUrl(this.rollup, importByPkgNameSlashes, indexFilePath, importerFile); const importByPkgNameOhmUrlSlashesOh = moduleSourceFile.getOhmUrl(this.rollup, importByPkgNameSlashesOh, indexFilePath, importerFile); + const importModuleRequetsOhmUrlSlashesOh = moduleSourceFile.getOhmUrl(this.rollup, importModuleRequets, indexFilePath, importerFile); const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&&bytecode_har/Index&1.0.0'; const standardImportPathNormalizedOhmUrl: string = '@normalized:N&&&bytecode_har/src/main/ets/utils/Calc&1.0.0'; const importByPkgNameNormalizedOhmUrlSlashes: string = '@normalized:N&&&bytecode_har/Index&1.0.0'; const importByPkgNameNormalizedOhmUrlSlashesOh: string = '@normalized:N&&&bytecode_alias_oh/Index&1.0.0'; + const importModuleRequetsNormalizedOhmUrlSlashesOh: string = '@normalized:N&&&bytecode_alias_oh/Index&1.0.0'; expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; expect(importByPkgNameOhmUrlSlashes == importByPkgNameNormalizedOhmUrlSlashes).to.be.true; expect(importByPkgNameOhmUrlSlashesOh == importByPkgNameNormalizedOhmUrlSlashesOh).to.be.true; + expect(importModuleRequetsOhmUrlSlashesOh == importModuleRequetsNormalizedOhmUrlSlashesOh).to.be.true; }); mocha.it('useNormalizedOHMUrl app builtins error message', function () { @@ -1274,6 +1289,40 @@ mocha.describe('generate ohmUrl', function () { loggerStub.restore(); }); + mocha.it('the error message of getNormalizedOhmUrlByModuleRequest', function () { + const moduleInfoByModuleRequest = { + normalizedPath: "bytecode_module/Index", + packageName: "bytecode_module" + }; + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'bytecode_module1': { + 'packageName': 'bytecode_module1', + 'bundleName': '', + 'moduleName': '', + 'version': '1.0.0', + 'entryPath': 'Index.ets', + 'isSO': false + } + } + const errInfo: LogData = LogDataFactory.newInstance( + ErrorCode.ETS2BUNDLE_INTERNAL_PACKAGE_NOT_FOUND_IN_CONTEXT_INFO, + ArkTSInternalErrorDescription, + "Failed to find package 'bytecode_module'. Failed to obtain package 'bytecode_module' " + + "from the package context information." + ); + const logger = CommonLogger.getInstance(this.rollup); + const loggerStub = sinon.stub(logger.getLoggerFromErrorCode(errInfo.code), 'printError'); + try { + delete this.rollup.share.projectConfig.pkgContextInfo['bytecode_module']; + getNormalizedOhmUrlByModuleRequest(moduleInfoByModuleRequest, this.rollup.share.projectConfig, logger); + } catch (e) { + } + 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; @@ -1321,7 +1370,7 @@ mocha.describe('generate ohmUrl', function () { const errInfo1: LogData = LogDataFactory.newInstance( ErrorCode.ETS2BUNDLE_INTERNAL_PACKAGE_NOT_FOUND_IN_CONTEXT_INFO, ArkTSInternalErrorDescription, - "Failed to find package 'bytecode_har'. Failed to obtain package 'bytecode_har' " + + "Failed to find package 'bytecode_har'. Failed to obtain package 'bytecode_har' " + "from the package context information." ); expect(loggerStub.getCall(1).calledWithMatch(errInfo1)).to.be.true; @@ -1379,7 +1428,7 @@ mocha.describe('generate ohmUrl', function () { const errInfo1: LogData = LogDataFactory.newInstance( ErrorCode.ETS2BUNDLE_INTERNAL_PACKAGE_NOT_FOUND_IN_CONTEXT_INFO, ArkTSInternalErrorDescription, - "Failed to find package 'bytecode_har'. Failed to obtain package 'bytecode_har' " + + "Failed to find package 'bytecode_har'. Failed to obtain package 'bytecode_har' " + "from the package context information." ); expect(loggerStub.getCall(1).calledWithMatch(errInfo1.toString())).to.be.true; -- Gitee