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..9073aefb7dc4243b7fac2d9783f56f10197e2deb 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_mode.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_mode.ts @@ -120,11 +120,12 @@ import { } from '../logger'; import { addDeclFilesConfig, + arkTSModuleMap, ArkTSEvolutionModule, getDeclgenBridgeCodePath, - pkgDeclFilesConfig, - arkTSModuleMap, - isArkTSEvolutionFile + genCachePathForBridgeCode, + isArkTSEvolutionFile, + pkgDeclFilesConfig } from '../../../process_arkts_evolution'; export class ModuleInfo { @@ -521,7 +522,8 @@ export class ModuleMode extends CommonMode { let moduleName: string = metaInfo.moduleName; let recordName: string = ''; - let cacheFilePath: string = isArkTSEvolutionFile(filePath, metaInfo) ? originalFilePath : + let cacheFilePath: string = isArkTSEvolutionFile(filePath, metaInfo) ? + genCachePathForBridgeCode(originalFilePath, metaInfo, this.projectConfig.cachePath) : this.genFileCachePath(filePath, this.projectConfig.projectRootPath, this.projectConfig.cachePath, metaInfo); let packageName: string = ''; 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..6d7407b478e4e26822ddc64bcb9ea23c848f8689 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 @@ -432,7 +432,7 @@ export class ModuleSourceFile { ModuleSourceFile.logger, parentEvent, this.metaInfo); } } else { - await writeBridgeCodeFileSyncByNode( this.source, this.moduleId); + await writeBridgeCodeFileSyncByNode( this.source, this.moduleId, this.metaInfo); } } diff --git a/compiler/src/process_arkts_evolution.ts b/compiler/src/process_arkts_evolution.ts index 272db9e37cbec5fd31ef4f9ffbfc39fcd76a0953..5e8ca16733bf68e390ae6dbbca9b241acf0cb97d 100644 --- a/compiler/src/process_arkts_evolution.ts +++ b/compiler/src/process_arkts_evolution.ts @@ -201,14 +201,25 @@ export function cleanUpProcessArkTSEvolutionObj(): void { fullNameToTmpVar = new Map(); } -export async function writeBridgeCodeFileSyncByNode(node: ts.SourceFile, moduleId: string): Promise { +export async function writeBridgeCodeFileSyncByNode(node: ts.SourceFile, moduleId: string, + metaInfo: Object): Promise { const printer: ts.Printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }); const writer: ts.EmitTextWriter = ts.createTextWriter( // @ts-ignore ts.getNewLineCharacter({ newLine: ts.NewLineKind.LineFeed, removeComments: false })); printer.writeFile(node, writer, undefined); - mkdirsSync(path.dirname(moduleId)); - fs.writeFileSync(moduleId, writer.getText()); + const cacheFilePath: string = genCachePathForBridgeCode(moduleId, metaInfo); + mkdirsSync(path.dirname(cacheFilePath)); + fs.writeFileSync(cacheFilePath, writer.getText()); +} + +export function genCachePathForBridgeCode(moduleId: string, metaInfo: Object, cachePath?: string): string { + const bridgeCodePath: string = getDeclgenBridgeCodePath(metaInfo.pkgName); + const filePath: string = toUnixPath(moduleId); + const relativeFilePath: string = filePath.replace( + toUnixPath(path.join(bridgeCodePath, metaInfo.pkgName)), metaInfo.moduleName); + const cacheFilePath: string = path.join(cachePath ? cachePath : process.env.cachePath, relativeFilePath); + return cacheFilePath; } export function getDeclgenBridgeCodePath(pkgName: string): string { diff --git a/compiler/test/ark_compiler_ut/mock/rollup_mock/common.ts b/compiler/test/ark_compiler_ut/mock/rollup_mock/common.ts index 123f315d9c320526cd48e88df059975bf4a9887d..fd2db982cc6825d5490d8cb28241fed2c2ca8fdd 100644 --- a/compiler/test/ark_compiler_ut/mock/rollup_mock/common.ts +++ b/compiler/test/ark_compiler_ut/mock/rollup_mock/common.ts @@ -83,4 +83,5 @@ export const NEWFILE: string = 'newFile'; export const DECLFILESPATH: string = '/entry/build/default/intermediates/loader_out/default/etsFortgz/decl-fileInfo.json'; export const DECLGENV2OUTPATH: string = '/entry/build/default/intermediates/declgen/default/declgenV2'; -export const HAR_DECLGENV2OUTPATH: string = '/har/build/default/intermediates/declgen/default/declgenV2'; \ No newline at end of file +export const HAR_DECLGENV2OUTPATH: string = '/har/build/default/intermediates/declgen/default/declgenV2'; +export const HAR_BRIDGECODEPATH: string = '/har/build/default/intermediates/declgen/default/declgenBridgeCode'; \ No newline at end of file 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 abce70bef037514febf86c4db8c480144c1d1e96..008cf81f21954207b341b62895b6cdd03810235f 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 @@ -36,7 +36,7 @@ class Meta { this.belongModulePath = `${PROJECT_ROOT}/${DEFAULT_PROJECT}/${DEFAULT_ENTRY}`; this.hostModulesInfo = []; this.moduleName = entryModuleName; - this.pkgName = ''; + this.pkgName = 'entry'; this.isLocalDependency = true; this.isNodeEntryFile = false; this.pkgPath = modulePath; diff --git a/compiler/test/ark_compiler_ut/module/module_mode.test.ts b/compiler/test/ark_compiler_ut/module/module_mode.test.ts index 42364286d43172134df4bc8389b9df3a74592d42..3239995d81763fcecb976ee491e2cae97ebf8bc6 100644 --- a/compiler/test/ark_compiler_ut/module/module_mode.test.ts +++ b/compiler/test/ark_compiler_ut/module/module_mode.test.ts @@ -58,7 +58,8 @@ import { ENTRY_MODULE_NAME_DEFAULT, TEST, NEWFILE, - ENTRY_MODULE_VERSION_DEFAULT + ENTRY_MODULE_VERSION_DEFAULT, + HAR_BRIDGECODEPATH } from '../mock/rollup_mock/common'; import projectConfig from '../utils/processProjectConfig'; import { @@ -101,6 +102,7 @@ import { LogData, LogDataFactory } from '../../../lib/fast_build/ark_compiler/logger'; +import { arkTSEvolutionModuleMap } from '../../../lib/process_arkts_evolution'; function checkGenerateEs2AbcCmdExpect(cmdArgs: Array, compatibleSdkVersion: string, byteCodeHar: boolean): void { const fileThreads: number = cpus(); @@ -789,6 +791,58 @@ mocha.describe('test module_mode file api', function () { SourceMapGenerator.cleanSourceMapObject(); }); + mocha.it('2-8: test addModuleInfoItem under build mixCompile', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'har': { + 'packageName': 'har', + 'bundleName': '', + 'moduleName': '', + 'version': '1.0.0', + 'entryPath': 'Index.ets', + 'isSO': false + }, + 'entry': { + 'packageName': 'entry', + 'bundleName': '', + 'moduleName': '', + 'version': '', + 'entryPath': 'Index.ets', + 'isSO': false + } + } + const arkTSEvoFile = path.join(HAR_BRIDGECODEPATH, 'har','Index.ts'); + const arkTSEvolutionModuleInfo = { + language: '1.2', + packageName: 'har', + moduleName: 'har', + declgenBridgeCodePath: HAR_BRIDGECODEPATH, + } + arkTSEvolutionModuleMap.set('har', arkTSEvolutionModuleInfo) + this.rollup.share.allFiles.add(arkTSEvoFile); + const moduleInfoMock = { + id: arkTSEvoFile, + meta: { + 'pkgName': 'har', + 'moduleName': 'har', + 'language': '1.2' + } + }; + + this.rollup.moduleInfos.push(moduleInfoMock); + const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup); + sourceMapGenerator.setNewSoureMaps(false); + const moduleMode = new ModuleModeMock(this.rollup); + moduleMode.addModuleInfoItemMock(this.rollup); + const cacheFilePath = moduleMode.moduleInfos.get(toUnixPath(arkTSEvoFile)).cacheFilePath; + const expectCacheFilePath = path.join(moduleMode.projectConfig.cachePath, 'har/Index.ts'); + expect(cacheFilePath === expectCacheFilePath).to.be.true; + this.rollup.share.projectConfig.useNormalizedOHMUrl = false; + this.rollup.share.allFiles.delete(arkTSEvoFile); + SourceMapGenerator.cleanSourceMapObject(); + }); + mocha.it('3-1-1: test updateCachedSourceMaps under build debug: cacheSourceMapPath not exist', function () { this.rollup.build(); const moduleMode = new ModuleModeMock(this.rollup);