mirror of
https://gitee.com/openharmony/developtools_ace_ets2bundle
synced 2024-11-23 16:39:56 +00:00
!3548 Fix collect router map's compile entries
Merge pull request !3548 from ElevenDuan/router_map
This commit is contained in:
commit
4504aafe24
@ -19,8 +19,12 @@ import type sourceMap from 'source-map';
|
||||
|
||||
import { minify, MinifyOutput } from 'terser';
|
||||
import { getMapFromJson, deleteLineInfoForNameString, MemoryUtils } from 'arkguard';
|
||||
|
||||
import { OH_MODULES } from './fast_build/ark_compiler/common/ark_define';
|
||||
import {
|
||||
OH_MODULES,
|
||||
SEPARATOR_AT,
|
||||
SEPARATOR_BITWISE_AND,
|
||||
SEPARATOR_SLASH
|
||||
} from './fast_build/ark_compiler/common/ark_define';
|
||||
import {
|
||||
ARKTS_MODULE_NAME,
|
||||
PACKAGES,
|
||||
@ -227,7 +231,7 @@ function processPackageDir(params: Object): string {
|
||||
}
|
||||
|
||||
|
||||
export function getOhmUrlBySystemApiOrLibRequest(moduleRequest: string, config?: Object,
|
||||
export function getOhmUrlBySystemApiOrLibRequest(moduleRequest: string, config?: Object, importerFile?: string,
|
||||
useNormalizedOHMUrl: boolean = false): string {
|
||||
// 'arkui-x' represents cross platform related APIs, processed as 'ohos'
|
||||
const REG_SYSTEM_MODULE: RegExp = new RegExp(`@(${sdkConfigPrefix})\\.(\\S+)`);
|
||||
@ -256,6 +260,10 @@ export function getOhmUrlBySystemApiOrLibRequest(moduleRequest: string, config?:
|
||||
if (REG_LIB_SO.test(moduleRequest.trim())) {
|
||||
if (useNormalizedOHMUrl) {
|
||||
const pkgInfo = config.pkgContextInfo[moduleRequest];
|
||||
if (pkgInfo === undefined) {
|
||||
this.logger.error(red, `ArkTS:INTERNAL ERROR: Can not get pkgContextInfo of package '${moduleRequest}' ` +
|
||||
`which being imported by ${importerFile}'`, reset);
|
||||
}
|
||||
const isSo = pkgInfo.isSO ? 'Y' : 'N';
|
||||
return `@normalized:${isSo}&${pkgInfo.moduleName}&${pkgInfo.bundleName}&${moduleRequest}&${pkgInfo.version}`;
|
||||
}
|
||||
@ -846,3 +854,20 @@ export function stopEvent(event: Object, syncFlag = false): void {
|
||||
export function compileToolIsRollUp(): boolean {
|
||||
return process.env.compileTool === 'rollup';
|
||||
}
|
||||
|
||||
export function transformOhmurlToRecordName(ohmurl: string): string {
|
||||
// @normalized:N&<moduleName>&<bunldName>&<packageName>/entry/ets/xxx/yyy&<version>
|
||||
// ----> <bunldName>&<packageName>/entry/ets/xxx/yyy&<version>
|
||||
return ohmurl.split(SEPARATOR_BITWISE_AND).slice(2).join(SEPARATOR_BITWISE_AND);
|
||||
}
|
||||
|
||||
export function transformOhmurlToPkgName(ohmurl: string): string {
|
||||
let normalizedPath: string = ohmurl.split(SEPARATOR_BITWISE_AND)[3];
|
||||
let paths: Array<string> = normalizedPath.split(SEPARATOR_SLASH);
|
||||
if (normalizedPath.startsWith(SEPARATOR_AT)){
|
||||
// Spec: If the normalized import path starts with '@', the package name is before the second '/' in the normalized
|
||||
// import path, like: @aaa/bbb/ccc/ddd ---> package name is @aaa/bbb
|
||||
return paths.slice(0, 2).join(SEPARATOR_SLASH);
|
||||
}
|
||||
return paths[0];
|
||||
}
|
@ -112,3 +112,7 @@ export const ISENDABLE_TYPE = 'ISendable';
|
||||
|
||||
export const USE_SHARED: string = 'use shared';
|
||||
export const USE_SHARED_COMMENT: string = '// "use shared"';
|
||||
|
||||
export const SEPARATOR_BITWISE_AND: string = '&';
|
||||
export const SEPARATOR_AT: string = '@';
|
||||
export const SEPARATOR_SLASH: string = '/';
|
||||
|
@ -117,6 +117,7 @@ export function initArkProjectConfig(share: Object): Object {
|
||||
arkProjectConfig.projectRootPath = buildJsonInfo.projectRootPath;
|
||||
arkProjectConfig.modulePathMap = buildJsonInfo.modulePathMap;
|
||||
arkProjectConfig.isOhosTest = buildJsonInfo.isOhosTest;
|
||||
arkProjectConfig.arkRouterMap = buildJsonInfo.routerMap;
|
||||
if (buildJsonInfo.patchConfig) {
|
||||
arkProjectConfig.oldMapFilePath = buildJsonInfo.patchConfig.oldMapFilePath;
|
||||
}
|
||||
|
@ -86,7 +86,9 @@ import {
|
||||
isTs2Abc,
|
||||
isEs2Abc,
|
||||
createAndStartEvent,
|
||||
stopEvent
|
||||
stopEvent,
|
||||
transformOhmurlToPkgName,
|
||||
transformOhmurlToRecordName
|
||||
} from '../../../ark_utils';
|
||||
import {
|
||||
generateAot,
|
||||
@ -185,7 +187,16 @@ export class ModuleMode extends CommonMode {
|
||||
private generateCompileContextInfo(rollupObject: Object): string {
|
||||
let compileContextInfoPath: string = path.join(this.projectConfig.cachePath, COMPILE_CONTEXT_INFO_JSON);
|
||||
let compileContextInfo: Object = {};
|
||||
let compileEntries: Array<string> = [];
|
||||
let hspPkgNames: Array<string> = [];
|
||||
for (const hspAliasName in this.projectConfig.hspNameOhmMap) {
|
||||
let hspPkgName: string = hspAliasName;
|
||||
if (this.projectConfig.dependencyAliasMap.has(hspAliasName)) {
|
||||
hspPkgName = this.projectConfig.dependencyAliasMap.get(hspAliasName);
|
||||
}
|
||||
hspPkgNames.push(toUnixPath(hspPkgName));
|
||||
}
|
||||
compileContextInfo.hspPkgNames = hspPkgNames;
|
||||
let compileEntries: Set<string> = new Set();
|
||||
let entryObj: Object = this.projectConfig.entryObj;
|
||||
if (!!this.projectConfig.widgetCompile) {
|
||||
entryObj = this.projectConfig.cardEntryObj;
|
||||
@ -204,25 +215,32 @@ export class ModuleMode extends CommonMode {
|
||||
};
|
||||
let recordName: string = getNormalizedOhmUrlByFilepath(moduleId, this.projectConfig, this.logger, pkgParams,
|
||||
undefined);
|
||||
compileEntries.push(recordName);
|
||||
compileEntries.add(recordName);
|
||||
}
|
||||
compileContextInfo.compileEntries = compileEntries;
|
||||
if (this.projectConfig.arkRouterMap) {
|
||||
// Collect router map entries to es2abc
|
||||
this.collectRouterMapEntries(compileEntries, hspPkgNames)
|
||||
}
|
||||
compileContextInfo.compileEntries = Array.from(compileEntries);
|
||||
if (!!this.projectConfig.pkgContextInfo) {
|
||||
compileContextInfo.pkgContextInfo = this.projectConfig.pkgContextInfo;
|
||||
}
|
||||
let hspPkgNames: Array<string> = [];
|
||||
for (const hspName in this.projectConfig.hspNameOhmMap) {
|
||||
let hspPkgName: string = hspName;
|
||||
if (this.projectConfig.dependencyAliasMap.has(hspName)) {
|
||||
hspPkgName = this.projectConfig.dependencyAliasMap.get(hspName);
|
||||
}
|
||||
hspPkgNames.push(toUnixPath(hspPkgName));
|
||||
}
|
||||
compileContextInfo.hspPkgNames = hspPkgNames;
|
||||
fs.writeFileSync(compileContextInfoPath, JSON.stringify(compileContextInfo), 'utf-8');
|
||||
return compileContextInfoPath;
|
||||
}
|
||||
|
||||
private collectRouterMapEntries(compileEntries: Set<string>, hspPkgNames: Array<string>): void {
|
||||
this.projectConfig.arkRouterMap.forEach((router) => {
|
||||
if (router.ohmurl) {
|
||||
let pkgName: string = transformOhmurlToPkgName(router.ohmurl);
|
||||
if (!hspPkgNames.includes(pkgName)) {
|
||||
let recordName: string = transformOhmurlToRecordName(router.ohmurl);
|
||||
compileEntries.add(recordName);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
prepareForCompilation(rollupObject: Object, parentEvent: Object): void {
|
||||
const eventPrepareForCompilation = createAndStartEvent(parentEvent, 'preparation for compilation');
|
||||
this.collectModuleFileList(rollupObject, rollupObject.getModuleIds());
|
||||
|
@ -381,7 +381,8 @@ export class ModuleSourceFile {
|
||||
if (!!rollupObject.share.projectConfig.useNormalizedOHMUrl) {
|
||||
useNormalizedOHMUrl = rollupObject.share.projectConfig.useNormalizedOHMUrl;
|
||||
}
|
||||
let systemOrLibOhmUrl = getOhmUrlBySystemApiOrLibRequest(moduleRequest, ModuleSourceFile.projectConfig, useNormalizedOHMUrl);
|
||||
let systemOrLibOhmUrl = getOhmUrlBySystemApiOrLibRequest(moduleRequest, ModuleSourceFile.projectConfig,
|
||||
importerFile, useNormalizedOHMUrl);
|
||||
if (systemOrLibOhmUrl !== undefined) {
|
||||
if (ModuleSourceFile.needProcessMock) {
|
||||
ModuleSourceFile.generateNewMockInfo(moduleRequest, systemOrLibOhmUrl, rollupObject, importerFile);
|
||||
|
@ -27,7 +27,11 @@ import {
|
||||
ModuleMode,
|
||||
PackageEntryInfo
|
||||
} from '../../../../lib/fast_build/ark_compiler/module/module_mode';
|
||||
import { getNormalizedOhmUrlByFilepath } from '../../../../lib/ark_utils';
|
||||
import {
|
||||
getNormalizedOhmUrlByFilepath,
|
||||
transformOhmurlToPkgName,
|
||||
transformOhmurlToRecordName
|
||||
} from '../../../../lib/ark_utils';
|
||||
import { changeFileExtension } from '../../../../lib/fast_build/ark_compiler/utils';
|
||||
import { toUnixPath } from '../../../../lib/utils';
|
||||
import { META } from '../rollup_mock/common';
|
||||
@ -94,9 +98,18 @@ class ModuleModeMock extends ModuleMode {
|
||||
const cacheCompileContextInfo = fs.readFileSync(this.compileContextInfoPath, 'utf-8');
|
||||
|
||||
let compileContextInfo: Object = {};
|
||||
let compileEntries: Array<string> = [];
|
||||
let hspPkgNames: Array<string> = [];
|
||||
for (const hspName in rollupObject.share.projectConfig.hspNameOhmMap) {
|
||||
let hspPkgName: string = hspName;
|
||||
if (rollupObject.share.projectConfig.dependencyAliasMap.has(hspName)) {
|
||||
hspPkgName = rollupObject.share.projectConfig.dependencyAliasMap.get(hspName);
|
||||
}
|
||||
hspPkgNames.push(toUnixPath(hspPkgName));
|
||||
}
|
||||
compileContextInfo.hspPkgNames = hspPkgNames;
|
||||
let compileEntries: Set<string> = new Set();
|
||||
let entryObj: Object = this.projectConfig.entryObj;
|
||||
if (!!this.projectConfig.widgetCompile) {
|
||||
if (this.projectConfig.widgetCompile) {
|
||||
entryObj = this.projectConfig.cardEntryObj;
|
||||
}
|
||||
for (const key in entryObj) {
|
||||
@ -110,21 +123,21 @@ class ModuleModeMock extends ModuleMode {
|
||||
};
|
||||
let recordName: string = getNormalizedOhmUrlByFilepath(moduleId, rollupObject.share.projectConfig,
|
||||
rollupObject.share.logger, pkgParams, undefined);
|
||||
compileEntries.push(recordName);
|
||||
compileEntries.add(recordName);
|
||||
}
|
||||
compileContextInfo.compileEntries = compileEntries;
|
||||
this.projectConfig.arkRouterMap.forEach((router) => {
|
||||
if (router.ohmurl) {
|
||||
let pkgName: string = transformOhmurlToPkgName(router.ohmurl);
|
||||
if (!hspPkgNames.includes(pkgName)) {
|
||||
let recordName: string = transformOhmurlToRecordName(router.ohmurl);
|
||||
compileEntries.add(recordName);
|
||||
}
|
||||
}
|
||||
});
|
||||
compileContextInfo.compileEntries = Array.from(compileEntries);
|
||||
if (Object.prototype.hasOwnProperty.call(rollupObject.share.projectConfig, 'pkgContextInfo')) {
|
||||
compileContextInfo.pkgContextInfo = rollupObject.share.projectConfig.pkgContextInfo;
|
||||
}
|
||||
let hspPkgNames: Array<string> = [];
|
||||
for (const hspName in rollupObject.share.projectConfig.hspNameOhmMap) {
|
||||
let hspPkgName: string = hspName;
|
||||
if (rollupObject.share.projectConfig.dependencyAliasMap.has(hspName)) {
|
||||
hspPkgName = rollupObject.share.projectConfig.dependencyAliasMap.get(hspName);
|
||||
}
|
||||
hspPkgNames.push(toUnixPath(hspPkgName));
|
||||
}
|
||||
compileContextInfo.hspPkgNames = hspPkgNames;
|
||||
if (JSON.stringify(compileContextInfo) === cacheCompileContextInfo) {
|
||||
return true;
|
||||
}
|
||||
|
@ -125,6 +125,7 @@ class ProjectConfig {
|
||||
hspNameOhmMap: object;
|
||||
cardEntryObj: object;
|
||||
widgetCompile: boolean;
|
||||
arkRouterMap: Array<object>;
|
||||
|
||||
constructor(buildMode: string) {
|
||||
this.watchMode = 'false';
|
||||
@ -137,6 +138,7 @@ class ProjectConfig {
|
||||
this.compileShared = false;
|
||||
this.harNameOhmMap = {};
|
||||
this.hspNameOhmMap = {};
|
||||
this.arkRouterMap = [];
|
||||
}
|
||||
|
||||
public scan(testcase: string) {
|
||||
@ -160,13 +162,13 @@ class ProjectConfig {
|
||||
public mockCompileContextInfo() {
|
||||
this.entryObj = {
|
||||
'entryAbility/EntryAbility': `${PROJECT_ROOT}/entry/src/main/ets/entryability/EntryAbility.ets`,
|
||||
'page/Intex': `${PROJECT_ROOT}\\entry\\src\\main\\ets\\page\\Index.ets`,
|
||||
'page/Intex': `${PROJECT_ROOT}/entry/src/main/ets/page/Index.ets`,
|
||||
'entryformability/EntryFormAbility': `${PROJECT_ROOT}/entry/src/main/ets/entryformability/EntryFormAbility.ets`,
|
||||
'ets/widget/page/WidgetCard': `${PROJECT_ROOT}\\entry\\src\\main\\ets\\widget\\page\\WidgetCard.ets`
|
||||
'ets/widget/page/WidgetCard': `${PROJECT_ROOT}/entry/src/main/ets/widget/page/WidgetCard.ets`
|
||||
}
|
||||
this.cardEntryObj = {
|
||||
'entryformability/EntryFormAbility': `${PROJECT_ROOT}/entry/src/main/ets/entryformability/EntryFormAbility.ets`,
|
||||
'ets/widget/page/WidgetCard': `${PROJECT_ROOT}\\entry\\src\\main\\ets\\widget\\page\\WidgetCard.ets`
|
||||
'ets/widget/page/WidgetCard': `${PROJECT_ROOT}/entry/src/main/ets/widget/page/WidgetCard.ets`
|
||||
}
|
||||
this.projectRootPath = PROJECT_ROOT;
|
||||
this.pkgContextInfo = {
|
||||
|
@ -1739,4 +1739,22 @@ mocha.describe('test module_mode file api', function () {
|
||||
expect(moduleMode.checkGenerateCompileContextInfo(this.rollup) === true).to.be.true;
|
||||
SourceMapGenerator.cleanSourceMapObject();
|
||||
});
|
||||
|
||||
mocha.it('18-9: test generateCompileContext has router map entries', function () {
|
||||
this.rollup.build();
|
||||
SourceMapGenerator.initInstance(this.rollup);
|
||||
this.rollup.mockCompileContextInfo();
|
||||
this.rollup.share.projectConfig.arkRouterMap = [
|
||||
{
|
||||
'ohmurl': '@normalized:N&&&har/src/main/ets/calc&'
|
||||
},
|
||||
{
|
||||
'ohmurl': '@normalized:N&&com.har.test&har/src/main/ets/test&1.0.0'
|
||||
}
|
||||
];
|
||||
const moduleMode = new ModuleModeMock(this.rollup);
|
||||
moduleMode.generateCompileContextInfoMock(this.rollup);
|
||||
expect(moduleMode.checkGenerateCompileContextInfo(this.rollup) === true).to.be.true;
|
||||
SourceMapGenerator.cleanSourceMapObject();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user