From f372d9734a7c0e6385a026a42ddd015ba74f2da9 Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Mon, 11 Jul 2022 11:33:48 +0800 Subject: [PATCH 1/4] fix multi ark preview process Signed-off-by: zhangrengao Change-Id: I3ce6048b3bc2da184152cb37c6c3d426d07858ea --- ace-loader/src/genAbc-plugin.js | 17 ++++++++++++++++- ace-loader/webpack.rich.config.js | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ace-loader/src/genAbc-plugin.js b/ace-loader/src/genAbc-plugin.js index c232b50..9567bf7 100644 --- a/ace-loader/src/genAbc-plugin.js +++ b/ace-loader/src/genAbc-plugin.js @@ -93,7 +93,7 @@ class GenAbcPlugin { }); compiler.hooks.afterEmit.tap('GenAbcPluginMultiThread', () => { buildPathInfo = output; - invokeWorkerToGenAbc(); + judgeWorkersToGenAbc(invokeWorkerToGenAbc); }); } } @@ -238,6 +238,7 @@ function clearGlobalInfo() { fileterIntermediateJsBundle = []; hashJsonObject = {}; buildPathInfo = ""; + process.env.compilerStatus = "on" } function filterIntermediateJsBundleByHashJson(buildPath, inputPaths) { @@ -349,3 +350,17 @@ module.exports = { GenAbcPlugin: GenAbcPlugin, checkWorksFile: checkWorksFile } + +function judgeWorkersToGenAbc(callback) { + let timeoutId = null; + if (process.env.compilerStatus && process.env.compilerStatus === "on") { + callback(); + process.env.compilerStatus = "off"; + if (timeoutId) { + clearTimeout(timeoutId) + } + return ; + } else { + timeoutId = setTimeout(judgeWorkersToGenAbc.bind(null, callback), 50); + } +} diff --git a/ace-loader/webpack.rich.config.js b/ace-loader/webpack.rich.config.js index a972081..d76af5f 100644 --- a/ace-loader/webpack.rich.config.js +++ b/ace-loader/webpack.rich.config.js @@ -205,6 +205,7 @@ function setConfigs(env) { function setArkPlugin(env, workerFile) { config.plugins.push(new ModuleCollectionPlugin()) if (env.isPreview === "true" || env.compilerType && env.compilerType === 'ark') { + process.env.compilerStatus = "on"; let arkDir = path.join(__dirname, 'bin', 'ark'); if (env.arkFrontendDir) { arkDir = env.arkFrontendDir; From 5f0d16d0fddb23c1380cdec9c9b4a93f64902dde Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Wed, 13 Jul 2022 15:52:38 +0800 Subject: [PATCH 2/4] modify condition of settimeout Signed-off-by: zhangrengao Change-Id: I58d9fd31ed5b7d3bd1652815be724fe5a840b75d --- ace-loader/src/compile-plugin.js | 33 ++--------------------------- ace-loader/src/genAbc-plugin.js | 35 ++++++++++++++++++++++--------- ace-loader/webpack.rich.config.js | 1 - 3 files changed, 27 insertions(+), 42 deletions(-) diff --git a/ace-loader/src/compile-plugin.js b/ace-loader/src/compile-plugin.js index 4ba79c8..be1a2cc 100644 --- a/ace-loader/src/compile-plugin.js +++ b/ace-loader/src/compile-plugin.js @@ -217,45 +217,16 @@ function printResult(buildPath) { if (noteCount > 0) { resultInfo.NOTE = noteCount; } - if (result === 'SUCCESS ' && process.env.isPreview) { - printPreviewResult(resultInfo); - } else { + if (!(result === 'SUCCESS ' && process.env.isPreview)) { console.log(blue, 'COMPILE RESULT:' + result + JSON.stringify(resultInfo), reset); } } else { - if (process.env.isPreview) { - printPreviewResult(); - } else { + if (!process.env.isPreview) { console.log(blue, 'COMPILE RESULT:SUCCESS ', reset); } } } -function printPreviewResult(resultInfo = "") { - let workerNum = Object.keys(cluster.workers).length; - let count_ = 0; - 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) { - if (resultInfo.length === 0) { - console.log(blue, 'COMPILE RESULT:SUCCESS ', reset); - } else { - console.log(blue, 'COMPILE RESULT:SUCCESS ' + JSON.stringify(resultInfo), reset); - } -} - function printWarning() { if (mWarningCount > 0) { const warnings = mStats.compilation.warnings; diff --git a/ace-loader/src/genAbc-plugin.js b/ace-loader/src/genAbc-plugin.js index 9567bf7..c373331 100644 --- a/ace-loader/src/genAbc-plugin.js +++ b/ace-loader/src/genAbc-plugin.js @@ -51,8 +51,10 @@ const SUCCESS = 0; const FAIL = 1; const red = '\u001b[31m'; const reset = '\u001b[39m'; +const blue = '\u001b[34m'; const hashFile = 'gen_hash.json'; const ARK = '/ark/'; +let delayCount = 0; class GenAbcPlugin { constructor(output_, arkDir_, nodeJs_, workerFile_, isDebug_) { @@ -221,27 +223,41 @@ function invokeWorkerToGenAbc() { let count_ = 0; cluster.on('exit', (worker, code, signal) => { - if (code === FAIL) { + if (code === FAIL || process.exitCode === FAIL) { process.exitCode = FAIL; + return; } count_++; if (count_ === workerNumber) { writeHashJson(); clearGlobalInfo(); + if (process.env.isPreview) { + console.log(blue, 'COMPILE RESULT:SUCCESS ', reset); + } } }); } } function clearGlobalInfo() { - intermediateJsBundle = []; + if (delayCount <= 1) { + intermediateJsBundle = []; + } fileterIntermediateJsBundle = []; hashJsonObject = {}; buildPathInfo = ""; - process.env.compilerStatus = "on" } function filterIntermediateJsBundleByHashJson(buildPath, inputPaths) { + let tempInputPaths = []; + inputPaths.forEach((item) => { + let check = tempInputPaths.every((newItem) => { + return item.path != newItem.path; + }) + check ? tempInputPaths.push(item) : "" + }); + inputPaths = tempInputPaths; + for (let i = 0; i < inputPaths.length; ++i) { fileterIntermediateJsBundle.push(inputPaths[i]); } @@ -308,7 +324,9 @@ function writeHashJson() { if (hashFilePath.length == 0) { return ; } - fs.writeFileSync(hashFilePath, JSON.stringify(hashJsonObject)); + if (delayCount <= 1) { + fs.writeFileSync(hashFilePath, JSON.stringify(hashJsonObject)); + } } function genHashJsonPath(buildPath) { @@ -352,15 +370,12 @@ module.exports = { } function judgeWorkersToGenAbc(callback) { - let timeoutId = null; - if (process.env.compilerStatus && process.env.compilerStatus === "on") { + const workerNumber = Object.keys(cluster.workers).length; + if (workerNumber === 0) { callback(); - process.env.compilerStatus = "off"; - if (timeoutId) { - clearTimeout(timeoutId) - } return ; } else { + delayCount++; timeoutId = setTimeout(judgeWorkersToGenAbc.bind(null, callback), 50); } } diff --git a/ace-loader/webpack.rich.config.js b/ace-loader/webpack.rich.config.js index d76af5f..a972081 100644 --- a/ace-loader/webpack.rich.config.js +++ b/ace-loader/webpack.rich.config.js @@ -205,7 +205,6 @@ function setConfigs(env) { function setArkPlugin(env, workerFile) { config.plugins.push(new ModuleCollectionPlugin()) if (env.isPreview === "true" || env.compilerType && env.compilerType === 'ark') { - process.env.compilerStatus = "on"; let arkDir = path.join(__dirname, 'bin', 'ark'); if (env.arkFrontendDir) { arkDir = env.arkFrontendDir; From b8a21ecb26b4fde93d4df7fa2b269aa80545f7af Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Tue, 19 Jul 2022 09:21:19 +0800 Subject: [PATCH 3/4] unlink temp file of process exit Signed-off-by: zhangrengao Change-Id: I1bb805992e86cce85f338c4cf7f94508a889725d --- ace-loader/src/genAbc-plugin.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/ace-loader/src/genAbc-plugin.js b/ace-loader/src/genAbc-plugin.js index c373331..b04e025 100644 --- a/ace-loader/src/genAbc-plugin.js +++ b/ace-loader/src/genAbc-plugin.js @@ -236,11 +236,19 @@ function invokeWorkerToGenAbc() { } } }); + process.on('exit', (code) => { + intermediateJsBundle.forEach((item) => { + let input = item.path; + if (fs.existsSync(input)) { + fs.unlinkSync(input); + } + }) + }); } } function clearGlobalInfo() { - if (delayCount <= 1) { + if (!process.env.isPreview) { intermediateJsBundle = []; } fileterIntermediateJsBundle = []; @@ -252,7 +260,7 @@ function filterIntermediateJsBundleByHashJson(buildPath, inputPaths) { let tempInputPaths = []; inputPaths.forEach((item) => { let check = tempInputPaths.every((newItem) => { - return item.path != newItem.path; + return item.path !== newItem.path; }) check ? tempInputPaths.push(item) : "" }); @@ -288,7 +296,9 @@ function filterIntermediateJsBundleByHashJson(buildPath, inputPaths) { if (jsonObject[input] === hashInputContentData && jsonObject[abcPath] === hashAbcContentData) { updateJsonObject[input] = hashInputContentData; updateJsonObject[abcPath] = hashAbcContentData; - fs.unlinkSync(input); + if (!process.env.isPreview) { + fs.unlinkSync(input); + } } else { fileterIntermediateJsBundle.push(inputPaths[i]); } @@ -316,7 +326,7 @@ function writeHashJson() { hashJsonObject[input] = hashInputContentData; hashJsonObject[abcPath] = hashAbcContentData; } - if (fs.existsSync(input)) { + if (!process.env.isPreview && fs.existsSync(input)) { fs.unlinkSync(input); } } @@ -324,7 +334,7 @@ function writeHashJson() { if (hashFilePath.length == 0) { return ; } - if (delayCount <= 1) { + if (!process.env.isPreview || delayCount < 1) { fs.writeFileSync(hashFilePath, JSON.stringify(hashJsonObject)); } } @@ -376,6 +386,6 @@ function judgeWorkersToGenAbc(callback) { return ; } else { delayCount++; - timeoutId = setTimeout(judgeWorkersToGenAbc.bind(null, callback), 50); + setTimeout(judgeWorkersToGenAbc.bind(null, callback), 50); } } From ef6b3a645babbf07caa0813eb061b44e0c7bd453 Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Thu, 21 Jul 2022 11:08:24 +0800 Subject: [PATCH 4/4] fix incre compile of preview Signed-off-by: zhangrengao Change-Id: I49269b86ca0b3af67f1d3b514e08ce5f24452a29 --- ace-loader/src/compile-plugin.js | 23 +++++++++++++++++++++-- ace-loader/src/genAbc-plugin.js | 7 ++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/ace-loader/src/compile-plugin.js b/ace-loader/src/compile-plugin.js index be1a2cc..2e5d0bb 100644 --- a/ace-loader/src/compile-plugin.js +++ b/ace-loader/src/compile-plugin.js @@ -217,16 +217,35 @@ function printResult(buildPath) { if (noteCount > 0) { resultInfo.NOTE = noteCount; } - if (!(result === 'SUCCESS ' && process.env.isPreview)) { + if (result === 'SUCCESS ' && process.env.isPreview) { + printPreviewResult(resultInfo); + } else { console.log(blue, 'COMPILE RESULT:' + result + JSON.stringify(resultInfo), reset); } } else { - if (!process.env.isPreview) { + if (process.env.isPreview) { + printPreviewResult(); + } else { console.log(blue, 'COMPILE RESULT:SUCCESS ', reset); } } } +function printPreviewResult(resultInfo = "") { + let workerNum = Object.keys(cluster.workers).length; + if (workerNum === 0) { + printSuccessInfo(resultInfo); + } +} + +function printSuccessInfo(resultInfo) { + if (resultInfo.length === 0) { + console.log(blue, 'COMPILE RESULT:SUCCESS ', reset); + } else { + console.log(blue, 'COMPILE RESULT:SUCCESS ' + JSON.stringify(resultInfo), reset); + } +} + function printWarning() { if (mWarningCount > 0) { const warnings = mStats.compilation.warnings; diff --git a/ace-loader/src/genAbc-plugin.js b/ace-loader/src/genAbc-plugin.js index b04e025..a964c39 100644 --- a/ace-loader/src/genAbc-plugin.js +++ b/ace-loader/src/genAbc-plugin.js @@ -253,7 +253,6 @@ function clearGlobalInfo() { } fileterIntermediateJsBundle = []; hashJsonObject = {}; - buildPathInfo = ""; } function filterIntermediateJsBundleByHashJson(buildPath, inputPaths) { @@ -261,8 +260,10 @@ function filterIntermediateJsBundleByHashJson(buildPath, inputPaths) { inputPaths.forEach((item) => { let check = tempInputPaths.every((newItem) => { return item.path !== newItem.path; - }) - check ? tempInputPaths.push(item) : "" + }); + if (check) { + tempInputPaths.push(item); + } }); inputPaths = tempInputPaths;