!461 so信息保存

Merge pull request !461 from 卡哥/so
This commit is contained in:
openharmony_ci
2022-03-22 14:56:30 +00:00
committed by Gitee
8 changed files with 36 additions and 10 deletions
+1
View File
@@ -62,6 +62,7 @@ function initProjectConfig(projectConfig) {
projectConfig.aceBuildJson = projectConfig.aceBuildJson || process.env.aceBuildJson;
projectConfig.cachePath = projectConfig.cachePath || process.env.cachePath ||
path.resolve(__dirname, 'node_modules/.cache');
projectConfig.aceSoPath = projectConfig.aceSoPath || process.env.aceSoPath;
}
function loadEntryObj(projectConfig) {
+23 -2
View File
@@ -29,9 +29,15 @@ import CachedSource from 'webpack-sources/lib/CachedSource';
import ConcatSource from 'webpack-sources/lib/ConcatSource';
import { transformLog } from './process_ui_syntax';
import { moduleCollection } from './validate_ui_syntax';
import {
moduleCollection,
useOSFiles
} from './validate_ui_syntax';
import { projectConfig } from '../main';
import { circularFile } from './utils';
import {
circularFile,
mkDir
} from './utils';
import { MODULE_SHARE_PATH, BUILD_SHARE_PATH } from './pre_define';
import {
createLanguageService,
@@ -179,6 +185,10 @@ export class ResultStates {
});
compiler.hooks.done.tap('Result States', (stats: Stats) => {
if (projectConfig.isPreview && projectConfig.aceSoPath &&
useOSFiles && useOSFiles.size > 0) {
this.writeUseOSFiles();
}
this.mStats = stats;
this.warningCount = 0;
this.noteCount = 0;
@@ -204,6 +214,17 @@ export class ResultStates {
}
}
private writeUseOSFiles(): void {
let info: string = '';
if (!fs.existsSync(projectConfig.aceSoPath)) {
const parent: string = path.join(projectConfig.aceSoPath, '..');
if (!(fs.existsSync(parent) && !fs.statSync(parent).isFile())) {
mkDir(parent);
}
}
fs.writeFileSync(projectConfig.aceSoPath, info + Array.from(useOSFiles).join('\n'));
}
private printResult(): void {
this.printWarning();
this.printError();
+3 -3
View File
@@ -76,7 +76,7 @@ export function createLanguageService(rootFileNames: string[]): ts.LanguageServi
}
if (/(?<!\.d)\.(ets|ts)$/.test(fileName)) {
checkUISyntax(fs.readFileSync(fileName).toString(), fileName);
return ts.ScriptSnapshot.fromString(processContent(fs.readFileSync(fileName).toString()));
return ts.ScriptSnapshot.fromString(processContent(fs.readFileSync(fileName).toString(), fileName));
}
return ts.ScriptSnapshot.fromString(fs.readFileSync(fileName).toString());
},
@@ -270,8 +270,8 @@ function processDraw(source: string): string {
});
}
function processContent(source: string): string {
source = processSystemApi(source);
function processContent(source: string, sourcePath: string): string {
source = processSystemApi(source, false, sourcePath);
source = preprocessExtend(source, extendCollection);
source = processDraw(source);
return source;
+1 -1
View File
@@ -55,7 +55,7 @@ function preProcess(source: string): string {
}
return newContent;
} else {
return processSystemApi(source);
return processSystemApi(source, false, this.resourcePath);
}
}
+1 -1
View File
@@ -89,7 +89,7 @@ export default function processImport(node: ts.ImportDeclaration | ts.ImportEqua
fs.readFileSync(fileResolvePath, { encoding: 'utf-8' }).replace(
new RegExp('\\b' + STRUCT + '\\b.+\\{', 'g'), item => {
return item.replace(new RegExp('\\b' + STRUCT + '\\b', 'g'), `${CLASS} `);
})));
}), false, fileResolvePath));
const sourceFile: ts.SourceFile = ts.createSourceFile(filePath, content,
ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
visitAllNode(sourceFile, defaultName, asName, path.dirname(fileResolvePath), log);
+1 -1
View File
@@ -16,5 +16,5 @@
import { processSystemApi } from './validate_ui_syntax';
module.exports = function processSystemModule(source: string): string {
return processSystemApi(source);
return processSystemApi(source, false, this.resourcePath);
};
+1 -1
View File
@@ -35,7 +35,7 @@ import { abilityConfig } from '../main';
module.exports = function resultProcess(source: string, map: any): void {
process.env.compiler = BUILD_OFF;
source = processSystemApi(source, true);
source = processSystemApi(source, true, this.resourcePath);
if (/\.ets$/.test(this.resourcePath)) {
componentInfo.id = 0;
propertyCollection.clear();
+5 -1
View File
@@ -112,6 +112,7 @@ export const objectLinkCollection: Map<string, Set<string>> = new Map();
export const isStaticViewCollection: Map<string, boolean> = new Map();
export const moduleCollection: Set<string> = new Set();
export const useOSFiles: Set<string> = new Set();
export function validateUISyntax(source: string, content: string, filePath: string,
fileQuery: string): LogInfo[] {
@@ -734,7 +735,7 @@ export function preprocessExtend(content: string, extendCollection?: Set<string>
});
}
export function processSystemApi(content: string, isProcessWhiteList: boolean = false): string {
export function processSystemApi(content: string, isProcessWhiteList: boolean = false, sourcePath: string): string {
let REG_SYSTEM: RegExp;
if (isProcessWhiteList) {
REG_SYSTEM =
@@ -749,6 +750,9 @@ export function processSystemApi(content: string, isProcessWhiteList: boolean =
const newContent: string = content.replace(REG_LIB_SO, (_, item1, item2, item3, item4) => {
const libSoValue: string = item1 || item3;
const libSoKey: string = item2 || item4;
if (sourcePath) {
useOSFiles.add(sourcePath);
}
return `var ${libSoValue} = globalThis.requireNapi("${libSoKey}", true);`;
}).replace(REG_SYSTEM, (item, item1, item2, item3, item4, item5, item6, item7) => {
let moduleType: string = item2 || item5;