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 e058778ec769298fac03da3a739ca9b386a362ad..04d649e96d5d457715b3af319cc7325907c0e261 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_mode.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_mode.ts @@ -119,10 +119,11 @@ import { } from '../logger'; import { addDeclFilesConfig, + arkTSModuleMap, ArkTSEvolutionModule, + genCachePathForBridgeCode, getDeclgenBridgeCodePath, pkgDeclFilesConfig, - arkTSModuleMap } from '../../../process_arkts_evolution'; export class ModuleInfo { @@ -519,7 +520,8 @@ export class ModuleMode extends CommonMode { let moduleName: string = metaInfo.moduleName; let recordName: string = ''; - let cacheFilePath: string = metaInfo.language === ARKTS_1_2 ? originalFilePath : + let cacheFilePath: string = metaInfo.language === ARKTS_1_2 ? + 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 fd3cd73f3fc0b30722dc1f5763f4bc9de513af97..78cd2330932fbc03e122e13ce7eecbce46a96238 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 @@ -430,7 +430,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 63eb61e391598e834d0d9349b01e7efb26648053..924e9cfb5d71567da6f5dc7f7f13c59d9474d647 100644 --- a/compiler/src/process_arkts_evolution.ts +++ b/compiler/src/process_arkts_evolution.ts @@ -186,14 +186,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);