From 3ad2d45207f6ed1ab260ff47af9c9ab5e29903e3 Mon Sep 17 00:00:00 2001 From: ElevenDuan Date: Wed, 20 Mar 2024 21:53:53 +0800 Subject: [PATCH 1/3] =?UTF-8?q?ohmurl=E6=96=B0=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ElevenDuan Change-Id: Iccb45f27e68c726e3cc60bab73cfa2cdc3819d44 --- compiler/src/ark_utils.ts | 98 +++++++++++++++---- .../ark_compiler/common/common_mode.ts | 9 ++ .../ark_compiler/module/module_mode.ts | 29 ++++-- .../ark_compiler/module/module_source_file.ts | 65 +++++++++--- .../module/ohmUrl/ohmUrl.test.ts | 8 +- 5 files changed, 164 insertions(+), 45 deletions(-) diff --git a/compiler/src/ark_utils.ts b/compiler/src/ark_utils.ts index 9c3684fe2..833657dba 100644 --- a/compiler/src/ark_utils.ts +++ b/compiler/src/ark_utils.ts @@ -72,6 +72,33 @@ export const SRC_MAIN: string = 'src/main'; export var newSourceMaps: Object = {}; export var nameCacheObj: Object = {}; export const packageCollection: Map> = new Map(); +export function getNormalizedOhmUrlByFilepath(filePath: string, projectConfig: Object, logger: Object, + pkgName?: string, pkgPath?: string, importerFile?: string, isRecordName: boolean = false): string { + // remove '\x00' from the rollup virtual commonjs file's filePath + if (filePath.startsWith('\x00')) { + filePath = filePath.replace('\x00', ''); + } + let unixFilePath: string = toUnixPath(filePath); + unixFilePath = unixFilePath.substring(0, filePath.lastIndexOf('.')); // remove extension + let projectFilePath: string = unixFilePath.replace(toUnixPath(pkgPath), ''); + const pkgContextInfo = projectConfig.pkgContextInfo; + if (projectFilePath === '') { + projectFilePath = `/${pkgContextInfo.entryPath}`; + projectFilePath = projectFilePath.substring(0, filePath.lastIndexOf('.')); + } + let pkgInfo = pkgContextInfo[pkgName]; + if (pkgInfo === undefined) { + logger.error(red, + `ArkTS:ERROR Failed to get a resolved OhmUrl for "${filePath}" imported by "${importerFile}". ` + + `Please check whether the module which ${filePath} belongs to is correctly configured ` + + `and the corresponding file name is correct(including case-sensitivity)`, reset); + } + let recordName = `${pkgInfo.bundleName}&${pkgName}${projectFilePath}&${pkgInfo.version}`; + if (isRecordName) { + return recordName; + } + return `${pkgInfo.isSO ? 'Y' : 'N'}&${pkgInfo.moduleName}&` + recordName; +} export function getOhmUrlByFilepath(filePath: string, projectConfig: Object, logger: Object, namespace?: string, importerFile?: string): string { // remove '\x00' from the rollup virtual commonjs file's filePath @@ -153,8 +180,8 @@ function processPackageDir(params: Object): string { logger.error(red, `ArkTS:ERROR Failed to get a resolved OhmUrl for "${originalFilePath}" imported by "${importerFile}". ` + - `Please check whether the module which ${originalFilePath} belongs to is correctly configured` + - `and the corresponding file name matches (case sensitive)`, reset); + `Please check whether the module which ${originalFilePath} belongs to is correctly configured ` + + `and the corresponding file name is correct(including case-sensitivity)`, reset); return originalFilePath; } @@ -186,14 +213,14 @@ function processPackageDir(params: Object): string { logger.error(red, `ArkTS:ERROR Failed to get a resolved OhmUrl for "${originalFilePath}" imported by "${importerFile}". ` + - `Please check whether the module which ${originalFilePath} belongs to is correctly configured` + - `and the corresponding file name matches (case sensitive)`, reset); + `Please check whether the module which ${originalFilePath} belongs to is correctly configured ` + + `and the corresponding file name is correct(including case-sensitivity)`, reset); return originalFilePath; } -export function getOhmUrlBySystemApiOrLibRequest(moduleRequest: string) : string -{ +export function getOhmUrlBySystemApiOrLibRequest(moduleRequest: string, config?: Object, + useNormalizedOHMUrl: boolean = false) : string { // 'arkui-x' represents cross platform related APIs, processed as 'ohos' const REG_SYSTEM_MODULE: RegExp = new RegExp(`@(${sdkConfigPrefix})\\.(\\S+)`); const REG_LIB_SO: RegExp = /lib(\S+)\.so/; @@ -219,6 +246,12 @@ export function getOhmUrlBySystemApiOrLibRequest(moduleRequest: string) : string }); } if (REG_LIB_SO.test(moduleRequest.trim())) { + if (useNormalizedOHMUrl) { + const pkgContextInfo = config.pkgContextInfo; + const pkgInfo = pkgContextInfo[moduleRequest]; + return `@normalized:${pkgInfo.isSO ? 'Y' : 'N'}&${pkgInfo.moduleName}&` + + `${pkgInfo.bundleName}&${moduleRequest}&${pkgInfo.version}`; + } return moduleRequest.replace(REG_LIB_SO, (_, libsoKey) => { return `@app:${projectConfig.bundleName}/${projectConfig.moduleName}/${libsoKey}`; }); @@ -281,21 +314,52 @@ export function transformModuleSpecifier(sourcePath: string, sourceCode: string, }); } -export function getOhmUrlByHarName(moduleRequest: string, projectConfig: Object): string | undefined { +function removeSuffix(filePath: string) { + const typeExts = ['.d.ets', '.d.ts','.ets', '.ts']; + const mainName = filePath.split(path.sep).join('/'); + const ext: string | undefined = typeExts.find(ext => mainName.endsWith(ext)); + return ext ? mainName.substring(0, mainName.lastIndexOf(ext)) : mainName; +} + +export function getNormalizedOhmUrlByHspName(pkgName: string, projectConfig: Object, + logger?: Object, filePath?: string) { + const pkgContextInfo = projectConfig.pkgContextInfo; + let pkgInfo = pkgContextInfo[pkgName]; + if (pkgInfo === undefined) { + logger.error(red, `ArkTS:INTERNAL ERROR: Not to found the package: ${pkgName}`, reset); + } + let normalizedPath = filePath; + if (normalizedPath === undefined) { + normalizedPath = `${pkgName}/${toUnixPath(pkgInfo.entryPath)}`; + normalizedPath = removeSuffix(normalizedPath); + } + return `@normalized:${pkgInfo.isSO ? 'Y' : 'N'}&${pkgInfo.moduleName}&` + + `${pkgInfo.bundleName}&${normalizedPath}&${pkgInfo.version}`; +} + +export function getOhmUrlByHspName(moduleRequest: string, projectConfig: Object, logger?: Object, + useNormalizedOHMUrl: boolean = false): string | undefined { + // The harNameOhmMap store the old ohmurl with hsp package. if (projectConfig.harNameOhmMap) { // case1: "@ohos/lib" ---> "@bundle:bundleName/lib/ets/index" if (projectConfig.harNameOhmMap.hasOwnProperty(moduleRequest)) { + if(useNormalizedOHMUrl) { + return getNormalizedOhmUrlByHspName(moduleRequest, projectConfig); + } return projectConfig.harNameOhmMap[moduleRequest]; } // case2: "@ohos/lib/src/main/ets/pages/page1" ---> "@bundle:bundleName/lib/ets/pages/page1" - for (const harName in projectConfig.harNameOhmMap) { - if (moduleRequest.startsWith(harName + '/')) { - const idx: number = projectConfig.harNameOhmMap[harName].split('/', 2).join('/').length; - const harOhmName: string = projectConfig.harNameOhmMap[harName].substring(0, idx); - if (moduleRequest.indexOf(harName + '/' + SRC_MAIN) === 0) { - return moduleRequest.replace(harName + '/' + SRC_MAIN, harOhmName); + for (const hspName in projectConfig.harNameOhmMap) { + if (moduleRequest.startsWith(hspName + '/')) { + if(useNormalizedOHMUrl) { + return getNormalizedOhmUrlByHspName(hspName, projectConfig, logger, moduleRequest); + } + const idx: number = projectConfig.harNameOhmMap[hspName].split('/', 2).join('/').length; + const hspOhmName: string = projectConfig.harNameOhmMap[hspName].substring(0, idx); + if (moduleRequest.indexOf(hspName + '/' + SRC_MAIN) === 0) { + return moduleRequest.replace(hspName + '/' + SRC_MAIN, hspOhmName); } else { - return moduleRequest.replace(harName, harOhmName); + return moduleRequest.replace(hspName, hspOhmName); } } } @@ -304,10 +368,10 @@ export function getOhmUrlByHarName(moduleRequest: string, projectConfig: Object) } function replaceHarDependency(item:string, moduleRequest: string, projectConfig: Object): string { - const harOhmUrl: string | undefined = getOhmUrlByHarName(moduleRequest, projectConfig); - if (harOhmUrl !== undefined) { + const hspOhmUrl: string | undefined = getOhmUrlByHspName(moduleRequest, projectConfig); + if (hspOhmUrl !== undefined) { return item.replace(/(['"])(?:\S+)['"]/, (_, quotation) => { - return quotation + harOhmUrl + quotation; + return quotation + hspOhmUrl + quotation; }); } return item; 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 285390780..551bde8b6 100644 --- a/compiler/src/fast_build/ark_compiler/common/common_mode.ts +++ b/compiler/src/fast_build/ark_compiler/common/common_mode.ts @@ -51,6 +51,7 @@ export abstract class CommonMode { genAbcScriptPath: string; triggerAsync: Object; triggerEndSignal: Object; + useNormalizedOHMUrl: boolean; constructor(rollupObject: Object) { this.projectConfig = Object.assign(rollupObject.share.arkProjectConfig, rollupObject.share.projectConfig); @@ -67,6 +68,7 @@ export abstract class CommonMode { // If the child process throws an error by calling throwArkTsCompilerError(), IDE will reset the counting state. this.triggerAsync = rollupObject.async; this.triggerEndSignal = rollupObject.signal; + this.useNormalizedOHMUrl = this.getUseNormalizedOHMUrl(); } initCmdEnv() { @@ -99,6 +101,13 @@ export abstract class CommonMode { return args; } + private getUseNormalizedOHMUrl() { + if (this.projectConfig.hasOwnProperty('useNormalizedOHMUrl')) { + return this.projectConfig.useNormalizedOHMUrl; + } + return false; + } + private genHashJsonFilePath() { if (this.projectConfig.cachePath) { if (!fs.existsSync(this.projectConfig.cachePath) || !fs.statSync(this.projectConfig.cachePath).isDirectory()) { 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 21bfbdddf..4255d37bf 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_mode.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_mode.ts @@ -75,8 +75,9 @@ import { } from '../../../utils'; import { getPackageInfo, + getNormalizedOhmUrlByFilepath, getOhmUrlByFilepath, - getOhmUrlByHarName, + getOhmUrlByHspName, isTs2Abc, isEs2Abc, createAndStartEvent, @@ -203,7 +204,8 @@ export class ModuleMode extends CommonMode { this.updatePkgEntryInfos(pkgEntryInfos, pkgName, ohmurl); continue; } - let hspOhmurl: string | undefined = getOhmUrlByHarName(pkgName, this.projectConfig); + let hspOhmurl: string | undefined = getOhmUrlByHspName(pkgName, this.projectConfig, this.logger, + this.useNormalizedOHMUrl); if (hspOhmurl !== undefined) { hspOhmurl = hspOhmurl.replace(/^@(\w+):(.*)/, '@$1.$2'); this.updatePkgEntryInfos(pkgEntryInfos, pkgName, hspOhmurl); @@ -225,7 +227,8 @@ export class ModuleMode extends CommonMode { private getPackageEntryInfo(filePath: string, metaInfo: Object, pkgEntryInfos: Map): void { if (metaInfo['isLocalDependency']) { const hostModulesInfo: Object = metaInfo.hostModulesInfo; - const pkgBuildPath: string = getOhmUrlByFilepath(filePath, this.projectConfig, this.logger, metaInfo['moduleName']); + let pkgBuildPath: string = getOhmUrlByFilepath(filePath, this.projectConfig, this.logger, metaInfo['moduleName']); + hostModulesInfo.forEach(hostModuleInfo => { const hostDependencyName: string = hostModuleInfo['hostDependencyName']; const hostModuleName: string = hostModuleInfo['hostModuleName']; @@ -242,6 +245,7 @@ export class ModuleMode extends CommonMode { this.logger.debug("ArkTS:INTERNAL ERROR: Failed to get 'pkgPath' from metaInfo. File: ", filePath); return; } + const pkgPath: string = metaInfo['pkgPath']; let originPkgEntryPath: string = toUnixPath(filePath.replace(pkgPath, '')); if (originPkgEntryPath.startsWith('/')) { @@ -304,17 +308,26 @@ export class ModuleMode extends CommonMode { const isPackageModules = isPackageModulesFile(filePath, this.projectConfig); // if release mode, enable obfuscation, enable filename obfuscation -> call mangleFilePath() filePath = this.handleObfuscatedFilePath(filePath, isPackageModules); + let namespace: string = metaInfo['moduleName']; - let recordName: string = getOhmUrlByFilepath(filePath, this.projectConfig, this.logger, namespace); + let recordName: string = ''; let sourceFile: string = filePath.replace(this.projectConfig.projectRootPath + path.sep, ''); let cacheFilePath: string = this.genFileCachePath(filePath, this.projectConfig.projectRootPath, this.projectConfig.cachePath); let packageName: string = ''; - if (isPackageModules) { - packageName = this.getPkgModulesFilePkgName(metaInfo['pkgPath']); + if (this.useNormalizedOHMUrl) { + packageName = metaInfo['pkgName']; + const pkgPath = metaInfo['pkgPath'] + recordName = getNormalizedOhmUrlByFilepath(filePath, this.projectConfig, this.logger, + packageName, pkgPath, undefined, true); } else { - packageName = - metaInfo['isLocalDependency'] ? namespace : getPackageInfo(this.projectConfig.aceModuleJsonPath)[1]; + recordName = getOhmUrlByFilepath(filePath, this.projectConfig, this.logger, namespace); + if (isPackageModules) { + packageName = this.getPkgModulesFilePkgName(metaInfo['pkgPath']); + } else { + packageName = + metaInfo['isLocalDependency'] ? namespace : getPackageInfo(this.projectConfig.aceModuleJsonPath)[1]; + } } if (extName.length !== 0) { 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 40fe8887c..beb1e940f 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 @@ -22,8 +22,9 @@ import { PACKAGES } from '../common/ark_define'; import { + getNormalizedOhmUrlByFilepath, getOhmUrlByFilepath, - getOhmUrlByHarName, + getOhmUrlByHspName, getOhmUrlBySystemApiOrLibRequest, mangleDeclarationFileName, } from '../../../ark_utils'; @@ -125,14 +126,31 @@ export class ModuleSourceFile { return; } + let useNormalizedOHMUrl = false; + if (rollupObject.share.projectConfig.hasOwnProperty('useNormalizedOHMUrl')) { + useNormalizedOHMUrl = rollupObject.share.projectConfig.useNormalizedOHMUrl; + } let mockFile: string = ModuleSourceFile.mockConfigInfo[originKey].source; let mockFilePath: string = `${toUnixPath(rollupObject.share.projectConfig.modulePath)}/${mockFile}`; - let mockFileOhmUrl: string = getOhmUrlByFilepath(mockFilePath, - ModuleSourceFile.projectConfig, - ModuleSourceFile.logger, - rollupObject.share.projectConfig.entryModuleName, - importerFile); - mockFileOhmUrl = mockFileOhmUrl.startsWith(PACKAGES) ? `@package:${mockFileOhmUrl}` : `@bundle:${mockFileOhmUrl}`; + let mockFileOhmUrl: string = ''; + if (useNormalizedOHMUrl) { + const targetModuleInfo: Object = rollupObject.getModuleInfo(filePath); + mockFileOhmUrl = getNormalizedOhmUrlByFilepath(mockFilePath, + ModuleSourceFile.projectConfig, + ModuleSourceFile.logger, + targetModuleInfo.meta.pkgName, + targetModuleInfo.meta.pkgPath, + importerFile); + mockFileOhmUrl = `@normalized:${mockFileOhmUrl}`; + } else { + mockFileOhmUrl = getOhmUrlByFilepath(mockFilePath, + ModuleSourceFile.projectConfig, + ModuleSourceFile.logger, + rollupObject.share.projectConfig.entryModuleName, + importerFile); + mockFileOhmUrl = mockFileOhmUrl.startsWith(PACKAGES) ? `@package:${mockFileOhmUrl}` : `@bundle:${mockFileOhmUrl}`; + } + // record mock target mapping for incremental compilation ModuleSourceFile.addNewMockConfig(transKey, mockFileOhmUrl); } @@ -275,26 +293,41 @@ export class ModuleSourceFile { } private getOhmUrl(rollupObject: Object, moduleRequest: string, filePath: string | undefined, importerFile: string): string | undefined { - let systemOrLibOhmUrl: string | undefined = getOhmUrlBySystemApiOrLibRequest(moduleRequest); + let useNormalizedOHMUrl = false; + if (rollupObject.share.projectConfig.hasOwnProperty('useNormalizedOHMUrl')) { + useNormalizedOHMUrl = rollupObject.share.projectConfig.useNormalizedOHMUrl; + } + let systemOrLibOhmUrl = getOhmUrlBySystemApiOrLibRequest(moduleRequest, ModuleSourceFile.projectConfig, useNormalizedOHMUrl); if (systemOrLibOhmUrl != undefined) { if (ModuleSourceFile.needProcessMock) { ModuleSourceFile.generateNewMockInfoByOrignMockConfig(moduleRequest, systemOrLibOhmUrl, rollupObject, importerFile); } return systemOrLibOhmUrl; } - const harOhmUrl: string | undefined = getOhmUrlByHarName(moduleRequest, ModuleSourceFile.projectConfig); - if (harOhmUrl !== undefined) { + const hspOhmurl: string | undefined = getOhmUrlByHspName(moduleRequest, ModuleSourceFile.projectConfig, + ModuleSourceFile.logger, useNormalizedOHMUrl); + if (hspOhmurl !== undefined) { if (ModuleSourceFile.needProcessMock) { - ModuleSourceFile.generateNewMockInfoByOrignMockConfig(moduleRequest, harOhmUrl, rollupObject, importerFile); + ModuleSourceFile.generateNewMockInfoByOrignMockConfig(moduleRequest, hspOhmurl, rollupObject, importerFile); } - return harOhmUrl; + return hspOhmurl; } if (filePath) { const targetModuleInfo: Object = rollupObject.getModuleInfo(filePath); - const namespace: string = targetModuleInfo['meta']['moduleName']; - const ohmUrl: string = - getOhmUrlByFilepath(filePath, ModuleSourceFile.projectConfig, ModuleSourceFile.logger, namespace, importerFile); - let res: string = ohmUrl.startsWith(PACKAGES) ? `@package:${ohmUrl}` : `@bundle:${ohmUrl}`; + let res: string = ""; + if (useNormalizedOHMUrl) { + const pkgName = targetModuleInfo['meta']['pkgName']; + const pkgPath = targetModuleInfo['meta']['pkgPath']; + const ohmUrl: string = + getNormalizedOhmUrlByFilepath(filePath, ModuleSourceFile.projectConfig, ModuleSourceFile.logger, + pkgName, pkgPath, importerFile); + res = `@normalized:${ohmUrl}`; + } else { + const namespace: string = targetModuleInfo['meta']['moduleName']; + const ohmUrl: string = + getOhmUrlByFilepath(filePath, ModuleSourceFile.projectConfig, ModuleSourceFile.logger, namespace, importerFile); + res = ohmUrl.startsWith(PACKAGES) ? `@package:${ohmUrl}` : `@bundle:${ohmUrl}`; + } if (ModuleSourceFile.needProcessMock) { // processing cases of har or lib mock targets ModuleSourceFile.generateNewMockInfoByOrignMockConfig(moduleRequest, res, rollupObject, importerFile); 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 887dad568..4ba56747e 100644 --- a/compiler/test/ark_compiler_ut/module/ohmUrl/ohmUrl.test.ts +++ b/compiler/test/ark_compiler_ut/module/ohmUrl/ohmUrl.test.ts @@ -17,7 +17,7 @@ import { expect } from 'chai'; import mocha from 'mocha'; import sinon from 'sinon'; -import { getOhmUrlByFilepath, getOhmUrlBySystemApiOrLibRequest, getOhmUrlByHarName } from '../../../../lib/ark_utils'; +import { getOhmUrlByFilepath, getOhmUrlBySystemApiOrLibRequest, getOhmUrlByHspName } from '../../../../lib/ark_utils'; import { PACKAGES } from '../../../../lib/pre_define'; import projectConfig from '../../utils/processProjectConfig'; import { projectConfig as mainProjectConfig } from '../../../../main'; @@ -80,9 +80,9 @@ mocha.describe('generate ohmUrl', function () { const sharedLibraryPackageName: string = "@ohos/sharedLibrary"; const sharedLibraryPage: string = "@ohos/sharedLibrary/src/main/ets/pages/page1"; const errorSharedLibrary: string = "@ohos/staticLibrary"; - const sharedLibraryPackageNameOhmUrl: string = getOhmUrlByHarName(sharedLibraryPackageName, projectConfig); - const sharedLibraryPageOhmUrl: string = getOhmUrlByHarName(sharedLibraryPage, projectConfig); - const errorSharedLibraryOhmUrl = getOhmUrlByHarName(errorSharedLibrary, projectConfig); + const sharedLibraryPackageNameOhmUrl: string = getOhmUrlByHspName(sharedLibraryPackageName, projectConfig); + const sharedLibraryPageOhmUrl: string = getOhmUrlByHspName(sharedLibraryPage, projectConfig); + const errorSharedLibraryOhmUrl = getOhmUrlByHspName(errorSharedLibrary, projectConfig); const expectedSharedLibraryOhmUrl: string = "@bundle:UtTestApplication/sharedLibrary/ets/index"; const expectedSharedLibraryPageOhmUrl: string = "@bundle:UtTestApplication/sharedLibrary/ets/pages/page1"; const expectedErrorSharedLibraryOhmUrl = undefined; -- Gitee From 637f74e9567db3b0830a3b26210f538133a42a5a Mon Sep 17 00:00:00 2001 From: wuhailong Date: Mon, 25 Mar 2024 12:07:57 +0000 Subject: [PATCH 2/3] add normalizedOHMUrl UT cases Signed-off-by: wuhailong Change-Id: I468b315c96211ebee737887ad42780c928aa39af --- .../mock/rollup_mock/module_info.ts | 4 +- .../mock/rollup_mock/project_config.ts | 2 + .../module/ohmUrl/ohmUrl.test.ts | 639 ++++++++++++++++++ 3 files changed, 644 insertions(+), 1 deletion(-) diff --git a/compiler/test/ark_compiler_ut/mock/rollup_mock/module_info.ts b/compiler/test/ark_compiler_ut/mock/rollup_mock/module_info.ts index 24ef5c920..b04c994eb 100644 --- a/compiler/test/ark_compiler_ut/mock/rollup_mock/module_info.ts +++ b/compiler/test/ark_compiler_ut/mock/rollup_mock/module_info.ts @@ -18,13 +18,15 @@ import { MODULE_ID_ROLLUP_PLACEHOLDER } from '../rollup_mock/path_config'; class Meta { hostModulesInfo: Array; moduleName: string; + pkgName: string; isLocalDependency: boolean; isNodeEntryFile: boolean; pkgPath: string; - constructor(entryModuleName: string, modulePath: string) { + constructor(entryModuleName: string, modulePath: string, packageName: string) { this.hostModulesInfo = []; this.moduleName = entryModuleName; + this.pkgName = packageName; this.isLocalDependency = true; this.isNodeEntryFile = false; this.pkgPath = modulePath; diff --git a/compiler/test/ark_compiler_ut/mock/rollup_mock/project_config.ts b/compiler/test/ark_compiler_ut/mock/rollup_mock/project_config.ts index 18bc552d4..726f009d5 100644 --- a/compiler/test/ark_compiler_ut/mock/rollup_mock/project_config.ts +++ b/compiler/test/ark_compiler_ut/mock/rollup_mock/project_config.ts @@ -107,6 +107,8 @@ class ProjectConfig { aceSoPath?: string; mockParams?: object; projectRootPath: string; + pkgContextInfo: object; + useNormalizedOHMUrl: boolean = false; constructor(buildMode: string) { this.watchMode = 'false'; 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 4ba56747e..24f0634e6 100644 --- a/compiler/test/ark_compiler_ut/module/ohmUrl/ohmUrl.test.ts +++ b/compiler/test/ark_compiler_ut/module/ohmUrl/ohmUrl.test.ts @@ -23,6 +23,7 @@ import projectConfig from '../../utils/processProjectConfig'; import { projectConfig as mainProjectConfig } from '../../../../main'; import RollUpPluginMock from '../../mock/rollup_mock/rollup_plugin_mock'; import { GEN_ABC_PLUGIN_NAME } from '../../../../lib/fast_build/ark_compiler/common/ark_define'; +import { ModuleSourceFile } from '../../../../lib/fast_build/ark_compiler/module/module_source_file'; mocha.describe('generate ohmUrl', function () { mocha.before(function () { @@ -169,4 +170,642 @@ mocha.describe('generate ohmUrl', function () { `and the corresponding file name matches (case sensitive)`, reset)).to.be.true; loggerStub.restore(); }); + + mocha.it('inter-app hsp self import', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'pkghsp': { + 'packageName': 'pkghsp', + 'bundleName': 'com.test.testHsp', + 'moduleName': '', + 'version': '', + 'entryPath': 'Index.ets', + 'isSO': false + } + } + const filePath = '/testHsp/hsp/src/main/ets/utils/Calc.ets'; + const moduleInfo = { + id: filePath, + meta: { + pkgName: 'pkghsp', + pkgPath: '/testHsp/hsp' + } + } + this.rollup.moduleInfos.push(moduleInfo); + const importerFile = '/testHsp/hsp/src/main/ets/pages/Index.ets' + const relativePath = '../utils/Calc'; + const etsBasedAbsolutePath = 'ets/utils/Calc'; + const standardImportPath = 'pkghsp/src/main/ets/utils/Calc'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const relativePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); + const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); + const expectedNormalizedOhmUrl = '@normalized:N&&com.test.testHsp&pkghsp/src/main/ets/utils/Calc&'; + expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + }); + + mocha.it('inter-app hsp others import', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'pkghsp': { + 'packageName': 'pkghsp', + 'bundleName': 'com.test.testHsp', + 'moduleName': 'hsp', + 'version': '', + 'entryPath': 'Index.ets', + 'isSO': false + } + } + this.rollup.share.projectConfig.harNameOhmMap ={ + 'pkghsp': '@bundle:com.test.testHsp/src/main/ets/utils/Calc' + } + const filePath = 'pkghsp/src/main/ets/utils/Calc'; + const indexFilePath = 'pkghsp'; + const importerFile = '/testHap/entry/src/main/ets/pages/index.ets' + const importByPkgName = 'pkghsp'; + const standardImportPath = 'pkghsp/src/main/ets/utils/Calc'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); + const importByPkgNameNormalizedOhmUrl = '@normalized:N&hsp&com.test.testHsp&pkghsp/Index&'; + const standardImportPathNormalizedOhmUrl = '@normalized:N&hsp&com.test.testHsp&pkghsp/src/main/ets/utils/Calc&'; + expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; + expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; + }); + + mocha.it('in-app hsp self import', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'pkghsp': { + 'packageName': 'pkghsp', + 'bundleName': '', + 'moduleName': '', + 'version': '', + 'entryPath': 'Index.ets', + 'isSO': false + } + } + const filePath = '/testHsp/hsp/src/main/ets/utils/Calc.ets'; + const moduleInfo = { + id: filePath, + meta: { + pkgName: 'pkghsp', + pkgPath: '/testHsp/hsp' + } + } + this.rollup.moduleInfos.push(moduleInfo); + const importerFile = '/testHsp/hsp/src/main/ets/pages/Index.ets' + const relativePath = '../utils/Calc'; + const etsBasedAbsolutePath = 'ets/utils/Calc'; + const standardImportPath = 'pkghsp/src/main/ets/utils/Calc'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const relativePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); + const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); + const expectedNormalizedOhmUrl = '@normalized:N&&&pkghsp/src/main/ets/utils/Calc&'; + expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + }); + + mocha.it('in-app hsp others import', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'pkghsp': { + 'packageName': 'pkghsp', + 'bundleName': '', + 'moduleName': 'hsp', + 'version': '', + 'entryPath': 'Index.ets', + 'isSO': false + } + } + this.rollup.share.projectConfig.harNameOhmMap ={ + 'pkghsp': '@bundle:com.test.testHap/src/main/ets/utils/Calc' + } + const filePath = 'pkghsp/src/main/ets/utils/Calc'; + const indexFilePath = 'pkghsp'; + + const importerFile = '/testHap/entry/src/main/ets/pages/index.ets' + const importByPkgName = 'pkghsp'; + const standardImportPath = 'pkghsp/src/main/ets/utils/Calc'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); + const importByPkgNameNormalizedOhmUrl = '@normalized:N&hsp&&pkghsp/Index&'; + const standardImportPathNormalizedOhmUrl = '@normalized:N&hsp&&pkghsp/src/main/ets/utils/Calc&'; + expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; + expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; + }); + + mocha.it('hap self import', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'entry': { + 'packageName': 'entry', + 'bundleName': '', + 'moduleName': '', + 'version': '', + 'entryPath': '', + 'isSO': false + } + } + const filePath = '/testHap/entry/src/main/ets/utils/Calc.ets'; + const moduleInfo = { + id: filePath, + meta: { + pkgName: 'entry', + pkgPath: '/testHap/entry' + } + } + this.rollup.moduleInfos.push(moduleInfo); + const importerFile = '/testHap/entry/src/main/ets/pages/index.ets' + const relativePath = '../utils/Calc'; + const etsBasedAbsolutePath = 'ets/utils/Calc'; + const standardImportPath = 'entry/src/main/ets/utils/Calc'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const relativePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); + const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); + const expectedNormalizedOhmUrl = '@normalized:N&&&entry/src/main/ets/utils/Calc&'; + expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + }); + + mocha.it('source code har self import (hap/in-app hsp)', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'pkghar': { + 'packageName': 'pkghar', + 'bundleName': '', + 'moduleName': '', + 'version': '1.0.1', + 'entryPath': 'Index.ets', + 'isSO': false + } + } + const filePath = '/testHar/har/src/main/ets/utils/Calc.ets'; + const moduleInfo = { + id: filePath, + meta: { + pkgName: 'pkghar', + pkgPath: '/testHar/har' + } + } + this.rollup.moduleInfos.push(moduleInfo); + const importerFile = '/testHar/har/src/main/ets/pages/Index.ets' + const relativePath = '../utils/Calc'; + const etsBasedAbsolutePath = 'ets/utils/Calc'; + const standardImportPath = 'pkghar/src/main/ets/utils/Calc'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const relativePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); + const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); + const expectedNormalizedOhmUrl = '@normalized:N&&&pkghar/src/main/ets/utils/Calc&1.0.1'; + expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + }); + + mocha.it('source code har others import (hap/in-app hsp)', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'pkghar': { + 'packageName': 'pkghar', + 'bundleName': '', + 'moduleName': '', + 'version': '1.0.1', + 'entryPath': 'Index.ets', + 'isSO': false + } + } + const filePath = '/testHar/har/src/main/ets/utils/Calc.ets'; + const indexFilePath = '/testHar/har/Index.ets'; + for (let file of [filePath, indexFilePath]) { + const moduleInfo = { + id: file, + meta: { + pkgName: 'pkghar', + pkgPath: '/testHar/har' + } + } + this.rollup.moduleInfos.push(moduleInfo); + } + const importerFile = '/testHar/entry/src/main/ets/pages/Index.ets' + const importByPkgName = 'pkghar'; + const standardImportPath = 'pkghar/src/main/ets/utils/Calc'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); + const importByPkgNameNormalizedOhmUrl = '@normalized:N&&&pkghar/Index&1.0.1'; + const standardImportPathNormalizedOhmUrl = '@normalized:N&&&pkghar/src/main/ets/utils/Calc&1.0.1'; + expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; + expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; + }); + + mocha.it('source code har self import (inter-app hsp)', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'pkghar': { + 'packageName': 'pkghar', + 'bundleName': 'com.test.testHsp', + 'moduleName': '', + 'version': '1.0.1', + 'entryPath': 'Index.ets', + 'isSO': false + } + } + const filePath = '/testHsp/har/src/main/ets/utils/Calc.ets'; + const moduleInfo = { + id: filePath, + meta: { + pkgName: 'pkghar', + pkgPath: '/testHsp/har' + } + } + this.rollup.moduleInfos.push(moduleInfo); + const importerFile = '/testHsp/har/src/main/ets/pages/Index.ets' + const relativePath = '../utils/Calc'; + const etsBasedAbsolutePath = 'ets/utils/Calc'; + const standardImportPath = 'pkghar/src/main/ets/utils/Calc'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const relativePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); + const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); + const expectedNormalizedOhmUrl = '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1'; + expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + }); + + mocha.it('source code har others import (inter-app hsp)', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'pkghar': { + 'packageName': 'pkghar', + 'bundleName': 'com.test.testHsp', + 'moduleName': '', + 'version': '1.0.1', + 'entryPath': 'Index.ets', + 'isSO': false + } + } + const filePath = '/testHsp/har/src/main/ets/utils/Calc.ets'; + const indexFilePath = '/testHsp/har/Index.ets'; + for (let file of [filePath, indexFilePath]) { + const moduleInfo = { + id: file, + meta: { + pkgName: 'pkghar', + pkgPath: '/testHsp/har' + } + } + this.rollup.moduleInfos.push(moduleInfo); + } + const importerFile = '/testHsp/hsp/src/main/ets/pages/Index.ets' + const importByPkgName = 'pkghar'; + const standardImportPath = 'pkghar/src/main/ets/utils/Calc'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); + const importByPkgNameNormalizedOhmUrl = '@normalized:N&&com.test.testHsp&pkghar/Index&1.0.1'; + const standardImportPathNormalizedOhmUrl = '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1'; + expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; + expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; + }); + + mocha.it('product har self import (hap/in-app hsp)', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'pkghar': { + 'packageName': 'pkghar', + 'bundleName': '', + 'moduleName': '', + 'version': '1.0.1', + 'entryPath': 'Index.ets', + 'isSO': false + } + } + const filePath = '/testHar/har/src/main/ets/utils/Calc.ets'; + const moduleInfo = { + id: filePath, + meta: { + pkgName: 'pkghar', + pkgPath: '/testHar/har' + } + } + this.rollup.moduleInfos.push(moduleInfo); + const importerFile = '/testHar/har/src/main/ets/pages/Index.ets' + const relativePath = '../utils/Calc'; + const etsBasedAbsolutePath = 'ets/utils/Calc'; + const standardImportPath = 'pkghar/src/main/ets/utils/Calc'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const relativePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); + const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); + const expectedNormalizedOhmUrl = '@normalized:N&&&pkghar/src/main/ets/utils/Calc&1.0.1'; + expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + }); + + mocha.it('product har others import (hap/in-app hsp)', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'pkghar': { + 'packageName': 'pkghar', + 'bundleName': '', + 'moduleName': '', + 'version': '1.0.1', + 'entryPath': 'Index.ets', + 'isSO': false + } + } + const filePath = '/testHap/oh_modules/.ohpm/pkghar@test=/oh_modules/pkghar/src/main/ets/utils/Calc.ets'; + const indexFilePath = '/testHap/oh_modules/.ohpm/pkghar@test=/oh_modules/pkghar/Index.ets'; + for (let file of [filePath, indexFilePath]) { + const moduleInfo = { + id: file, + meta: { + pkgName: 'pkghar', + pkgPath: '/testHap/oh_modules/.ohpm/pkghar@test=/oh_modules/pkghar' + } + } + this.rollup.moduleInfos.push(moduleInfo); + } + const importerFile = '/testHar/entry/src/main/ets/pages/index.ets' + const importByPkgName = 'pkghar'; + const standardImportPath = 'pkghar/src/main/ets/utils/Calc'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); + const importByPkgNameNormalizedOhmUrl = '@normalized:N&&&pkghar/Index&1.0.1'; + const standardImportPathNormalizedOhmUrl = '@normalized:N&&&pkghar/src/main/ets/utils/Calc&1.0.1'; + expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; + expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; + }); + + mocha.it('remote source code har self import (inter-app hsp)', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'pkghar': { + 'packageName': 'pkghar', + 'bundleName': 'com.test.testHsp', + 'moduleName': '', + 'version': '1.0.1', + 'entryPath': 'Index.ets', + 'isSO': false + } + } + const filePath = '/testHsp/har/src/main/ets/utils/Calc.ets'; + const moduleInfo = { + id: filePath, + meta: { + pkgName: 'pkghar', + pkgPath: '/testHsp/har' + } + } + this.rollup.moduleInfos.push(moduleInfo); + const importerFile = '/testHsp/har/src/main/ets/pages/Index.ets' + const relativePath = '../utils/Calc'; + const etsBasedAbsolutePath = 'ets/utils/Calc'; + const standardImportPath = 'pkghar/src/main/ets/utils/Calc'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const relativePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); + const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); + const expectedNormalizedOhmUrl = '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1'; + expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; + }); + + mocha.it('remote source code har others import (inter-app hsp)', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'pkghar': { + 'packageName': 'pkghar', + 'bundleName': 'com.test.testHsp', + 'moduleName': '', + 'version': '1.0.1', + 'entryPath': 'Index.ets', + 'isSO': false + } + } + const filePath = '/testHsp/har/src/main/ets/utils/Calc.ets'; + const indexFilePath = '/testHsp/har/Index.ets'; + for (let file of [filePath, indexFilePath]) { + const moduleInfo = { + id: file, + meta: { + pkgName: 'pkghar', + pkgPath: '/testHsp/har' + } + } + this.rollup.moduleInfos.push(moduleInfo); + } + const importerFile = '/testHsp/hsp/src/main/ets/pages/Index.ets' + const importByPkgName = 'pkghar'; + const standardImportPath = 'pkghar/src/main/ets/utils/Calc'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); + const importByPkgNameNormalizedOhmUrl = '@normalized:N&&com.test.testHsp&pkghar/Index&1.0.1'; + const standardImportPathNormalizedOhmUrl = '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1'; + expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; + expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; + }); + + mocha.it('native so others import (hap/in-app hsp)', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'libproduct.so': { + 'packageName': 'libproduct.so', + 'bundleName': '', + 'moduleName': '', + 'version': '', + 'entryPath': '', + 'isSO': true + } + } + const importerFile = '/testHap/hsp/src/main/ets/pages/Index.ets' + const moduleRequest = 'libproduct.so'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const moduleRequestOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, undefined, importerFile); + const expectedNormalizedOhmUrl = '@normalized:Y&&&libproduct.so&'; + expect(moduleRequestOhmUrl == expectedNormalizedOhmUrl).to.be.true; + }); + + mocha.it('native so others import (inter-app hsp)', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'libproduct.so': { + 'packageName': 'libproduct.so', + 'bundleName': 'com.test.testHsp', + 'moduleName': '', + 'version': '', + 'entryPath': '', + 'isSO': true + } + } + const importerFile = '/testHsp/hsp/src/main/ets/pages/Index.ets' + const moduleRequest = 'libproduct.so'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const moduleRequestOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, undefined, importerFile); + const expectedNormalizedOhmUrl = '@normalized:Y&&com.test.testHsp&libproduct.so&'; + expect(moduleRequestOhmUrl == expectedNormalizedOhmUrl).to.be.true; + }); + + mocha.it('native so others import (source code har)', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'libhar.so': { + 'packageName': 'libhar.so', + 'bundleName': '', + 'moduleName': '', + 'version': '', + 'entryPath': '', + 'isSO': true + } + } + const importerFile = '/testHap/har/src/main/ets/pages/Index.ets' + const moduleRequest = 'libhar.so'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const moduleRequestOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, undefined, importerFile); + const expectedNormalizedOhmUrl = '@normalized:Y&&&libhar.so&'; + expect(moduleRequestOhmUrl == expectedNormalizedOhmUrl).to.be.true; + }); + + mocha.it('native so others import (product har)', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'libhar.so': { + 'packageName': 'libhar.so', + 'bundleName': '', + 'moduleName': '', + 'version': '', + 'entryPath': '', + 'isSO': true + } + } + const importerFile = '/testHap/oh_modules/.ohpm/pkghar@test+har=/oh_modules/pkghar/src/main/ets/pages/Index.ets'; + const moduleRequest = 'libhar.so'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const moduleRequestOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, undefined, importerFile); + const expectedNormalizedOhmUrl = '@normalized:Y&&&libhar.so&'; + expect(moduleRequestOhmUrl == expectedNormalizedOhmUrl).to.be.true; + }); + + mocha.it('ohpm package others import (hap/in-app hsp)', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + '@ohos/Test': { + 'packageName': '@ohos/Test', + 'bundleName': '', + 'moduleName': '', + 'version': '2.3.1', + 'entryPath': 'index.ets', + 'isSO': false + } + } + const filePath = '/testHap/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/src/main/ets/utils/Calc.ets' + const indexFilePath = '/testHap/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/index.ets'; + for (let file of [filePath, indexFilePath]) { + const moduleInfo = { + id: file, + meta: { + pkgName: '@ohos/Test', + pkgPath: '/testHap/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test' + } + } + this.rollup.moduleInfos.push(moduleInfo); + } + const importerFile = '/testHap/entry/src/main/ets/pages/index.ets' + const importByPkgName = '@ohos/Test'; + const standardImportPath = '@ohos/Test/src/main/ets/utils/Calc'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); + const importByPkgNameNormalizedOhmUrl = '@normalized:N&&&@ohos/Test/index&2.3.1'; + const standardImportPathNormalizedOhmUrl = '@normalized:N&&&@ohos/Test/src/main/ets/utils/Calc&2.3.1'; + expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; + expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; + }); + + mocha.it('ohpm package others import (inter-app hsp)', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + '@ohos/Test': { + 'packageName': '@ohos/Test', + 'bundleName': 'com.test.testHsp', + 'moduleName': '', + 'version': '2.3.1', + 'entryPath': 'index.ets', + 'isSO': false + } + } + const filePath = '/testHsp/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/src/main/ets/utils/Calc.ets' + const indexFilePath = '/testHsp/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/index.ets'; + for (let file of [filePath, indexFilePath]) { + const moduleInfo = { + id: file, + meta: { + pkgName: '@ohos/Test', + pkgPath: '/testHsp/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test' + } + } + this.rollup.moduleInfos.push(moduleInfo); + } + const importerFile = '/testHsp/entry/src/main/ets/pages/index.ets' + const importByPkgName = '@ohos/Test'; + const standardImportPath = '@ohos/Test/src/main/ets/utils/Calc'; + const moduleSourceFile = new ModuleSourceFile(); + ModuleSourceFile.initPluginEnv(this.rollup); + const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); + const importByPkgNameNormalizedOhmUrl = '@normalized:N&&com.test.testHsp&@ohos/Test/index&2.3.1'; + const standardImportPathNormalizedOhmUrl = '@normalized:N&&com.test.testHsp&@ohos/Test/src/main/ets/utils/Calc&2.3.1'; + expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; + expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; + }); }); \ No newline at end of file -- Gitee From b8b85bd580355db41525ecfe0174cb6fd5bec8b2 Mon Sep 17 00:00:00 2001 From: ElevenDuan Date: Sat, 30 Mar 2024 16:24:26 +0800 Subject: [PATCH 3/3] Fixed comments with ohmurl Signed-off-by: ElevenDuan Change-Id: I8877f8569abe6948ae875853a2594e449a99d9fe --- compiler/src/ark_utils.ts | 65 +-- .../ark_compiler/common/common_mode.ts | 9 - .../ark_compiler/module/module_mode.ts | 34 +- .../ark_compiler/module/module_source_file.ts | 39 +- .../mock/rollup_mock/project_config.ts | 1 + .../module/ohmUrl/ohmUrl.test.ts | 427 ++++++++++-------- 6 files changed, 313 insertions(+), 262 deletions(-) diff --git a/compiler/src/ark_utils.ts b/compiler/src/ark_utils.ts index 833657dba..115ff2a6e 100644 --- a/compiler/src/ark_utils.ts +++ b/compiler/src/ark_utils.ts @@ -72,21 +72,26 @@ export const SRC_MAIN: string = 'src/main'; export var newSourceMaps: Object = {}; export var nameCacheObj: Object = {}; export const packageCollection: Map> = new Map(); +// Splicing ohmurl or record name based on filePath and context information table. export function getNormalizedOhmUrlByFilepath(filePath: string, projectConfig: Object, logger: Object, - pkgName?: string, pkgPath?: string, importerFile?: string, isRecordName: boolean = false): string { - // remove '\x00' from the rollup virtual commonjs file's filePath + pkgParams: Object, importerFile: string): string { + const {pkgName, pkgPath, isRecordName} = pkgParams; + // rollup uses commonjs plugin to handle commonjs files, + // the commonjs files are prefixed with '\x00' and need to be removed. if (filePath.startsWith('\x00')) { filePath = filePath.replace('\x00', ''); } let unixFilePath: string = toUnixPath(filePath); unixFilePath = unixFilePath.substring(0, filePath.lastIndexOf('.')); // remove extension let projectFilePath: string = unixFilePath.replace(toUnixPath(pkgPath), ''); - const pkgContextInfo = projectConfig.pkgContextInfo; - if (projectFilePath === '') { - projectFilePath = `/${pkgContextInfo.entryPath}`; - projectFilePath = projectFilePath.substring(0, filePath.lastIndexOf('.')); - } - let pkgInfo = pkgContextInfo[pkgName]; + // case1: /entry/src/main/ets/xxx/yyy + // case2: /entry/src/ohosTest/ets/xxx/yyy + // case3: /node_modules/xxx/yyy + // case4: /entry/node_modules/xxx/yyy + // case5: /library/node_modules/xxx/yyy + // case6: /library/index.ts + // ---> @normalized:N&&&/entry/ets/xxx/yyy& + let pkgInfo = projectConfig.pkgContextInfo[pkgName]; if (pkgInfo === undefined) { logger.error(red, `ArkTS:ERROR Failed to get a resolved OhmUrl for "${filePath}" imported by "${importerFile}". ` + @@ -95,12 +100,14 @@ export function getNormalizedOhmUrlByFilepath(filePath: string, projectConfig: O } let recordName = `${pkgInfo.bundleName}&${pkgName}${projectFilePath}&${pkgInfo.version}`; if (isRecordName) { + // record name style: &/entry/ets/xxx/yyy& return recordName; } - return `${pkgInfo.isSO ? 'Y' : 'N'}&${pkgInfo.moduleName}&` + recordName; + return `${pkgInfo.isSO ? 'Y' : 'N'}&${pkgInfo.moduleName}&${recordName}`; } -export function getOhmUrlByFilepath(filePath: string, projectConfig: Object, logger: Object, namespace?: string, importerFile?: string): string { +export function getOhmUrlByFilepath(filePath: string, projectConfig: Object, logger: Object, namespace?: string, + importerFile?: string): string { // remove '\x00' from the rollup virtual commonjs file's filePath if (filePath.startsWith('\x00')) { filePath = filePath.replace('\x00', ''); @@ -247,10 +254,9 @@ export function getOhmUrlBySystemApiOrLibRequest(moduleRequest: string, config?: } if (REG_LIB_SO.test(moduleRequest.trim())) { if (useNormalizedOHMUrl) { - const pkgContextInfo = config.pkgContextInfo; - const pkgInfo = pkgContextInfo[moduleRequest]; - return `@normalized:${pkgInfo.isSO ? 'Y' : 'N'}&${pkgInfo.moduleName}&` + - `${pkgInfo.bundleName}&${moduleRequest}&${pkgInfo.version}`; + const pkgInfo = config.pkgContextInfo[moduleRequest]; + const isSo = pkgInfo.isSO ? 'Y' : 'N'; + return `@normalized:${isSo}&${pkgInfo.moduleName}&${pkgInfo.bundleName}&${moduleRequest}&${pkgInfo.version}`; } return moduleRequest.replace(REG_LIB_SO, (_, libsoKey) => { return `@app:${projectConfig.bundleName}/${projectConfig.moduleName}/${libsoKey}`; @@ -315,31 +321,36 @@ export function transformModuleSpecifier(sourcePath: string, sourceCode: string, } function removeSuffix(filePath: string) { - const typeExts = ['.d.ets', '.d.ts','.ets', '.ts']; - const mainName = filePath.split(path.sep).join('/'); - const ext: string | undefined = typeExts.find(ext => mainName.endsWith(ext)); - return ext ? mainName.substring(0, mainName.lastIndexOf(ext)) : mainName; + const SUFFIX_REG = /\.(?:d\.)?e?ts$/; + return filePath.split(path.sep).join('/').replace(SUFFIX_REG ,''); } -export function getNormalizedOhmUrlByHspName(pkgName: string, projectConfig: Object, +export function getNormalizedOhmUrlByHspName(aliasName: string, projectConfig: Object, logger?: Object, filePath?: string) { - const pkgContextInfo = projectConfig.pkgContextInfo; - let pkgInfo = pkgContextInfo[pkgName]; + let pkgName: string = aliasName; + const aliasPkgNameMap: Map = projectConfig.dependencyAliasMap; + if (aliasPkgNameMap.has(aliasName)) { + pkgName = aliasPkgNameMap.get(aliasName); + } + const pkgInfo: Object = projectConfig.pkgContextInfo[pkgName]; if (pkgInfo === undefined) { - logger.error(red, `ArkTS:INTERNAL ERROR: Not to found the package: ${pkgName}`, reset); + logger.error(red, `ArkTS:INTERNAL ERROR: package ${pkgName} not found`, reset); } - let normalizedPath = filePath; - if (normalizedPath === undefined) { + let normalizedPath: string = ''; + if (filePath === undefined) { normalizedPath = `${pkgName}/${toUnixPath(pkgInfo.entryPath)}`; normalizedPath = removeSuffix(normalizedPath); + } else { + const relativePath = toUnixPath(filePath).replace(aliasName, ''); + normalizedPath = `${pkgName}${relativePath}`; } - return `@normalized:${pkgInfo.isSO ? 'Y' : 'N'}&${pkgInfo.moduleName}&` + - `${pkgInfo.bundleName}&${normalizedPath}&${pkgInfo.version}`; + const isSo = pkgInfo.isSO ? 'Y' : 'N'; + return `@normalized:${isSo}&${pkgInfo.moduleName}&${pkgInfo.bundleName}&${normalizedPath}&${pkgInfo.version}`; } export function getOhmUrlByHspName(moduleRequest: string, projectConfig: Object, logger?: Object, useNormalizedOHMUrl: boolean = false): string | undefined { - // The harNameOhmMap store the old ohmurl with hsp package. + // The harNameOhmMap store the ohmurl with the alias of hsp package . if (projectConfig.harNameOhmMap) { // case1: "@ohos/lib" ---> "@bundle:bundleName/lib/ets/index" if (projectConfig.harNameOhmMap.hasOwnProperty(moduleRequest)) { 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 551bde8b6..285390780 100644 --- a/compiler/src/fast_build/ark_compiler/common/common_mode.ts +++ b/compiler/src/fast_build/ark_compiler/common/common_mode.ts @@ -51,7 +51,6 @@ export abstract class CommonMode { genAbcScriptPath: string; triggerAsync: Object; triggerEndSignal: Object; - useNormalizedOHMUrl: boolean; constructor(rollupObject: Object) { this.projectConfig = Object.assign(rollupObject.share.arkProjectConfig, rollupObject.share.projectConfig); @@ -68,7 +67,6 @@ export abstract class CommonMode { // If the child process throws an error by calling throwArkTsCompilerError(), IDE will reset the counting state. this.triggerAsync = rollupObject.async; this.triggerEndSignal = rollupObject.signal; - this.useNormalizedOHMUrl = this.getUseNormalizedOHMUrl(); } initCmdEnv() { @@ -101,13 +99,6 @@ export abstract class CommonMode { return args; } - private getUseNormalizedOHMUrl() { - if (this.projectConfig.hasOwnProperty('useNormalizedOHMUrl')) { - return this.projectConfig.useNormalizedOHMUrl; - } - return false; - } - private genHashJsonFilePath() { if (this.projectConfig.cachePath) { if (!fs.existsSync(this.projectConfig.cachePath) || !fs.statSync(this.projectConfig.cachePath).isDirectory()) { 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 4255d37bf..cda5f1289 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_mode.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_mode.ts @@ -137,6 +137,7 @@ export class ModuleMode extends CommonMode { protoFilePath: string; filterModuleInfos: Map; symlinkMap: Object; + useNormalizedOHMUrl: boolean; constructor(rollupObject: Object) { super(rollupObject); @@ -158,6 +159,7 @@ export class ModuleMode extends CommonMode { this.hashJsonObject = {}; this.filterModuleInfos = new Map(); this.symlinkMap = rollupObject.share.symlinkMap; + this.useNormalizedOHMUrl = this.isUsingNormalizedOHMUrl(); } prepareForCompilation(rollupObject: Object, parentEvent: Object): void { @@ -175,18 +177,24 @@ export class ModuleMode extends CommonMode { continue; } const moduleInfo: Object = module.getModuleInfo(moduleId); - if (moduleInfo['meta']['isNodeEntryFile']) { + if (moduleInfo['meta']['isNodeEntryFile'] && !this.useNormalizedOHMUrl) { this.getPackageEntryInfo(moduleId, moduleInfo['meta'], pkgEntryInfos); } this.processModuleInfos(moduleId, moduleInfos, moduleInfo['meta']); } - this.getDynamicImportEntryInfo(pkgEntryInfos); - this.getNativeModuleEntryInfo(pkgEntryInfos); + if (!this.useNormalizedOHMUrl) { + this.getDynamicImportEntryInfo(pkgEntryInfos); + this.getNativeModuleEntryInfo(pkgEntryInfos); + } this.moduleInfos = moduleInfos; this.pkgEntryInfos = pkgEntryInfos; } + private isUsingNormalizedOHMUrl() { + return !!this.projectConfig.useNormalizedOHMUrl; + } + private updatePkgEntryInfos(pkgEntryInfos: Map, key: String, value: PackageEntryInfo): void { if (!pkgEntryInfos.has(key)) { pkgEntryInfos.set(key, new PackageEntryInfo(key, value)); @@ -227,8 +235,7 @@ export class ModuleMode extends CommonMode { private getPackageEntryInfo(filePath: string, metaInfo: Object, pkgEntryInfos: Map): void { if (metaInfo['isLocalDependency']) { const hostModulesInfo: Object = metaInfo.hostModulesInfo; - let pkgBuildPath: string = getOhmUrlByFilepath(filePath, this.projectConfig, this.logger, metaInfo['moduleName']); - + const pkgBuildPath: string = getOhmUrlByFilepath(filePath, this.projectConfig, this.logger, metaInfo['moduleName']); hostModulesInfo.forEach(hostModuleInfo => { const hostDependencyName: string = hostModuleInfo['hostDependencyName']; const hostModuleName: string = hostModuleInfo['hostModuleName']; @@ -245,7 +252,6 @@ export class ModuleMode extends CommonMode { this.logger.debug("ArkTS:INTERNAL ERROR: Failed to get 'pkgPath' from metaInfo. File: ", filePath); return; } - const pkgPath: string = metaInfo['pkgPath']; let originPkgEntryPath: string = toUnixPath(filePath.replace(pkgPath, '')); if (originPkgEntryPath.startsWith('/')) { @@ -308,8 +314,7 @@ export class ModuleMode extends CommonMode { const isPackageModules = isPackageModulesFile(filePath, this.projectConfig); // if release mode, enable obfuscation, enable filename obfuscation -> call mangleFilePath() filePath = this.handleObfuscatedFilePath(filePath, isPackageModules); - - let namespace: string = metaInfo['moduleName']; + let moduleName: string = metaInfo['moduleName']; let recordName: string = ''; let sourceFile: string = filePath.replace(this.projectConfig.projectRootPath + path.sep, ''); let cacheFilePath: string = @@ -317,16 +322,19 @@ export class ModuleMode extends CommonMode { let packageName: string = ''; if (this.useNormalizedOHMUrl) { packageName = metaInfo['pkgName']; - const pkgPath = metaInfo['pkgPath'] - recordName = getNormalizedOhmUrlByFilepath(filePath, this.projectConfig, this.logger, - packageName, pkgPath, undefined, true); + const pkgParams = { + pkgName: packageName, + pkgPath: metaInfo['pkgPath'], + isRecordName: true + }; + recordName = getNormalizedOhmUrlByFilepath(filePath, this.projectConfig, this.logger, pkgParams, undefined); } else { - recordName = getOhmUrlByFilepath(filePath, this.projectConfig, this.logger, namespace); + recordName = getOhmUrlByFilepath(filePath, this.projectConfig, this.logger, moduleName); if (isPackageModules) { packageName = this.getPkgModulesFilePkgName(metaInfo['pkgPath']); } else { packageName = - metaInfo['isLocalDependency'] ? namespace : getPackageInfo(this.projectConfig.aceModuleJsonPath)[1]; + metaInfo['isLocalDependency'] ? moduleName : getPackageInfo(this.projectConfig.aceModuleJsonPath)[1]; } } 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 beb1e940f..90a8fb47f 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 @@ -135,19 +135,13 @@ export class ModuleSourceFile { let mockFileOhmUrl: string = ''; if (useNormalizedOHMUrl) { const targetModuleInfo: Object = rollupObject.getModuleInfo(filePath); - mockFileOhmUrl = getNormalizedOhmUrlByFilepath(mockFilePath, - ModuleSourceFile.projectConfig, - ModuleSourceFile.logger, - targetModuleInfo.meta.pkgName, - targetModuleInfo.meta.pkgPath, - importerFile); - mockFileOhmUrl = `@normalized:${mockFileOhmUrl}`; + mockFileOhmUrl = ModuleSourceFile.spliceNormalizedOhmurl(targetModuleInfo, mockFilePath, importerFile); } else { mockFileOhmUrl = getOhmUrlByFilepath(mockFilePath, - ModuleSourceFile.projectConfig, - ModuleSourceFile.logger, - rollupObject.share.projectConfig.entryModuleName, - importerFile); + ModuleSourceFile.projectConfig, + ModuleSourceFile.logger, + rollupObject.share.projectConfig.entryModuleName, + importerFile); mockFileOhmUrl = mockFileOhmUrl.startsWith(PACKAGES) ? `@package:${mockFileOhmUrl}` : `@bundle:${mockFileOhmUrl}`; } @@ -316,16 +310,11 @@ export class ModuleSourceFile { const targetModuleInfo: Object = rollupObject.getModuleInfo(filePath); let res: string = ""; if (useNormalizedOHMUrl) { - const pkgName = targetModuleInfo['meta']['pkgName']; - const pkgPath = targetModuleInfo['meta']['pkgPath']; - const ohmUrl: string = - getNormalizedOhmUrlByFilepath(filePath, ModuleSourceFile.projectConfig, ModuleSourceFile.logger, - pkgName, pkgPath, importerFile); - res = `@normalized:${ohmUrl}`; + res = ModuleSourceFile.spliceNormalizedOhmurl(targetModuleInfo, filePath, importerFile); } else { - const namespace: string = targetModuleInfo['meta']['moduleName']; + const moduleName: string = targetModuleInfo['meta']['moduleName']; const ohmUrl: string = - getOhmUrlByFilepath(filePath, ModuleSourceFile.projectConfig, ModuleSourceFile.logger, namespace, importerFile); + getOhmUrlByFilepath(filePath, ModuleSourceFile.projectConfig, ModuleSourceFile.logger, moduleName, importerFile); res = ohmUrl.startsWith(PACKAGES) ? `@package:${ohmUrl}` : `@bundle:${ohmUrl}`; } if (ModuleSourceFile.needProcessMock) { @@ -342,6 +331,18 @@ export class ModuleSourceFile { return undefined; } + private static spliceNormalizedOhmurl(moduleInfo: Object, filePath: string, importerFile: string): string { + const pkgParams = { + pkgName: moduleInfo['meta']['pkgName'], + pkgPath: moduleInfo['meta']['pkgPath'], + isRecordName: false + }; + const ohmUrl: string = + getNormalizedOhmUrlByFilepath(filePath, ModuleSourceFile.projectConfig, ModuleSourceFile.logger, pkgParams, + importerFile); + return `@normalized:${ohmUrl}`; + } + private processJsModuleRequest(rollupObject: Object): void { const moduleInfo: Object = rollupObject.getModuleInfo(this.moduleId); const importMap: Object = moduleInfo.importedIdMaps; diff --git a/compiler/test/ark_compiler_ut/mock/rollup_mock/project_config.ts b/compiler/test/ark_compiler_ut/mock/rollup_mock/project_config.ts index 726f009d5..db92c7b10 100644 --- a/compiler/test/ark_compiler_ut/mock/rollup_mock/project_config.ts +++ b/compiler/test/ark_compiler_ut/mock/rollup_mock/project_config.ts @@ -109,6 +109,7 @@ class ProjectConfig { projectRootPath: string; pkgContextInfo: object; useNormalizedOHMUrl: boolean = false; + dependencyAliasMap: Map; constructor(buildMode: string) { this.watchMode = 'false'; 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 24f0634e6..c98f599e6 100644 --- a/compiler/test/ark_compiler_ut/module/ohmUrl/ohmUrl.test.ts +++ b/compiler/test/ark_compiler_ut/module/ohmUrl/ohmUrl.test.ts @@ -17,7 +17,11 @@ import { expect } from 'chai'; import mocha from 'mocha'; import sinon from 'sinon'; -import { getOhmUrlByFilepath, getOhmUrlBySystemApiOrLibRequest, getOhmUrlByHspName } from '../../../../lib/ark_utils'; +import { + getOhmUrlByFilepath, + getOhmUrlByHspName, + getOhmUrlBySystemApiOrLibRequest +} from '../../../../lib/ark_utils'; import { PACKAGES } from '../../../../lib/pre_define'; import projectConfig from '../../utils/processProjectConfig'; import { projectConfig as mainProjectConfig } from '../../../../main'; @@ -35,10 +39,10 @@ mocha.describe('generate ohmUrl', function () { }); mocha.it('nested src main ets|js in filePath', function () { - const filePath = `${projectConfig.projectRootPath}/entry/src/main/ets/feature/src/main/js/` + const filePath: string = `${projectConfig.projectRootPath}/entry/src/main/ets/feature/src/main/js/` + `subfeature/src/main/ets/pages/test.ts`; - const moduleName = 'entry'; - const moduleNamespace = 'library'; + const moduleName: string = 'entry'; + const moduleNamespace: string = 'library'; let ohmUrl_1 = getOhmUrlByFilepath(filePath, projectConfig, undefined, moduleName); let ohmUrl_2 = getOhmUrlByFilepath(filePath, projectConfig, undefined, moduleNamespace); let expected_1 = 'UtTestApplication/entry/ets/feature/src/main/js/subfeature/src/main/ets/pages/test'; @@ -48,10 +52,10 @@ mocha.describe('generate ohmUrl', function () { }); mocha.it('nested src ohosTest ets|js in filePath', function () { - const filePath = `${projectConfig.projectRootPath}/entry/src/ohosTest/ets/feature/src/main/js/` + const filePath: string = `${projectConfig.projectRootPath}/entry/src/ohosTest/ets/feature/src/main/js/` + `subfeature/src/main/ets/pages/test.ts`; - const moduleName = 'entry'; - const moduleNamespace = 'library'; + const moduleName: string = 'entry'; + const moduleNamespace: string = 'library'; let ohmUrl_1 = getOhmUrlByFilepath(filePath, projectConfig, undefined, moduleName); let ohmUrl_2 = getOhmUrlByFilepath(filePath, projectConfig, undefined, moduleNamespace); let expected_1 = 'UtTestApplication/entry/ets/feature/src/main/js/subfeature/src/main/ets/pages/test'; @@ -93,10 +97,10 @@ mocha.describe('generate ohmUrl', function () { }); mocha.it('project module', function () { - const filePath = `${projectConfig.projectRootPath}/entry/src/main/ets/pages/test.ts`; + const filePath: string = `${projectConfig.projectRootPath}/entry/src/main/ets/pages/test.ts`; const harFilePath = `${projectConfig.projectRootPath}/library/src/main/ets/pages/test.ts`; - const moduleName = 'entry'; - const moduleNamespace = 'library'; + const moduleName: string = 'entry'; + const moduleNamespace: string = 'library'; const ohmUrl = getOhmUrlByFilepath(filePath, projectConfig, undefined, moduleName); const harOhmUrl = getOhmUrlByFilepath(harFilePath, projectConfig, undefined, moduleNamespace); const expected = 'UtTestApplication/entry/ets/pages/test'; @@ -108,7 +112,7 @@ mocha.describe('generate ohmUrl', function () { mocha.it('thirdParty module', function () { const moduleLevelPkgPath = `${projectConfig.projectRootPath}/entry/oh_modules/json5/dist/index.js`; const projectLevelPkgPath = `${projectConfig.projectRootPath}/oh_modules/json5/dist/index.js`; - const moduleName = 'entry'; + const moduleName: string = 'entry'; const moduleLevelPkgOhmUrl = getOhmUrlByFilepath(moduleLevelPkgPath, projectConfig, undefined, undefined); const projectLevelPkgOhmUrl = getOhmUrlByFilepath(projectLevelPkgPath, projectConfig, undefined, undefined); const moduleLevelPkgOhmUrlExpected = `${PACKAGES}@${moduleName}/json5/dist/index`; @@ -119,7 +123,7 @@ mocha.describe('generate ohmUrl', function () { mocha.it('static library entry', function () { const staticLibraryEntry = `${projectConfig.projectRootPath}/library/index.ets`; - const moduleNamespace = 'library'; + const moduleNamespace: string = 'library'; const staticLibraryEntryOhmUrl = getOhmUrlByFilepath(staticLibraryEntry, projectConfig, undefined, moduleNamespace); const staticLibraryEntryOhmUrlExpected = 'UtTestApplication/entry@library/index'; @@ -128,7 +132,7 @@ mocha.describe('generate ohmUrl', function () { mocha.it('ohosTest module', function () { const ohosTestfilePath = `${projectConfig.projectRootPath}/entry/src/ohosTest/ets/pages/test.ts`; - const moduleName = 'entry'; + const moduleName: string = 'entry'; const ohmUrl = getOhmUrlByFilepath(ohosTestfilePath, projectConfig, undefined, moduleName); const expected = 'UtTestApplication/entry/ets/pages/test'; expect(ohmUrl == expected).to.be.true; @@ -139,16 +143,16 @@ mocha.describe('generate ohmUrl', function () { projectConfig.modulePathMap = {}; const red: string = '\u001b[31m'; const reset: string = '\u001b[39m'; - const filePath = `${projectConfig.projectRootPath}/entry/oh_modules/json5/dist/index.js`; - const moduleName = 'entry'; - const importerFile = 'importTest.ts'; + const filePath: string = `${projectConfig.projectRootPath}/entry/oh_modules/json5/dist/index.js`; + const moduleName: string = 'entry'; + const importerFile: string = 'importTest.ts'; const logger = this.rollup.share.getLogger(GEN_ABC_PLUGIN_NAME) const loggerStub = sinon.stub(logger, 'error'); getOhmUrlByFilepath(filePath, projectConfig, logger, moduleName, importerFile); expect(loggerStub.calledWith(red, `ArkTS:ERROR Failed to get a resolved OhmUrl for "${filePath}" imported by "${importerFile}". ` + - `Please check whether the module which ${filePath} belongs to is correctly configured` + - `and the corresponding file name matches (case sensitive)`, reset)).to.be.true; + `Please check whether the module which ${filePath} belongs to is correctly configured ` + + `and the corresponding file name is correct(including case-sensitivity)`, reset)).to.be.true; loggerStub.restore(); }); @@ -158,20 +162,20 @@ mocha.describe('generate ohmUrl', function () { projectConfig.modulePathMap = {}; const red: string = '\u001b[31m'; const reset: string = '\u001b[39m'; - const filePath = `${projectConfig.projectRootPath}/entry/oh_modules/json5/dist/index.js`; - const moduleName = 'entry'; - const importerFile = 'importTest.ts'; + const filePath: string = `${projectConfig.projectRootPath}/entry/oh_modules/json5/dist/index.js`; + const moduleName: string = 'entry'; + const importerFile: string = 'importTest.ts'; const logger = this.rollup.share.getLogger(GEN_ABC_PLUGIN_NAME) const loggerStub = sinon.stub(logger, 'error'); getOhmUrlByFilepath(filePath, projectConfig, logger, moduleName, importerFile); expect(loggerStub.calledWith(red, `ArkTS:ERROR Failed to get a resolved OhmUrl for "${filePath}" imported by "${importerFile}". ` + - `Please check whether the module which ${filePath} belongs to is correctly configured` + - `and the corresponding file name matches (case sensitive)`, reset)).to.be.true; + `Please check whether the module which ${filePath} belongs to is correctly configured ` + + `and the corresponding file name is correct(including case-sensitivity)`, reset)).to.be.true; loggerStub.restore(); }); - mocha.it('inter-app hsp self import', function () { + mocha.it('NormalizedOHMUrl inter-app hsp self import', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -184,7 +188,7 @@ mocha.describe('generate ohmUrl', function () { 'isSO': false } } - const filePath = '/testHsp/hsp/src/main/ets/utils/Calc.ets'; + const filePath: string = '/testHsp/hsp/src/main/ets/utils/Calc.ets'; const moduleInfo = { id: filePath, meta: { @@ -193,22 +197,24 @@ mocha.describe('generate ohmUrl', function () { } } this.rollup.moduleInfos.push(moduleInfo); - const importerFile = '/testHsp/hsp/src/main/ets/pages/Index.ets' - const relativePath = '../utils/Calc'; - const etsBasedAbsolutePath = 'ets/utils/Calc'; - const standardImportPath = 'pkghsp/src/main/ets/utils/Calc'; - const moduleSourceFile = new ModuleSourceFile(); + const importerFile: string = '/testHsp/hsp/src/main/ets/pages/Index.ets' + const relativePath: string = '../utils/Calc'; + const etsBasedAbsolutePath: string = 'ets/utils/Calc'; + const standardImportPath: string = 'pkghsp/src/main/ets/utils/Calc'; + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); - const relativePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); - const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, importerFile); - const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); - const expectedNormalizedOhmUrl = '@normalized:N&&com.test.testHsp&pkghsp/src/main/ets/utils/Calc&'; + const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); + const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, + importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, + importerFile); + const expectedNormalizedOhmUrl: string = '@normalized:N&&com.test.testHsp&pkghsp/src/main/ets/utils/Calc&'; expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; }); - mocha.it('inter-app hsp others import', function () { + mocha.it('NormalizedOHMUrl inter-app hsp others import', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -221,25 +227,30 @@ mocha.describe('generate ohmUrl', function () { 'isSO': false } } - this.rollup.share.projectConfig.harNameOhmMap ={ - 'pkghsp': '@bundle:com.test.testHsp/src/main/ets/utils/Calc' + this.rollup.share.projectConfig.dependencyAliasMap = new Map([ + ['pkghsp_alias', 'pkghsp'] + ]); + this.rollup.share.projectConfig.harNameOhmMap = { + 'pkghsp_alias': '@bundle:com.test.testHsp/src/main/ets/utils/Calc' } - const filePath = 'pkghsp/src/main/ets/utils/Calc'; - const indexFilePath = 'pkghsp'; - const importerFile = '/testHap/entry/src/main/ets/pages/index.ets' - const importByPkgName = 'pkghsp'; - const standardImportPath = 'pkghsp/src/main/ets/utils/Calc'; - const moduleSourceFile = new ModuleSourceFile(); + const filePath: string = 'pkghsp/src/main/ets/utils/Calc'; + const indexFilePath: string = 'pkghsp_alias'; + const importerFile: string = '/testHap/entry/src/main/ets/pages/index.ets' + const importByPkgName = 'pkghsp_alias'; + const standardImportPath: string = 'pkghsp_alias/src/main/ets/utils/Calc'; + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); - const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); - const importByPkgNameNormalizedOhmUrl = '@normalized:N&hsp&com.test.testHsp&pkghsp/Index&'; - const standardImportPathNormalizedOhmUrl = '@normalized:N&hsp&com.test.testHsp&pkghsp/src/main/ets/utils/Calc&'; + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, + importerFile); + const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&hsp&com.test.testHsp&pkghsp/Index&'; + const standardImportPathNormalizedOhmUrl: string = + '@normalized:N&hsp&com.test.testHsp&pkghsp/src/main/ets/utils/Calc&'; expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; }); - mocha.it('in-app hsp self import', function () { + mocha.it('NormalizedOHMUrl in-app hsp self import', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -252,7 +263,7 @@ mocha.describe('generate ohmUrl', function () { 'isSO': false } } - const filePath = '/testHsp/hsp/src/main/ets/utils/Calc.ets'; + const filePath: string = '/testHsp/hsp/src/main/ets/utils/Calc.ets'; const moduleInfo = { id: filePath, meta: { @@ -261,22 +272,24 @@ mocha.describe('generate ohmUrl', function () { } } this.rollup.moduleInfos.push(moduleInfo); - const importerFile = '/testHsp/hsp/src/main/ets/pages/Index.ets' - const relativePath = '../utils/Calc'; - const etsBasedAbsolutePath = 'ets/utils/Calc'; - const standardImportPath = 'pkghsp/src/main/ets/utils/Calc'; - const moduleSourceFile = new ModuleSourceFile(); + const importerFile: string = '/testHsp/hsp/src/main/ets/pages/Index.ets' + const relativePath: string = '../utils/Calc'; + const etsBasedAbsolutePath: string = 'ets/utils/Calc'; + const standardImportPath: string = 'pkghsp/src/main/ets/utils/Calc'; + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); - const relativePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); - const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, importerFile); - const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); - const expectedNormalizedOhmUrl = '@normalized:N&&&pkghsp/src/main/ets/utils/Calc&'; + const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); + const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, + importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, + importerFile); + const expectedNormalizedOhmUrl: string = '@normalized:N&&&pkghsp/src/main/ets/utils/Calc&'; expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; }); - mocha.it('in-app hsp others import', function () { + mocha.it('NormalizedOHMUrl in-app hsp others import', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -289,26 +302,30 @@ mocha.describe('generate ohmUrl', function () { 'isSO': false } } - this.rollup.share.projectConfig.harNameOhmMap ={ - 'pkghsp': '@bundle:com.test.testHap/src/main/ets/utils/Calc' + this.rollup.share.projectConfig.dependencyAliasMap = new Map([ + ['pkghsp_alias', 'pkghsp'] + ]); + this.rollup.share.projectConfig.harNameOhmMap = { + 'pkghsp_alias': '@bundle:com.test.testHap/src/main/ets/utils/Calc' } - const filePath = 'pkghsp/src/main/ets/utils/Calc'; - const indexFilePath = 'pkghsp'; + const filePath: string = 'pkghsp_alias/src/main/ets/utils/Calc'; + const indexFilePath: string = 'pkghsp_alias'; - const importerFile = '/testHap/entry/src/main/ets/pages/index.ets' - const importByPkgName = 'pkghsp'; - const standardImportPath = 'pkghsp/src/main/ets/utils/Calc'; - const moduleSourceFile = new ModuleSourceFile(); + const importerFile: string = '/testHap/entry/src/main/ets/pages/index.ets' + const importByPkgName = 'pkghsp_alias'; + const standardImportPath: string = 'pkghsp_alias/src/main/ets/utils/Calc'; + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); - const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); - const importByPkgNameNormalizedOhmUrl = '@normalized:N&hsp&&pkghsp/Index&'; - const standardImportPathNormalizedOhmUrl = '@normalized:N&hsp&&pkghsp/src/main/ets/utils/Calc&'; + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, + importerFile); + const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&hsp&&pkghsp/Index&'; + const standardImportPathNormalizedOhmUrl: string = '@normalized:N&hsp&&pkghsp/src/main/ets/utils/Calc&'; expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; }); - mocha.it('hap self import', function () { + mocha.it('NormalizedOHMUrl hap self import', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -321,7 +338,7 @@ mocha.describe('generate ohmUrl', function () { 'isSO': false } } - const filePath = '/testHap/entry/src/main/ets/utils/Calc.ets'; + const filePath: string = '/testHap/entry/src/main/ets/utils/Calc.ets'; const moduleInfo = { id: filePath, meta: { @@ -330,22 +347,24 @@ mocha.describe('generate ohmUrl', function () { } } this.rollup.moduleInfos.push(moduleInfo); - const importerFile = '/testHap/entry/src/main/ets/pages/index.ets' - const relativePath = '../utils/Calc'; - const etsBasedAbsolutePath = 'ets/utils/Calc'; - const standardImportPath = 'entry/src/main/ets/utils/Calc'; - const moduleSourceFile = new ModuleSourceFile(); + const importerFile: string = '/testHap/entry/src/main/ets/pages/index.ets' + const relativePath: string = '../utils/Calc'; + const etsBasedAbsolutePath: string = 'ets/utils/Calc'; + const standardImportPath: string = 'entry/src/main/ets/utils/Calc'; + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); - const relativePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); - const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, importerFile); - const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); - const expectedNormalizedOhmUrl = '@normalized:N&&&entry/src/main/ets/utils/Calc&'; + const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); + const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, + importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, + importerFile); + const expectedNormalizedOhmUrl: string = '@normalized:N&&&entry/src/main/ets/utils/Calc&'; expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; }); - mocha.it('source code har self import (hap/in-app hsp)', function () { + mocha.it('NormalizedOHMUrl source code har self import (hap/in-app hsp)', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -358,7 +377,7 @@ mocha.describe('generate ohmUrl', function () { 'isSO': false } } - const filePath = '/testHar/har/src/main/ets/utils/Calc.ets'; + const filePath: string = '/testHar/har/src/main/ets/utils/Calc.ets'; const moduleInfo = { id: filePath, meta: { @@ -367,22 +386,24 @@ mocha.describe('generate ohmUrl', function () { } } this.rollup.moduleInfos.push(moduleInfo); - const importerFile = '/testHar/har/src/main/ets/pages/Index.ets' - const relativePath = '../utils/Calc'; - const etsBasedAbsolutePath = 'ets/utils/Calc'; - const standardImportPath = 'pkghar/src/main/ets/utils/Calc'; - const moduleSourceFile = new ModuleSourceFile(); + const importerFile: string = '/testHar/har/src/main/ets/pages/Index.ets' + const relativePath: string = '../utils/Calc'; + const etsBasedAbsolutePath: string = 'ets/utils/Calc'; + const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc'; + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); - const relativePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); - const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, importerFile); - const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); - const expectedNormalizedOhmUrl = '@normalized:N&&&pkghar/src/main/ets/utils/Calc&1.0.1'; + const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); + const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, + importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, + importerFile); + const expectedNormalizedOhmUrl: string = '@normalized:N&&&pkghar/src/main/ets/utils/Calc&1.0.1'; expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; }); - mocha.it('source code har others import (hap/in-app hsp)', function () { + mocha.it('NormalizedOHMUrl source code har others import (hap/in-app hsp)', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -395,8 +416,8 @@ mocha.describe('generate ohmUrl', function () { 'isSO': false } } - const filePath = '/testHar/har/src/main/ets/utils/Calc.ets'; - const indexFilePath = '/testHar/har/Index.ets'; + const filePath: string = '/testHar/har/src/main/ets/utils/Calc.ets'; + const indexFilePath: string = '/testHar/har/Index.ets'; for (let file of [filePath, indexFilePath]) { const moduleInfo = { id: file, @@ -407,20 +428,21 @@ mocha.describe('generate ohmUrl', function () { } this.rollup.moduleInfos.push(moduleInfo); } - const importerFile = '/testHar/entry/src/main/ets/pages/Index.ets' + const importerFile: string = '/testHar/entry/src/main/ets/pages/Index.ets' const importByPkgName = 'pkghar'; - const standardImportPath = 'pkghar/src/main/ets/utils/Calc'; - const moduleSourceFile = new ModuleSourceFile(); + const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc'; + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); - const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); - const importByPkgNameNormalizedOhmUrl = '@normalized:N&&&pkghar/Index&1.0.1'; - const standardImportPathNormalizedOhmUrl = '@normalized:N&&&pkghar/src/main/ets/utils/Calc&1.0.1'; + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, + importerFile); + const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&&pkghar/Index&1.0.1'; + const standardImportPathNormalizedOhmUrl: string = '@normalized:N&&&pkghar/src/main/ets/utils/Calc&1.0.1'; expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; }); - mocha.it('source code har self import (inter-app hsp)', function () { + mocha.it('NormalizedOHMUrl source code har self import (inter-app hsp)', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -433,7 +455,7 @@ mocha.describe('generate ohmUrl', function () { 'isSO': false } } - const filePath = '/testHsp/har/src/main/ets/utils/Calc.ets'; + const filePath: string = '/testHsp/har/src/main/ets/utils/Calc.ets'; const moduleInfo = { id: filePath, meta: { @@ -442,22 +464,24 @@ mocha.describe('generate ohmUrl', function () { } } this.rollup.moduleInfos.push(moduleInfo); - const importerFile = '/testHsp/har/src/main/ets/pages/Index.ets' - const relativePath = '../utils/Calc'; - const etsBasedAbsolutePath = 'ets/utils/Calc'; - const standardImportPath = 'pkghar/src/main/ets/utils/Calc'; - const moduleSourceFile = new ModuleSourceFile(); + const importerFile: string = '/testHsp/har/src/main/ets/pages/Index.ets' + const relativePath: string = '../utils/Calc'; + const etsBasedAbsolutePath: string = 'ets/utils/Calc'; + const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc'; + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); - const relativePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); - const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, importerFile); - const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); - const expectedNormalizedOhmUrl = '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1'; + const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); + const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, + importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, + importerFile); + const expectedNormalizedOhmUrl: string = '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1'; expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; }); - mocha.it('source code har others import (inter-app hsp)', function () { + mocha.it('NormalizedOHMUrl source code har others import (inter-app hsp)', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -470,8 +494,8 @@ mocha.describe('generate ohmUrl', function () { 'isSO': false } } - const filePath = '/testHsp/har/src/main/ets/utils/Calc.ets'; - const indexFilePath = '/testHsp/har/Index.ets'; + const filePath: string = '/testHsp/har/src/main/ets/utils/Calc.ets'; + const indexFilePath: string = '/testHsp/har/Index.ets'; for (let file of [filePath, indexFilePath]) { const moduleInfo = { id: file, @@ -482,20 +506,22 @@ mocha.describe('generate ohmUrl', function () { } this.rollup.moduleInfos.push(moduleInfo); } - const importerFile = '/testHsp/hsp/src/main/ets/pages/Index.ets' + const importerFile: string = '/testHsp/hsp/src/main/ets/pages/Index.ets' const importByPkgName = 'pkghar'; - const standardImportPath = 'pkghar/src/main/ets/utils/Calc'; - const moduleSourceFile = new ModuleSourceFile(); + const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc'; + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); - const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); - const importByPkgNameNormalizedOhmUrl = '@normalized:N&&com.test.testHsp&pkghar/Index&1.0.1'; - const standardImportPathNormalizedOhmUrl = '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1'; + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, + importerFile); + const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&com.test.testHsp&pkghar/Index&1.0.1'; + const standardImportPathNormalizedOhmUrl: string = + '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1'; expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; }); - mocha.it('product har self import (hap/in-app hsp)', function () { + mocha.it('NormalizedOHMUrl product har self import (hap/in-app hsp)', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -508,7 +534,7 @@ mocha.describe('generate ohmUrl', function () { 'isSO': false } } - const filePath = '/testHar/har/src/main/ets/utils/Calc.ets'; + const filePath: string = '/testHar/har/src/main/ets/utils/Calc.ets'; const moduleInfo = { id: filePath, meta: { @@ -517,22 +543,24 @@ mocha.describe('generate ohmUrl', function () { } } this.rollup.moduleInfos.push(moduleInfo); - const importerFile = '/testHar/har/src/main/ets/pages/Index.ets' - const relativePath = '../utils/Calc'; - const etsBasedAbsolutePath = 'ets/utils/Calc'; - const standardImportPath = 'pkghar/src/main/ets/utils/Calc'; - const moduleSourceFile = new ModuleSourceFile(); + const importerFile: string = '/testHar/har/src/main/ets/pages/Index.ets' + const relativePath: string = '../utils/Calc'; + const etsBasedAbsolutePath: string = 'ets/utils/Calc'; + const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc'; + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); - const relativePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); - const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, importerFile); - const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); - const expectedNormalizedOhmUrl = '@normalized:N&&&pkghar/src/main/ets/utils/Calc&1.0.1'; + const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); + const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, + importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, + importerFile); + const expectedNormalizedOhmUrl: string = '@normalized:N&&&pkghar/src/main/ets/utils/Calc&1.0.1'; expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; }); - mocha.it('product har others import (hap/in-app hsp)', function () { + mocha.it('NormalizedOHMUrl product har others import (hap/in-app hsp)', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -545,8 +573,8 @@ mocha.describe('generate ohmUrl', function () { 'isSO': false } } - const filePath = '/testHap/oh_modules/.ohpm/pkghar@test=/oh_modules/pkghar/src/main/ets/utils/Calc.ets'; - const indexFilePath = '/testHap/oh_modules/.ohpm/pkghar@test=/oh_modules/pkghar/Index.ets'; + const filePath: string = '/testHap/oh_modules/.ohpm/pkghar@test=/oh_modules/pkghar/src/main/ets/utils/Calc.ets'; + const indexFilePath: string = '/testHap/oh_modules/.ohpm/pkghar@test=/oh_modules/pkghar/Index.ets'; for (let file of [filePath, indexFilePath]) { const moduleInfo = { id: file, @@ -557,20 +585,21 @@ mocha.describe('generate ohmUrl', function () { } this.rollup.moduleInfos.push(moduleInfo); } - const importerFile = '/testHar/entry/src/main/ets/pages/index.ets' + const importerFile: string = '/testHar/entry/src/main/ets/pages/index.ets' const importByPkgName = 'pkghar'; - const standardImportPath = 'pkghar/src/main/ets/utils/Calc'; - const moduleSourceFile = new ModuleSourceFile(); + const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc'; + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); - const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); - const importByPkgNameNormalizedOhmUrl = '@normalized:N&&&pkghar/Index&1.0.1'; - const standardImportPathNormalizedOhmUrl = '@normalized:N&&&pkghar/src/main/ets/utils/Calc&1.0.1'; + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, + importerFile); + const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&&pkghar/Index&1.0.1'; + const standardImportPathNormalizedOhmUrl: string = '@normalized:N&&&pkghar/src/main/ets/utils/Calc&1.0.1'; expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; }); - mocha.it('remote source code har self import (inter-app hsp)', function () { + mocha.it('NormalizedOHMUrl remote source code har self import (inter-app hsp)', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -583,7 +612,7 @@ mocha.describe('generate ohmUrl', function () { 'isSO': false } } - const filePath = '/testHsp/har/src/main/ets/utils/Calc.ets'; + const filePath: string = '/testHsp/har/src/main/ets/utils/Calc.ets'; const moduleInfo = { id: filePath, meta: { @@ -592,22 +621,24 @@ mocha.describe('generate ohmUrl', function () { } } this.rollup.moduleInfos.push(moduleInfo); - const importerFile = '/testHsp/har/src/main/ets/pages/Index.ets' - const relativePath = '../utils/Calc'; - const etsBasedAbsolutePath = 'ets/utils/Calc'; - const standardImportPath = 'pkghar/src/main/ets/utils/Calc'; - const moduleSourceFile = new ModuleSourceFile(); + const importerFile: string = '/testHsp/har/src/main/ets/pages/Index.ets' + const relativePath: string = '../utils/Calc'; + const etsBasedAbsolutePath: string = 'ets/utils/Calc'; + const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc'; + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); - const relativePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); - const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, importerFile); - const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); - const expectedNormalizedOhmUrl = '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1'; + const relativePathOhmUrl: string = moduleSourceFile.getOhmUrl(this.rollup, relativePath, filePath, importerFile); + const etsBasedAbsolutePathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, etsBasedAbsolutePath, filePath, + importerFile); + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, + importerFile); + const expectedNormalizedOhmUrl: string = '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1'; expect(relativePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; expect(etsBasedAbsolutePathOhmUrl == expectedNormalizedOhmUrl).to.be.true; expect(standardImportPathOhmUrl == expectedNormalizedOhmUrl).to.be.true; }); - mocha.it('remote source code har others import (inter-app hsp)', function () { + mocha.it('NormalizedOHMUrl remote source code har others import (inter-app hsp)', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -620,8 +651,8 @@ mocha.describe('generate ohmUrl', function () { 'isSO': false } } - const filePath = '/testHsp/har/src/main/ets/utils/Calc.ets'; - const indexFilePath = '/testHsp/har/Index.ets'; + const filePath: string = '/testHsp/har/src/main/ets/utils/Calc.ets'; + const indexFilePath: string = '/testHsp/har/Index.ets'; for (let file of [filePath, indexFilePath]) { const moduleInfo = { id: file, @@ -632,20 +663,22 @@ mocha.describe('generate ohmUrl', function () { } this.rollup.moduleInfos.push(moduleInfo); } - const importerFile = '/testHsp/hsp/src/main/ets/pages/Index.ets' + const importerFile: string = '/testHsp/hsp/src/main/ets/pages/Index.ets' const importByPkgName = 'pkghar'; - const standardImportPath = 'pkghar/src/main/ets/utils/Calc'; - const moduleSourceFile = new ModuleSourceFile(); + const standardImportPath: string = 'pkghar/src/main/ets/utils/Calc'; + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); - const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); - const importByPkgNameNormalizedOhmUrl = '@normalized:N&&com.test.testHsp&pkghar/Index&1.0.1'; - const standardImportPathNormalizedOhmUrl = '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1'; + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, + importerFile); + const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&com.test.testHsp&pkghar/Index&1.0.1'; + const standardImportPathNormalizedOhmUrl: string = + '@normalized:N&&com.test.testHsp&pkghar/src/main/ets/utils/Calc&1.0.1'; expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; }); - mocha.it('native so others import (hap/in-app hsp)', function () { + mocha.it('NormalizedOHMUrl native so others import (hap/in-app hsp)', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -658,16 +691,16 @@ mocha.describe('generate ohmUrl', function () { 'isSO': true } } - const importerFile = '/testHap/hsp/src/main/ets/pages/Index.ets' + const importerFile: string = '/testHap/hsp/src/main/ets/pages/Index.ets' const moduleRequest = 'libproduct.so'; - const moduleSourceFile = new ModuleSourceFile(); + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); const moduleRequestOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, undefined, importerFile); - const expectedNormalizedOhmUrl = '@normalized:Y&&&libproduct.so&'; + const expectedNormalizedOhmUrl: string = '@normalized:Y&&&libproduct.so&'; expect(moduleRequestOhmUrl == expectedNormalizedOhmUrl).to.be.true; }); - mocha.it('native so others import (inter-app hsp)', function () { + mocha.it('NormalizedOHMUrl native so others import (inter-app hsp)', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -680,16 +713,16 @@ mocha.describe('generate ohmUrl', function () { 'isSO': true } } - const importerFile = '/testHsp/hsp/src/main/ets/pages/Index.ets' + const importerFile: string = '/testHsp/hsp/src/main/ets/pages/Index.ets' const moduleRequest = 'libproduct.so'; - const moduleSourceFile = new ModuleSourceFile(); + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); const moduleRequestOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, undefined, importerFile); - const expectedNormalizedOhmUrl = '@normalized:Y&&com.test.testHsp&libproduct.so&'; + const expectedNormalizedOhmUrl: string = '@normalized:Y&&com.test.testHsp&libproduct.so&'; expect(moduleRequestOhmUrl == expectedNormalizedOhmUrl).to.be.true; }); - mocha.it('native so others import (source code har)', function () { + mocha.it('NormalizedOHMUrl native so others import (source code har)', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -702,16 +735,16 @@ mocha.describe('generate ohmUrl', function () { 'isSO': true } } - const importerFile = '/testHap/har/src/main/ets/pages/Index.ets' + const importerFile: string = '/testHap/har/src/main/ets/pages/Index.ets' const moduleRequest = 'libhar.so'; - const moduleSourceFile = new ModuleSourceFile(); + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); const moduleRequestOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, undefined, importerFile); - const expectedNormalizedOhmUrl = '@normalized:Y&&&libhar.so&'; + const expectedNormalizedOhmUrl: string = '@normalized:Y&&&libhar.so&'; expect(moduleRequestOhmUrl == expectedNormalizedOhmUrl).to.be.true; }); - mocha.it('native so others import (product har)', function () { + mocha.it('NormalizedOHMUrl native so others import (product har)', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -724,16 +757,17 @@ mocha.describe('generate ohmUrl', function () { 'isSO': true } } - const importerFile = '/testHap/oh_modules/.ohpm/pkghar@test+har=/oh_modules/pkghar/src/main/ets/pages/Index.ets'; + const importerFile: string = + '/testHap/oh_modules/.ohpm/pkghar@test+har=/oh_modules/pkghar/src/main/ets/pages/Index.ets'; const moduleRequest = 'libhar.so'; - const moduleSourceFile = new ModuleSourceFile(); + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); const moduleRequestOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, moduleRequest, undefined, importerFile); - const expectedNormalizedOhmUrl = '@normalized:Y&&&libhar.so&'; + const expectedNormalizedOhmUrl: string = '@normalized:Y&&&libhar.so&'; expect(moduleRequestOhmUrl == expectedNormalizedOhmUrl).to.be.true; }); - mocha.it('ohpm package others import (hap/in-app hsp)', function () { + mocha.it('NormalizedOHMUrl ohpm package others import (hap/in-app hsp)', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -746,8 +780,9 @@ mocha.describe('generate ohmUrl', function () { 'isSO': false } } - const filePath = '/testHap/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/src/main/ets/utils/Calc.ets' - const indexFilePath = '/testHap/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/index.ets'; + const filePath: string = + '/testHap/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/src/main/ets/utils/Calc.ets' + const indexFilePath: string = '/testHap/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/index.ets'; for (let file of [filePath, indexFilePath]) { const moduleInfo = { id: file, @@ -758,20 +793,21 @@ mocha.describe('generate ohmUrl', function () { } this.rollup.moduleInfos.push(moduleInfo); } - const importerFile = '/testHap/entry/src/main/ets/pages/index.ets' + const importerFile: string = '/testHap/entry/src/main/ets/pages/index.ets' const importByPkgName = '@ohos/Test'; - const standardImportPath = '@ohos/Test/src/main/ets/utils/Calc'; - const moduleSourceFile = new ModuleSourceFile(); + const standardImportPath: string = '@ohos/Test/src/main/ets/utils/Calc'; + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); - const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); - const importByPkgNameNormalizedOhmUrl = '@normalized:N&&&@ohos/Test/index&2.3.1'; - const standardImportPathNormalizedOhmUrl = '@normalized:N&&&@ohos/Test/src/main/ets/utils/Calc&2.3.1'; + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, + importerFile); + const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&&@ohos/Test/index&2.3.1'; + const standardImportPathNormalizedOhmUrl: string = '@normalized:N&&&@ohos/Test/src/main/ets/utils/Calc&2.3.1'; expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; }); - mocha.it('ohpm package others import (inter-app hsp)', function () { + mocha.it('NormalizedOHMUrl ohpm package others import (inter-app hsp)', function () { this.rollup.build(); this.rollup.share.projectConfig.useNormalizedOHMUrl = true; this.rollup.share.projectConfig.pkgContextInfo = { @@ -784,8 +820,9 @@ mocha.describe('generate ohmUrl', function () { 'isSO': false } } - const filePath = '/testHsp/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/src/main/ets/utils/Calc.ets' - const indexFilePath = '/testHsp/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/index.ets'; + const filePath: string = + '/testHsp/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/src/main/ets/utils/Calc.ets' + const indexFilePath: string = '/testHsp/oh_modules/.ohpm/@ohos+test@2.3.1/oh_modules/@ohos/test/index.ets'; for (let file of [filePath, indexFilePath]) { const moduleInfo = { id: file, @@ -796,15 +833,17 @@ mocha.describe('generate ohmUrl', function () { } this.rollup.moduleInfos.push(moduleInfo); } - const importerFile = '/testHsp/entry/src/main/ets/pages/index.ets' + const importerFile: string = '/testHsp/entry/src/main/ets/pages/index.ets' const importByPkgName = '@ohos/Test'; - const standardImportPath = '@ohos/Test/src/main/ets/utils/Calc'; - const moduleSourceFile = new ModuleSourceFile(); + const standardImportPath: string = '@ohos/Test/src/main/ets/utils/Calc'; + const moduleSourceFile: string = new ModuleSourceFile(); ModuleSourceFile.initPluginEnv(this.rollup); const importByPkgNameOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, importByPkgName, indexFilePath, importerFile); - const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, importerFile); - const importByPkgNameNormalizedOhmUrl = '@normalized:N&&com.test.testHsp&@ohos/Test/index&2.3.1'; - const standardImportPathNormalizedOhmUrl = '@normalized:N&&com.test.testHsp&@ohos/Test/src/main/ets/utils/Calc&2.3.1'; + const standardImportPathOhmUrl = moduleSourceFile.getOhmUrl(this.rollup, standardImportPath, filePath, + importerFile); + const importByPkgNameNormalizedOhmUrl: string = '@normalized:N&&com.test.testHsp&@ohos/Test/index&2.3.1'; + const standardImportPathNormalizedOhmUrl: string = + '@normalized:N&&com.test.testHsp&@ohos/Test/src/main/ets/utils/Calc&2.3.1'; expect(importByPkgNameOhmUrl == importByPkgNameNormalizedOhmUrl).to.be.true; expect(standardImportPathOhmUrl == standardImportPathNormalizedOhmUrl).to.be.true; }); -- Gitee