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..5b6e33f 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -148,11 +148,11 @@ export class GenAbcPlugin { } // case ESMODULE - // | --- merge -- debug -- not removeDir - // | --- merge -- release -- removeDir - // | --- unmerge -- removeDir + // | --- es2abc -- debug -- not removeDir + // | --- es2abc -- release -- removeDir + // | --- ts2abc -- removeDir if (projectConfig.compileMode === ESMODULE) { - if (!projectConfig.processMergeabc || projectConfig.buildArkMode !== 'debug') { + if ((projectConfig.buildArkMode !== 'debug' && process.env.panda === ES2ABC) || process.env.panda === TS2ABC) { removeDir(output); removeDir(projectConfig.nodeModulesPath); } @@ -207,8 +207,8 @@ function clearGlobalInfo() { // fix bug of multi trigger if (!process.env.watchMode) { intermediateJsBundle = []; - moduleInfos = []; } + moduleInfos = []; fileterIntermediateJsBundle = []; filterModuleInfos = []; commonJsModuleInfos = []; @@ -216,6 +216,7 @@ function clearGlobalInfo() { entryInfos = new Map(); hashJsonObject = {}; moduleHashJsonObject = {}; + buildMapFileList = []; } function getEntryInfo(tempFilePath: string, resourceResolveData: any): void { @@ -351,7 +352,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,12 +387,13 @@ function handleFinishModules(modules, callback): any { } }); - if (projectConfig.processMergeabc) { + if (projectConfig.compileMode === ESMODULE && process.env.panda !== TS2ABC) { if (projectConfig.buildArkMode === 'debug') { eliminateUnusedFiles(buildMapFileList); updateCachedModuleList(buildMapFileList); } generateMergedAbc(moduleInfos, entryInfos); + clearGlobalInfo(); } else { judgeModuleWorkersToGenAbc(invokeWorkersModuleToGenAbc); processEntryToGenAbc(entryInfos); @@ -518,7 +524,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..14d5ffe 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: ModuleInfo[] = Array(); + moduleInfos.forEach((item) => { + let check: boolean = 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 => {