adapter of preview ark

Signed-off-by: panzhenyu1 <panzhenyu1@huawei.com>
Change-Id: I9c9b2e5edace10918e2bc44fa206ac2ec684da86
This commit is contained in:
panzhenyu1
2022-06-20 17:27:35 +08:00
parent 8cb6e28c77
commit b20bc09016
4 changed files with 92 additions and 33 deletions
+40 -3
View File
@@ -42,7 +42,8 @@ import {
import {
MODULE_ETS_PATH,
MODULE_SHARE_PATH,
BUILD_SHARE_PATH
BUILD_SHARE_PATH,
ARK
} from './pre_define';
import {
createLanguageService,
@@ -51,6 +52,7 @@ import {
createWatchCompilerHost
} from './ets_checker';
import { globalProgram } from '../main';
import cluster from 'cluster';
configure({
appenders: { 'ETS': {type: 'stderr', layout: {type: 'messagePassThrough'}}},
@@ -298,9 +300,17 @@ export class ResultStates {
if (this.noteCount > 0) {
resultInfo += ` NOTE:${this.noteCount}`;
}
logger.info(this.blue, 'COMPILE RESULT:' + result + `{${resultInfo}}`, this.reset);
if (result === 'SUCCESS' && projectConfig.isPreview) {
this.printPreviewResult(resultInfo);
} else {
logger.info(this.blue, 'COMPILE RESULT:' + result + `{${resultInfo}}`, this.reset);
}
} else {
console.info(this.blue, 'COMPILE RESULT:SUCCESS ', this.reset);
if (projectConfig.isPreview) {
this.printPreviewResult();
} else {
console.info(this.blue, 'COMPILE RESULT:SUCCESS ', this.reset);
}
}
this.clearCount();
}
@@ -311,6 +321,33 @@ export class ResultStates {
this.noteCount = 0;
}
private printPreviewResult(resultInfo: string = ""): void {
let workerNum: number = Object.keys(cluster.workers).length;
let count_: number = 0;
let blue = this.blue;
let reset = this.reset;
if (workerNum > 0) {
for (const worker of Object.values(cluster.workers)) {
worker.on('exit', function(code, signal) {
count_++;
if (count_ === workerNum) {
printSuccessInfo(resultInfo);
}
});
}
} else {
printSuccessInfo(resultInfo);
}
function printSuccessInfo(resultInfo: string) {
if (resultInfo.length === 0) {
console.info(blue, 'COMPILE RESULT:SUCCESS ', reset);
} else {
console.info(blue, 'COMPILE RESULT:SUCCESS ' + `{${resultInfo}}`, reset);
}
}
}
private printWarning(): void {
if (this.mWarningCount > 0) {
const warnings: Info[] = this.mStats.compilation.warnings;
+5 -2
View File
@@ -36,18 +36,21 @@ function js2abcByWorkers(jsonInput: string, cmd: string): Promise<void> {
childProcess.execSync(singleCmd);
} catch (e) {
logger.error(red, `ETS:ERROR Failed to convert file ${input} to abc `, reset);
return;
process.exit(FAIL);
}
const abcFile: string = input.replace(/\.js$/, '.abc');
if (fs.existsSync(abcFile)) {
const abcFileNew: string = abcFile.replace(/_.abc$/, '.abc');
fs.renameSync(abcFile, abcFileNew);
fs.copyFileSync(abcFile, abcFileNew);
fs.unlinkSync(abcFile);
} else {
logger.error(red, `ETS:ERROR ${abcFile} is lost`, reset);
process.exit(FAIL);
}
}
return;
}
logger.debug('worker data is: ', JSON.stringify(process.env));
+27 -13
View File
@@ -60,13 +60,13 @@ interface File {
path: string,
size: number
}
const intermediateJsBundle: Array<File> = [];
let intermediateJsBundle: Array<File> = [];
let fileterIntermediateJsBundle: Array<File> = [];
const moduleInfos: Array<ModuleInfo> = [];
let moduleInfos: Array<ModuleInfo> = [];
let filterModuleInfos: Array<ModuleInfo> = [];
const commonJsModuleInfos: Array<ModuleInfo> = [];
const ESMModuleInfos: Array<ModuleInfo> = [];
const entryInfos: Map<string, EntryInfo> = new Map<string, EntryInfo>();
let commonJsModuleInfos: Array<ModuleInfo> = [];
let ESMModuleInfos: Array<ModuleInfo> = [];
let entryInfos: Map<string, EntryInfo> = new Map<string, EntryInfo>();
let hashJsonObject = {};
let moduleHashJsonObject = {};
let buildPathInfo: string = '';
@@ -173,6 +173,19 @@ export class GenAbcPlugin {
}
}
function clearGlobalInfo() {
intermediateJsBundle = [];
fileterIntermediateJsBundle = [];
moduleInfos = [];
filterModuleInfos = [];
commonJsModuleInfos = [];
ESMModuleInfos = [];
entryInfos = new Map<string, EntryInfo>();
hashJsonObject = {};
moduleHashJsonObject = {};
buildPathInfo = '';
}
function getEntryInfo(tempFilePath: string, resourceResolveData: any): void {
if (!resourceResolveData.descriptionFilePath) {
return;
@@ -356,7 +369,9 @@ function getSmallestSizeGroup(groupSize: Map<number, number>): any {
function splitJsBundlesBySize(bundleArray: Array<File>, groupNumber: number): any {
const result: any = [];
if (bundleArray.length < groupNumber) {
result.push(bundleArray);
for (let value of bundleArray){
result.push([value]);
}
return result;
}
@@ -535,18 +550,17 @@ function invokeWorkersToGenAbc(): void {
cluster.fork(workerData);
}
let count_ = 0;
cluster.on('exit', (worker, code, signal) => {
if (code === FAIL) {
process.exitCode = FAIL;
}
logger.debug(`worker ${worker.process.pid} finished`);
});
process.on('exit', (code) => {
if (process.exitCode === FAIL) {
return;
count_++;
if (count_ === workerNumber) {
writeHashJson();
clearGlobalInfo();
}
writeHashJson();
logger.debug(`worker ${worker.process.pid} finished`);
});
}
}
+20 -15
View File
@@ -310,6 +310,24 @@ function setTsConfigFile() {
}
}
function setGenAbcPlugin(env, config) {
process.env.compilerType = 'ark';
let arkDir = path.join(__dirname, 'bin', 'ark');
if (env.arkFrontendDir) {
arkDir = env.arkFrontendDir;
}
let nodeJs = 'node';
if (env.nodeJs) {
nodeJs = env.nodeJs;
}
config.plugins.push(new GenAbcPlugin(projectConfig.buildPath, arkDir, nodeJs,
env.buildMode === 'debug'));
if (env.buildMode === 'release') {
config.output.path = path.join(projectConfig.cachePath, 'releaseAssets',
path.basename(projectConfig.buildPath))
}
}
module.exports = (env, argv) => {
const config = {};
setProjectConfig(env);
@@ -324,25 +342,12 @@ module.exports = (env, argv) => {
if (env.isPreview !== "true") {
loadWorker(projectConfig, workerFile);
if (env.compilerType && env.compilerType === 'ark') {
process.env.compilerType = 'ark';
let arkDir = path.join(__dirname, 'bin', 'ark');
if (env.arkFrontendDir) {
arkDir = env.arkFrontendDir;
}
let nodeJs = 'node';
if (env.nodeJs) {
nodeJs = env.nodeJs;
}
config.plugins.push(new GenAbcPlugin(projectConfig.buildPath, arkDir, nodeJs,
env.buildMode === 'debug'));
if (env.buildMode === 'release') {
config.output.path = path.join(projectConfig.cachePath, 'releaseAssets',
path.basename(projectConfig.buildPath))
}
setGenAbcPlugin(env, config);
}
} else {
projectConfig.isPreview = true;
projectConfig.checkEntry = env.checkEntry;
setGenAbcPlugin(env, config);
let port;
process.argv.forEach((val, index) => {
if(val.startsWith('port=')){