!1017 Add sourcefile of module compiler

Merge pull request !1017 from zrg/cherry-pick-1661438580
This commit is contained in:
openharmony_ci
2022-08-27 10:13:56 +00:00
committed by Gitee
3 changed files with 33 additions and 5 deletions
+8 -4
View File
@@ -142,6 +142,11 @@ export class GenAbcPlugin {
return;
}
if (projectConfig.compileMode === ESMODULE) {
removeDir(output);
removeDir(projectConfig.nodeModulesPath);
}
compiler.hooks.compilation.tap('GenAbcPlugin', (compilation) => {
if (projectConfig.compileMode === JSBUNDLE || projectConfig.compileMode === undefined) {
return;
@@ -167,7 +172,6 @@ export class GenAbcPlugin {
if (projectConfig.compileMode === ESMODULE) {
return;
}
removeDir(output);
Object.keys(compilation.assets).forEach(key => {
// choose *.js
if (output && path.extname(key) === EXTNAME_JS) {
@@ -372,6 +376,8 @@ function writeFileSync(inputString: string, output: string, jsBundleFile: string
fs.writeFileSync(cacheOutputPath, inputString);
if (fs.existsSync(cacheOutputPath)) {
const fileSize: any = fs.statSync(cacheOutputPath).size;
output = toUnixPath(output);
cacheOutputPath = toUnixPath(cacheOutputPath);
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);
@@ -425,8 +431,6 @@ function splitJsBundlesBySize(bundleArray: Array<File>, groupNumber: number): an
}
function invokeWorkersModuleToGenAbc(moduleInfos: Array<ModuleInfo>): void {
removeDir(buildPathInfo);
removeDir(projectConfig.nodeModulesPath);
invokeCluterModuleToAbc();
}
@@ -841,7 +845,7 @@ function writeHashJson(): void {
mkdirsSync(path.dirname(abcFile));
fs.copyFileSync(cacheAbcFilePath, abcFile);
}
if (fs.existsSync(intermediateJsBundle[i].path)) {
if (process.env.cachePath === undefined && fs.existsSync(intermediateJsBundle[i].path)) {
fs.unlinkSync(intermediateJsBundle[i].path);
}
}
+1 -1
View File
@@ -60,7 +60,7 @@ function es2abcByWorkers(jsonInput: string, cmd: string): Promise<void> {
for (let i = 0; i < inputPaths.length; ++i) {
const input: string = inputPaths[i].tempFilePath;
const abcFile: string = input.replace(/\.js$/, '.abc');
const singleCmd: any = `${cmd} "${input}" --output "${abcFile}"`;
const singleCmd: any = `${cmd} "${input}" --output "${abcFile}" --source-file "${input}"`;
logger.debug('gen abc cmd is: ', singleCmd);
try {
childProcess.execSync(singleCmd);
+24
View File
@@ -17,6 +17,7 @@ const path = require('path');
const fs = require('fs');
const CopyPlugin = require('copy-webpack-plugin');
const Webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const { GenAbcPlugin } = require('./lib/gen_abc_plugin');
const { OHMResolverPlugin } = require('./lib/resolve_ohm_url');
const buildPipeServer = require('./server/build_pipe_server');
@@ -344,6 +345,28 @@ function setGenAbcPlugin(env, config) {
}
}
function setCleanWebpackPlugin(workerFile, config) {
if (projectConfig.compileMode === 'esmodule') {
return;
}
let cleanPath = [];
cleanPath.push(projectConfig.buildPath);
if (workerFile) {
let workerFilesPath = Object.keys(workerFile);
for (let workerFilePath of workerFilesPath) {
cleanPath.push(path.join(projectConfig.buildPath, workerFilePath, '..'));
}
}
config.plugins.push(
new CleanWebpackPlugin({
dry: false,
dangerouslyAllowCleanPatternsOutsideProject: true,
cleanOnceBeforeBuildPatterns: cleanPath
})
);
}
module.exports = (env, argv) => {
const config = {};
setProjectConfig(env);
@@ -354,6 +377,7 @@ module.exports = (env, argv) => {
const workerFile = readWorkerFile();
setOptimizationConfig(config, workerFile);
setCopyPluginConfig(config);
setCleanWebpackPlugin(workerFile, config);
if (env.isPreview !== "true") {
loadWorker(projectConfig, workerFile);