diff --git a/compiler/src/ets_checker.ts b/compiler/src/ets_checker.ts index 3e3ed92b29e113a3f5d6b0219b527c17d6b5b59b..2645190289ae1717e98ae138bd37a363d1098c82 100644 --- a/compiler/src/ets_checker.ts +++ b/compiler/src/ets_checker.ts @@ -1073,6 +1073,7 @@ export function resolveTypeReferenceDirectives(typeDirectiveNames: string[] | ts export const resolvedModulesCache: Map = new Map(); export function resolveModuleNames(moduleNames: string[], containingFile: string): ts.ResolvedModuleFull[] { + const languageVersion = FileManager.mixCompile? FileManager.getInstance().getLanguageVersionByFilePath(containingFile).languageVersion: ARKTS_1_1; startTimeStatisticsLocation(resolveModuleNamesTime); const resolvedModules: ts.ResolvedModuleFull[] = []; const cacheFileContent: ts.ResolvedModuleFull[] = resolvedModulesCache.get(path.resolve(containingFile)); @@ -1108,19 +1109,19 @@ export function resolveModuleNames(moduleNames: string[], containingFile: string resolvedModules.push(result.resolvedModule); } } else if (new RegExp(`^@(${sdkConfigPrefix})\\.`, 'i').test(moduleName.trim())) { - let apiFileExist: boolean = false; - for (let i = 0; i < sdkConfigs.length; i++) { - const sdkConfig = sdkConfigs[i]; - const resolveModuleInfo: ResolveModuleInfo = getRealModulePath(sdkConfig.apiPath, moduleName, ['.d.ts', '.d.ets']); - const modulePath: string = resolveModuleInfo.modulePath; - const isDETS: boolean = resolveModuleInfo.isEts; - if (systemModules.includes(moduleName + (isDETS ? '.d.ets' : '.d.ts')) && ts.sys.fileExists(modulePath)) { - resolvedModules.push(getResolveModule(modulePath, isDETS ? '.d.ets' : '.d.ts')); - apiFileExist = true; - break; - } - } - if (!apiFileExist) { + const searchPaths = languageVersion && languageVersion === ARKTS_1_2 + ? Array.from(FileManager.staticSDKDeclPath) + : [...new Set(sdkConfigs.flatMap(config => config.apiPath))]; + const resolveModuleInfo = getRealModulePath(searchPaths, moduleName, ['.d.ts', '.d.ets']); + const modulePath = resolveModuleInfo.modulePath; + const extension = resolveModuleInfo.isEts ? '.d.ets' : '.d.ts'; + const fullModuleName = moduleName + extension; + + if (systemModules.includes(fullModuleName) && ts.sys.fileExists(modulePath)) { + resolvedModules.push(getResolveModule(modulePath, extension)); + } else if(languageVersion===ARKTS_1_2){ + resolvedModules.push(getResolveModule(modulePath, extension)); + }else{ resolvedModules.push(null); } } else if (/\.ets$/.test(moduleName) && !/\.d\.ets$/.test(moduleName)) { @@ -1138,6 +1139,18 @@ export function resolveModuleNames(moduleNames: string[], containingFile: string resolvedModules.push(null); } } else { + const aliasConfig = FileManager.getInstance().queryOriginApiName(moduleName,containingFile); + if(aliasConfig){ + if(aliasConfig){ + const searchPaths = aliasConfig.isStatic + ? Array.from(FileManager.staticSDKDeclPath) + : [...new Set(sdkConfigs.flatMap(config => config.apiPath))]; + const resolveModuleInfo = getRealModulePath(searchPaths, aliasConfig.originalAPIName, ['.d.ts', '.d.ets']); + const modulePath = resolveModuleInfo.modulePath; + const extension = resolveModuleInfo.isEts ? '.d.ets' : '.d.ts'; + resolvedModules.push(getResolveModule(modulePath, extension)); + } + }else{ const modulePath: string = path.resolve(__dirname, '../../../api', moduleName + '.d.ts'); const systemDETSModulePath: string = path.resolve(__dirname, '../../../api', moduleName + '.d.ets'); const kitModulePath: string = path.resolve(__dirname, '../../../kits', moduleName + '.d.ts'); @@ -1180,6 +1193,7 @@ export function resolveModuleNames(moduleNames: string[], containingFile: string resolvedModules.push(null); } } + } } if (projectConfig.hotReload && resolvedModules.length && resolvedModules[resolvedModules.length - 1]) { diff --git a/compiler/src/fast_build/ark_compiler/interop/interop_manager.ts b/compiler/src/fast_build/ark_compiler/interop/interop_manager.ts index 3ea51946e4eb6c587bd8eb5755dd2de587b29727..ce6ca4a168e786e279aab1a5c65cf84021ff5afc 100644 --- a/compiler/src/fast_build/ark_compiler/interop/interop_manager.ts +++ b/compiler/src/fast_build/ark_compiler/interop/interop_manager.ts @@ -31,6 +31,7 @@ export class FileManager { private static instance: FileManager | undefined = undefined; static arkTSModuleMap: Map = new Map(); + static aliasConfig: Map> = new Map(); static dynamicLibPath: Set = new Set(); static staticSDKDeclPath: Set = new Set(); static staticSDKGlueCodePath: Set = new Set(); @@ -41,6 +42,7 @@ export class FileManager { public static init( dependentModuleMap: Map, + aliasPaths: Map, dynamicSDKPath?: Set, staticSDKDeclPath?: Set, staticSDKGlueCodePath?: Set @@ -48,6 +50,7 @@ export class FileManager { if (FileManager.instance === undefined) { FileManager.instance = new FileManager(); FileManager.initLanguageVersionFromDependentModuleMap(dependentModuleMap); + FileManager.initAliasConfig(aliasPaths); FileManager.initSDK(dynamicSDKPath, staticSDKDeclPath, staticSDKGlueCodePath); } } @@ -79,6 +82,34 @@ export class FileManager { this.arkTSModuleMap = convertedMap; } + private static initAliasConfig(aliasPaths: Map) { + for (const [pkgName, filePath] of aliasPaths) { + try { + const rawContent = fs.readFileSync(filePath, 'utf-8'); + const jsonData = JSON.parse(rawContent); + const pkgAliasMap = new Map(); + + for (const [aliasKey, config] of Object.entries(jsonData)) { + if (typeof config !== 'object' || config === null || + !('originalAPIName' in config) || !('isStatic' in config)) { + throw new Error(`Invalid AliasConfig format in ${pkgName} -> ${aliasKey}`); + } + + const aliasConfig = config as AliasConfig; + pkgAliasMap.set(aliasKey, { + originalAPIName: aliasConfig.originalAPIName, + isStatic: aliasConfig.isStatic + }); + } + + this.aliasConfig.set(pkgName, pkgAliasMap); + } catch (error) { + console.error(`Failed to init alias config for ${pkgName}:`, error); + throw new Error(`Failed to init alias config for ${pkgName}: ${error instanceof Error ? error.message : String(error)}`); + } + } + } + private static initSDK( dynamicSDKPath?: Set, staticSDKBaseUrl?: Set, @@ -199,6 +230,35 @@ export class FileManager { } return undefined; } + + queryOriginApiName(moduleName: string, containingFile: string): AliasConfig { + const result = this.getLanguageVersionByFilePath(containingFile); + if (!result) return undefined; + + const alias = FileManager.aliasConfig.get(result.pkgName); + if (!alias) return undefined; + + return alias.get(moduleName); + } + + getGlueCodePathByModuleRequest(moduleRequest: string): { + fullPath: string, + basePath: string, + } { + const extensions = ['.ts', '.ets']; + for (const basePath of FileManager.staticSDKGlueCodePath) { + for (const ext of extensions) { + const fullPath = path.resolve(basePath, moduleRequest + ext); + if (fs.existsSync(fullPath)) { + return { + fullPath: toUnixPath(fullPath), + basePath: toUnixPath(basePath) + }; + } + } + } + return undefined; + } } export function initFileManagerInRollup(share: Object): void { @@ -259,4 +319,4 @@ function collectSDKInfo(share: Object): { staticSDKInteropDecl: staticSDKInteropDecl, staticSDKGlueCodePath: staticSDKGlueCodePath }; -} \ No newline at end of file +} diff --git a/compiler/src/fast_build/ark_compiler/interop/type.ts b/compiler/src/fast_build/ark_compiler/interop/type.ts index 132f76602b588bc41b9835f177bcdcffadc5d986..a1533d57bd75f511e9acbbd6cc484118c94d6836 100644 --- a/compiler/src/fast_build/ark_compiler/interop/type.ts +++ b/compiler/src/fast_build/ark_compiler/interop/type.ts @@ -93,4 +93,60 @@ export interface DeclFilesConfig { interface DeclFileConfig { declPath: string; ohmUrl: string; +} +export interface ArkTSEvolutionModule { + language: string; + packageName: string; + pkgPath: string; + moduleName: string; + modulePath: string; + declgenV1OutPath?: string; + declgenV2OutPath?: string; + declgenBridgeCodePath?: string; + declFilesPath?: string; + dynamicFileList: string[]; + staticFileList: string[]; + cachePath: string; + byteCodeHarInfo?: Object; +} + +export const ARKTS_1_2: string = '1.2'; +export const ARKTS_1_1: string = '1.1'; +export const ARKTS_1_0: string = '1.0'; +export const HYBRID: string = 'hybrid'; + +export interface Params { + dependentModuleMap: Map; + projectConfig: ProjectConfig; + tasks: taskInfo[]; +} + +interface ProjectConfig{ + cachePath:string; + bundleName:string; + mainModuleName:string; + projectRootPath:string; +}; + +enum BuildType { + DECLGEN = 'declgen', + BYTE_CODE_HARY = 'byteCodeHar', + //TODO + INTEROP_CONTEXT = 'interopContext' +} + +interface taskInfo{ + packageName:string; + buildTask:BuildType +} + +export interface AliasConfig{ + originalAPIName:string; + isStatic:boolean; +} + +export interface FileInfo{ + recordName:string; + baseUrl:string; + abstractPath:string; } \ No newline at end of file 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 562661f77d5c9b6688f935e9a383b65893a74843..1ed595bc4c9f5d1a778d1cb5ccbf9b96920b73fe 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_mode.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_mode.ts @@ -641,6 +641,10 @@ export class ModuleMode extends CommonMode { }); } + for (const [pkgName, fileInfo] of FileManager.glueCodeFileInfos) { + filesInfo += `${fileInfo.abstractPath};${fileInfo.recordName};${ESM};${fileInfo.abstractPath};${this.projectConfig.entryPackageName};` + + `${false};ts\n`; + } fs.writeFileSync(this.filesInfoPath, filesInfo, 'utf-8'); } 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 8d9771f04ff5069876d8ea145b2af173c48d5da4..bcbab01c85a02b4ce959abd789bbb35e0b6cfd88 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 @@ -442,7 +442,12 @@ export class ModuleSourceFile { if (!!rollupObject.share.projectConfig.useNormalizedOHMUrl) { useNormalizedOHMUrl = rollupObject.share.projectConfig.useNormalizedOHMUrl; } - let systemOrLibOhmUrl = getOhmUrlBySystemApiOrLibRequest(moduleRequest, ModuleSourceFile.projectConfig, + const queryResult = FileManager.getInstance().queryOriginApiName(moduleRequest, this.moduleId); + let api = moduleRequest; + if (queryResult?.originalAPIName && !queryResult.isStatic) { + api = queryResult.originalAPIName; + } + let systemOrLibOhmUrl = getOhmUrlBySystemApiOrLibRequest(api, ModuleSourceFile.projectConfig, ModuleSourceFile.logger, importerFile, useNormalizedOHMUrl); if (systemOrLibOhmUrl !== undefined) { if (ModuleSourceFile.needProcessMock) { @@ -466,6 +471,18 @@ export class ModuleSourceFile { } return byteCodeHarOhmurl; } + if (queryResult) { + const recordName = ModuleSourceFile.generateNormalizedOhmulrForSDkIntero(ModuleSourceFile.projectConfig, queryResult.originalAPIName); + const ohmUrl = `${'N'}&${ModuleSourceFile.projectConfig.moduleName}&${recordName}`; + const glueCodeInfo = FileManager.getInstance().getGlueCodePathByModuleRequest(queryResult.originalAPIName); + + FileManager.glueCodeFileInfos.set(queryResult.originalAPIName, { + recordName: recordName, + baseUrl: glueCodeInfo.basePath, + abstractPath: glueCodeInfo.fullPath + }) + return `@normalized:${ohmUrl}` + } if (filePath) { const targetModuleInfo: Object = rollupObject.getModuleInfo(filePath); if (!targetModuleInfo) { @@ -500,8 +517,8 @@ export class ModuleSourceFile { ModuleSourceFile.generateNewMockInfo(moduleRequest, res, rollupObject, importerFile); // processing cases of user-defined mock targets let mockedTarget: string = toUnixPath(filePath). - replace(toUnixPath(rollupObject.share.projectConfig.modulePath), ''). - replace(`/${rollupObject.share.projectConfig.mockParams.etsSourceRootPath}/`, ''); + replace(toUnixPath(rollupObject.share.projectConfig.modulePath), ''). + replace(`/${rollupObject.share.projectConfig.mockParams.etsSourceRootPath}/`, ''); ModuleSourceFile.generateNewMockInfo(mockedTarget, res, rollupObject, importerFile); } return res; @@ -509,6 +526,10 @@ export class ModuleSourceFile { return undefined; } + private static generateNormalizedOhmulrForSDkIntero(project: Object, projectFilePath: string): string { + return `${project.bundleName}&${project.entryPackageName}/${projectFilePath}&1.0.0`; + } + private static spliceNormalizedOhmurl(moduleInfo: Object, filePath: string, importerFile?: string): string { const isArkTSEvolution: boolean = isArkTSEvolutionFile(filePath, moduleInfo.meta); const pkgPath: string = isArkTSEvolution ?