From 1fdf1bf23b9503ea68cf95f29f6e7709f398c77d Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Tue, 31 May 2022 12:27:29 +0800 Subject: [PATCH 1/3] fix check works file Signed-off-by: zhangrengao Change-Id: I8ddaf7d22d78df2f38f5d84138ee4ede6987f4be --- ace-loader/src/genAbc-plugin.js | 22 ++++++++++++++++++++-- ace-loader/src/genBin-plugin.js | 22 ++++++++++++++++++++-- ace-loader/webpack.rich.config.js | 10 +++++----- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/ace-loader/src/genAbc-plugin.js b/ace-loader/src/genAbc-plugin.js index a4de364..b03c7a9 100644 --- a/ace-loader/src/genAbc-plugin.js +++ b/ace-loader/src/genAbc-plugin.js @@ -42,13 +42,15 @@ let isDebug = false; let arkDir; let nodeJs; let intermediateJsBundle = []; +let workerFile = null; class GenAbcPlugin { - constructor(output_, arkDir_, nodeJs_, isDebug_) { + constructor(output_, arkDir_, nodeJs_, workerFile_, isDebug_) { output = output_; arkDir = arkDir_; nodeJs = nodeJs_; isDebug = isDebug_; + workerFile = workerFile_; } apply(compiler) { if (fs.existsSync(path.resolve(arkDir, 'build-win'))) { @@ -66,7 +68,7 @@ class GenAbcPlugin { // choice *.js if (output && path.extname(key) === '.js') { let newContent = assets[key].source(); - if (key.search('workers/') !== 0 && key !== 'commons.js' && key !== 'vendors.js') { + if (checkWorksFile(key, workerFile) && key !== 'commons.js' && key !== 'vendors.js') { newContent = forward + newContent + last; } if (key === 'commons.js' || key === 'vendors.js') { @@ -83,6 +85,22 @@ class GenAbcPlugin { } } +function checkWorksFile(assetPath, workerFile) { + if (workerFile === null) { + if (assetPath.search("./workers/")) { + return true; + } + } else { + for (const key in workerFile) { + if (key === assetPath || workerFile[key] === assetPath) { + return true; + } + } + } + + return false; +} + function writeFileSync(inputString, output, jsBundleFile) { const parent = path.join(output, '..'); if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) { diff --git a/ace-loader/src/genBin-plugin.js b/ace-loader/src/genBin-plugin.js index 16d372a..adfadda 100644 --- a/ace-loader/src/genBin-plugin.js +++ b/ace-loader/src/genBin-plugin.js @@ -38,11 +38,13 @@ const sencondFileEXT = '.c' const lastFileEXT = '.bin' let output let webpackPath +let workerFile = null; class GenBinPlugin { - constructor(output_, webpackPath_) { + constructor(output_, webpackPath_, workerFile_) { output = output_ webpackPath = webpackPath_ + workerFile = workerFile_ } apply(compiler) { if (!fs.existsSync(path.resolve(webpackPath, 'qjsc.exe')) && !fs.existsSync(path.resolve(webpackPath, 'qjsc'))) { @@ -55,7 +57,7 @@ class GenBinPlugin { // choice *.js if (output && webpackPath && path.extname(key) === '.js') { let newContent = assets[key].source() - if (key.search('workers/') !== 0) { + if (checkWorksFile(key, workerFile)) { newContent = forward + newContent + last } const keyPath = key.replace(/\.js$/, firstFileEXT) @@ -66,6 +68,22 @@ class GenBinPlugin { } } +function checkWorksFile(assetPath, workerFile) { + if (workerFile_ === null) { + if (assetPath.search("./workers/")) { + return true; + } + } else { + for (const key in workerFile) { + if (key === assetPath || workerFile[key] === assetPath) { + return true; + } + } + } + + return false; +} + function writeFileSync(inputString, output, jsBundleFile) { const parent = path.join(output, '..') if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) { diff --git a/ace-loader/webpack.rich.config.js b/ace-loader/webpack.rich.config.js index d18366d..ab244cd 100644 --- a/ace-loader/webpack.rich.config.js +++ b/ace-loader/webpack.rich.config.js @@ -198,7 +198,7 @@ function setConfigs(env) { } } -function notPreview(env) { +function notPreview(env, workerFile) { config.plugins.push(new ModuleCollectionPlugin()) if (env.compilerType && env.compilerType === 'ark') { let arkDir = path.join(__dirname, 'bin', 'ark'); @@ -209,7 +209,7 @@ function notPreview(env) { if (env.nodeJs) { nodeJs = env.nodeJs; } - config.plugins.push(new GenAbcPlugin(process.env.buildPath, arkDir, nodeJs, + config.plugins.push(new GenAbcPlugin(process.env.buildPath, arkDir, nodeJs, workerFile, env.buildMode === 'debug')) if (env.buildMode === 'release' && process.env.DEVICE_LEVEL !== 'card') { config.output.path = path.join(process.env.cachePath, "releaseAssets", @@ -220,7 +220,7 @@ function notPreview(env) { let deviceArr = env.deviceType.split(/,/) let isDefault = deviceArr.indexOf('tv') >= 0 || deviceArr.indexOf('wearable') >= 0 ? true : false if (isDefault) { - config.plugins.push(new GenBinPlugin(process.env.buildPath, path.join(__dirname, 'bin'))) + config.plugins.push(new GenBinPlugin(process.env.buildPath, path.join(__dirname, 'bin', workerFile))) } } } @@ -307,7 +307,7 @@ module.exports = (env) => { config.module = cardModule config.plugins.push(new AfterEmitPlugin()) if (env.isPreview !== "true") { - notPreview(env) + notPreview(env, workerFile) } } else { if (process.env.compileMode !== 'moduleJson' && process.env.abilityType === 'page') { @@ -335,7 +335,7 @@ module.exports = (env) => { } } if (env.isPreview !== "true") { - notPreview(env) + notPreview(env, workerFile) } if (env.sourceMap === 'none') { config.devtool = false From 73e7d2f89cf75288565a22f7cb1f6103a307d1c0 Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Tue, 31 May 2022 15:22:01 +0800 Subject: [PATCH 2/3] fix bugs Signed-off-by: zhangrengao Change-Id: Icb27a7ea03f2de17837faad607619f86bcc44ffe --- ace-loader/src/genAbc-plugin.js | 11 +++++++---- ace-loader/src/genBin-plugin.js | 13 ++++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ace-loader/src/genAbc-plugin.js b/ace-loader/src/genAbc-plugin.js index b03c7a9..a722e5e 100644 --- a/ace-loader/src/genAbc-plugin.js +++ b/ace-loader/src/genAbc-plugin.js @@ -87,18 +87,21 @@ class GenAbcPlugin { function checkWorksFile(assetPath, workerFile) { if (workerFile === null) { - if (assetPath.search("./workers/")) { + if (assetPath.search("./workers/") !== 0) { return true; + } else { + return false; } } else { for (const key in workerFile) { - if (key === assetPath || workerFile[key] === assetPath) { - return true; + let keyExt = key + '.js'; + if (keyExt === assetPath) { + return false; } } } - return false; + return true; } function writeFileSync(inputString, output, jsBundleFile) { diff --git a/ace-loader/src/genBin-plugin.js b/ace-loader/src/genBin-plugin.js index adfadda..3bf9a58 100644 --- a/ace-loader/src/genBin-plugin.js +++ b/ace-loader/src/genBin-plugin.js @@ -69,19 +69,22 @@ class GenBinPlugin { } function checkWorksFile(assetPath, workerFile) { - if (workerFile_ === null) { - if (assetPath.search("./workers/")) { + if (workerFile === null) { + if (assetPath.search("./workers/") !== 0) { return true; + } else { + return false; } } else { for (const key in workerFile) { - if (key === assetPath || workerFile[key] === assetPath) { - return true; + let keyExt = key + '.js'; + if (keyExt === assetPath) { + return false; } } } - return false; + return true; } function writeFileSync(inputString, output, jsBundleFile) { From 0012682958ac576ac473b9edf940f4e1c9d99d3a Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Tue, 31 May 2022 17:50:10 +0800 Subject: [PATCH 3/3] remove duplicate function Signed-off-by: zhangrengao Change-Id: I3be9fda6839b5e9d4be2c38cc43617f33b4349b9 --- ace-loader/src/genAbc-plugin.js | 5 ++++- ace-loader/src/genBin-plugin.js | 20 +------------------- ace-loader/webpack.rich.config.js | 2 +- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/ace-loader/src/genAbc-plugin.js b/ace-loader/src/genAbc-plugin.js index a722e5e..7953c70 100644 --- a/ace-loader/src/genAbc-plugin.js +++ b/ace-loader/src/genAbc-plugin.js @@ -204,4 +204,7 @@ function invokeWorkerToGenAbc() { } } -module.exports = GenAbcPlugin; +module.exports = { + GenAbcPlugin: GenAbcPlugin, + checkWorksFile: checkWorksFile +} diff --git a/ace-loader/src/genBin-plugin.js b/ace-loader/src/genBin-plugin.js index 3bf9a58..5e800bc 100644 --- a/ace-loader/src/genBin-plugin.js +++ b/ace-loader/src/genBin-plugin.js @@ -17,6 +17,7 @@ const fs = require('fs') const path = require('path') const process = require('child_process') const qjsc = path.join(__dirname, '..', 'bin', 'qjsc') +const checkWorksFile = require('./genAbc-plugin').checkWorksFile const forward = '(global.___mainEntry___ = function (globalObjects) {' + '\n' + ' const define = globalObjects.define;' + '\n' + @@ -68,25 +69,6 @@ class GenBinPlugin { } } -function checkWorksFile(assetPath, workerFile) { - if (workerFile === null) { - if (assetPath.search("./workers/") !== 0) { - return true; - } else { - return false; - } - } else { - for (const key in workerFile) { - let keyExt = key + '.js'; - if (keyExt === assetPath) { - return false; - } - } - } - - return true; -} - function writeFileSync(inputString, output, jsBundleFile) { const parent = path.join(output, '..') if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) { diff --git a/ace-loader/webpack.rich.config.js b/ace-loader/webpack.rich.config.js index ab244cd..58c9340 100644 --- a/ace-loader/webpack.rich.config.js +++ b/ace-loader/webpack.rich.config.js @@ -19,7 +19,7 @@ var fs = require('fs') var ResourcePlugin = require('./lib/resource-plugin') var ResultStates = require('./lib/compile-plugin') var GenBinPlugin = require('./lib/genBin-plugin') -var GenAbcPlugin = require('./lib/genAbc-plugin') +var GenAbcPlugin = require('./lib/genAbc-plugin').GenAbcPlugin var AfterEmitPlugin = require('./lib/cardJson-plugin').AfterEmitPlugin var ModuleCollectionPlugin = require('./lib/module-collection-plugin')