From a2e839087ffd3cf3df5532d6badfeb27f5a9f124 Mon Sep 17 00:00:00 2001 From: hufeng Date: Tue, 6 Sep 2022 20:08:44 +0800 Subject: [PATCH 1/2] Remove duplicate webpack's module Signed-off-by: hufeng Change-Id: I8d1b3f053c14f98d0ca969df9d6883ff52587854 --- compiler/main.js | 1 - compiler/src/gen_abc_plugin.ts | 24 +++++++++++++----------- compiler/src/gen_merged_abc.ts | 11 +++++++++++ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/compiler/main.js b/compiler/main.js index 1d9f5fc..dbb05f4 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -380,7 +380,6 @@ function loadModuleInfo(projectConfig, envArgs) { projectConfig.modulePathMap = buildJsonInfo.modulePathMap; projectConfig.isOhosTest = buildJsonInfo.isOhosTest; projectConfig.processTs = false; - projectConfig.processMergeabc = false; projectConfig.buildArkMode = envArgs.buildMode; if (buildJsonInfo.compileMode === 'esmodule') { projectConfig.nodeModulesPath = buildJsonInfo.nodeModulesPath; diff --git a/compiler/src/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index f118c9c..5f3f511 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -148,14 +148,12 @@ export class GenAbcPlugin { } // case ESMODULE - // | --- merge -- debug -- not removeDir - // | --- merge -- release -- removeDir - // | --- unmerge -- removeDir - if (projectConfig.compileMode === ESMODULE) { - if (!projectConfig.processMergeabc || projectConfig.buildArkMode !== 'debug') { - removeDir(output); - removeDir(projectConfig.nodeModulesPath); - } + // | --- es2abc -- debug -- not removeDir + // | --- es2abc -- release -- removeDir + // | --- ts2abc -- removeDir + if (projectConfig.compileMode === ESMODULE && ((projectConfig.buildArkMode !== 'debug' && process.env.panda === ES2ABC) || process.env.panda === TS2ABC)) { + removeDir(output); + removeDir(projectConfig.nodeModulesPath); } compiler.hooks.compilation.tap('GenAbcPlugin', (compilation) => { @@ -351,7 +349,11 @@ function eliminateUnusedFiles(moduleList: Array): void{ let cachedModuleList: Array = getCachedModuleList(); if (cachedModuleList.length !== 0) { const eliminateFiles: Array = cachedModuleList.filter(m => !moduleList.includes(m)); - eliminateFiles.forEach((file) => {fs.unlinkSync(file);}); + eliminateFiles.forEach((file) => { + if (fs.existsSync(file)) { + fs.unlinkSync(file); + } + }); } } @@ -382,7 +384,7 @@ function handleFinishModules(modules, callback): any { } }); - if (projectConfig.processMergeabc) { + if (projectConfig.compileMode === ESMODULE && process.env.panda !== TS2ABC) { if (projectConfig.buildArkMode === 'debug') { eliminateUnusedFiles(buildMapFileList); updateCachedModuleList(buildMapFileList); @@ -518,7 +520,7 @@ export function initAbcEnv() : string[] { if (isDebug) { args.push('--debug-info'); } - if (projectConfig.processMergeabc) { + if (projectConfig.compileMode === ESMODULE) { args.push('--merge-abc'); } } else { diff --git a/compiler/src/gen_merged_abc.ts b/compiler/src/gen_merged_abc.ts index 974eb3a..cee7540 100644 --- a/compiler/src/gen_merged_abc.ts +++ b/compiler/src/gen_merged_abc.ts @@ -35,6 +35,17 @@ const red: string = '\u001b[31m'; const reset: string = '\u001b[39m'; function generateCompileFilesInfo(moduleInfos: Array) { + const tempModuleInfos = Array(); + moduleInfos.forEach((item) => { + const check = tempModuleInfos.every((newItem) => { + return item.tempFilePath !== newItem.tempFilePath; + }); + if (check) { + tempModuleInfos.push(item); + } + }); + moduleInfos = tempModuleInfos; + const filesInfoPath: string = path.join(process.env.cachePath, FILESINFO_TXT); let filesInfo: string = ''; moduleInfos.forEach(info => { From 2292827066fd36a07562713a4d73f3950d4e2800 Mon Sep 17 00:00:00 2001 From: hufeng Date: Tue, 6 Sep 2022 21:48:44 +0800 Subject: [PATCH 2/2] clear buildMapFileList after execute ark Signed-off-by: hufeng Change-Id: Ie62aa2ce3b3810b4fbdd6330a07d1fa736bef85f --- compiler/src/gen_abc_plugin.ts | 12 ++++++++---- compiler/src/gen_merged_abc.ts | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/compiler/src/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index 5f3f511..5b6e33f 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -151,9 +151,11 @@ export class GenAbcPlugin { // | --- es2abc -- debug -- not removeDir // | --- es2abc -- release -- removeDir // | --- ts2abc -- removeDir - if (projectConfig.compileMode === ESMODULE && ((projectConfig.buildArkMode !== 'debug' && process.env.panda === ES2ABC) || process.env.panda === TS2ABC)) { - removeDir(output); - removeDir(projectConfig.nodeModulesPath); + if (projectConfig.compileMode === ESMODULE) { + if ((projectConfig.buildArkMode !== 'debug' && process.env.panda === ES2ABC) || process.env.panda === TS2ABC) { + removeDir(output); + removeDir(projectConfig.nodeModulesPath); + } } compiler.hooks.compilation.tap('GenAbcPlugin', (compilation) => { @@ -205,8 +207,8 @@ function clearGlobalInfo() { // fix bug of multi trigger if (!process.env.watchMode) { intermediateJsBundle = []; - moduleInfos = []; } + moduleInfos = []; fileterIntermediateJsBundle = []; filterModuleInfos = []; commonJsModuleInfos = []; @@ -214,6 +216,7 @@ function clearGlobalInfo() { entryInfos = new Map(); hashJsonObject = {}; moduleHashJsonObject = {}; + buildMapFileList = []; } function getEntryInfo(tempFilePath: string, resourceResolveData: any): void { @@ -390,6 +393,7 @@ function handleFinishModules(modules, callback): any { updateCachedModuleList(buildMapFileList); } generateMergedAbc(moduleInfos, entryInfos); + clearGlobalInfo(); } else { judgeModuleWorkersToGenAbc(invokeWorkersModuleToGenAbc); processEntryToGenAbc(entryInfos); diff --git a/compiler/src/gen_merged_abc.ts b/compiler/src/gen_merged_abc.ts index cee7540..14d5ffe 100644 --- a/compiler/src/gen_merged_abc.ts +++ b/compiler/src/gen_merged_abc.ts @@ -35,9 +35,9 @@ const red: string = '\u001b[31m'; const reset: string = '\u001b[39m'; function generateCompileFilesInfo(moduleInfos: Array) { - const tempModuleInfos = Array(); + const tempModuleInfos: ModuleInfo[] = Array(); moduleInfos.forEach((item) => { - const check = tempModuleInfos.every((newItem) => { + let check: boolean = tempModuleInfos.every((newItem) => { return item.tempFilePath !== newItem.tempFilePath; }); if (check) {