From fdd4530e8d6a3527fb0ffaecae50a077ca2d1452 Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Sun, 28 Aug 2022 19:37:05 +0800 Subject: [PATCH] Fix dup name of temp file Signed-off-by: zhangrengao Change-Id: Iabf21097688cf1ad8bb8c999ea01c249534df181 --- compiler/src/gen_abc.ts | 2 +- compiler/src/gen_abc_plugin.ts | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/compiler/src/gen_abc.ts b/compiler/src/gen_abc.ts index b4df1ce..55008ea 100644 --- a/compiler/src/gen_abc.ts +++ b/compiler/src/gen_abc.ts @@ -27,7 +27,7 @@ function js2abcByWorkers(jsonInput: string, cmd: string): Promise { for (let i = 0; i < inputPaths.length; ++i) { const input = inputPaths[i].path; const cacheOutputPath: string = inputPaths[i].cacheOutputPath; - const cacheAbcFilePath: string = cacheOutputPath.replace(/\_.js$/, ".abc"); + const cacheAbcFilePath: string = cacheOutputPath.replace(/\.temp\.js$/, ".abc"); const singleCmd: any = `${cmd} "${cacheOutputPath}" -o "${cacheAbcFilePath}" --source-file "${input}"`; logger.debug('gen abc cmd is: ', singleCmd, ' ,file size is:', inputPaths[i].size, ' byte'); try { diff --git a/compiler/src/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index 48caaf8..00155c0 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -92,9 +92,10 @@ function writeFileSync(inputString: string, buildPath: string, keyPath: string, } let cacheOutputPath: string = ""; if (process.env.cachePath) { - cacheOutputPath = path.join(process.env.cachePath, "temporary", keyPath); + let temporaryKeyPath = keyPath.replace(/\_.js$/, '.temp.js'); + cacheOutputPath = path.join(process.env.cachePath, "temporary", temporaryKeyPath); } else { - cacheOutputPath = output; + cacheOutputPath = output.replace(/\_.js$/, '.temp.js'); } parent = path.join(cacheOutputPath, '..'); if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) { @@ -224,7 +225,7 @@ function filterIntermediateJsBundleByHashJson(buildPath: string, inputPaths: Fil const input = inputPaths[i].path; const abcPath = input.replace(/_.js$/, '.abc'); const cacheOutputPath: string = inputPaths[i].cacheOutputPath; - const cacheAbcFilePath: string = cacheOutputPath.replace(/\_.js$/, '.abc'); + const cacheAbcFilePath: string = cacheOutputPath.replace(/\.temp\.js$/, '.abc'); if (!fs.existsSync(cacheOutputPath)) { logger.error(red, `ETS:ERROR ${cacheOutputPath} is lost`, reset); continue; @@ -252,7 +253,7 @@ function writeHashJson() { const input = fileterIntermediateJsBundle[i].path; const abcPath = input.replace(/_.js$/, '.abc'); const cacheOutputPath: string = fileterIntermediateJsBundle[i].cacheOutputPath; - const cacheAbcFilePath: string = cacheOutputPath.replace(/\_.js$/, '.abc'); + const cacheAbcFilePath: string = cacheOutputPath.replace(/\.temp\.js$/, '.abc'); if (!fs.existsSync(cacheOutputPath) || !fs.existsSync(cacheAbcFilePath)) { logger.error(red, `ETS:ERROR ${input} is lost`, reset); continue; @@ -295,7 +296,8 @@ function copyFileCachePathToBuildPath() { for (let i = 0; i < intermediateJsBundle.length; ++i) { const inputPath: string = intermediateJsBundle[i].path; const abcFile: string = intermediateJsBundle[i].path.replace(/\_.js$/, ".abc"); - const cacheAbcFilePath: string = intermediateJsBundle[i].cacheOutputPath.replace(/\_.js$/, ".abc"); + const cacheOutputPath: string = intermediateJsBundle[i].cacheOutputPath; + const cacheAbcFilePath: string = intermediateJsBundle[i].cacheOutputPath.replace(/\.temp\.js$/, ".abc"); if (!fs.existsSync(cacheAbcFilePath)) { logger.error(red, `ETS:ERROR ${cacheAbcFilePath} is lost`, reset); break; @@ -307,8 +309,8 @@ function copyFileCachePathToBuildPath() { if (!fs.existsSync(abcFile)) { fs.copyFileSync(cacheAbcFilePath, abcFile); } - if (process.env.cachePath === undefined && fs.existsSync(inputPath)) { - fs.unlinkSync(inputPath); + if (process.env.cachePath === undefined && fs.existsSync(cacheOutputPath)) { + fs.unlinkSync(cacheOutputPath); } } }