diff --git a/compiler/src/interop/src/fast_build/ark_compiler/interop/interop_manager.ts b/compiler/src/interop/src/fast_build/ark_compiler/interop/interop_manager.ts index 4ec3efcc8d9dee4c0057eb1c10c37528a0fe2a38..dedb37f4bdf9913f31062dc01f67f7d8ddf290cb 100644 --- a/compiler/src/interop/src/fast_build/ark_compiler/interop/interop_manager.ts +++ b/compiler/src/interop/src/fast_build/ark_compiler/interop/interop_manager.ts @@ -33,7 +33,8 @@ import { ArkTSEvolutionModule, FileInfo, AliasConfig, - InteropConfig + InteropConfig, + InteropInfo } from './type'; import { hasExistingPaths, @@ -59,7 +60,7 @@ import { readFirstLineSync } from './utils'; let entryFileLanguageInfo = new Map(); export let workerFile = null; -export let mixCompile = undefined; +export let mixCompile = false; export function setEntryFileLanguage(filePath: string, language: string): void { entryFileLanguageInfo.set(filePath, language); @@ -461,10 +462,7 @@ export function isBridgeCode(filePath: string, projectConfig: Object): boolean { } export function isMixCompile(): boolean { - if (typeof mixCompile === 'boolean') { - return mixCompile; - } - return process.env.mixCompile === 'true'; + return mixCompile; } /** @@ -517,7 +515,7 @@ export function transformAbilityPages(abilityPath: string): boolean { if (abilityPath.includes(':')) { abilityPath = abilityPath.substring(0, abilityPath.lastIndexOf(':')); } - const bridgeCodePath = path.join(entryBridgeCodePath, abilityPath + EXTNAME_TS); + const bridgeCodePath = path.join(entryBridgeCodePath.declgenBridgeCodePath, abilityPath + EXTNAME_TS); if (fs.existsSync(bridgeCodePath)) { projectConfig.entryObj[transformModuleNameToRelativePath(abilityPath)] = bridgeCodePath; return true; @@ -575,8 +573,8 @@ export function rebuildEntryObj(projectConfig: Object, interopConfig: InteropCon if (!firstLine.includes('use static')) { newEntry[newKey] = rawPath; } else if (rawPath.startsWith(projectConfig.projectRootPath)) { - const bridgePath = getBrdigeCodeRootPath(rawPath, interopConfig); - if (!bridgePath) { + const interopInfo = getBrdigeCodeRootPath(rawPath, interopConfig); + if (!interopInfo) { const errInfo = LogDataFactory.newInstance( ErrorCode.ETS2BUNDLE_INTERNAL_MISSING_BRIDGECODE_PATH_INFO, ArkTSInternalErrorDescription, @@ -585,23 +583,22 @@ export function rebuildEntryObj(projectConfig: Object, interopConfig: InteropCon throw Error(errInfo.toString()); } - const relativePath = path.relative(projectConfig.projectRootPath, rawPath); + const relativePath = path.relative(interopInfo.moduleRootPath, rawPath); const withoutExt = removeExt(relativePath); - newEntry[newKey] = path.join(bridgePath, withoutExt + '.ts'); + newEntry[newKey] = path.join(interopInfo.declgenBridgeCodePath, interopInfo.packageName, withoutExt + '.ts'); } return newEntry; }, {} as Record); } - /** * corresponds to compiler/src/fast_build/common/init_config.ts - initConfig() * As the entry for mix compile,so mixCompile status will be set true */ export function initConfigForInterop(interopConfig: InteropConfig): Object { + mixCompile = true; initFileManagerInRollup(interopConfig); - function getEntryObj(): void { loadEntryObj(projectConfig); initBuildInfo(); @@ -621,7 +618,6 @@ export function initConfigForInterop(interopConfig: InteropConfig): Object { return newEntry; }, {}); } - mixCompile = true; getEntryObj(); if (process.env.appResource) { readAppResource(process.env.appResource); @@ -634,14 +630,11 @@ export function initConfigForInterop(interopConfig: InteropConfig): Object { }; } -export function getBrdigeCodeRootPath(filePath: string, interopConfig: InteropConfig): string | undefined { - if (!interopConfig) { - return process.env.entryBridgeCodePath; - } - - for (const [moduleRootPath, InteropInfo] of interopConfig.interopModuleInfo) { +export function getBrdigeCodeRootPath(filePath: string, interopConfig: InteropConfig): InteropInfo | undefined { + for (const [moduleRootPath, interopInfo] of interopConfig.interopModuleInfo) { if (isSubPathOf(filePath, moduleRootPath)) { - return InteropInfo.declgenBridgeCodePath; + interopInfo.moduleRootPath = moduleRootPath; + return interopInfo; } } diff --git a/compiler/src/interop/src/fast_build/ark_compiler/interop/type.ts b/compiler/src/interop/src/fast_build/ark_compiler/interop/type.ts index cb4b3a29ea850cd50e2b8e6bab823639be24949f..c752ffa4ad8284a5aa539048dcb48bb49768e71d 100644 --- a/compiler/src/interop/src/fast_build/ark_compiler/interop/type.ts +++ b/compiler/src/interop/src/fast_build/ark_compiler/interop/type.ts @@ -116,6 +116,8 @@ export interface FileInfo { export interface InteropInfo { declgenBridgeCodePath: string; declgenV1OutPath: string; + packageName: string; + moduleRootPath: string; } export interface InteropConfig { diff --git a/compiler/src/interop/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts b/compiler/src/interop/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts index dd986076f062c32502d48d8a75abc6d1c147bb83..b6b29c5e8ddd85b0c76dca0f44a3721cffdff9b9 100644 --- a/compiler/src/interop/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts +++ b/compiler/src/interop/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts @@ -76,8 +76,6 @@ export function etsChecker() { const recordInfo = MemoryMonitor.recordStage(MemoryDefine.ROLLUP_PLUGIN_BUILD_START); const hookEventFactory: CompileEvent = getHookEventFactory(this.share, 'etsChecker', 'buildStart'); const eventServiceChecker = createAndStartEvent(hookEventFactory, 'serviceChecker'); - // remove after hvigor use another api - initFileManagerInRollup(this.share); if (process.env.watchMode === 'true' && process.env.triggerTsWatch === 'true') { tsWatchEmitter = new EventEmitter(); tsWatchEndPromise = new Promise(resolve => { diff --git a/compiler/test/ark_compiler_ut/interop/interop_manager.test.ts b/compiler/test/ark_compiler_ut/interop/interop_manager.test.ts index 5f3569ad7629b1266c3ca160ea5c19c310048c83..1f0aaf5786f79cacf143063950dec77c35a512c6 100644 --- a/compiler/test/ark_compiler_ut/interop/interop_manager.test.ts +++ b/compiler/test/ark_compiler_ut/interop/interop_manager.test.ts @@ -331,7 +331,7 @@ mocha.describe('test getBrdigeCodeRootPath api', function () { }; const result = getBrdigeCodeRootPath(filePath, mockConfig); - expect(result).to.equal('/bridge/a/b'); + expect(result.declgenBridgeCodePath).to.equal('/bridge/a/b'); }); mocha.it('1-2: should return undefined when filePath does not match any moduleRootPath', function () { @@ -350,12 +350,31 @@ mocha.describe('test getBrdigeCodeRootPath api', function () { expect(result).to.be.undefined; }); - mocha.it('1-3: should return process.env.entryBridgeCodePath when interopConfig is null', function () { - process.env.entryBridgeCodePath = '/default/bridge/path'; + mocha.it('1-3: should return declgenBridgeCodePath when interopConfig is provided', function () { const filePath = '/any/file.ts'; + this.rollup = new RollUpPluginMock(); + this.rollup.build(); + this.rollup.share.projectConfig.mixCompile = true; + + initConfigForInterop(this.rollup.share); + + const interopInfo = { + declgenBridgeCodePath: '/some/bridge/path', + declgenV1OutPath: '/some/v1/out/path', + packageName: 'test-package', + moduleRootPath: '' + }; + const fakeConfig = { + interopModuleInfo: new Map([ + ['/any', { ...interopInfo }] + ]), + projectConfig: {} + }; + + const result = getBrdigeCodeRootPath(filePath, fakeConfig as any); + destroyInterop(); - const result = getBrdigeCodeRootPath(filePath, undefined as any); - expect(result).to.equal('/default/bridge/path'); + expect(result?.declgenBridgeCodePath).to.equal('/some/bridge/path'); }); });