!1019 Fix cachePath is undefined

Merge pull request !1019 from zrg/jsbundle_unix_beta
This commit is contained in:
openharmony_ci
2022-08-26 15:17:28 +00:00
committed by Gitee
2 changed files with 27 additions and 3 deletions
+6 -3
View File
@@ -137,6 +137,10 @@ export class GenAbcPlugin {
return;
}
if (projectConfig.compileMode === ESMODULE) {
removeDir(projectConfig.nodeModulesPath);
}
compiler.hooks.compilation.tap('GenAbcPlugin', (compilation) => {
if (projectConfig.compileMode === JSBUNDLE || projectConfig.compileMode === undefined) {
return;
@@ -162,7 +166,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) {
@@ -365,6 +368,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);
@@ -418,8 +423,6 @@ function splitJsBundlesBySize(bundleArray: Array<File>, groupNumber: number): an
}
function invokeWorkersModuleToGenAbc(moduleInfos: Array<ModuleInfo>): void {
removeDir(buildPathInfo);
removeDir(projectConfig.nodeModulesPath);
filterIntermediateModuleByHashJson(buildPathInfo, moduleInfos);
filterModuleInfos.forEach(moduleInfo => {
if (moduleInfo.isCommonJs) {
+21
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');
@@ -338,6 +339,25 @@ function setGenAbcPlugin(env, config) {
}
}
function setCleanWebpackPlugin(workerFile, config) {
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);
@@ -348,6 +368,7 @@ module.exports = (env, argv) => {
const workerFile = readWorkerFile();
setOptimizationConfig(config, workerFile);
setCopyPluginConfig(config);
setCleanWebpackPlugin(workerFile, config);
if (env.isPreview !== "true") {
loadWorker(projectConfig, workerFile);