Skip to content

Commit fe8c76f

Browse files
authored
fix: add rpk in rpks when missing subpackages config and fix bug in watch mode (#104)
Signed-off-by: lileirjyb <lileirjyb@vivo.com>
1 parent e739a90 commit fe8c76f

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

packages/hap-packager/src/plugins/zip-plugin.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,11 @@ function ZipPlugin(options) {
290290
ZipPlugin.prototype.apply = function (compiler) {
291291
const options = this.options
292292

293-
let subpackageOptions = []
294-
if (!options.disableSubpackages && options.subpackages && options.subpackages.length > 0) {
295-
subpackageOptions = options.subpackages
296-
}
297-
298293
compiler.hooks.done.tapAsync('ZipPlugin', async (stats, callback) => {
294+
let subpackageOptions = []
295+
if (!options.disableSubpackages && options.subpackages && options.subpackages.length > 0) {
296+
subpackageOptions = [...options.subpackages]
297+
}
299298
// 更新 options 里的值,防止改变 manifest 文件字段导致的问题
300299
let manifestPath
301300
if (fs.pathExistsSync(path.join(options.pathSrc, 'manifest-phone.json'))) {
@@ -304,6 +303,8 @@ ZipPlugin.prototype.apply = function (compiler) {
304303
} else {
305304
manifestPath = path.join(options.pathSrc, 'manifest.json')
306305
}
306+
307+
let isPureWidgetProject = true
307308
if (fs.pathExistsSync(manifestPath)) {
308309
const manifestContent = fs.readFileSync(manifestPath, 'utf8')
309310
const manifest = JSON.parse(manifestContent)
@@ -323,6 +324,9 @@ ZipPlugin.prototype.apply = function (compiler) {
323324
})
324325
})
325326
}
327+
if (Object.keys(manifest?.router?.pages || {}).length > 0) {
328+
isPureWidgetProject = false
329+
}
326330
}
327331

328332
try {
@@ -397,7 +401,7 @@ ZipPlugin.prototype.apply = function (compiler) {
397401
this.signConfig,
398402
options.disableStreamPack,
399403
compiler.watchMode,
400-
!options.disableSubpackages && options.subpackages && options.subpackages.length > 0
404+
!options.disableSubpackages && !isPureWidgetProject
401405
)
402406

403407
fs.ensureDirSync(options.output)

packages/hap-packager/src/process/index.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,13 @@ async function buildProjectAndOutput(
121121
signConfig,
122122
disableStreamPack,
123123
watchMode,
124-
isAppSubpackage
124+
needFullPackage
125125
) {
126126
// 如果是watch模式,走快速编译的模式
127127
if (watchMode) {
128128
return buildDebugModeProjectAndOutput.apply(null, arguments)
129129
}
130130

131-
// 如果不是快应用分包,则移除第一个 base 包
132-
// 只有快应用分包才需要base包,卡片分包不需要 —— update: 卡片需要保留base包,调试器处理rpks时需要读取
133-
// if (!isAppSubpackage && subPackages) {
134-
// subPackages.shift()
135-
// }
136-
137131
// Step1. 生成整包rpk
138132
let fullPackageBuffer = await createZipBufferForPackage(fullPackage)
139133

@@ -165,9 +159,9 @@ async function buildProjectAndOutput(
165159

166160
if (subPackageBuffers.length) {
167161
const rpksFileList = []
168-
if (isAppSubpackage) {
169-
// 只有快应用分包才需要保留整包(历史遗留保持现状)
170-
// 卡片分包不需要保留
162+
if (needFullPackage) {
163+
// 非纯卡片工程rpks包里面需要保留整包
164+
// 纯卡片工程rpks包里面不需要保留整包
171165
rpksFileList.push({
172166
path: fullPackage.fileName,
173167
content: fullPackageBuffer

0 commit comments

Comments
 (0)