Skip to content

Commit 3f22fbe

Browse files
committed
feat: modify new jscard judgement by minCardPlatform
Signed-off-by: lilei946 <snowinter2008@gmail.com>
1 parent f89a0dc commit 3f22fbe

File tree

12 files changed

+85
-33
lines changed

12 files changed

+85
-33
lines changed

packages/hap-compiler/src/template/validator.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ const tagNatives = {
546546
}
547547
},
548548
picker: {
549+
minRequiredRuntimeVersion: 1201,
549550
supportCard: true,
550551
selfClosing: true,
551552
atomic: true,
@@ -588,6 +589,8 @@ const tagNatives = {
588589
events: ['change', 'selectionchange', 'linechange']
589590
},
590591
video: {
592+
supportCard: true,
593+
minRequiredRuntimeVersion: 1201,
591594
empty: true,
592595
attrs: {
593596
src: {},
@@ -806,6 +809,7 @@ const tagNatives = {
806809
excludeRoot: true
807810
},
808811
marquee: {
812+
minRequiredRuntimeVersion: 1201,
809813
supportCard: true,
810814
textContent: true,
811815
atomic: true,
@@ -1097,6 +1101,25 @@ function checkTagName(node, output, options = {}) {
10971101
})
10981102
}
10991103

1104+
if (
1105+
(options.uxType === ENTRY_TYPE.CARD || options.uxType === ENTRY_TYPE.COMP) &&
1106+
tagNatives[tagName] &&
1107+
options.minCardRuntimeVersion &&
1108+
options.minCardRuntimeVersion < tagNatives[tagName].minRequiredRuntimeVersion
1109+
) {
1110+
const locationAddr =
1111+
location.line && location.column ? '@' + location.line + ':' + location.column : ''
1112+
colorconsole.throw(
1113+
'ERROR: ' +
1114+
locationAddr +
1115+
' 使用 `' +
1116+
tagName +
1117+
'` 组件,要求卡片配置 minCardPlatformVersion 或 minPlatformVersion 不低于 ' +
1118+
tagNatives[tagName].minRequiredRuntimeVersion +
1119+
', 请修改'
1120+
)
1121+
}
1122+
11001123
// 检测根组件合法性
11011124
if (node._isroot && tagNotRoot.hasOwnProperty(tagName)) {
11021125
log.push({

packages/hap-dsl-xvm/src/loaders/ux-fragment-utils.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,15 @@ function makeLoaderString(type, config, newJSCard, uxType) {
269269
* @returns {string}
270270
*/
271271
function processImportFrag($loader, imports, importNames, queryOptions = {}) {
272-
const { newJSCard, lite, cardEntry } = queryOptions
272+
const { newJSCard, lite, cardEntry, minCardRuntimeVersion } = queryOptions
273273
let retStr = ''
274274
if (imports.length) {
275275
const newJSCardParam = newJSCard ? `&newJSCard=${newJSCard}` : ''
276276
const liteParam = lite ? `&lite=${lite}` : ''
277277
const cardEntryParam = cardEntry ? `&cardEntry=${cardEntry}` : ''
278+
const minCardRuntimeVersionParam = minCardRuntimeVersion
279+
? `&minCardRuntimeVersion=${minCardRuntimeVersion}`
280+
: ''
278281
for (let i = 0; i < imports.length; i++) {
279282
const imp = imports[i]
280283
let importSrc = imp.attrs.src
@@ -311,7 +314,7 @@ function processImportFrag($loader, imports, importNames, queryOptions = {}) {
311314
let reqStr = makeRequireString(
312315
$loader,
313316
makeLoaderString(FRAG_TYPE.IMPORT, null, newJSCard),
314-
`${importSrc}?uxType=${ENTRY_TYPE.COMP}&name=${importName}${newJSCardParam}${liteParam}${cardEntryParam}`
317+
`${importSrc}?uxType=${ENTRY_TYPE.COMP}&name=${importName}${newJSCardParam}${liteParam}${cardEntryParam}${minCardRuntimeVersionParam}`
315318
)
316319

317320
if (compileOptionsObject.stats) {
@@ -335,7 +338,7 @@ function processImportFrag($loader, imports, importNames, queryOptions = {}) {
335338
* @param {number} lite 轻卡
336339
*/
337340
function processTemplateFrag($loader, templates, importNames, queryOptions = {}) {
338-
const { uxType, newJSCard, lite, cardEntry } = queryOptions
341+
const { uxType, newJSCard, lite, cardEntry, minCardRuntimeVersion } = queryOptions
339342
let retStr = '{}'
340343
if (!templates.length) {
341344
$loader.emitError(new Error('需要模板 <template> 片段'))
@@ -354,6 +357,9 @@ function processTemplateFrag($loader, templates, importNames, queryOptions = {})
354357
const liteParam = lite ? `&lite=${lite}` : ''
355358
const pathParam = newJSCard ? `&uxPath=${encodeURIComponent(src)}` : ''
356359
const cardEntryParam = cardEntry ? `&cardEntry=${encodeURIComponent(cardEntry)}` : ''
360+
const minCardRuntimeVersionParam = minCardRuntimeVersion
361+
? `&minCardRuntimeVersion=${minCardRuntimeVersion}`
362+
: ''
357363
// 解析成类似url中key[]=xxx 的形式,便于loader-utils解析
358364
importNames = importNames.map((item) => 'importNames[]=' + item)
359365
retStr = makeRequireString(
@@ -367,7 +373,7 @@ function processTemplateFrag($loader, templates, importNames, queryOptions = {})
367373
),
368374
`${src}?uxType=${uxType}&${importNames.join(
369375
','
370-
)}${newJSCardParam}${liteParam}${pathParam}${cardEntryParam}`
376+
)}${newJSCardParam}${liteParam}${pathParam}${cardEntryParam}${minCardRuntimeVersionParam}`
371377
)
372378
}
373379
return retStr

packages/hap-dsl-xvm/src/loaders/ux-loader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ export default function uxLoader(source) {
138138
uxType: resourceQuery.uxType, // 文件类型
139139
newJSCard: resourceQuery.newJSCard, // 新打包格式的 JS卡
140140
lite: resourceQuery.lite, // 轻卡
141-
cardEntry: resourceQuery.cardEntry // 卡片入口
141+
cardEntry: resourceQuery.cardEntry, // 卡片入口
142+
minCardRuntimeVersion: resourceQuery.minCardRuntimeVersion // 卡片配置的最小平台版本
142143
}
143144
// 使用原有文件名(不包含扩展名)
144145
const name = resourceQuery.name || getNameByPath(resourcePath)

packages/hap-packager/src/common/shared.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ function searchModuleImport(fileCont, options = {}) {
193193
/**
194194
* 检测manifest里面的widget,包括:
195195
* 检测不支持的feature
196-
* 增加 widget 中 path 缺失时的默认值
197196
*/
198197
function checkFeatureInCard(obj = {}) {
199198
Object.keys(obj).forEach((key) => {
@@ -207,8 +206,6 @@ function checkFeatureInCard(obj = {}) {
207206
}
208207
})
209208
})
210-
211-
populateWidgetFields(obj)
212209
}
213210

214211
/**
@@ -237,13 +234,13 @@ function populateWidgetFields(widgetsObj) {
237234
conf.minPlatformVersion = conf.minCardPlatformVersion
238235
} else if (!conf.minPlatformVersion) {
239236
// 没写 minCardPlatformVersion 和 minPlatformVersion 字段
240-
throw new Error(
237+
colorconsole.throw(
241238
`manifest.json 文件 widgets 字段下,${routePath} 缺少 minCardPlatformVersion 字段`
242239
)
243240
}
244241
}
245242
if (conf.type === 'lite' && !conf.minCardPlatformVersion) {
246-
throw new Error(
243+
colorconsole.throw(
247244
`manifest.json 文件 widgets 字段下,轻卡 ${routePath} 缺少 minCardPlatformVersion 字段`
248245
)
249246
}
@@ -268,9 +265,10 @@ function updateManifest(manifest, debug) {
268265

269266
// 更新features
270267
manifest.features = manifest.features || []
271-
272268
checkFeatureInCard(manifest.router.widgets || {})
273269

270+
populateWidgetFields(manifest.router.widgets || {})
271+
274272
// 在项目所有引用的模块列表中删除manifest已声明的模块
275273
const projectFeatureList = [].concat(global.framework.project.featureList)
276274
manifest.features.forEach((feature) => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class CardPlugin {
136136
}
137137
const { _valueAsString, _valueAsBuffer } = _source || {}
138138
const sourceValueStr = _valueAsString || _valueAsBuffer?.toString() || ''
139-
let obj
139+
let obj = {}
140140
let jsonStr = sourceValueStr
141141
const sourceValueStrTrim = sourceValueStr.trim()
142142
if (sourceValueStrTrim.indexOf('module.exports') === 0) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ function minifyWidgetJSONFiles(targetDir, specifiedDirArray) {
141141
// 轻卡和写了minCardPlatformVersion的新打包格式的JS卡会进行多语言扁平化处理
142142
const needFlatten =
143143
directoryName === I18N_DIRECTORY &&
144-
(widgetsOption[key].type === 'lite' || widgetsOption[key].minCardPlatformVersion)
144+
(widgetsOption[key].type === 'lite' ||
145+
(widgetsOption[key].minCardPlatformVersion &&
146+
widgetsOption[key].minCardPlatformVersion >= 2000))
145147
if (fs.existsSync(dir)) {
146148
// onlyRoot: 是否仅遍历根目录
147149
const jsonPath = onlyRoot ? '*.json' : '**/**.json'

packages/hap-packager/src/router/routes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
globalConfig,
1515
recordClient,
1616
getRecordClient,
17-
isNeedFullPackage
17+
getUseFullPackage
1818
} from '@hap-toolkit/shared-utils'
1919

2020
import {
@@ -67,7 +67,7 @@ async function bundle(context, next) {
6767
let useFullPackage = false
6868
// 调试器选择应用模式下
6969
if (parseInt(context.request.query.mode || 0) === 0) {
70-
useFullPackage = isNeedFullPackage(projectPath)
70+
useFullPackage = getUseFullPackage(projectPath)
7171
}
7272

7373
if (platformVersion && platformVersion >= RPKS_SUPPORT_VERSION_FROM && !useFullPackage) {

packages/hap-shared-utils/src/index.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,14 +436,33 @@ function getHash(compPath) {
436436
return res
437437
}
438438

439+
// 读取 manifest
440+
let manifest
441+
439442
export function isNeedFullPackage() {
440-
// 读取 manifest
441-
let manifest
442443
let needFullPackage = false
443-
try {
444-
manifest = readJson(path.join(globalConfig.projectPath, './src/manifest.json'))
445-
} catch (err) {
446-
manifest = null
444+
if (!manifest) {
445+
try {
446+
manifest = readJson(path.join(globalConfig.projectPath, './src/manifest.json'))
447+
} catch (err) {
448+
manifest = null
449+
}
450+
}
451+
// 存在卡片
452+
if (manifest.router.widgets && Object.keys(manifest.router.widgets).length > 0) {
453+
needFullPackage = true
454+
}
455+
return needFullPackage
456+
}
457+
458+
export function getUseFullPackage() {
459+
let useFullPackage = false
460+
if (!manifest) {
461+
try {
462+
manifest = readJson(path.join(globalConfig.projectPath, './src/manifest.json'))
463+
} catch (err) {
464+
manifest = null
465+
}
447466
}
448467
// 快应用项目,不存在分包
449468
if (
@@ -455,8 +474,8 @@ export function isNeedFullPackage() {
455474
) {
456475
// 存在卡片
457476
if (manifest.router.widgets && Object.keys(manifest.router.widgets).length > 0) {
458-
needFullPackage = true
477+
useFullPackage = true
459478
}
460479
}
461-
return needFullPackage
480+
return useFullPackage
462481
}

packages/hap-toolkit/__tests__/__snapshots__/appchunks.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ $app_define$('@app-component/index', [], function($app_require$, $app_exports$,
4444
if ($app_exports$.__esModule && $app_exports$.default) {
4545
$app_module$.exports = $app_exports$.default
4646
}
47-
$app_module$.exports.template = require(\\"!../../../../../hap-dsl-xvm/lib/loaders/template-loader.js!../../../../../hap-dsl-xvm/lib/loaders/fragment-loader.js?index=0&type=template!./index.ux?uxType=card&&cardEntry=CardDemo\\")
47+
$app_module$.exports.template = require(\\"!../../../../../hap-dsl-xvm/lib/loaders/template-loader.js!../../../../../hap-dsl-xvm/lib/loaders/fragment-loader.js?index=0&type=template!./index.ux?uxType=card&&cardEntry=CardDemo&minCardRuntimeVersion=2000\\")
4848
$app_module$.exports.style = require(\\"!../../../../../hap-dsl-xvm/lib/loaders/style-loader.js?index=0&type=style!../../../../../hap-dsl-xvm/lib/loaders/fragment-loader.js?index=0&type=style!./index.ux?uxType=card&cardEntry=CardDemo\\")
4949
});
5050
$app_bootstrap$('@app-component/index',{ packagerVersion: QUICKAPP_TOOLKIT_VERSION });"

packages/hap-toolkit/__tests__/__snapshots__/compile.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ $app_define$('@app-component/index', [], function($app_require$, $app_exports$,
5050
if ($app_exports$.__esModule && $app_exports$.default) {
5151
$app_module$.exports = $app_exports$.default
5252
}
53-
$app_module$.exports.template = require(\\"!../../../../../hap-dsl-xvm/lib/loaders/template-loader.js!../../../../../hap-dsl-xvm/lib/loaders/fragment-loader.js?index=0&type=template!./index.ux?uxType=card&&cardEntry=CardDemo\\")
53+
$app_module$.exports.template = require(\\"!../../../../../hap-dsl-xvm/lib/loaders/template-loader.js!../../../../../hap-dsl-xvm/lib/loaders/fragment-loader.js?index=0&type=template!./index.ux?uxType=card&&cardEntry=CardDemo&minCardRuntimeVersion=2000\\")
5454
$app_module$.exports.style = require(\\"!../../../../../hap-dsl-xvm/lib/loaders/style-loader.js?index=0&type=style!../../../../../hap-dsl-xvm/lib/loaders/fragment-loader.js?index=0&type=style!./index.ux?uxType=card&cardEntry=CardDemo\\")
5555
});
5656
$app_bootstrap$('@app-component/index',{ packagerVersion: QUICKAPP_TOOLKIT_VERSION });"
@@ -355,7 +355,7 @@ Array [
355355
356356
exports[`测试compile generate webpack config 1`] = `
357357
Object {
358-
"CardDemo/index": "./src/CardDemo/index.ux?uxType=card&cardEntry=CardDemo",
358+
"CardDemo/index": "./src/CardDemo/index.ux?uxType=card&minCardRuntimeVersion=2000&cardEntry=CardDemo",
359359
"Demo/index": "./src/Demo/index.ux?uxType=page",
360360
"app": "./src/app.ux?uxType=app",
361361
"workers/request/index": "./src/workers/request/index.js",

0 commit comments

Comments
 (0)