@mpxjs/webpack-plugin 2.9.8 → 2.9.11-test.0

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
@@ -9,7 +9,6 @@ const NullFactory = require('webpack/lib/NullFactory')
9
9
  const CommonJsVariableDependency = require('./dependencies/CommonJsVariableDependency')
10
10
  const CommonJsAsyncDependency = require('./dependencies/CommonJsAsyncDependency')
11
11
  const CommonJsExtractDependency = require('./dependencies/CommonJsExtractDependency')
12
- const harmonySpecifierTag = require('webpack/lib/dependencies/HarmonyImportDependencyParserPlugin').harmonySpecifierTag
13
12
  const NormalModule = require('webpack/lib/NormalModule')
14
13
  const EntryPlugin = require('webpack/lib/EntryPlugin')
15
14
  const JavascriptModulesPlugin = require('webpack/lib/javascript/JavascriptModulesPlugin')
@@ -1089,7 +1088,7 @@ class MpxWebpackPlugin {
1089
1088
  if (tarRoot) {
1090
1089
  // 删除root query
1091
1090
  if (queryObj.root) request = addQuery(request, {}, false, ['root'])
1092
- // 目前仅wx和ali支持require.async,ali需要开启enableAliRequireAsync,其余平台使用CommonJsAsyncDependency进行模拟抹平
1091
+ // wx、ali(需开启enableAliRequireAsync)web平台支持require.async,其余平台使用CommonJsAsyncDependency进行模拟抹平
1093
1092
  if (mpx.supportRequireAsync) {
1094
1093
  if (mpx.mode === 'web') {
1095
1094
  const depBlock = new AsyncDependenciesBlock(
@@ -1305,56 +1304,56 @@ class MpxWebpackPlugin {
1305
1304
  }
1306
1305
 
1307
1306
  // 为跨平台api调用注入srcMode参数指导api运行时转换
1308
- const apiBlackListMap = [
1309
- 'createApp',
1310
- 'createPage',
1311
- 'createComponent',
1312
- 'createStore',
1313
- 'createStoreWithThis',
1314
- 'mixin',
1315
- 'injectMixins',
1316
- 'toPureObject',
1317
- 'observable',
1318
- 'watch',
1319
- 'use',
1320
- 'set',
1321
- 'remove',
1322
- 'delete',
1323
- 'setConvertRule',
1324
- 'getMixin',
1325
- 'getComputed',
1326
- 'implement'
1327
- ].reduce((map, api) => {
1328
- map[api] = true
1329
- return map
1330
- }, {})
1331
-
1332
- const injectSrcModeForTransApi = (expr, members) => {
1333
- // members为空数组时,callee并不是memberExpression
1334
- if (!members.length) return
1335
- const callee = expr.callee
1336
- const args = expr.arguments
1337
- const name = callee.object.name
1338
- const { queryObj, resourcePath } = parseRequest(parser.state.module.resource)
1339
- const localSrcMode = queryObj.mode
1340
- const globalSrcMode = mpx.srcMode
1341
- const srcMode = localSrcMode || globalSrcMode
1342
-
1343
- if (srcMode === globalSrcMode || apiBlackListMap[callee.property.name || callee.property.value] || (name !== 'mpx' && name !== 'wx') || (name === 'wx' && !matchCondition(resourcePath, this.options.transMpxRules))) return
1344
-
1345
- const srcModeString = `__mpx_src_mode_${srcMode}__`
1346
- const dep = new InjectDependency({
1347
- content: args.length
1348
- ? `, ${JSON.stringify(srcModeString)}`
1349
- : JSON.stringify(srcModeString),
1350
- index: expr.end - 1
1351
- })
1352
- parser.state.current.addPresentationalDependency(dep)
1353
- }
1354
-
1355
- parser.hooks.callMemberChain.for(harmonySpecifierTag).tap('MpxWebpackPlugin', injectSrcModeForTransApi)
1356
- parser.hooks.callMemberChain.for('mpx').tap('MpxWebpackPlugin', injectSrcModeForTransApi)
1357
- parser.hooks.callMemberChain.for('wx').tap('MpxWebpackPlugin', injectSrcModeForTransApi)
1307
+ // const apiBlackListMap = [
1308
+ // 'createApp',
1309
+ // 'createPage',
1310
+ // 'createComponent',
1311
+ // 'createStore',
1312
+ // 'createStoreWithThis',
1313
+ // 'mixin',
1314
+ // 'injectMixins',
1315
+ // 'toPureObject',
1316
+ // 'observable',
1317
+ // 'watch',
1318
+ // 'use',
1319
+ // 'set',
1320
+ // 'remove',
1321
+ // 'delete',
1322
+ // 'setConvertRule',
1323
+ // 'getMixin',
1324
+ // 'getComputed',
1325
+ // 'implement'
1326
+ // ].reduce((map, api) => {
1327
+ // map[api] = true
1328
+ // return map
1329
+ // }, {})
1330
+ //
1331
+ // const injectSrcModeForTransApi = (expr, members) => {
1332
+ // // members为空数组时,callee并不是memberExpression
1333
+ // if (!members.length) return
1334
+ // const callee = expr.callee
1335
+ // const args = expr.arguments
1336
+ // const name = callee.object.name
1337
+ // const { queryObj, resourcePath } = parseRequest(parser.state.module.resource)
1338
+ // const localSrcMode = queryObj.mode
1339
+ // const globalSrcMode = mpx.srcMode
1340
+ // const srcMode = localSrcMode || globalSrcMode
1341
+ //
1342
+ // if (srcMode === globalSrcMode || apiBlackListMap[callee.property.name || callee.property.value] || (name !== 'mpx' && name !== 'wx') || (name === 'wx' && !matchCondition(resourcePath, this.options.transMpxRules))) return
1343
+ //
1344
+ // const srcModeString = `__mpx_src_mode_${srcMode}__`
1345
+ // const dep = new InjectDependency({
1346
+ // content: args.length
1347
+ // ? `, ${JSON.stringify(srcModeString)}`
1348
+ // : JSON.stringify(srcModeString),
1349
+ // index: expr.end - 1
1350
+ // })
1351
+ // parser.state.current.addPresentationalDependency(dep)
1352
+ // }
1353
+ //
1354
+ // parser.hooks.callMemberChain.for(harmonySpecifierTag).tap('MpxWebpackPlugin', injectSrcModeForTransApi)
1355
+ // parser.hooks.callMemberChain.for('mpx').tap('MpxWebpackPlugin', injectSrcModeForTransApi)
1356
+ // parser.hooks.callMemberChain.for('wx').tap('MpxWebpackPlugin', injectSrcModeForTransApi)
1358
1357
  }
1359
1358
  }
1360
1359
  normalModuleFactory.hooks.parser.for('javascript/auto').tap('MpxWebpackPlugin', normalModuleFactoryParserCallback)
@@ -14,6 +14,9 @@ const RecordGlobalComponentsDependency = require('../dependencies/RecordGlobalCo
14
14
  const RecordIndependentDependency = require('../dependencies/RecordIndependentDependency')
15
15
  const { MPX_DISABLE_EXTRACTOR_CACHE, RESOLVE_IGNORED_ERR, JSON_JS_EXT } = require('../utils/const')
16
16
  const resolve = require('../utils/resolve')
17
+ const normalize = require('../utils/normalize')
18
+ const mpxViewPath = normalize.lib('runtime/components/ali/mpx-view.mpx')
19
+ const mpxTextPath = normalize.lib('runtime/components/ali/mpx-text.mpx')
17
20
 
18
21
  module.exports = function (content) {
19
22
  const nativeCallback = this.async()
@@ -65,9 +68,13 @@ module.exports = function (content) {
65
68
  }
66
69
  const normalizePlaceholder = (placeholder) => {
67
70
  if (typeof placeholder === 'string') {
68
- placeholder = {
69
- name: placeholder
71
+ const placeholderMap = mode === 'ali'
72
+ ? {
73
+ view: { name: 'mpx-view', resource: mpxViewPath },
74
+ text: { name: 'mpx-text', resource: mpxTextPath }
70
75
  }
76
+ : {}
77
+ placeholder = placeholderMap[placeholder] || { name: placeholder }
71
78
  }
72
79
  if (!placeholder.name) {
73
80
  emitError('The asyncSubpackageRules configuration format of @mpxjs/webpack-plugin a is incorrect')
@@ -211,7 +218,7 @@ module.exports = function (content) {
211
218
  const processComponents = (components, context, callback) => {
212
219
  if (components) {
213
220
  async.eachOf(components, (component, name, callback) => {
214
- processComponent(component, context, { relativePath }, (err, entry, { tarRoot, placeholder }) => {
221
+ processComponent(component, context, { relativePath }, (err, entry, { tarRoot, placeholder } = {}) => {
215
222
  if (err === RESOLVE_IGNORED_ERR) {
216
223
  delete components[name]
217
224
  return callback()
@@ -14,7 +14,7 @@ web的额外逻辑,因为小程序组件和web存在差异,比如事件相
14
14
 
15
15
  Mpx的转换一个重要原则是转不了的东西通过控制台打印提示用户,要求用户提供一份符合对应平台的代码通过条件编译支持。因此错误输出格式保持一致是有必要的。
16
16
 
17
- 在 index.js 中,会汇总每个组件的转换规则函数,为了使错误信息标准化,一致化,错误打印函数的生成函数实现在index.js里。
17
+ 在 index.web.js 中,会汇总每个组件的转换规则函数,为了使错误信息标准化,一致化,错误打印函数的生成函数实现在index.js里。
18
18
 
19
19
  每个组件文件是一个方法,接受错误打印生成方法,根据组件名生成对应的错误打印方法。
20
20
 
@@ -95,7 +95,7 @@
95
95
  },
96
96
  speed: {
97
97
  type: Number,
98
- default: 1000
98
+ default: 500
99
99
  },
100
100
  scrollOptions: {
101
101
  type: Object,
@@ -4,7 +4,8 @@
4
4
 
5
5
  <script>
6
6
  import { getCustomEvent } from './getInnerListeners'
7
- import { redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy/src/web/api/index'
7
+ import promisify from './promisify'
8
+ import { redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy'
8
9
 
9
10
  const eventLoad = 'load'
10
11
  const eventError = 'error'
@@ -95,7 +96,7 @@
95
96
  messageCallback (event) {
96
97
  const hostValidate = this.hostValidate(event.origin)
97
98
  const data = event.data
98
- const value = data.payload
99
+ let value = data.payload
99
100
  if (!hostValidate) {
100
101
  return
101
102
  }
@@ -108,19 +109,19 @@
108
109
  })
109
110
  break
110
111
  case 'navigateTo':
111
- asyncCallback = navigateTo(value)
112
+ asyncCallback = promisify(value, navigateTo)
112
113
  break
113
114
  case 'navigateBack':
114
- asyncCallback = value ? navigateBack(value) : navigateBack()
115
+ asyncCallback = promisify(value = {}, navigateBack)
115
116
  break
116
117
  case 'redirectTo':
117
- asyncCallback = redirectTo(value)
118
+ asyncCallback = promisify(value, redirectTo)
118
119
  break
119
120
  case 'switchTab':
120
- asyncCallback = switchTab(value)
121
+ asyncCallback = promisify(value, switchTab)
121
122
  break
122
123
  case 'reLaunch':
123
- asyncCallback = reLaunch(value)
124
+ asyncCallback = promisify(value, reLaunch)
124
125
  break
125
126
  case 'getLocation':
126
127
  const getLocation = mpx.config.webviewConfig.apiImplementations && mpx.config.webviewConfig.apiImplementations.getLocation
@@ -0,0 +1,19 @@
1
+ function promisify (obj = {}, callback) {
2
+ return new Promise((resolve, reject) => {
3
+ const originSuccess = obj.success
4
+ const originFail = obj.fail
5
+ obj.success = function (res) {
6
+ originSuccess && originSuccess.call(this, res)
7
+ resolve(res)
8
+ }
9
+ obj.fail = function (e) {
10
+ originFail && originFail.call(this, e)
11
+ reject(e)
12
+ }
13
+ if (callback) {
14
+ callback(obj)
15
+ }
16
+ })
17
+ }
18
+
19
+ export default promisify
@@ -6,8 +6,10 @@ declare global {
6
6
  }
7
7
  }
8
8
 
9
- export default function processOption (...args: any): object
9
+ export function processComponentOption (...args: any): object
10
10
 
11
11
  export function getComponent (...args: any): object
12
12
 
13
13
  export function getWxsMixin (...args: any): object
14
+
15
+ export function processAppOption (...args: any): void
@@ -1,9 +1,9 @@
1
- import { hasOwn } from './utils'
1
+ import { hasOwn, isEmptyObject } from './utils'
2
2
  import { isBrowser } from './env'
3
3
  import transRpxStyle from './transRpxStyle'
4
4
  import animation from './animation'
5
5
 
6
- export default function processComponentOption (
6
+ export function processComponentOption (
7
7
  {
8
8
  option,
9
9
  ctorType,
@@ -12,7 +12,7 @@ export default function processComponentOption (
12
12
  componentsMap,
13
13
  componentGenerics,
14
14
  genericsInfo,
15
- mixin,
15
+ wxsMixin,
16
16
  hasApp
17
17
  }
18
18
  ) {
@@ -40,7 +40,7 @@ registered in parent context!`)
40
40
  })
41
41
  }
42
42
 
43
- if (componentGenerics) {
43
+ if (!isEmptyObject(componentGenerics)) {
44
44
  option.props = option.props || {}
45
45
  option.props.generichash = String
46
46
  Object.keys(componentGenerics).forEach((genericName) => {
@@ -64,10 +64,9 @@ registered in parent context!`)
64
64
  option.filters = { transRpxStyle }
65
65
  }
66
66
 
67
- if (option.mixins) {
68
- option.mixins.push(mixin)
69
- } else {
70
- option.mixins = [mixin]
67
+ if (wxsMixin) {
68
+ option.mixins = option.mixins || []
69
+ option.mixins.push(wxsMixin)
71
70
  }
72
71
 
73
72
  if (outputPath) {
@@ -85,7 +84,7 @@ export function getComponent (component, extendOptions) {
85
84
  }
86
85
 
87
86
  export function getWxsMixin (wxsModules) {
88
- if (!wxsModules || !Object.keys(wxsModules).length) return {}
87
+ if (!wxsModules || !Object.keys(wxsModules).length) return
89
88
  return {
90
89
  created () {
91
90
  Object.keys(wxsModules).forEach((key) => {
@@ -533,7 +533,7 @@ function compileScriptSetup (
533
533
  (node.type === 'VariableDeclaration' && node.declare)
534
534
  ) {
535
535
  recordType(node, declaredTypes)
536
- _s.move(node.start, node.end, 0)
536
+ _s.move(node.start, node.end + 1, 0)
537
537
  }
538
538
  }
539
539
 
@@ -96,12 +96,11 @@ function checkDelAndGetPath (path) {
96
96
  } else {
97
97
  delPath = current.parentPath
98
98
  }
99
- } else if (t.isLogicalExpression(current.container)) { // case: a || ''
99
+ } else if (t.isLogicalExpression(current.container)) { // 只处理case: a || '' or '123' || a
100
100
  const key = current.key === 'left' ? 'right' : 'left'
101
101
  if (t.isLiteral(current.parent[key])) {
102
102
  delPath = current.parentPath
103
103
  } else {
104
- canDel = false
105
104
  break
106
105
  }
107
106
  } else if (current.key === 'expression' && t.isExpressionStatement(current.parentPath)) { // dealRemove删除节点时需要
@@ -116,11 +115,23 @@ function checkDelAndGetPath (path) {
116
115
  // 确定是否可删除
117
116
  while (!t.isBlockStatement(current) && canDel) {
118
117
  const { key, container } = current
118
+ if (t.isIfStatement(container) && key === 'test') { // if (a) {}
119
+ canDel = false
120
+ break
121
+ }
122
+
123
+ if (t.isLogicalExpression(container)) { // case: a || ((b || c) && d)
124
+ ignore = true
125
+ break
126
+ }
127
+
128
+ // case: a ??= b
119
129
  if (
120
- t.isLogicalExpression(container) || // a && b
121
- (t.isIfStatement(container) && key === 'test') // if (a) {}
130
+ key === 'right' &&
131
+ t.isAssignmentExpression(container) &&
132
+ ['??=', '||=', '&&='].includes(container.operator)
122
133
  ) {
123
- canDel = false
134
+ ignore = true
124
135
  break
125
136
  }
126
137
 
@@ -166,13 +177,16 @@ function dealRemove (path, replace) {
166
177
  if (replace) {
167
178
  path.replaceWith(t.stringLiteral(''))
168
179
  } else {
169
- t.validate(path, path.key, null)
180
+ if (path.inList) {
181
+ t.validate(path.parent, path.key, [null])
182
+ } else {
183
+ t.validate(path.parent, path.key, null)
184
+ }
170
185
  path.remove()
171
186
  }
172
187
  delete path.needBind
173
188
  delete path.collectInfo
174
- } catch (e) {
175
- }
189
+ } catch (e) {}
176
190
  }
177
191
 
178
192
  module.exports = {
@@ -1931,7 +1931,7 @@ function postProcessTemplate (el) {
1931
1931
  }
1932
1932
  }
1933
1933
 
1934
- const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd,noMode')
1934
+ const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd,tenon,noMode')
1935
1935
 
1936
1936
  const wrapRE = /^\((.*)\)$/
1937
1937
 
@@ -3,10 +3,12 @@ module.exports = function (loaderContext) {
3
3
  const moduleGraph = loaderContext._compilation.moduleGraph
4
4
  let entryName = ''
5
5
  for (const [name, { dependencies }] of loaderContext._compilation.entries) {
6
- const entryModule = moduleGraph.getModule(dependencies[0])
7
- if (entryModule && entryModule.resource === loaderContext.resource) {
8
- entryName = name
9
- break
6
+ for (const dep of dependencies) {
7
+ const entryModule = moduleGraph.getModule(dep)
8
+ if (entryModule && entryModule.resource === loaderContext.resource) {
9
+ entryName = name
10
+ break
11
+ }
10
12
  }
11
13
  }
12
14
  return entryName
@@ -46,7 +46,6 @@ module.exports = function (script, {
46
46
  output += ` import Vue from 'vue'
47
47
  import VueRouter from 'vue-router'
48
48
  import Mpx from '@mpxjs/core'
49
- import App from ${stringifyRequest(loaderContext, addQuery(resource, { isApp: true }))}
50
49
  import { processAppOption, getComponent } from ${stringifyRequest(loaderContext, optionProcessorPath)}
51
50
  Vue.use(VueRouter)\n`
52
51
 
@@ -64,6 +63,9 @@ module.exports = function (script, {
64
63
  isMain: true,
65
64
  globalTabBar
66
65
  })
66
+
67
+ output += `\n const App = require(${stringifyRequest(loaderContext, addQuery(resource, { isApp: true }))}).default\n`
68
+
67
69
  output += `
68
70
  export default processAppOption({
69
71
  App,
@@ -40,7 +40,7 @@ module.exports = function (script, {
40
40
  return attrs
41
41
  },
42
42
  content (script) {
43
- let content = `\n import processComponentOption, { getComponent, getWxsMixin } from ${stringifyRequest(optionProcessorPath)}\n`
43
+ let content = `\n import { processComponentOption, getComponent, getWxsMixin } from ${stringifyRequest(optionProcessorPath)}\n`
44
44
  let hasApp = true
45
45
  if (!appInfo.name) {
46
46
  hasApp = false
@@ -85,7 +85,7 @@ module.exports = function (script, {
85
85
  componentsMap: ${shallowStringify(componentsMap)},
86
86
  componentGenerics: ${JSON.stringify(componentGenerics)},
87
87
  genericsInfo: ${JSON.stringify(genericsInfo)},
88
- mixin: getWxsMixin(wxsModules),
88
+ wxsMixin: getWxsMixin(wxsModules),
89
89
  hasApp: ${hasApp}
90
90
  })\n`
91
91
  return content
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.9.8",
3
+ "version": "2.9.11-test.0",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -83,5 +83,5 @@
83
83
  "engines": {
84
84
  "node": ">=14.14.0"
85
85
  },
86
- "gitHead": "0c6800cb1e8fcaf6bebf94d678ccb0480f2bcb64"
86
+ "gitHead": "d244d661acb081b709fc99ca8f6add541f793877"
87
87
  }