@mpxjs/webpack-plugin 2.10.18 → 2.10.20

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.
Files changed (70) hide show
  1. package/lib/dependencies/ResolveDependency.js +2 -2
  2. package/lib/index.js +25 -6
  3. package/lib/json-compiler/helper.js +11 -10
  4. package/lib/json-compiler/index.js +7 -4
  5. package/lib/json-compiler/plugin.js +4 -4
  6. package/lib/loader.js +4 -4
  7. package/lib/native-loader.js +4 -4
  8. package/lib/platform/create-diagnostic.js +168 -0
  9. package/lib/platform/index.js +16 -3
  10. package/lib/platform/json/wx/index.js +66 -17
  11. package/lib/platform/run-rules.js +9 -5
  12. package/lib/platform/style/wx/index.js +4 -3
  13. package/lib/platform/template/normalize-component-rules.js +7 -9
  14. package/lib/platform/template/wx/component-config/camera.js +12 -0
  15. package/lib/platform/template/wx/component-config/custom-built-in-component.js +34 -0
  16. package/lib/platform/template/wx/component-config/index.js +18 -3
  17. package/lib/platform/template/wx/component-config/input.js +1 -7
  18. package/lib/platform/template/wx/component-config/movable-view.js +1 -7
  19. package/lib/platform/template/wx/component-config/text.js +1 -1
  20. package/lib/platform/template/wx/component-config/textarea.js +1 -25
  21. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  22. package/lib/platform/template/wx/index.js +48 -34
  23. package/lib/react/processJSON.js +7 -4
  24. package/lib/react/processStyles.js +22 -8
  25. package/lib/react/processTemplate.js +85 -41
  26. package/lib/react/style-helper.js +120 -85
  27. package/lib/react/template-loader.js +148 -0
  28. package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +1 -1
  29. package/lib/runtime/components/react/dist/mpx-camera.d.ts +31 -0
  30. package/lib/runtime/components/react/dist/mpx-camera.jsx +270 -0
  31. package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -1
  32. package/lib/runtime/components/react/dist/mpx-image.jsx +1 -2
  33. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +1 -1
  34. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +92 -15
  35. package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
  36. package/lib/runtime/components/react/dist/utils.jsx +3 -2
  37. package/lib/runtime/components/react/mpx-async-suspense.tsx +2 -1
  38. package/lib/runtime/components/react/mpx-camera.tsx +358 -0
  39. package/lib/runtime/components/react/mpx-image.tsx +1 -3
  40. package/lib/runtime/components/react/mpx-picker/type.ts +1 -1
  41. package/lib/runtime/components/react/mpx-scroll-view.tsx +106 -16
  42. package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
  43. package/lib/runtime/components/react/utils.tsx +3 -2
  44. package/lib/runtime/components/wx/default-component.mpx +9 -0
  45. package/lib/runtime/components/wx/default-page.mpx +3 -11
  46. package/lib/runtime/optionProcessor.d.ts +2 -0
  47. package/lib/runtime/optionProcessor.js +77 -1
  48. package/lib/style-compiler/index.js +2 -0
  49. package/lib/style-compiler/plugins/remove-strip-conditional-comments.js +14 -0
  50. package/lib/style-compiler/strip-conditional.js +40 -26
  51. package/lib/template-compiler/compiler.js +274 -116
  52. package/lib/template-compiler/gen-node-react.js +35 -7
  53. package/lib/template-compiler/index.js +9 -7
  54. package/lib/utils/const.js +4 -1
  55. package/lib/utils/dom-tag-config.js +1 -1
  56. package/lib/utils/partial-compile-rules.js +27 -0
  57. package/lib/utils/pre-process-json.js +3 -0
  58. package/lib/utils/source-location.js +96 -0
  59. package/lib/web/compile-wx-template-fragment.js +68 -0
  60. package/lib/web/index.js +2 -0
  61. package/lib/web/processJSON.js +7 -4
  62. package/lib/web/processScript.js +41 -3
  63. package/lib/web/processTemplate.js +61 -19
  64. package/lib/web/template-loader.js +123 -0
  65. package/lib/web/template-shared.js +48 -0
  66. package/lib/wxml/loader.js +3 -2
  67. package/lib/wxss/loader.js +1 -1
  68. package/lib/wxss/utils.js +6 -4
  69. package/package.json +12 -4
  70. package/lib/platform/template/wx/component-config/component.js +0 -41
