@mpxjs/webpack-plugin 2.9.9 → 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')
|
|
@@ -1305,56 +1304,56 @@ class MpxWebpackPlugin {
|
|
|
1305
1304
|
}
|
|
1306
1305
|
|
|
1307
1306
|
// 为跨平台api调用注入srcMode参数指导api运行时转换
|
|
1308
|
-
const apiBlackListMap = [
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
].reduce((map, api) => {
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
}, {})
|
|
1331
|
-
|
|
1332
|
-
const injectSrcModeForTransApi = (expr, members) => {
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
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,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
|
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
<script>
|
|
6
6
|
import { getCustomEvent } from './getInnerListeners'
|
|
7
|
-
import
|
|
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
|
-
|
|
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 =
|
|
112
|
+
asyncCallback = promisify(value, navigateTo)
|
|
112
113
|
break
|
|
113
114
|
case 'navigateBack':
|
|
114
|
-
asyncCallback = value
|
|
115
|
+
asyncCallback = promisify(value = {}, navigateBack)
|
|
115
116
|
break
|
|
116
117
|
case 'redirectTo':
|
|
117
|
-
asyncCallback =
|
|
118
|
+
asyncCallback = promisify(value, redirectTo)
|
|
118
119
|
break
|
|
119
120
|
case 'switchTab':
|
|
120
|
-
asyncCallback =
|
|
121
|
+
asyncCallback = promisify(value, switchTab)
|
|
121
122
|
break
|
|
122
123
|
case 'reLaunch':
|
|
123
|
-
asyncCallback =
|
|
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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.9.
|
|
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": "
|
|
86
|
+
"gitHead": "d244d661acb081b709fc99ca8f6add541f793877"
|
|
87
87
|
}
|