mirror of
https://github.com/openharmony/developtools_ace-ets2bundle.git
synced 2026-07-20 19:47:44 -04:00
!1030 Fix clean webpack of ark incre compile
Merge pull request !1030 from zrg/fix_clean_incre_8_28_api8
This commit is contained in:
+5
-10
@@ -25,8 +25,11 @@ const reset: string = '\u001b[39m';
|
||||
function js2abcByWorkers(jsonInput: string, cmd: string): Promise<void> {
|
||||
const inputPaths = JSON.parse(jsonInput);
|
||||
for (let i = 0; i < inputPaths.length; ++i) {
|
||||
const input = inputPaths[i].path;
|
||||
const singleCmd = `${cmd} "${input}"`;
|
||||
// for matching debug info mechanism
|
||||
const input = inputPaths[i].path.replace(/\.temp\.js$/, "_.js");
|
||||
const cacheOutputPath: string = inputPaths[i].cacheOutputPath;
|
||||
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 {
|
||||
childProcess.execSync(singleCmd);
|
||||
@@ -34,14 +37,6 @@ function js2abcByWorkers(jsonInput: string, cmd: string): Promise<void> {
|
||||
logger.error(red, `ETS:ERROR Failed to convert file ${input} to abc `, reset);
|
||||
return;
|
||||
}
|
||||
|
||||
const abcFile: string = input.replace(/\.js$/, '.abc');
|
||||
if (fs.existsSync(abcFile)) {
|
||||
const abcFileNew: string = abcFile.replace(/_.abc$/, '.abc');
|
||||
fs.renameSync(abcFile, abcFileNew);
|
||||
} else {
|
||||
logger.error(red, `ETS:ERROR ${abcFile} is lost`, reset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import Compiler from 'webpack/lib/Compiler';
|
||||
import { logger } from './compile_info';
|
||||
import { toUnixPath, toHashData } from './utils';
|
||||
|
||||
const firstFileEXT: string = '_.js';
|
||||
const genAbcScript = 'gen_abc.js';
|
||||
let output: string;
|
||||
let isWin: boolean = false;
|
||||
@@ -32,7 +31,8 @@ let nodeJs: string;
|
||||
|
||||
interface File {
|
||||
path: string,
|
||||
size: number
|
||||
size: number,
|
||||
cacheOutputPath: string
|
||||
}
|
||||
const intermediateJsBundle: Array<File> = [];
|
||||
let fileterIntermediateJsBundle: Array<File> = [];
|
||||
@@ -70,8 +70,8 @@ export class GenAbcPlugin {
|
||||
// choose *.js
|
||||
if (output && path.extname(key) === '.js') {
|
||||
const newContent: string = compilation.assets[key].source();
|
||||
const keyPath: string = key.replace(/\.js$/, firstFileEXT);
|
||||
writeFileSync(newContent, path.resolve(output, keyPath), key);
|
||||
const keyPath: string = key.replace(/\.js$/, ".temp.js");
|
||||
writeFileSync(newContent, output, keyPath, key);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -83,15 +83,26 @@ export class GenAbcPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
function writeFileSync(inputString: string, output: string, jsBundleFile: string): void {
|
||||
const parent: string = path.join(output, '..');
|
||||
function writeFileSync(inputString: string, buildPath: string, keyPath: string, jsBundleFile: string): void {
|
||||
let output = path.resolve(buildPath, keyPath);
|
||||
let parent: string = path.join(output, '..');
|
||||
if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) {
|
||||
mkDir(parent);
|
||||
}
|
||||
fs.writeFileSync(output, inputString);
|
||||
if (fs.existsSync(output)) {
|
||||
const fileSize = fs.statSync(output).size;
|
||||
intermediateJsBundle.push({path: output, size: fileSize});
|
||||
let cacheOutputPath: string = "";
|
||||
if (process.env.cachePath) {
|
||||
cacheOutputPath = path.join(process.env.cachePath, "temporary", keyPath);
|
||||
} else {
|
||||
cacheOutputPath = output;
|
||||
}
|
||||
parent = path.join(cacheOutputPath, '..');
|
||||
if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) {
|
||||
mkDir(parent);
|
||||
}
|
||||
fs.writeFileSync(cacheOutputPath, inputString);
|
||||
if (fs.existsSync(cacheOutputPath)) {
|
||||
const fileSize = fs.statSync(cacheOutputPath).size;
|
||||
intermediateJsBundle.push({path: output, size: fileSize, cacheOutputPath: cacheOutputPath});
|
||||
} else {
|
||||
logger.error(red, `ETS:ERROR Failed to convert file ${jsBundleFile} to bin. ${output} is lost`, reset);
|
||||
}
|
||||
@@ -188,6 +199,7 @@ function invokeWorkersToGenAbc() {
|
||||
|
||||
process.on('exit', (code) => {
|
||||
writeHashJson();
|
||||
copyFileCachePathToBuildPath()
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -208,19 +220,18 @@ function filterIntermediateJsBundleByHashJson(buildPath: string, inputPaths: Fil
|
||||
jsonObject = JSON.parse(jsonFile);
|
||||
fileterIntermediateJsBundle = [];
|
||||
for (let i = 0; i < inputPaths.length; ++i) {
|
||||
const input = inputPaths[i].path;
|
||||
const abcPath = input.replace(/_.js$/, '.abc');
|
||||
if (!fs.existsSync(input)) {
|
||||
logger.error(red, `ETS:ERROR ${input} is lost`, reset);
|
||||
const cacheOutputPath: string = inputPaths[i].cacheOutputPath;
|
||||
const cacheAbcFilePath: string = cacheOutputPath.replace(/\.temp\.js$/, '.abc');
|
||||
if (!fs.existsSync(cacheOutputPath)) {
|
||||
logger.error(red, `ETS:ERROR ${cacheOutputPath} is lost`, reset);
|
||||
continue;
|
||||
}
|
||||
if (fs.existsSync(abcPath)) {
|
||||
const hashInputContentData = toHashData(input);
|
||||
const hashAbcContentData = toHashData(abcPath);
|
||||
if (jsonObject[input] === hashInputContentData && jsonObject[abcPath] === hashAbcContentData) {
|
||||
updateJsonObject[input] = hashInputContentData;
|
||||
updateJsonObject[abcPath] = hashAbcContentData;
|
||||
fs.unlinkSync(input);
|
||||
if (fs.existsSync(cacheAbcFilePath)) {
|
||||
const hashInputContentData = toHashData(cacheOutputPath);
|
||||
const hashAbcContentData = toHashData(cacheAbcFilePath);
|
||||
if (jsonObject[cacheOutputPath] === hashInputContentData && jsonObject[cacheAbcFilePath] === hashAbcContentData) {
|
||||
updateJsonObject[cacheOutputPath] = hashInputContentData;
|
||||
updateJsonObject[cacheAbcFilePath] = hashAbcContentData;
|
||||
} else {
|
||||
fileterIntermediateJsBundle.push(inputPaths[i]);
|
||||
}
|
||||
@@ -235,17 +246,16 @@ function filterIntermediateJsBundleByHashJson(buildPath: string, inputPaths: Fil
|
||||
|
||||
function writeHashJson() {
|
||||
for (let i = 0; i < fileterIntermediateJsBundle.length; ++i) {
|
||||
const input = fileterIntermediateJsBundle[i].path;
|
||||
const abcPath = input.replace(/_.js$/, '.abc');
|
||||
if (!fs.existsSync(input) || !fs.existsSync(abcPath)) {
|
||||
logger.error(red, `ETS:ERROR ${input} is lost`, reset);
|
||||
const cacheOutputPath: string = fileterIntermediateJsBundle[i].cacheOutputPath;
|
||||
const cacheAbcFilePath: string = cacheOutputPath.replace(/\.temp\.js$/, '.abc');
|
||||
if (!fs.existsSync(cacheOutputPath) || !fs.existsSync(cacheAbcFilePath)) {
|
||||
logger.error(red, `ETS:ERROR ${cacheOutputPath} is lost`, reset);
|
||||
continue;
|
||||
}
|
||||
const hashInputContentData = toHashData(input);
|
||||
const hashAbcContentData = toHashData(abcPath);
|
||||
hashJsonObject[input] = hashInputContentData;
|
||||
hashJsonObject[abcPath] = hashAbcContentData;
|
||||
fs.unlinkSync(input);
|
||||
const hashInputContentData: any = toHashData(cacheOutputPath);
|
||||
const hashAbcContentData: any = toHashData(cacheAbcFilePath);
|
||||
hashJsonObject[cacheOutputPath] = hashInputContentData;
|
||||
hashJsonObject[cacheAbcFilePath] = hashAbcContentData;
|
||||
}
|
||||
const hashFilePath = genHashJsonPath(buildPathInfo);
|
||||
if (hashFilePath.length === 0) {
|
||||
@@ -275,3 +285,25 @@ function genHashJsonPath(buildPath: string) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function copyFileCachePathToBuildPath() {
|
||||
for (let i = 0; i < intermediateJsBundle.length; ++i) {
|
||||
const abcFile: string = intermediateJsBundle[i].path.replace(/\.temp\.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;
|
||||
}
|
||||
let parent: string = path.join(abcFile, '..');
|
||||
if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) {
|
||||
mkDir(parent);
|
||||
}
|
||||
if (!fs.existsSync(abcFile)) {
|
||||
fs.copyFileSync(cacheAbcFilePath, abcFile);
|
||||
}
|
||||
if (process.env.cachePath === undefined && fs.existsSync(cacheOutputPath)) {
|
||||
fs.unlinkSync(cacheOutputPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user