@mpxjs/webpack-plugin 2.9.42 → 2.9.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -27,6 +27,7 @@ const ExternalsPlugin = require('webpack/lib/ExternalsPlugin')
27
27
  const AddModePlugin = require('./resolver/AddModePlugin')
28
28
  const AddEnvPlugin = require('./resolver/AddEnvPlugin')
29
29
  const PackageEntryPlugin = require('./resolver/PackageEntryPlugin')
30
+ const DynamicRuntimePlugin = require('./resolver/DynamicRuntimePlugin')
30
31
  const FixDescriptionInfoPlugin = require('./resolver/FixDescriptionInfoPlugin')
31
32
  // const CommonJsRequireDependency = require('webpack/lib/dependencies/CommonJsRequireDependency')
32
33
  // const HarmonyImportSideEffectDependency = require('webpack/lib/dependencies/HarmonyImportSideEffectDependency')
@@ -343,6 +344,9 @@ class MpxWebpackPlugin {
343
344
  if (this.options.env) {
344
345
  compiler.options.resolve.plugins.push(addEnvPlugin)
345
346
  }
347
+ if (this.options.dynamicRuntime) {
348
+ compiler.options.resolve.plugins.push(new DynamicRuntimePlugin('before-file', 'file'))
349
+ }
346
350
  compiler.options.resolve.plugins.push(packageEntryPlugin)
347
351
  compiler.options.resolve.plugins.push(new FixDescriptionInfoPlugin())
348
352
  compiler.options.resolve.plugins.push(dynamicPlugin)
@@ -59,8 +59,8 @@ module.exports = function getSpec ({ warn, error }) {
59
59
  color: 'color',
60
60
  default: 'default' // 不校验
61
61
  }
62
- // number 类型支持的单位
63
- const numberRegExp = /^\s*(\d+(\.\d+)?)(rpx|px|%)?\s*$/
62
+ // number 类型支持的单位(包含auto)
63
+ const numberRegExp = /^\s*((\d+(\.\d+)?)(rpx|px|%)?)|(auto)\s*$/
64
64
  // RN 不支持的颜色格式
65
65
  const colorRegExp = /^\s*(lab|lch|oklab|oklch|color-mix|color|hwb|lch|light-dark).*$/
66
66
 
@@ -70,8 +70,8 @@ module.exports = function getSpec ({ warn, error }) {
70
70
  case ValueType.color: {
71
71
  const isNumber = numberRegExp.test(value)
72
72
  const isUnsupporttedColor = colorRegExp.test(value)
73
- isNumber && warn(`React Native property [${prop}]'s valueType is ${valueType}, we does not set type number`)
74
- isUnsupporttedColor && warn('React Native color does not support type [lab,lch,oklab,oklch,color-mix,color,hwb,lch,light-dark]')
73
+ isNumber && warn(`Property [${prop}] receives a valid color as value, not a number.`)
74
+ isUnsupporttedColor && warn('React Native\'s supported color format does not contain [lab,lch,oklab,oklch,color-mix,color,hwb,lch,light-dark].')
75
75
  return !isNumber && !isUnsupporttedColor
76
76
  }
77
77
  case ValueType.number: {
@@ -392,17 +392,17 @@ module.exports = function getSpec ({ warn, error }) {
392
392
  ios: getAbbreviation,
393
393
  android: getAbbreviation
394
394
  },
395
+ { // line-height 换算
396
+ test: 'line-height',
397
+ ios: formatLineHeight,
398
+ android: formatLineHeight
399
+ },
395
400
  // 值类型校验放到最后
396
401
  { // color 颜色值校验
397
402
  test: /.*color.*/i,
398
403
  ios: checkCommonValue(ValueType.color),
399
404
  android: checkCommonValue(ValueType.color)
400
405
  },
401
- { // color 颜色值校验
402
- test: 'line-height',
403
- ios: formatLineHeight,
404
- android: formatLineHeight
405
- },
406
406
  { // number 值校验
407
407
  test: /.*width|height|left|right|top|bottom|radius|margin|padding|spacing|offset|size.*/i,
408
408
  ios: checkCommonValue(ValueType.number),
@@ -93,10 +93,11 @@ function buildGlobalParams ({
93
93
  if (ctorType === 'app') {
94
94
  content += `
95
95
  global.getApp = function () {}
96
- global.getCurrentPages = function () {}
96
+ global.getCurrentPages = function () { return [] }
97
97
  global.__networkTimeout = ${JSON.stringify(jsonConfig.networkTimeout)}
98
98
  global.__mpxGenericsMap = {}
99
99
  global.__mpxOptionsMap = {}
100
+ global.__mpxPagesMap = {}
100
101
  global.__style = ${JSON.stringify(jsonConfig.style || 'v1')}
101
102
  global.__mpxPageConfig = ${JSON.stringify(jsonConfig.window)}
102
103
  global.__getAppComponents = function () {
@@ -0,0 +1,25 @@
1
+ const { matchCondition } = require('../utils/match-condition')
2
+
3
+ const matcher = {
4
+ include: ['@mpxjs/core/src/dynamic/dynamicRenderMixin.empty.js']
5
+ }
6
+
7
+ module.exports = class DynamicRuntimePlugin {
8
+ constructor (source, target) {
9
+ this.source = source
10
+ this.target = target
11
+ }
12
+
13
+ apply (resolver) {
14
+ const target = resolver.ensureHook(this.target)
15
+ resolver.getHook(this.source).tapAsync('DynamicRuntimePlugin', (request, resolveContext, callback) => {
16
+ const resourcePath = request.path
17
+ if (matchCondition(resourcePath, matcher)) {
18
+ request.path = resourcePath.replace(/\.empty/, '')
19
+ resolver.doResolve(target, request, 'resolve dynamicRenderMixin file', resolveContext, callback)
20
+ } else {
21
+ callback()
22
+ }
23
+ })
24
+ }
25
+ }
@@ -1,15 +1,14 @@
1
1
  // 可选链wxs
2
2
  module.exports.g = function (val, valKeyArr) {
3
3
  var res = val
4
- if (typeof val !== 'object') {
5
- return undefined
6
- }
7
4
  var len = valKeyArr.length
8
5
  var i = 0
9
6
  while (i < len) {
10
- if ((res = res[valKeyArr[i]]) === undefined) {
7
+ if (typeof res !== 'object' || res === null) {
8
+ res = undefined
11
9
  break
12
10
  }
11
+ res = res[valKeyArr[i]]
13
12
  i++
14
13
  }
15
14
  return res
@@ -137,9 +137,9 @@ function stringifyArray (value) {
137
137
  return res
138
138
  }
139
139
 
140
- var mpxDashReg = genRegExp('(.+)MpxDash$')
141
- // 转义字符在wxs正则中存在平台兼容性问题,用[$]规避使用转义字符
142
- var mpxDashReplaceReg = genRegExp('[$]', 'g')
140
+ var mpxEscapeReg = genRegExp('(.+)MpxEscape$')
141
+ var dashEscapeReg = genRegExp('_da_', 'g')
142
+ var spaceEscapeReg = genRegExp('_sp_', 'g')
143
143
 
144
144
  function stringifyObject (value) {
145
145
  var res = ''
@@ -148,8 +148,8 @@ function stringifyObject (value) {
148
148
  var key = objKeys[i]
149
149
  if (value[key]) {
150
150
  if (res) res += ' '
151
- if (mpxDashReg.test(key)) {
152
- key = mpxDashReg.exec(key)[1].replace(mpxDashReplaceReg, '-')
151
+ if (mpxEscapeReg.test(key)) {
152
+ key = mpxEscapeReg.exec(key)[1].replace(dashEscapeReg, '-').replace(spaceEscapeReg, ' ')
153
153
  }
154
154
  res += key
155
155
  }
@@ -127,12 +127,8 @@ function checkDelAndGetPath (path) {
127
127
  }
128
128
 
129
129
  if (t.isMemberExpression(parent) && parent.computed) {
130
- if (key === 'property') {
131
- replace = true
132
- } else {
133
- canDel = false
134
- break
135
- }
130
+ canDel = false
131
+ break
136
132
  }
137
133
 
138
134
  if (t.isLogicalExpression(parent)) { // case: a || ((b || c) && d)
@@ -1950,7 +1950,7 @@ function processText (el) {
1950
1950
  // RN中文字需被Text包裹
1951
1951
  function processWrapTextReact (el) {
1952
1952
  const parentTag = el.parent.tag
1953
- if (parentTag !== 'mpx-text' && parentTag !== 'Text') {
1953
+ if (parentTag !== 'mpx-text' && parentTag !== 'Text' && parentTag !== 'wxs') {
1954
1954
  const wrapper = createASTElement('Text')
1955
1955
  replaceNode(el, wrapper, true)
1956
1956
  addChild(wrapper, el)
@@ -1971,7 +1971,7 @@ function processWrapTextReact (el) {
1971
1971
  // }
1972
1972
 
1973
1973
  function injectWxs (meta, module, src) {
1974
- if (runtimeCompile || addWxsModule(meta, module, src)) {
1974
+ if (runtimeCompile || addWxsModule(meta, module, src) || isReact(mode)) {
1975
1975
  return
1976
1976
  }
1977
1977
 
@@ -2574,6 +2574,7 @@ function closeElement (el, meta, options) {
2574
2574
  return
2575
2575
  }
2576
2576
  if (isReact(mode)) {
2577
+ postProcessWxs(el, meta)
2577
2578
  postProcessForReact(el)
2578
2579
  postProcessIfReact(el)
2579
2580
  return
@@ -2,6 +2,7 @@ const babylon = require('@babel/parser')
2
2
  const t = require('@babel/types')
3
3
  const traverse = require('@babel/traverse').default
4
4
  const generate = require('@babel/generator').default
5
+ const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
5
6
  const escapeReg = /[()[\]{}#!.:,%'"+$]/g
6
7
  const escapeMap = {
7
8
  '(': '_pl_',
@@ -31,6 +32,12 @@ function mpEscape (str) {
31
32
  })
32
33
  }
33
34
 
35
+ function keyEscape (str) {
36
+ let result = str.replace(/-/g, '_da_').replace(/\s+/g, '_sp_')
37
+ if (result !== str) result += 'MpxEscape'
38
+ return result
39
+ }
40
+
34
41
  module.exports = function transDynamicClassExpr (expr, { error } = {}) {
35
42
  try {
36
43
  const ast = babylon.parse(expr, {
@@ -42,10 +49,10 @@ module.exports = function transDynamicClassExpr (expr, { error } = {}) {
42
49
  ObjectExpression (path) {
43
50
  path.node.properties.forEach((property) => {
44
51
  if (t.isObjectProperty(property) && !property.computed) {
45
- let propertyName = property.key.name || property.key.value
46
- propertyName = mpEscape(propertyName)
47
- if (/-/.test(propertyName)) {
48
- property.key = t.identifier(propertyName.replace(/-/g, '$$') + 'MpxDash')
52
+ const rawPropertyName = property.key.name || property.key.value
53
+ const propertyName = keyEscape(mpEscape(rawPropertyName))
54
+ if (!isValidIdentifierStr(propertyName)) {
55
+ error && error(`Dynamic classname [${rawPropertyName}] can not be escaped as a valid identifier, which is not supported.`)
49
56
  } else {
50
57
  property.key = t.identifier(propertyName)
51
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.9.42",
3
+ "version": "2.9.43",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -85,5 +85,5 @@
85
85
  "engines": {
86
86
  "node": ">=14.14.0"
87
87
  },
88
- "gitHead": "45c7fd96af6723fa8c8ea2d659065417e66c77e2"
88
+ "gitHead": "92a347518d15400f87c380bc7248b8b6254631cf"
89
89
  }