From e4ffecb810b585f9d91c6cb5dbdeecfdff41200c Mon Sep 17 00:00:00 2001 From: hufeng Date: Fri, 18 Nov 2022 03:44:06 +0000 Subject: [PATCH] fixed ccb66b3 from https://gitee.com/hufeng20/developtools_ace-js2bundle/pulls/452 Set sourceFile as relative when compiling jsbundle Signed-off-by: hufeng Change-Id: I04e428114a2e960899d176f957d15befd1563327 --- ace-loader/src/gen-abc.js | 5 ++--- ace-loader/src/genAbc-plugin.js | 13 +++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ace-loader/src/gen-abc.js b/ace-loader/src/gen-abc.js index a52b3de..dac39c0 100644 --- a/ace-loader/src/gen-abc.js +++ b/ace-loader/src/gen-abc.js @@ -20,8 +20,6 @@ const SUCCESS = 0; const FAIL = 1; const red = '\u001b[31m'; const reset = '\u001b[39m'; -const TS2ABC = 'ts2abc'; -const ES2ABC = 'es2abc'; function js2abcByWorkers(jsonInput, cmd) { const inputPaths = JSON.parse(jsonInput); @@ -30,7 +28,8 @@ function js2abcByWorkers(jsonInput, cmd) { const input = inputPaths[i].path.replace(/\.temp\.js$/, "_.js"); const cacheOutputPath = inputPaths[i].cacheOutputPath; const cacheAbcFilePath = cacheOutputPath.replace(/\.temp\.js$/, ".abc"); - const singleCmd = `${cmd} "${cacheOutputPath}" -o "${cacheAbcFilePath}" --source-file "${input}"`; + const sourceFile = inputPaths[i].sourceFile; + const singleCmd = `${cmd} "${cacheOutputPath}" -o "${cacheAbcFilePath}" --source-file "${sourceFile}"`; try { childProcess.execSync(singleCmd); } catch (e) { diff --git a/ace-loader/src/genAbc-plugin.js b/ace-loader/src/genAbc-plugin.js index a0d7b1f..d63f10b 100644 --- a/ace-loader/src/genAbc-plugin.js +++ b/ace-loader/src/genAbc-plugin.js @@ -198,9 +198,18 @@ function writeFileSync(inputString, buildPath, keyPath, jsBundleFile, isToBin) { fs.writeFileSync(cacheOutputPath, inputString); if (fs.existsSync(cacheOutputPath)) { let fileSize = fs.statSync(cacheOutputPath).size; + let sourceFile = output.replace(/\.temp\.js$/, "_.js"); + if (!isDebug && (process.env.aceBuildJson && fs.existsSync(process.env.aceBuildJson))) { + const buildJsonInfo = JSON.parse(fs.readFileSync(process.env.aceBuildJson).toString()); + sourceFile = toUnixPath(sourceFile.replace(buildJsonInfo.projectRootPath + path.sep, '')); + } else { + sourceFile = toUnixPath(sourceFile); + } output = toUnixPath(output); cacheOutputPath = toUnixPath(cacheOutputPath); - intermediateJsBundle.push({path: output, size: fileSize, cacheOutputPath: cacheOutputPath}); + intermediateJsBundle.push({ + path: output, size: fileSize, cacheOutputPath: cacheOutputPath, sourceFile: sourceFile + }); } else { console.debug(red, `ERROR Failed to convert file ${jsBundleFile} to bin. ${output} is lost`, reset); process.exitCode = FAIL; @@ -679,7 +688,7 @@ function generateFileOfBundle(inputPaths) { const cacheOutputPath = info.cacheOutputPath; const recordName = 'null_recordName'; const moduleType = 'script'; - const sourceFile = info.path.replace(/\.temp\.js$/, "_.js"); + const sourceFile = info.sourceFile; const abcFilePath = cacheOutputPath.replace(/\.temp\.js$/, ".abc"); filesInfo += `${cacheOutputPath};${recordName};${moduleType};${sourceFile};${abcFilePath}\n`; }); -- Gitee