!677 fix worker debug bug.

Merge pull request !677 from lihong/master
This commit is contained in:
openharmony_ci
2022-05-27 08:20:27 +00:00
committed by Gitee
2 changed files with 34 additions and 22 deletions
+20 -17
View File
@@ -236,18 +236,9 @@ function setEntrance(abilityConfig, abilityPages) {
}
}
function loadWorker(projectConfig) {
if (validateWorkOption()) {
const workerConfig = JSON.parse(fs.readFileSync(projectConfig.aceBuildJson).toString());
workerConfig.workers.forEach(worker => {
if (!/\.(ts|js)$/.test(worker)) {
worker += '.ts';
}
const relativePath = path.relative(projectConfig.projectPath, worker);
if (filterWorker(relativePath)) {
projectConfig.entryObj[relativePath.replace(/\.(ts|js)$/,'').replace(/\\/g, '/')] = worker;
}
})
function loadWorker(projectConfig, workerFileEntry) {
if (workerFileEntry) {
projectConfig.entryObj = Object.assign(projectConfig.entryObj, workerFileEntry);
} else {
const workerPath = path.resolve(projectConfig.projectPath, WORKERS_DIR);
if (fs.existsSync(workerPath)) {
@@ -255,7 +246,8 @@ function loadWorker(projectConfig) {
readFile(workerPath, workerFiles);
workerFiles.forEach((item) => {
if (/\.(ts|js)$/.test(item)) {
const relativePath = path.relative(workerPath, item).replace(/\.(ts|js)$/, '');
const relativePath = path.relative(workerPath, item)
.replace(/\.(ts|js)$/, '').replace(/\\/g, '/');
projectConfig.entryObj[`./${WORKERS_DIR}/` + relativePath] = item;
}
})
@@ -263,14 +255,24 @@ function loadWorker(projectConfig) {
}
}
function validateWorkOption() {
function readWorkerFile() {
const workerFileEntry = {};
if (projectConfig.aceBuildJson && fs.existsSync(projectConfig.aceBuildJson)) {
const workerConfig = JSON.parse(fs.readFileSync(projectConfig.aceBuildJson).toString());
if(workerConfig.workers) {
return true;
if (workerConfig.workers) {
workerConfig.workers.forEach(worker => {
if (!/\.(ts|js)$/.test(worker)) {
worker += '.ts';
}
const relativePath = path.relative(projectConfig.projectPath, worker);
if (filterWorker(relativePath)) {
workerFileEntry[relativePath.replace(/\.(ts|js)$/, '').replace(/\\/g, '/')] = worker;
}
});
return workerFileEntry;
}
}
return false;
return null;
}
function filterWorker(workerPath) {
@@ -337,3 +339,4 @@ exports.readAppResource = readAppResource;
exports.resources = resources;
exports.loadWorker = loadWorker;
exports.abilityConfig = abilityConfig;
exports.readWorkerFile = readWorkerFile;
+14 -5
View File
@@ -26,7 +26,8 @@ const {
readAppResource,
resources,
loadWorker,
abilityConfig
abilityConfig,
readWorkerFile
} = require('./main');
const { ResultStates } = require('./lib/compile_info');
const { processUISyntax } = require('./lib/process_ui_syntax');
@@ -251,12 +252,19 @@ function setCopyPluginConfig(config) {
config.plugins.push(new CopyPlugin({ patterns: copyPluginPattrens }));
}
function setOptimizationConfig(config) {
function excludeWorker(workerFile, name) {
if (workerFile) {
return Object.keys(workerFile).includes(name);
}
return /^\.\/workers\//.test(name);
}
function setOptimizationConfig(config, workerFile) {
if (process.env.compileMode !== 'moduleJson' && abilityConfig.abilityType === 'page') {
config.optimization = {
splitChunks: {
chunks(chunk) {
return !/^\.\/workers\//.test(chunk.name) && !/^\.\/TestAbility/.test(chunk.name);
return !excludeWorker(workerFile, chunk.name) && !/^\.\/TestAbility/.test(chunk.name);
},
minSize: 0,
cacheGroups: {
@@ -282,10 +290,11 @@ module.exports = (env, argv) => {
setProjectConfig(env);
loadEntryObj(projectConfig);
initConfig(config);
setOptimizationConfig(config);
const workerFile = readWorkerFile();
setOptimizationConfig(config, workerFile);
setCopyPluginConfig(config);
if (env.isPreview !== "true") {
loadWorker(projectConfig);
loadWorker(projectConfig, workerFile);
if (env.compilerType && env.compilerType === 'ark') {
let arkDir = path.join(__dirname, 'bin', 'ark');
if (env.arkFrontendDir) {