Fix the issue that declaration files are not generated for modules outside of independent compilation projects

Issue: IA9ZEA

Signed-off-by: wuhailong <wuhailong22@huawei.com>
Change-Id: I4957d1803b4760bc8661719b52f18c3938dd94a9
This commit is contained in:
wuhailong 2024-07-02 16:24:30 +08:00
parent 6b5323d630
commit 2e71c141ca
12 changed files with 152 additions and 43 deletions

View File

@ -56,6 +56,7 @@ import {
toUnixPath,
validateFilePathLength,
harFilesRecord,
getProjectRootPath
} from './utils';
import type { GeneratedFileInHar } from './utils';
import {
@ -125,7 +126,7 @@ export function getOhmUrlByFilepath(filePath: string, projectConfig: Object, log
const bundleName: string = packageInfo[0];
const moduleName: string = packageInfo[1];
const moduleRootPath: string = toUnixPath(projectConfig.modulePathMap[moduleName]);
const projectRootPath: string = toUnixPath(projectConfig.projectRootPath);
const projectRootPath: string = toUnixPath(getProjectRootPath(filePath, projectConfig, projectConfig?.rootPathSet));
// case1: /entry/src/main/ets/xxx/yyy ---> @bundle:<bundleName>/entry/ets/xxx/yyy
// case2: /entry/src/ohosTest/ets/xxx/yyy ---> @bundle:<bundleName>/entry_test@entry/ets/xxx/yyy
// case3: /node_modules/xxx/yyy ---> @package:pkg_modules/xxx/yyy
@ -294,7 +295,8 @@ export function getBuildModeInLowerCase(projectConfig: Object): string {
* @param sourceCode The intermediate js source code
*/
export function writeFileSyncByString(sourcePath: string, sourceCode: string, projectConfig: Object, logger: Object): void {
const filePath: string = genTemporaryPath(sourcePath, projectConfig.projectPath, process.env.cachePath, projectConfig, undefined, logger);
const filePath: string = genTemporaryPath(sourcePath, projectConfig.projectPath, process.env.cachePath,
projectConfig.projectRootPath, projectConfig, undefined, logger);
if (filePath.length === 0) {
return;
}
@ -708,7 +710,8 @@ export function getPackageInfo(configFile: string): Array<string> {
*/
export function generateSourceFilesToTemporary(sourcePath: string, sourceContent: string, sourceMap: Object,
projectConfig: Object, logger: Object): void {
let jsFilePath: string = genTemporaryPath(sourcePath, projectConfig.projectPath, process.env.cachePath, projectConfig, undefined, logger);
let jsFilePath: string = genTemporaryPath(sourcePath, projectConfig.projectPath, process.env.cachePath,
projectConfig.projectRootPath, projectConfig, undefined, logger);
if (jsFilePath.length === 0) {
return;
}

View File

@ -482,9 +482,9 @@ function handleFinishModules(modules, callback) {
const filePath: string = module.resourceResolveData.path;
if (!filePath.match(/node_modules/)) {
const jsCacheFilePath: string = genTemporaryPath(filePath, projectConfig.moduleRootPath, process.env.cachePath,
projectConfig, undefined, undefined);
projectConfig.projectRootPath, projectConfig, undefined, undefined);
const jsBuildFilePath: string = genTemporaryPath(filePath, projectConfig.moduleRootPath,
projectConfig.buildPath, projectConfig, undefined, undefined, true);
projectConfig.buildPath, projectConfig.projectRootPath, projectConfig, undefined, undefined, true);
if (filePath.match(/\.e?ts$/)) {
this.incrementalFileInHar.set(jsCacheFilePath.replace(/\.ets$/, '.d.ets').replace(/\.ts$/, '.d.ts'),
jsBuildFilePath.replace(/\.ets$/, '.d.ets').replace(/\.ts$/, '.d.ts'));

View File

@ -461,7 +461,7 @@ export const warnCheckerResult: WarnCheckerResult = { count: 0 };
export let languageService: ts.LanguageService = null;
let tsImportSendable: boolean = false;
export function serviceChecker(rootFileNames: string[], newLogger: Object = null, resolveModulePaths: string[] = null,
compilationTime: CompilationTimeStatistics = null, rollupShareObject?: any): void {
compilationTime: CompilationTimeStatistics = null, rollupShareObject?: Object): void {
fastBuildLogger = newLogger;
let cacheFile: string = null;
tsImportSendable = rollupShareObject?.projectConfig.tsImportSendable;
@ -504,7 +504,7 @@ export function serviceChecker(rootFileNames: string[], newLogger: Object = null
stopTimeStatisticsLocation(compilationTime ? compilationTime.runArkTSLinterTime : undefined);
if (process.env.watchMode !== 'true') {
processBuildHap(cacheFile, rootFileNames, compilationTime);
processBuildHap(cacheFile, rootFileNames, compilationTime, rollupShareObject);
}
}
// collect the compiled files of tsc and rollup for obfuscation scanning.
@ -566,7 +566,8 @@ export function emitBuildInfo(): void {
globalProgram.builderProgram.emitBuildInfo(buildInfoWriteFile);
}
function processBuildHap(cacheFile: string, rootFileNames: string[], compilationTime: CompilationTimeStatistics): void {
function processBuildHap(cacheFile: string, rootFileNames: string[], compilationTime: CompilationTimeStatistics,
rollupShareObject: Object): void {
startTimeStatisticsLocation(compilationTime ? compilationTime.diagnosticTime : undefined);
const allDiagnostics: ts.Diagnostic[] = globalProgram.builderProgram
.getSyntacticDiagnostics()
@ -589,12 +590,13 @@ function processBuildHap(cacheFile: string, rootFileNames: string[], compilation
let writeFile = (fileName: string, text: string, writeByteOrderMark: boolean): void => {
emit = text;
};
const rootPathSet: Object = rollupShareObject?.projectConfig.rootPathSet;
[...allResolvedModules, ...rootFileNames].forEach(moduleFile => {
if (!(moduleFile.match(new RegExp(projectConfig.packageDir)) && projectConfig.compileHar)) {
try {
if ((/\.d\.e?ts$/).test(moduleFile)) {
generateSourceFilesInHar(moduleFile, fs.readFileSync(moduleFile, 'utf-8'), path.extname(moduleFile),
projectConfig);
projectConfig, rootPathSet);
} else if ((/\.e?ts$/).test(moduleFile)) {
emit = undefined;
let sourcefile = globalProgram.program.getSourceFile(moduleFile);
@ -602,7 +604,7 @@ function processBuildHap(cacheFile: string, rootFileNames: string[], compilation
globalProgram.program.emit(sourcefile, writeFile, undefined, true, undefined, true);
}
if (emit) {
generateSourceFilesInHar(moduleFile, emit, '.d' + path.extname(moduleFile), projectConfig);
generateSourceFilesInHar(moduleFile, emit, '.d' + path.extname(moduleFile), projectConfig, rootPathSet);
}
}
} catch (err) { }

View File

@ -37,7 +37,8 @@ import {
} from "./utils";
import {
toUnixPath,
isPackageModulesFile
isPackageModulesFile,
getProjectRootPath
} from "../../utils";
import {
handleObfuscatedFilePath,
@ -241,8 +242,9 @@ export class SourceMapGenerator {
}
// adapt compatibilty with hvigor
const projectRootPath = getProjectRootPath(moduleId, this.projectConfig, this.projectConfig?.rootPathSet);
moduleId = this.getIntermediateModuleId(
toUnixPath(moduleId).replace(toUnixPath(this.projectConfig.projectRootPath), toUnixPath(this.projectConfig.cachePath)));
toUnixPath(moduleId).replace(toUnixPath(projectRootPath), toUnixPath(this.projectConfig.cachePath)));
const isPackageModules = isPackageModulesFile(moduleId, this.projectConfig);
if (enableObfuscateFileName(isPackageModules, this.projectConfig)) {

View File

@ -36,7 +36,8 @@ import {
mkdirsSync,
validateFilePathLength,
toUnixPath,
isPackageModulesFile
isPackageModulesFile,
getProjectRootPath
} from '../../utils';
import {
tryMangleFileName,
@ -99,7 +100,8 @@ function removeCacheFile(cacheFilePath: string, ext: string): void {
}
export function shouldETSOrTSFileTransformToJS(filePath: string, projectConfig: Object): boolean {
const sufStr: string = toUnixPath(filePath).replace(toUnixPath(projectConfig.projectRootPath), '');
const projectRootPath: string = getProjectRootPath(filePath, projectConfig, projectConfig?.rootPathSet)
const sufStr: string = toUnixPath(filePath).replace(toUnixPath(projectRootPath), '');
let cacheFilePath: string = path.join(projectConfig.cachePath, sufStr);
if (!projectConfig.processTs) {
@ -144,9 +146,10 @@ export async function writeFileContentToTempDir(id: string, content: string, pro
filePath = genTemporaryPath(id,
projectConfig.compileShared ? projectConfig.projectRootPath : projectConfig.moduleRootPath,
projectConfig.compileShared ? path.resolve(projectConfig.aceModuleBuild, '../etsFortgz') : projectConfig.cachePath,
projectConfig, metaInfo, logger, projectConfig.compileShared);
projectConfig.projectRootPath, projectConfig, metaInfo, logger, projectConfig.compileShared);
} else {
filePath = genTemporaryPath(id, projectConfig.projectPath, projectConfig.cachePath, projectConfig, metaInfo, logger);
filePath = genTemporaryPath(id, projectConfig.projectPath, projectConfig.cachePath,
projectConfig.projectRootPath, projectConfig, metaInfo, logger);
}
const eventWriteFileContent = createAndStartEvent(parentEvent, 'write file content');

View File

@ -179,9 +179,9 @@ export function etsTransform() {
}
const cacheFilePath: string = genTemporaryPath(filePath, projectConfig.moduleRootPath,
process.env.cachePath, projectConfig, undefined, undefined);
process.env.cachePath, projectConfig.projectRootPath, projectConfig, undefined, undefined);
const buildFilePath: string = genTemporaryPath(filePath, projectConfig.moduleRootPath,
projectConfig.buildPath, projectConfig, undefined, undefined, true);
projectConfig.buildPath, projectConfig.projectRootPath, projectConfig, undefined, undefined, true);
if (filePath.match(/\.e?ts$/)) {
setIncrementalFileInHar(cacheFilePath, buildFilePath, allFilesInHar);
} else {

View File

@ -322,7 +322,7 @@ function getEntryInfo(filePath: string, resourceResolveData: Object): string {
const fakeEntryPath: string = path.resolve(npmInfoPath, 'fake.js');
const tempFakeEntryPath: string = genTemporaryPath(fakeEntryPath, projectConfig.projectPath, process.env.cachePath,
projectConfig, undefined, undefined);
projectConfig.projectRootPath, projectConfig, undefined, undefined);
const buildFakeEntryPath: string = genBuildPath(fakeEntryPath, projectConfig.projectPath, projectConfig.buildPath,
projectConfig);
npmInfoPath = toUnixPath(path.resolve(tempFakeEntryPath, '..'));
@ -543,7 +543,8 @@ function handleFullModuleFiles(modules, callback): void {
modules.forEach(module => {
if (module !== undefined && module.resourceResolveData !== undefined) {
const filePath: string = module.resourceResolveData.path;
let tempFilePath = genTemporaryPath(filePath, projectConfig.projectPath, process.env.cachePath, projectConfig, undefined, undefined);
let tempFilePath = genTemporaryPath(filePath, projectConfig.projectPath, process.env.cachePath,
projectConfig.projectRootPath, projectConfig, undefined, undefined);
if (tempFilePath.length === 0) {
return;
}
@ -1099,7 +1100,8 @@ function handleHotReloadChangedFiles() {
for (let file of changedFileList) {
let filePath: string = path.join(projectConfig.projectPath, file);
validateFilePathLength(filePath, logger);
let tempFilePath: string = genTemporaryPath(filePath, projectConfig.projectPath, process.env.cachePath, projectConfig, undefined, undefined);
let tempFilePath: string = genTemporaryPath(filePath, projectConfig.projectPath, process.env.cachePath,
projectConfig.projectRootPath, projectConfig, undefined, undefined);
if (tempFilePath.length === 0) {
return;
}

View File

@ -59,7 +59,7 @@ export async function writeFileSyncByNode(node: ts.SourceFile, projectConfig: Ob
* In the current realization, when moduleId mechanism is changed, there would be a compilation error.
*/
let temporaryFile: string = genTemporaryPath(moduleId ? moduleId : node.fileName, projectConfig.projectPath, process.env.cachePath,
projectConfig, metaInfo, logger);
projectConfig.projectRootPath, projectConfig, metaInfo, logger);
if (temporaryFile.length === 0) {
return;
}

View File

@ -335,7 +335,8 @@ export function genLoaderOutPathOfHar(filePath: string, cachePath: string, build
return output;
}
export function genTemporaryPath(filePath: string, projectPath: string, buildPath: string,
// projectRootPath: When compiling har or hsp, the project path of the module file outside the project.
export function genTemporaryPath(filePath: string, projectPath: string, buildPath: string, projectRootPath: string,
projectConfig: Object, metaInfo: Object, logger: Object, buildInHar: boolean = false): string {
filePath = toUnixPath(filePath).replace(/\.[cm]js$/, EXTNAME_JS);
projectPath = toUnixPath(projectPath);
@ -343,11 +344,11 @@ export function genTemporaryPath(filePath: string, projectPath: string, buildPat
if (process.env.compileTool === 'rollup') {
const red: string = '\u001b[31m';
const reset: string = '\u001b[39m';
const projectRootPath: string = toUnixPath(buildInHar ? projectPath : projectConfig.projectRootPath);
projectRootPath = toUnixPath(buildInHar ? projectPath : projectRootPath);
let relativeFilePath: string = '';
if (filePath.startsWith(projectRootPath)) {
relativeFilePath = filePath.replace(projectRootPath, '');
} else if (metaInfo.belongProjectPath) {
} else if (metaInfo && metaInfo.belongProjectPath) {
relativeFilePath = filePath.replace(toUnixPath(metaInfo.belongProjectPath), '');
} else {
logger.error(red, 'ARKTS:INTERNAL ERROR\n' +
@ -418,12 +419,14 @@ export interface GeneratedFileInHar {
export const harFilesRecord: Map<string, GeneratedFileInHar> = new Map();
export function generateSourceFilesInHar(sourcePath: string, sourceContent: string, suffix: string, projectConfig: any) {
export function generateSourceFilesInHar(sourcePath: string, sourceContent: string, suffix: string,
projectConfig: Object, rootPathSet?: Object) {
const projectRootPath: string = getProjectRootPath(sourcePath, projectConfig, rootPathSet) ;
// compileShared: compile shared har of project
let jsFilePath: string = genTemporaryPath(sourcePath,
projectConfig.compileShared ? projectConfig.projectRootPath : projectConfig.moduleRootPath,
projectConfig.compileShared ? projectRootPath : projectConfig.moduleRootPath,
projectConfig.compileShared || projectConfig.byteCodeHar ? path.resolve(projectConfig.aceModuleBuild, '../etsFortgz') : projectConfig.cachePath,
projectConfig, undefined, undefined, projectConfig.compileShared);
projectRootPath, projectConfig, undefined, undefined, projectConfig.compileShared);
if (!jsFilePath.match(new RegExp(projectConfig.packageDir))) {
jsFilePath = jsFilePath.replace(/\.ets$/, suffix).replace(/\.ts$/, suffix);
if (projectConfig.obfuscateHarType === 'uglify' && suffix === '.js') {
@ -432,7 +435,11 @@ export function generateSourceFilesInHar(sourcePath: string, sourceContent: stri
// collect the declaration files for obfuscation
if (projectConfig.compileMode === ESMODULE && (/\.d\.e?ts$/).test(jsFilePath)) {
sourcePath = toUnixPath(sourcePath);
const genFilesInHar: GeneratedFileInHar = { sourcePath: sourcePath, originalDeclarationCachePath: jsFilePath, originalDeclarationContent: sourceContent };
const genFilesInHar: GeneratedFileInHar = {
sourcePath: sourcePath,
originalDeclarationCachePath: jsFilePath,
originalDeclarationContent: sourceContent
};
harFilesRecord.set(sourcePath, genFilesInHar);
return;
} else {
@ -1230,3 +1237,14 @@ export function removeDecorator(decorators: readonly ts.Decorator[], decoratorNa
return true;
});
}
export function getProjectRootPath(filePath: string, projectConfig: Object, rootPathSet: Object): string {
if (rootPathSet) {
for (const rootPath of rootPathSet) {
if (toUnixPath(filePath).indexOf(toUnixPath(rootPath)) !== -1) {
return rootPath;
}
}
}
return projectConfig.projectRootPath;
}

View File

@ -18,6 +18,7 @@ import mocha from 'mocha';
import fs from "fs";
import path from "path";
import MagicString from 'magic-string';
import sinon from 'sinon';
import {
needAotCompiler,
@ -52,19 +53,23 @@ import {
EXTNAME_ETS,
EXTNAME_JSON,
RELEASE,
DEBUG
DEBUG,
GEN_ABC_PLUGIN_NAME
} from '../../../lib/fast_build/ark_compiler/common/ark_define';
import ModuleSourceFileMock from '../mock/class_mock/module_source_files_mock';
import {
genTemporaryPath,
toUnixPath
toUnixPath,
getProjectRootPath
} from '../../../lib/utils';
import projectConfig from '../utils/processProjectConfig';
import {
TEST_TS,
TEST_JS,
TEST_ETS,
TEST_JSON
TEST_JSON,
PROJECT_ROOT,
DEFAULT_PROJECT
} from '../mock/rollup_mock/path_config';
import { scanFiles } from "../utils/utils";
import { SourceMapGenerator } from '../../../lib/fast_build/ark_compiler/generate_sourcemap';
@ -265,10 +270,12 @@ mocha.describe('test utils file api', function () {
for (const moduleId of mockFileList) {
if (moduleId.endsWith(EXTNAME_TS) || moduleId.endsWith(EXTNAME_ETS) || moduleId.endsWith(EXTNAME_JS)) {
const code: string = fs.readFileSync(moduleId, 'utf-8');
const moduleSource = new ModuleSourceFileMock(moduleId, code);
const metaInfo: Object = this.rollup.getModuleInfo(moduleId).meta;
const moduleSource = new ModuleSourceFileMock(moduleId, code, metaInfo);
moduleSource.initPluginEnvMock(this.rollup);
const filePath = genTemporaryPath(moduleSource.moduleId, moduleSource.projectConfig.projectPath,
moduleSource.projectConfig.cachePath, moduleSource.projectConfig);
moduleSource.projectConfig.cachePath, moduleSource.projectConfig.projectRootPath, moduleSource.projectConfig,
moduleSource.metaInfo, moduleSource.logger);
utUtils.writeFileContent(moduleSource.moduleId, filePath, moduleSource.source,
moduleSource.projectConfig, moduleSource.logger);
const newFilePath = changeFileExtension(filePath, EXTNAME_JS);
@ -285,10 +292,12 @@ mocha.describe('test utils file api', function () {
for (const moduleId of mockFileList) {
if (moduleId.endsWith(EXTNAME_TS) || moduleId.endsWith(EXTNAME_ETS) || moduleId.endsWith(EXTNAME_JS)) {
const code: string = fs.readFileSync(moduleId, 'utf-8');
const moduleSource = new ModuleSourceFileMock(moduleId, code);
const metaInfo: Object = this.rollup.getModuleInfo(moduleId).meta;
const moduleSource = new ModuleSourceFileMock(moduleId, code, metaInfo);
moduleSource.initPluginEnvMock(this.rollup);
const filePath = genTemporaryPath(moduleSource.moduleId, moduleSource.projectConfig.projectPath,
moduleSource.projectConfig.cachePath, moduleSource.projectConfig);
moduleSource.projectConfig.cachePath, moduleSource.projectConfig.projectRootPath, moduleSource.projectConfig,
moduleSource.metaInfo, moduleSource.logger);
utUtils.writeFileContent(moduleSource.moduleId, filePath, moduleSource.source,
moduleSource.projectConfig, moduleSource.logger);
const newFilePath = changeFileExtension(filePath, EXTNAME_JS);
@ -305,10 +314,12 @@ mocha.describe('test utils file api', function () {
for (const moduleId of mockFileList) {
if (moduleId.endsWith(EXTNAME_TS) || moduleId.endsWith(EXTNAME_ETS) || moduleId.endsWith(EXTNAME_JS)) {
const code: string = fs.readFileSync(moduleId, 'utf-8');
const moduleSource = new ModuleSourceFileMock(moduleId, code);
const metaInfo: Object = this.rollup.getModuleInfo(moduleId).meta;
const moduleSource = new ModuleSourceFileMock(moduleId, code, metaInfo);
moduleSource.initPluginEnvMock(this.rollup);
const filePath = genTemporaryPath(moduleSource.moduleId, moduleSource.projectConfig.projectPath,
moduleSource.projectConfig.cachePath, moduleSource.projectConfig);
moduleSource.projectConfig.cachePath, moduleSource.projectConfig.projectRootPath, moduleSource.projectConfig,
moduleSource.metaInfo, moduleSource.logger);
utUtils.writeFileContent(moduleSource.moduleId, filePath, moduleSource.source,
moduleSource.projectConfig, moduleSource.logger);
const newFilePath = changeFileExtension(filePath, EXTNAME_JS);
@ -324,10 +335,12 @@ mocha.describe('test utils file api', function () {
for (const moduleId of mockFileList) {
if (moduleId.endsWith(EXTNAME_TS) || moduleId.endsWith(EXTNAME_ETS) || moduleId.endsWith(EXTNAME_JS)) {
const code: string = fs.readFileSync(moduleId, 'utf-8');
const moduleSource = new ModuleSourceFileMock(moduleId, code);
const metaInfo: Object = this.rollup.getModuleInfo(moduleId).meta;
const moduleSource = new ModuleSourceFileMock(moduleId, code, metaInfo);
moduleSource.initPluginEnvMock(this.rollup);
const filePath = genTemporaryPath(moduleSource.moduleId, moduleSource.projectConfig.projectPath,
moduleSource.projectConfig.cachePath, moduleSource.projectConfig);
moduleSource.projectConfig.cachePath, moduleSource.projectConfig.projectRootPath, moduleSource.projectConfig,
moduleSource.metaInfo, moduleSource.logger);
utUtils.writeFileContent(moduleSource.moduleId, filePath, moduleSource.source,
moduleSource.projectConfig, moduleSource.logger);
const newFilePath = changeFileExtension(filePath, EXTNAME_JS);
@ -1252,4 +1265,64 @@ mocha.describe('test utils file api', function () {
expect(getRollupCache(this.rollup.share, projectConfig, cacheKeyNotExist)).to.be.equal(undefined);
});
mocha.it('16-1: test genTemporaryPath adapt external modules', function () {
this.rollup.build();
const filePath: string = '/testHar/har/src/main/ets/utils/Calc.ets';
const moduleInfo = {
id: filePath,
meta: {
belongProjectPath: '/testHar'
}
};
this.rollup.moduleInfos.push(moduleInfo);
const projectConfig = this.rollup.share.projectConfig;
const logger = this.rollup.share.getLogger(GEN_ABC_PLUGIN_NAME);
const metaInfo = this.rollup.getModuleInfo(filePath).meta;
const cacheFilePath = genTemporaryPath(filePath, projectConfig.projectPath, projectConfig.cachePath,
projectConfig.projectRootPath, projectConfig, metaInfo, logger);
const expectCacheFilePath = `${projectConfig.cachePath}/har/src/main/ets/utils/Calc.ets`;
expect(cacheFilePath === expectCacheFilePath).to.be.true;
});
mocha.it('16-2: test genTemporaryPath error message', function () {
this.rollup.build();
const filePath: string = '/testHar/har/src/main/ets/utils/Calc.ets';
const moduleInfo = {
id: filePath,
meta: {
belongProjectPath: undefined
}
};
this.rollup.moduleInfos.push(moduleInfo);
const red: string = '\u001b[31m';
const reset: string = '\u001b[39m';
const projectConfig = this.rollup.share.projectConfig;
const logger = this.rollup.share.getLogger(GEN_ABC_PLUGIN_NAME);
const loggerStub = sinon.stub(logger, 'error');
const metaInfo = this.rollup.getModuleInfo(filePath).meta;
genTemporaryPath(filePath, projectConfig.projectPath, projectConfig.cachePath,
projectConfig.projectRootPath, projectConfig, metaInfo, logger);
expect(loggerStub.calledWith(red, 'ARKTS:INTERNAL ERROR\n' +
`Error Message: Failed to generate the cache path corresponding to file ${filePath}.\n` +
'Because the file belongs to a module outside the project and has no project information.', reset)).to.be.true;
loggerStub.restore();
});
mocha.it('17-1: test getProjectRootPath adapt external modules', function () {
this.rollup.build();
const filePath: string = '/testHar/har/src/main/ets/utils/Calc.ets';
this.rollup.share.projectConfig.rootPathSet = ['/testHar', `${PROJECT_ROOT}/${DEFAULT_PROJECT}`];
const projectConfig = this.rollup.share.projectConfig;
const projectRootPath: string = getProjectRootPath(filePath, projectConfig, projectConfig.rootPathSet);
const expectProjectConfig: string = '/testHar';
expect(projectRootPath === expectProjectConfig).to.be.true;
});
mocha.it('17-2: test getProjectRootPath under build', function () {
this.rollup.build();
const filePath: string = `${PROJECT_ROOT}/${DEFAULT_PROJECT}/har/src/main/ets/utils/Calc.ets`;
const projectConfig = this.rollup.share.projectConfig;
const projectRootPath: string = getProjectRootPath(filePath, projectConfig, projectConfig.rootPathSet);
expect(projectRootPath === projectConfig.projectRootPath).to.be.true;
});
});

View File

@ -13,7 +13,10 @@
* limitations under the License.
*/
import { MODULE_ID_ROLLUP_PLACEHOLDER } from '../rollup_mock/path_config';
import {
MODULE_ID_ROLLUP_PLACEHOLDER,
PROJECT_ROOT
} from '../rollup_mock/path_config';
class Meta {
hostModulesInfo: Array<object>;
@ -23,15 +26,17 @@ class Meta {
isNodeEntryFile: boolean;
pkgPath: string;
dependencyPkgInfo: Object;
belongProjectPath: string;
constructor(entryModuleName: string, modulePath: string, packageName: string) {
constructor(entryModuleName: string, modulePath: string) {
this.hostModulesInfo = [];
this.moduleName = entryModuleName;
this.pkgName = packageName;
this.pkgName = '';
this.isLocalDependency = true;
this.isNodeEntryFile = false;
this.pkgPath = modulePath;
this.dependencyPkgInfo = undefined;
this.belongProjectPath = PROJECT_ROOT;
}
};

View File

@ -102,6 +102,7 @@ class ProjectConfig {
compileShared: boolean;
moduleRootPath: object;
buildPath: string;
rootPathSet: Object;
deviceType?: string;
checkEntry?: string;