diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index 01bfccb..9fee66f 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -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; diff --git a/compiler/src/gen_abc.ts b/compiler/src/gen_abc.ts index 13b0e78..632a5d5 100644 --- a/compiler/src/gen_abc.ts +++ b/compiler/src/gen_abc.ts @@ -36,18 +36,21 @@ function js2abcByWorkers(jsonInput: string, cmd: string): Promise { 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)); diff --git a/compiler/src/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index 29ae968..4c16764 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -60,13 +60,13 @@ interface File { path: string, size: number } -const intermediateJsBundle: Array = []; +let intermediateJsBundle: Array = []; let fileterIntermediateJsBundle: Array = []; -const moduleInfos: Array = []; +let moduleInfos: Array = []; let filterModuleInfos: Array = []; -const commonJsModuleInfos: Array = []; -const ESMModuleInfos: Array = []; -const entryInfos: Map = new Map(); +let commonJsModuleInfos: Array = []; +let ESMModuleInfos: Array = []; +let entryInfos: Map = new Map(); 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(); + hashJsonObject = {}; + moduleHashJsonObject = {}; + buildPathInfo = ''; +} + function getEntryInfo(tempFilePath: string, resourceResolveData: any): void { if (!resourceResolveData.descriptionFilePath) { return; @@ -356,7 +369,9 @@ function getSmallestSizeGroup(groupSize: Map): any { function splitJsBundlesBySize(bundleArray: Array, 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`); }); } } diff --git a/compiler/webpack.config.js b/compiler/webpack.config.js index 4c259f5..bb91ff4 100644 --- a/compiler/webpack.config.js +++ b/compiler/webpack.config.js @@ -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=')){