@@ -1,7 +1,7 @@
1
1
  const NullDependency = require('webpack/lib/dependencies/NullDependency')
2
2
  const parseRequest = require('../utils/parse-request')
3
3
  const makeSerializable = require('webpack/lib/util/makeSerializable')
4
- const { matchCondition } = require('../utils/match-condition')
4
+ const { isPartialCompileExcluded } = require('../utils/partial-compile-rules')
5
5
 
6
6
  class ResolveDependency extends NullDependency {
7
7
  constructor (resource, packageName, issuerResource, range) {
@@ -35,7 +35,7 @@ class ResolveDependency extends NullDependency {
35
35
  const mainStaticResourcesMap = staticResourcesMap.main
36
36
  const resolveResult = pagesMap[resourcePath] || currentComponentsMap[resourcePath] || mainComponentsMap[resourcePath] || currentStaticResourcesMap[resourcePath] || mainStaticResourcesMap[resourcePath] || ''
37
37
  if (!resolveResult) {
38
- if (!partialCompileRules || matchCondition(resourcePath, partialCompileRules)) {
38
+ if (!isPartialCompileExcluded(resourcePath, partialCompileRules, 'page') && !isPartialCompileExcluded(resourcePath, partialCompileRules, 'component')) {
39
39
  compilation.errors.push(new Error(`[Mpx json error]:Path ${resource} is not a page/component/static resource, which is resolved from ${issuerResource}!`))
40
40
  }
41
41
  }
package/lib/index.js CHANGED
@@ -51,6 +51,7 @@ const fixRelative = require('./utils/fix-relative')
51
51
  const parseRequest = require('./utils/parse-request')
52
52
  const { transSubpackage } = require('./utils/trans-async-sub-rules')
53
53
  const { matchCondition } = require('./utils/match-condition')
54
+ const { getPartialCompileRules } = require('./utils/partial-compile-rules')
54
55
  const processDefs = require('./utils/process-defs')
55
56
  const config = require('./config')
56
57
  const hash = require('hash-sum')
@@ -494,13 +495,31 @@ class MpxWebpackPlugin {
494
495
 
495
496
  let mpx
496
497
 
497
- if (this.options.partialCompileRules) {
498
+ const pagePartialCompileRules = getPartialCompileRules(this.options.partialCompileRules, 'page')
499
+ const componentPartialCompileRules = getPartialCompileRules(this.options.partialCompileRules, 'component')
500
+
501
+ if (pagePartialCompileRules || componentPartialCompileRules) {
498
502
  function isResolvingPage (obj) {
499
503
  // valid query should start with '?'
500
504
  const query = parseQuery(obj.query || '?')
501
505
  return query.isPage && !query.type
502
506
  }
503
507
 
508
+ function isResolvingComponent (obj) {
509
+ // valid query should start with '?'
510
+ const query = parseQuery(obj.query || '?')
511
+ return query.isComponent && !query.type
512
+ }
513
+
514
+ const replaceResource = (obj, target) => {
515
+ const infix = obj.query ? '&' : '?'
516
+ obj.query += `${infix}resourcePath=${obj.path}`
517
+ obj.path = target
518
+ }
519
+
520
+ const defaultPagePath = require.resolve('./runtime/components/wx/default-page.mpx')
521
+ const defaultComponentPath = require.resolve('./runtime/components/wx/default-component.mpx')
522
+
504
523
  // new PartialCompilePlugin(this.options.partialCompile).apply(compiler)
505
524
  compiler.resolverFactory.hooks.resolver.intercept({
506
525
  factory: (type, hook) => {
@@ -509,13 +528,13 @@ class MpxWebpackPlugin {
509
528
  name: 'MpxPartialCompilePlugin',
510
529
  stage: -100
511
530
  }, (obj, resolverContext, callback) => {
512
- if (obj.path.startsWith(require.resolve('./runtime/components/wx/default-page.mpx'))) {
531
+ if (obj.path.startsWith(defaultPagePath) || obj.path.startsWith(defaultComponentPath)) {
513
532
  return callback(null, obj)
514
533
  }
515
- if (isResolvingPage(obj) && !matchCondition(obj.path, this.options.partialCompileRules)) {
516
- const infix = obj.query ? '&' : '?'
517
- obj.query += `${infix}resourcePath=${obj.path}`
518
- obj.path = require.resolve('./runtime/components/wx/default-page.mpx')
534
+ if (pagePartialCompileRules && isResolvingPage(obj) && !matchCondition(obj.path, pagePartialCompileRules)) {
535
+ replaceResource(obj, defaultPagePath)
536
+ } else if (componentPartialCompileRules && isResolvingComponent(obj) && !matchCondition(obj.path, componentPartialCompileRules)) {
537
+ replaceResource(obj, defaultComponentPath)
519
538
  }
520
539
  callback(null, obj)
521
540
  })
@@ -51,6 +51,8 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
51
51
  if (resolveMode === 'native') {
52
52
  component = urlToRequest(component)
53
53
  }
54
+ // 增加 component 标识,与 page 的 partialCompile 处理保持一致
55
+ component = addQuery(component, { isComponent: true })
54
56
  resolve(context, component, loaderContext, (err, resource, info) => {
55
57
  if (err) return callback(err)
56
58
  const { resourcePath, queryObj } = parseRequest(resource)
@@ -168,14 +170,14 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
168
170
  })
169
171
  }
170
172
 
171
- const fillInComponentPlaceholder = ({ jsonObj, name: componentName, placeholder, placeholderEntry, resolveResourcePathMap }, callback) => {
173
+ const fillInComponentPlaceholder = ({ jsonObj, name: componentName, placeholder, placeholderEntry, resolveResourcePathMap }) => {
172
174
  let placeholderComponentName = placeholder.name
173
175
  const componentPlaceholder = jsonObj.componentPlaceholder || {}
174
176
  if (componentPlaceholder[componentName]) {
175
- callback()
176
177
  return
177
178
  }
178
179
  jsonObj.componentPlaceholder = componentPlaceholder
180
+ componentPlaceholder[componentName] = placeholderComponentName
179
181
  if (placeholderEntry) {
180
182
  if (resolveResourcePathMap.has(placeholderComponentName) && resolveResourcePathMap.get(placeholderComponentName) !== placeholder.resourcePath) {
181
183
  // 如果存在placeholder与已有usingComponents冲突, 重新生成一个组件名,在当前组件后增加一个数字
@@ -184,16 +186,15 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
184
186
  while (jsonObj.usingComponents[newPlaceholder]) {
185
187
  newPlaceholder = placeholderComponentName + ++i
186
188
  }
187
- placeholderComponentName = newPlaceholder
189
+ componentPlaceholder[componentName] = placeholderComponentName = newPlaceholder
188
190
  }
189
191
  jsonObj.usingComponents[placeholderComponentName] = placeholderEntry
190
192
  resolveResourcePathMap.set(placeholderComponentName, placeholder.resourcePath)
193
+ return {
194
+ name: placeholderComponentName,
195
+ entry: placeholderEntry
196
+ }
191
197
  }
192
- componentPlaceholder[componentName] = placeholderComponentName
193
- callback(null, {
194
- name: placeholderComponentName,
195
- entry: placeholderEntry
196
- })
197
198
  }
198
199
 
199
200
  const getNormalizePlaceholder = (placeholder) => {
@@ -218,10 +219,10 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
218
219
  processComponent(placeholder.resource, context, { relativePath }, (err, entry, { resourcePath }) => {
219
220
  if (err) return callback(err)
220
221
  placeholder.resourcePath = resourcePath
221
- fillInComponentPlaceholder({ jsonObj, name, placeholder, placeholderEntry: entry, resolveResourcePathMap }, callback)
222
+ callback(null, fillInComponentPlaceholder({ jsonObj, name, placeholder, placeholderEntry: entry, resolveResourcePathMap }))
222
223
  })
223
224
  } else {
224
- fillInComponentPlaceholder({ jsonObj, name, placeholder }, callback)
225
+ callback(null, fillInComponentPlaceholder({ jsonObj, name, placeholder }))
225
226
  }
226
227
  } else {
227
228
  if (!jsonObj.componentPlaceholder || !jsonObj.componentPlaceholder[name]) {
@@ -46,15 +46,15 @@ module.exports = function (content) {
46
46
  const fs = this._compiler.inputFileSystem
47
47
  const runtimeCompile = queryObj.isDynamic
48
48
 
49
- const emitWarning = (msg) => {
49
+ const emitWarning = (msg, loc) => {
50
50
  this.emitWarning(
51
- new Error('[Mpx json error][' + this.resource + ']: ' + msg)
51
+ new Error('[Mpx json error][' + (loc || this.resourcePath) + ']: ' + msg)
52
52
  )
53
53
  }
54
54
 
55
- const emitError = (msg) => {
55
+ const emitError = (msg, loc) => {
56
56
  this.emitError(
57
- new Error('[Mpx json error][' + this.resource + ']: ' + msg)
57
+ new Error('[Mpx json error][' + (loc || this.resourcePath) + ']: ' + msg)
58
58
  )
59
59
  }
60
60
 
@@ -180,6 +180,9 @@ module.exports = function (content) {
180
180
  waterfall: true,
181
181
  warn: emitWarning,
182
182
  error: emitError,
183
+ diagnostic: {
184
+ file: resourcePath
185
+ },
183
186
  data: {
184
187
  // polyfill global usingComponents
185
188
  globalComponents: mpx.globalComponents
@@ -21,15 +21,15 @@ module.exports = function (source) {
21
21
 
22
22
  this._module.addPresentationalDependency(new FlagPluginDependency())
23
23
 
24
- const emitWarning = (msg) => {
24
+ const emitWarning = (msg, loc) => {
25
25
  this.emitWarning(
26
- new Error('[Mpx json warning][' + this.resource + ']: ' + msg)
26
+ new Error('[Mpx json warning][' + (loc || this.resourcePath) + ']: ' + msg)
27
27
  )
28
28
  }
29
29
 
30
- const emitError = (msg) => {
30
+ const emitError = (msg, loc) => {
31
31
  this.emitError(
32
- new Error('[Mpx json error][' + this.resource + ']: ' + msg)
32
+ new Error('[Mpx json error][' + (loc || this.resourcePath) + ']: ' + msg)
33
33
  )
34
34
  }
35
35
 
package/lib/loader.js CHANGED
@@ -53,15 +53,15 @@ module.exports = function (content) {
53
53
  const autoScope = matchCondition(resourcePath, mpx.autoScopeRules)
54
54
  const isRuntimeMode = queryObj.isDynamic
55
55
 
56
- const emitWarning = (msg) => {
56
+ const emitWarning = (msg, loc) => {
57
57
  this.emitWarning(
58
- new Error('[Mpx json warning][' + this.resource + ']: ' + msg)
58
+ new Error('[Mpx json warning][' + (loc || this.resourcePath) + ']: ' + msg)
59
59
  )
60
60
  }
61
61
 
62
- const emitError = (msg) => {
62
+ const emitError = (msg, loc) => {
63
63
  this.emitError(
64
- new Error('[Mpx json error][' + this.resource + ']: ' + msg)
64
+ new Error('[Mpx json error][' + (loc || this.resourcePath) + ']: ' + msg)
65
65
  )
66
66
  }
67
67
 
@@ -105,15 +105,15 @@ module.exports = function (content) {
105
105
  })
106
106
  }
107
107
 
108
- const emitWarning = (msg) => {
108
+ const emitWarning = (msg, loc) => {
109
109
  this.emitWarning(
110
- new Error('[Mpx json warning][native-loader][' + this.resource + ']: ' + msg)
110
+ new Error('[Mpx json warning][native-loader][' + (loc || this.resourcePath) + ']: ' + msg)
111
111
  )
112
112
  }
113
113
 
114
- const emitError = (msg) => {
114
+ const emitError = (msg, loc) => {
115
115
  this.emitError(
116
- new Error('[Mpx json error][native-loader][' + this.resource + ']: ' + msg)
116
+ new Error('[Mpx json error][native-loader][' + (loc || this.resourcePath) + ']: ' + msg)
117
117
  )
118
118
  }
119
119
  let ctorType = pagesMap[resourcePath]
@@ -0,0 +1,168 @@
1
+ const {
2
+ normalizeLoc,
3
+ createCodeFrame,
4
+ originalPositionFor,
5
+ readSource
6
+ } = require('../utils/source-location')
7
+
8
+ function formatAttr (attr) {
9
+ if (!attr) return ''
10
+ if (attr.value === true || attr.value == null) return attr.name
11
+ return `${attr.name}="${attr.value}"`
12
+ }
13
+
14
+ function formatTarget (context, extra) {
15
+ const target = extra && extra.target
16
+ if (target) {
17
+ if (target.kind === 'css-decl') return `${target.prop}: ${target.value}`
18
+ if (target.kind === 'css-atrule') return `@${target.name}${target.params ? ' ' + target.params : ''}`
19
+ if (target.kind === 'selector') return target.value
20
+ if (target.kind === 'event') return target.name
21
+ }
22
+ const input = context && context.input
23
+ const data = context && context.data
24
+ if (data && data.attr) {
25
+ return `<${data.el && data.el.tag}${formatAttr(data.attr) ? ' ' + formatAttr(data.attr) : ''}>`
26
+ }
27
+ if (input && input.prop) {
28
+ return `${input.prop}: ${input.value}`
29
+ }
30
+ if (input && input.selector) {
31
+ return input.selector
32
+ }
33
+ return ''
34
+ }
35
+
36
+ function inferPath (context, extra) {
37
+ if (extra && extra.path) {
38
+ return Array.isArray(extra.path) ? extra.path.join('.') : extra.path
39
+ }
40
+ const data = context && context.data
41
+ const meta = context && context.meta
42
+ if (data && meta && Array.isArray(meta.paths)) {
43
+ const paths = meta.paths.join('|')
44
+ return (data.pathArr || []).concat(paths).filter(Boolean).join('.')
45
+ }
46
+ }
47
+
48
+ function formatValue (value) {
49
+ if (value === undefined) return 'undefined'
50
+ let result
51
+ try {
52
+ result = JSON.stringify(value)
53
+ } catch (e) {
54
+ result = String(value)
55
+ }
56
+ if (result === undefined) result = String(value)
57
+ return result.length > 120 ? result.slice(0, 117) + '...' : result
58
+ }
59
+
60
+ function inferJsonTarget (context, extra) {
61
+ const path = inferPath(context, extra)
62
+ if (!path) return ''
63
+ if (extra && Object.prototype.hasOwnProperty.call(extra, 'value')) {
64
+ return `${path}: ${formatValue(extra.value)}`
65
+ }
66
+ return path
67
+ }
68
+
69
+ function inferLoc (context, extra) {
70
+ if (extra) {
71
+ if (extra.loc) return normalizeLoc(extra.loc)
72
+ if (extra.node && extra.node.source) return normalizeLoc(extra.node.source.start)
73
+ if (extra.decl && extra.decl.source) return normalizeLoc(extra.decl.source.start)
74
+ if (extra.attr) return normalizeLoc(extra.attr.loc)
75
+ if (extra.el) return normalizeLoc(extra.el.loc)
76
+ }
77
+ const input = context && context.input
78
+ const data = context && context.data
79
+ if (data) {
80
+ if (data.attr && data.attr.loc) return normalizeLoc(data.attr.loc)
81
+ if (data.el && data.el.loc) return normalizeLoc(data.el.loc)
82
+ }
83
+ if (input) {
84
+ if (input.decl && input.decl.source) return normalizeLoc(input.decl.source.start)
85
+ if (input.rule && input.rule.source) return normalizeLoc(input.rule.source.start)
86
+ if (input.loc) return normalizeLoc(input.loc)
87
+ }
88
+ }
89
+
90
+ function inferSourceMap (context, extra, base) {
91
+ if (extra && extra.sourceMap) return extra.sourceMap
92
+ if (context && context.input && context.input.sourceMap) return context.input.sourceMap
93
+ return base && base.sourceMap
94
+ }
95
+
96
+ function createDiagnostic ({
97
+ type,
98
+ mode,
99
+ srcMode,
100
+ warn,
101
+ error,
102
+ diagnostic = {}
103
+ }) {
104
+ const stack = []
105
+ const file = diagnostic.file
106
+ const source = diagnostic.source
107
+ const inputFileSystem = diagnostic.inputFileSystem
108
+
109
+ function withContext (context, fn) {
110
+ stack.push(context)
111
+ try {
112
+ return fn()
113
+ } finally {
114
+ stack.pop()
115
+ }
116
+ }
117
+
118
+ function format (msg, extra) {
119
+ msg = msg && msg.message ? msg.message : String(msg)
120
+ const context = stack[stack.length - 1]
121
+ const lines = []
122
+ const loc = inferLoc(context, extra)
123
+ const sourceMap = inferSourceMap(context, extra, diagnostic)
124
+ let finalFile = file
125
+ let finalLoc = loc
126
+ let finalSource = source
127
+ let original
128
+ if (sourceMap && loc) {
129
+ original = originalPositionFor(sourceMap, loc)
130
+ if (original) {
131
+ finalFile = original.file
132
+ finalLoc = original.loc
133
+ finalSource = original.source || readSource(original.file, inputFileSystem)
134
+ }
135
+ }
136
+ const hasLoc = finalLoc && finalLoc.start
137
+ const locText = finalFile && hasLoc
138
+ ? `${finalFile}:${finalLoc.start.line}:${finalLoc.start.column}`
139
+ : ''
140
+ lines.push(msg)
141
+ const target = formatTarget(context, extra) || (type === 'json' ? inferJsonTarget(context, extra) : inferPath(context, extra))
142
+ if (target) lines.push(`Target: ${target}`)
143
+ if (srcMode || mode) lines.push(`Mode: ${srcMode || ''}${srcMode && mode ? ' -> ' : ''}${mode || ''}`)
144
+ const frame = createCodeFrame(finalSource, finalLoc)
145
+ if (frame) {
146
+ lines.push('')
147
+ lines.push(frame)
148
+ }
149
+ return {
150
+ message: lines.join('\n'),
151
+ loc: locText || undefined
152
+ }
153
+ }
154
+
155
+ return {
156
+ warn (msg, extra) {
157
+ const result = format(msg, extra)
158
+ warn && warn(result.message, result.loc)
159
+ },
160
+ error (msg, extra) {
161
+ const result = format(msg, extra)
162
+ error && error(result.message, result.loc)
163
+ },
164
+ withContext
165
+ }
166
+ }
167
+
168
+ module.exports = createDiagnostic
@@ -1,4 +1,5 @@
1
1
  const runRules = require('./run-rules')
2
+ const createDiagnostic = require('./create-diagnostic')
2
3
 
3
4
  module.exports = function getRulesRunner ({
4
5
  type,
@@ -10,7 +11,8 @@ module.exports = function getRulesRunner ({
10
11
  mainKey,
11
12
  waterfall,
12
13
  warn,
13
- error
14
+ error,
15
+ diagnostic
14
16
  }) {
15
17
  const specMap = {
16
18
  template: {
@@ -23,13 +25,24 @@ module.exports = function getRulesRunner ({
23
25
  wx: require('./json/wx')
24
26
  }
25
27
  }
26
- const spec = specMap[type] && specMap[type][srcMode] && specMap[type][srcMode]({ warn, error })
28
+ diagnostic = createDiagnostic({
29
+ type,
30
+ mode,
31
+ srcMode,
32
+ warn,
33
+ error,
34
+ diagnostic
35
+ })
36
+ const spec = specMap[type] && specMap[type][srcMode] && specMap[type][srcMode]({
37
+ warn: diagnostic.warn,
38
+ error: diagnostic.error
39
+ })
27
40
  if (spec && spec.supportedModes.indexOf(mode) > -1) {
28
41
  const normalizeTest = spec.normalizeTest
29
42
  const mainRules = mainKey ? spec[mainKey] : spec
30
43
  if (mainRules) {
31
44
  return function (input) {
32
- return runRules(mainRules, input, { mode, data, meta, testKey, waterfall, normalizeTest })
45
+ return runRules(mainRules, input, { mode, data, meta, testKey, waterfall, normalizeTest, diagnostic })
33
46
  }
34
47
  }
35
48
  }
@@ -6,9 +6,11 @@ const { isOriginTag, isBuildInWebTag, isBuildInReactTag } = require('../../../ut
6
6
  const getBuildInTagComponent = require('../../../utils/get-build-tag-component')
7
7
 
8
8
  module.exports = function getSpec ({ warn, error }) {
9
- function print (mode, path, isError) {
9
+ const reactModes = ['ios', 'android', 'harmony']
10
+
11
+ function print (mode, path, value, isError) {
10
12
  const msg = `Json path <${path}> is not supported in ${mode} environment!`
11
- isError ? error(msg) : warn(msg)
13
+ isError ? error(msg, { path, value }) : warn(msg, { path, value })
12
14
  }
13
15
 
14
16
  function deletePath (opts) {
@@ -20,9 +22,10 @@ module.exports = function getSpec ({ warn, error }) {
20
22
  }
21
23
 
22
24
  return function (input, { mode, pathArr = [] }, meta) {
23
- const currPath = meta.paths.join('|')
24
25
  if (shouldLog) {
25
- print(mode, pathArr.concat(currPath).join('.'), isError)
26
+ meta.paths.forEach((path) => {
27
+ print(mode, pathArr.concat(path).join('.'), input[path], isError)
28
+ })
26
29
  }
27
30
  meta.paths.forEach((path) => {
28
31
  delete input[path]
@@ -31,6 +34,14 @@ module.exports = function getSpec ({ warn, error }) {
31
34
  }
32
35
  }
33
36
 
37
+ function createReactRule (test, processor) {
38
+ const rule = { test }
39
+ reactModes.forEach(mode => {
40
+ rule[mode] = processor
41
+ })
42
+ return rule
43
+ }
44
+
34
45
  /**
35
46
  * @desc 在app.mpx里配置usingComponents作为全局组件
36
47
  */
@@ -72,7 +83,10 @@ module.exports = function getSpec ({ warn, error }) {
72
83
  if (componentGenerics && typeof componentGenerics === 'object') {
73
84
  Object.keys(componentGenerics).forEach(key => {
74
85
  if (!componentGenerics[key].default) {
75
- error(`Ali environment componentGenerics need to specify a default custom component! please check the configuration of component ${key}`)
86
+ error(`Ali environment componentGenerics need to specify a default custom component! please check the configuration of component ${key}`, {
87
+ path: ['componentGenerics', key],
88
+ value: componentGenerics[key]
89
+ })
76
90
  }
77
91
  })
78
92
  }
@@ -102,7 +116,10 @@ module.exports = function getSpec ({ warn, error }) {
102
116
  if (keyNeed) {
103
117
  newK = capitalToHyphen(k)
104
118
  if (obj[newK]) {
105
- warn && warn(`Component name "${newK}" already exists, so component "${k}" can't be converted automatically and it isn't supported in ali/swan environment!`)
119
+ warn && warn(`Component name "${newK}" already exists, so component "${k}" can't be converted automatically and it isn't supported in ali/swan environment!`, {
120
+ path: [type, k],
121
+ value: v
122
+ })
106
123
  } else {
107
124
  obj[newK] = v
108
125
  delete obj[k]
@@ -213,6 +230,7 @@ module.exports = function getSpec ({ warn, error }) {
213
230
  },
214
231
  jd: deletePath()
215
232
  },
233
+ createReactRule('enablePullDownRefresh|onReachBottomDistance', deletePath()),
216
234
  {
217
235
  test: 'navigationBarBackgroundColor',
218
236
  ali (input) {
@@ -240,8 +258,13 @@ module.exports = function getSpec ({ warn, error }) {
240
258
  {
241
259
  test: 'backgroundColorTop|backgroundColorBottom',
242
260
  ali: deletePath(),
243
- swan: deletePath()
261
+ swan: deletePath(),
262
+ ios: deletePath(),
263
+ android: deletePath(),
264
+ harmony: deletePath()
244
265
  },
266
+ createReactRule('backgroundColor|backgroundTextStyle', deletePath()),
267
+ createReactRule('pageOrientation', deletePath()),
245
268
  {
246
269
  test: 'navigationBarTextStyle|navigationStyle|backgroundTextStyle',
247
270
  ali: deletePath()
@@ -255,11 +278,12 @@ module.exports = function getSpec ({ warn, error }) {
255
278
  }
256
279
  ]
257
280
 
258
- const getTabBarRule = () => (input, { mode }) => {
281
+ const getTabBarRule = () => (input, { mode, diagnostic }) => {
259
282
  input.tabBar = runRules(spec.tabBar, input.tabBar, {
260
283
  mode,
261
284
  normalizeTest,
262
285
  waterfall: true,
286
+ diagnostic,
263
287
  data: {
264
288
  pathArr: ['tabBar']
265
289
  }
@@ -267,11 +291,12 @@ module.exports = function getSpec ({ warn, error }) {
267
291
  return input
268
292
  }
269
293
 
270
- const getWindowRule = () => (input, { mode }) => {
294
+ const getWindowRule = () => (input, { mode, diagnostic }) => {
271
295
  input.window = runRules(spec.window, input.window, {
272
296
  mode,
273
297
  normalizeTest,
274
298
  waterfall: true,
299
+ diagnostic,
275
300
  data: {
276
301
  pathArr: ['window']
277
302
  }
@@ -329,7 +354,7 @@ module.exports = function getSpec ({ warn, error }) {
329
354
  },
330
355
  {
331
356
  test: 'list',
332
- ali (input) {
357
+ ali (input, { diagnostic }) {
333
358
  const value = input.list
334
359
  delete input.list
335
360
  input.items = value.map((item) => {
@@ -337,6 +362,7 @@ module.exports = function getSpec ({ warn, error }) {
337
362
  mode: 'ali',
338
363
  normalizeTest,
339
364
  waterfall: true,
365
+ diagnostic,
340
366
  data: {
341
367
  pathArr: ['tabBar', 'list']
342
368
  }
@@ -372,7 +398,10 @@ module.exports = function getSpec ({ warn, error }) {
372
398
  qq: deletePath(),
373
399
  swan: deletePath(),
374
400
  tt: deletePath(),
375
- jd: deletePath()
401
+ jd: deletePath(),
402
+ ios: deletePath(),
403
+ android: deletePath(),
404
+ harmony: deletePath()
376
405
  },
377
406
  {
378
407
  test: 'preloadRule',
@@ -384,14 +413,20 @@ module.exports = function getSpec ({ warn, error }) {
384
413
  qq: deletePath(true),
385
414
  swan: deletePath(true),
386
415
  tt: deletePath(),
387
- jd: deletePath(true)
416
+ jd: deletePath(true),
417
+ ios: deletePath(true),
418
+ android: deletePath(true),
419
+ harmony: deletePath(true)
388
420
  },
389
421
  {
390
422
  test: 'plugins',
391
423
  qq: deletePath(true),
392
424
  swan: deletePath(true),
393
425
  tt: deletePath(),
394
- jd: deletePath(true)
426
+ jd: deletePath(true),
427
+ ios: deletePath(true),
428
+ android: deletePath(true),
429
+ harmony: deletePath(true)
395
430
  },
396
431
  {
397
432
  test: 'usingComponents',
@@ -417,19 +452,28 @@ module.exports = function getSpec ({ warn, error }) {
417
452
  {
418
453
  test: 'debug',
419
454
  ali: deletePath(),
420
- swan: deletePath()
455
+ swan: deletePath(),
456
+ ios: deletePath(),
457
+ android: deletePath(),
458
+ harmony: deletePath()
421
459
  },
422
460
  {
423
461
  test: 'requiredBackgroundModes',
424
462
  ali: deletePath(),
425
- tt: deletePath()
463
+ tt: deletePath(),
464
+ ios: deletePath(),
465
+ android: deletePath(),
466
+ harmony: deletePath()
426
467
  },
427
468
  {
428
469
  test: 'workers',
429
470
  jd: deletePath(),
430
471
  ali: deletePath(),
431
472
  swan: deletePath(),
432
- tt: deletePath()
473
+ tt: deletePath(),
474
+ ios: deletePath(),
475
+ android: deletePath(),
476
+ harmony: deletePath()
433
477
  },
434
478
  {
435
479
  test: 'subpackages|subPackages',
@@ -444,6 +488,8 @@ module.exports = function getSpec ({ warn, error }) {
444
488
  ali: deletePath(),
445
489
  jd: deletePath()
446
490
  },
491
+ createReactRule('navigateToMiniProgramAppIdList', deletePath()),
492
+ createReactRule('tabBar', deletePath(true)),
447
493
  {
448
494
  test: 'tabBar',
449
495
  ali: getTabBarRule(),
@@ -460,7 +506,10 @@ module.exports = function getSpec ({ warn, error }) {
460
506
  swan: getWindowRule(),
461
507
  tt: getWindowRule(),
462
508
  ks: getWindowRule(),
463
- jd: getWindowRule()
509
+ jd: getWindowRule(),
510
+ ios: getWindowRule(),
511
+ android: getWindowRule(),
512
+ harmony: getWindowRule()
464
513
  }
465
514
  ]
466
515
  }