mirror of
https://github.com/openharmony/developtools_ace-ets2bundle.git
synced 2026-07-18 16:04:32 -04:00
!879 adapter es2abc
Merge pull request !879 from zrg/adapter_es2abc_7_28
This commit is contained in:
@@ -375,6 +375,7 @@ function loadModuleInfo(projectConfig, envArgs) {
|
||||
if (buildJsonInfo.compileMode === 'esmodule') {
|
||||
projectConfig.nodeModulesPath = buildJsonInfo.nodeModulesPath;
|
||||
}
|
||||
projectConfig.pandaMode = buildJsonInfo.pandaMode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+29
-2
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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';
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user