adapter es2abc

Change-Id: Ib2b35215b55963c1802d29fdbff9328db8ecc611
Signed-off-by: zhangrengao <zhangrengao1@huawei.com>
This commit is contained in:
zhangrengao
2022-06-21 10:42:47 +08:00
parent 0a19a6c920
commit b850123d16
5 changed files with 63 additions and 12 deletions
+1
View File
@@ -375,6 +375,7 @@ function loadModuleInfo(projectConfig, envArgs) {
if (buildJsonInfo.compileMode === 'esmodule') {
projectConfig.nodeModulesPath = buildJsonInfo.nodeModulesPath;
}
projectConfig.pandaMode = buildJsonInfo.pandaMode;
}
}
+29 -2
View File
@@ -20,7 +20,9 @@ import cluster from 'cluster';
import { logger } from './compile_info';
import {
SUCCESS,
FAIL
FAIL,
TS2ABC,
ES2ABC
} from './pre_define';
const red: string = '\u001b[31m';
@@ -53,10 +55,35 @@ function js2abcByWorkers(jsonInput: string, cmd: string): Promise<void> {
return;
}
function es2abcByWorkers(jsonInput: string, cmd: string): Promise<void> {
const inputPaths: any = JSON.parse(jsonInput);
for (let i = 0; i < inputPaths.length; ++i) {
const input: string = inputPaths[i].path;
const abcFile: string = input.replace(/_.js$/, '.abc');
const singleCmd: any = `${cmd} "${input}" --output "${abcFile}"`;
logger.debug('gen abc cmd is: ', singleCmd, ' ,file size is:', inputPaths[i].size, ' byte');
try {
childProcess.execSync(singleCmd);
} catch (e) {
logger.error(red, `ETS:ERROR Failed to convert file ${input} to abc `, reset);
process.exit(FAIL);
}
}
return;
}
logger.debug('worker data is: ', JSON.stringify(process.env));
logger.debug('gen_abc isWorker is: ', cluster.isWorker);
if (cluster.isWorker && process.env['inputs'] !== undefined && process.env['cmd'] !== undefined) {
logger.debug('==>worker #', cluster.worker.id, 'started!');
js2abcByWorkers(process.env['inputs'], process.env['cmd']);
if (process.env.panda === TS2ABC) {
js2abcByWorkers(process.env['inputs'], process.env['cmd']);
} else if (process.env.panda === ES2ABC || process.env.panda === 'undefined' || process.env.panda === undefined) {
es2abcByWorkers(process.env['inputs'], process.env['cmd']);
} else {
logger.error(red, `ETS:ERROR please set panda module`, reset);
process.exit(FAIL);
}
process.exit(SUCCESS);
}
+29 -10
View File
@@ -43,7 +43,9 @@ import {
EXTNAME_D_TS,
EXTNAME_ABC,
FAIL,
EXTNAME_JS_MAP
EXTNAME_JS_MAP,
TS2ABC,
ES2ABC
} from './pre_define';
const firstFileEXT: string = '_.js';
@@ -556,22 +558,39 @@ function judgeModuleWorkersToGenAbc(callback): void {
function invokeWorkersToGenAbc(): void {
let param: string = '';
if (isDebug) {
param += ' --debug';
}
let cmdPrefix: string = '';
let js2abc: string = path.join(arkDir, 'build', 'src', 'index.js');
if (isWin) {
js2abc = path.join(arkDir, 'build-win', 'src', 'index.js');
} else if (isMac) {
js2abc = path.join(arkDir, 'build-mac', 'src', 'index.js');
if (process.env.panda === TS2ABC) {
if (isDebug) {
param += ' --debug';
}
let js2abc: string = path.join(arkDir, 'build', 'src', 'index.js');
if (isWin) {
js2abc = path.join(arkDir, 'build-win', 'src', 'index.js');
} else if (isMac) {
js2abc = path.join(arkDir, 'build-mac', 'src', 'index.js');
}
cmdPrefix = `${nodeJs} --expose-gc "${js2abc}" ${param} `;
} else if (process.env.panda === ES2ABC || process.env.panda === 'undefined' || process.env.panda === undefined) {
if (isDebug) {
param += ' --debug-info';
}
let es2abc: string = path.join(arkDir, 'build', 'bin', 'es2abc');
if (isWin) {
es2abc = path.join(arkDir, 'build-win', 'bin', 'es2abc.exe');
} else if (isMac) {
es2abc = path.join(arkDir, 'build-mac', 'bin', 'es2abc');
}
cmdPrefix = `"${es2abc}" ${param}`;
} else {
logger.error(red, `ETS:ERROR please set panda module`, reset);
}
filterIntermediateJsBundleByHashJson(buildPathInfo, intermediateJsBundle);
const maxWorkerNumber: number = 3;
const splitedBundles: any[] = splitJsBundlesBySize(fileterIntermediateJsBundle, maxWorkerNumber);
const workerNumber: number = maxWorkerNumber < splitedBundles.length ? maxWorkerNumber : splitedBundles.length;
const cmdPrefix: string = `${nodeJs} --expose-gc "${js2abc}" ${param} `;
const clusterNewApiVersion: number = 16;
const currentNodeVersion: number = parseInt(process.version.split('.')[0]);
+3
View File
@@ -263,3 +263,6 @@ export const EXTNAME_ABC: string = '.abc';
export const SUCCESS: number = 0;
export const FAIL: number = 1;
export const TS2ABC: string = 'ts2abc';
export const ES2ABC: string = 'es2abc';
+1
View File
@@ -312,6 +312,7 @@ function setTsConfigFile() {
function setGenAbcPlugin(env, config) {
process.env.compilerType = 'ark';
process.env.panda = projectConfig.pandaMode;
let arkDir = path.join(__dirname, 'bin', 'ark');
if (env.arkFrontendDir) {
arkDir = env.arkFrontendDir;