!67 fix the problem of using absolute path

Merge pull request !67 from houhaoyu/yangbo
This commit is contained in:
openharmony_ci
2021-10-20 11:11:57 +00:00
committed by Gitee
+6 -4
View File
@@ -42,6 +42,7 @@ import {
IComponentSet
} from './validate_ui_syntax';
import { LogInfo } from './utils';
import { projectConfig } from '../main';
export default function processImport(node: ts.ImportDeclaration | ts.ImportEqualsDeclaration |
ts.ExportDeclaration, pagesDir: string, log: LogInfo[]): void {
@@ -81,7 +82,7 @@ export default function processImport(node: ts.ImportDeclaration | ts.ImportEqua
} else if (/^\//.test(filePath)) {
fileResolvePath = filePath;
} else {
fileResolvePath = getFileResolvePath(fileResolvePath, pagesDir, filePath);
fileResolvePath = getFileResolvePath(fileResolvePath, pagesDir, filePath, projectConfig.projectPath);
}
if (fs.existsSync(fileResolvePath) && fs.statSync(fileResolvePath).isFile()) {
const content: string = preprocessExtend(processSystemApi(
@@ -247,13 +248,14 @@ function getModuleFilePath(filePath: string): string {
return filePath;
}
function getFileResolvePath(fileResolvePath: string, pagesDir: string, filePath: string): string {
function getFileResolvePath(fileResolvePath: string, pagesDir: string, filePath: string,
projectPath: string): string {
const moduleFilePath: string = getModuleFilePath(filePath);
const defaultModule: string = path.join(pagesDir, '../', moduleFilePath);
const defaultModule: string = path.join(projectPath, moduleFilePath);
if (fs.existsSync(defaultModule)) {
return defaultModule;
}
const entryModule: string = path.join(pagesDir, '../../../../../../', moduleFilePath);
const entryModule: string = path.join(projectPath, '../../../../../', moduleFilePath);
if (fs.existsSync(entryModule)) {
return entryModule;
}