mirror of
https://github.com/openharmony/developtools_ace-js2bundle.git
synced 2026-07-21 06:05:27 -04:00
!274 fix check works file
Merge pull request !274 from zrg/fix_works_object_release
This commit is contained in:
@@ -42,13 +42,15 @@ let isDebug = false;
|
||||
let arkDir;
|
||||
let nodeJs;
|
||||
let intermediateJsBundle = [];
|
||||
let workerFile = null;
|
||||
|
||||
class GenAbcPlugin {
|
||||
constructor(output_, arkDir_, nodeJs_, isDebug_) {
|
||||
constructor(output_, arkDir_, nodeJs_, workerFile_, isDebug_) {
|
||||
output = output_;
|
||||
arkDir = arkDir_;
|
||||
nodeJs = nodeJs_;
|
||||
isDebug = isDebug_;
|
||||
workerFile = workerFile_;
|
||||
}
|
||||
apply(compiler) {
|
||||
if (fs.existsSync(path.resolve(arkDir, 'build-win'))) {
|
||||
@@ -66,7 +68,7 @@ class GenAbcPlugin {
|
||||
// choice *.js
|
||||
if (output && path.extname(key) === '.js') {
|
||||
let newContent = assets[key].source();
|
||||
if (key.search('workers/') !== 0 && key !== 'commons.js' && key !== 'vendors.js') {
|
||||
if (checkWorksFile(key, workerFile) && key !== 'commons.js' && key !== 'vendors.js') {
|
||||
newContent = forward + newContent + last;
|
||||
}
|
||||
if (key === 'commons.js' || key === 'vendors.js') {
|
||||
@@ -83,6 +85,25 @@ class GenAbcPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
function checkWorksFile(assetPath, workerFile) {
|
||||
if (workerFile === null) {
|
||||
if (assetPath.search("./workers/") !== 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
for (const key in workerFile) {
|
||||
let keyExt = key + '.js';
|
||||
if (keyExt === assetPath) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function writeFileSync(inputString, output, jsBundleFile) {
|
||||
const parent = path.join(output, '..');
|
||||
if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) {
|
||||
@@ -183,4 +204,7 @@ function invokeWorkerToGenAbc() {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GenAbcPlugin;
|
||||
module.exports = {
|
||||
GenAbcPlugin: GenAbcPlugin,
|
||||
checkWorksFile: checkWorksFile
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ const fs = require('fs')
|
||||
const path = require('path')
|
||||
const process = require('child_process')
|
||||
const qjsc = path.join(__dirname, '..', 'bin', 'qjsc')
|
||||
const checkWorksFile = require('./genAbc-plugin').checkWorksFile
|
||||
|
||||
const forward = '(global.___mainEntry___ = function (globalObjects) {' + '\n' +
|
||||
' const define = globalObjects.define;' + '\n' +
|
||||
@@ -38,11 +39,13 @@ const sencondFileEXT = '.c'
|
||||
const lastFileEXT = '.bin'
|
||||
let output
|
||||
let webpackPath
|
||||
let workerFile = null;
|
||||
|
||||
class GenBinPlugin {
|
||||
constructor(output_, webpackPath_) {
|
||||
constructor(output_, webpackPath_, workerFile_) {
|
||||
output = output_
|
||||
webpackPath = webpackPath_
|
||||
workerFile = workerFile_
|
||||
}
|
||||
apply(compiler) {
|
||||
if (!fs.existsSync(path.resolve(webpackPath, 'qjsc.exe')) && !fs.existsSync(path.resolve(webpackPath, 'qjsc'))) {
|
||||
@@ -55,7 +58,7 @@ class GenBinPlugin {
|
||||
// choice *.js
|
||||
if (output && webpackPath && path.extname(key) === '.js') {
|
||||
let newContent = assets[key].source()
|
||||
if (key.search('workers/') !== 0) {
|
||||
if (checkWorksFile(key, workerFile)) {
|
||||
newContent = forward + newContent + last
|
||||
}
|
||||
const keyPath = key.replace(/\.js$/, firstFileEXT)
|
||||
|
||||
@@ -19,7 +19,7 @@ var fs = require('fs')
|
||||
var ResourcePlugin = require('./lib/resource-plugin')
|
||||
var ResultStates = require('./lib/compile-plugin')
|
||||
var GenBinPlugin = require('./lib/genBin-plugin')
|
||||
var GenAbcPlugin = require('./lib/genAbc-plugin')
|
||||
var GenAbcPlugin = require('./lib/genAbc-plugin').GenAbcPlugin
|
||||
var AfterEmitPlugin = require('./lib/cardJson-plugin').AfterEmitPlugin
|
||||
var ModuleCollectionPlugin = require('./lib/module-collection-plugin')
|
||||
|
||||
@@ -198,7 +198,7 @@ function setConfigs(env) {
|
||||
}
|
||||
}
|
||||
|
||||
function notPreview(env) {
|
||||
function notPreview(env, workerFile) {
|
||||
config.plugins.push(new ModuleCollectionPlugin())
|
||||
if (env.compilerType && env.compilerType === 'ark') {
|
||||
let arkDir = path.join(__dirname, 'bin', 'ark');
|
||||
@@ -209,7 +209,7 @@ function notPreview(env) {
|
||||
if (env.nodeJs) {
|
||||
nodeJs = env.nodeJs;
|
||||
}
|
||||
config.plugins.push(new GenAbcPlugin(process.env.buildPath, arkDir, nodeJs,
|
||||
config.plugins.push(new GenAbcPlugin(process.env.buildPath, arkDir, nodeJs, workerFile,
|
||||
env.buildMode === 'debug'))
|
||||
if (env.buildMode === 'release' && process.env.DEVICE_LEVEL !== 'card') {
|
||||
config.output.path = path.join(process.env.cachePath, "releaseAssets",
|
||||
@@ -220,7 +220,7 @@ function notPreview(env) {
|
||||
let deviceArr = env.deviceType.split(/,/)
|
||||
let isDefault = deviceArr.indexOf('tv') >= 0 || deviceArr.indexOf('wearable') >= 0 ? true : false
|
||||
if (isDefault) {
|
||||
config.plugins.push(new GenBinPlugin(process.env.buildPath, path.join(__dirname, 'bin')))
|
||||
config.plugins.push(new GenBinPlugin(process.env.buildPath, path.join(__dirname, 'bin', workerFile)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -307,7 +307,7 @@ module.exports = (env) => {
|
||||
config.module = cardModule
|
||||
config.plugins.push(new AfterEmitPlugin())
|
||||
if (env.isPreview !== "true") {
|
||||
notPreview(env)
|
||||
notPreview(env, workerFile)
|
||||
}
|
||||
} else {
|
||||
if (process.env.compileMode !== 'moduleJson' && process.env.abilityType === 'page') {
|
||||
@@ -335,7 +335,7 @@ module.exports = (env) => {
|
||||
}
|
||||
}
|
||||
if (env.isPreview !== "true") {
|
||||
notPreview(env)
|
||||
notPreview(env, workerFile)
|
||||
}
|
||||
if (env.sourceMap === 'none') {
|
||||
config.devtool = false
|
||||
|
||||
Reference in New Issue
Block a user