Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/didi/mpx
Browse files Browse the repository at this point in the history
  • Loading branch information
hiyuki committed Jul 28, 2023
2 parents ddeee91 + af1a776 commit 926aaa2
Show file tree
Hide file tree
Showing 29 changed files with 137 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: test

on: [push]
on: [push, pull_request]

jobs:
lint:
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"packages": [
"packages/*"
],
"version": "2.8.35"
"version": "2.8.38"
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mpxjs/core",
"version": "2.8.33",
"version": "2.8.36",
"description": "mpx runtime core",
"keywords": [
"miniprogram",
Expand Down
2 changes: 1 addition & 1 deletion packages/size-report/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mpxjs/size-report",
"version": "2.8.34",
"version": "2.8.37",
"description": "mpx size report plugin",
"main": "src/index.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions packages/size-report/src/SizeReportPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,12 +647,16 @@ class SizeReportPlugin {

function checkThreshold (threshold, size, sizeInfo, reportGroupName) {
const sizeThreshold = normalizeThreshold(threshold.size || threshold)
const preWarningThreshold = normalizeThreshold(threshold.preWarningSize || threshold)
const packagesThreshold = threshold.packages
const prefix = reportGroupName ? `${reportGroupName}体积分组` : '总包'

if (sizeThreshold && size && size > sizeThreshold) {
compilation.errors.push(`${prefix}的总体积(${size}B)超过设定阈值(${sizeThreshold}B),共${(size - sizeThreshold) / 1024}kb,请检查!`)
}
if (preWarningThreshold && size && size > preWarningThreshold) {
compilation.warnings.push(`${prefix}的总体积(${size}B)超过设定预警阈值(${preWarningThreshold}B),共${(size - preWarningThreshold) / 1024}kb,请注意!`)
}

if (packagesThreshold && sizeInfo) {
for (const packageName in sizeInfo) {
Expand Down
6 changes: 3 additions & 3 deletions packages/webpack-plugin/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ class MpxWebpackPlugin {
useRelativePath: this.options.useRelativePath,
removedChunks: [],
forceProxyEventRules: this.options.forceProxyEventRules,
enableAliRequireAsync: this.options.enableAliRequireAsync,
enableRequireAsync: this.options.mode === 'wx' || (this.options.mode === 'ali' && this.options.enableAliRequireAsync),
pathHash: (resourcePath) => {
if (this.options.pathHashMode === 'relative' && this.options.projectRoot) {
return hash(path.relative(this.options.projectRoot, resourcePath))
Expand Down Expand Up @@ -1003,8 +1003,8 @@ class MpxWebpackPlugin {
if (queryObj.root) {
// 删除root query
request = addQuery(request, {}, false, ['root'])
// 目前仅wx支持require.async,其余平台使用CommonJsAsyncDependency进行模拟抹平
if (mpx.mode === 'wx' || (mpx.mode === 'ali' && mpx.enableAliRequireAsync)) {
// 目前仅wx和ali支持require.async,ali需要开启enableAliRequireAsync,其余平台使用CommonJsAsyncDependency进行模拟抹平
if (mpx.enableRequireAsync) {
const dep = new DynamicEntryDependency(request, 'export', '', queryObj.root, '', context, range, {
isRequireAsync: true,
retryRequireAsync: !!this.options.retryRequireAsync
Expand Down
4 changes: 2 additions & 2 deletions packages/webpack-plugin/lib/json-compiler/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
const pathHash = mpx.pathHash
const getOutputPath = mpx.getOutputPath
const mode = mpx.mode
const enableAliRequireAsync = mpx.enableAliRequireAsync
const enableRequireAsync = mpx.enableRequireAsync

const isUrlRequest = r => isUrlRequestRaw(r, root, externals)
const urlToRequest = r => loaderUtils.urlToRequest(r)
Expand Down Expand Up @@ -54,7 +54,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
// 删除root query
resource = addQuery(resource, {}, false, ['root'])
// 目前只有微信支持分包异步化
if (mode === 'wx' || (mode === 'ali' && enableAliRequireAsync)) tarRoot = queryObj.root
if (enableRequireAsync) tarRoot = queryObj.root
}
const parsed = path.parse(resourcePath)
const ext = parsed.ext
Expand Down
20 changes: 11 additions & 9 deletions packages/webpack-plugin/lib/json-compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,17 @@ module.exports = function (content) {
}

// 校验异步组件占位符 componentPlaceholder 不为空
const { usingComponents, componentPlaceholder = {} } = json
if (usingComponents) {
for (const compName in usingComponents) {
const compPath = usingComponents[compName]
if (!/\?root=/g.test(compPath)) continue
const compPlaceholder = componentPlaceholder[compName]
if (!compPlaceholder) {
const errMsg = `componentPlaceholder of "${compName}" doesn't exist! \n\r`
emitError(errMsg)
if (mpx.enableRequireAsync) {
const { usingComponents, componentPlaceholder = {} } = json
if (usingComponents) {
for (const compName in usingComponents) {
const compPath = usingComponents[compName]
if (!/\?root=/g.test(compPath)) continue
const compPlaceholder = componentPlaceholder[compName]
if (!compPlaceholder) {
const errMsg = `componentPlaceholder of "${compName}" doesn't exist! \n\r`
emitError(errMsg)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,25 @@ export function inheritEvent (type, oe, detail = {}) {
}

export function getCustomEvent (type, detail = {}, target = null) {
const targetInfo = {}
if (target) {
const targetEl = target.$el || {}
const info = {
id: targetEl.id || '',
dataset: targetEl.dataset || {},
offsetTop: targetEl.offsetTop || 0,
offsetLeft: targetEl.offsetLeft || 0
}
Object.assign(targetInfo, {
target: info,
currentTarget: info
})
}
return {
type,
detail,
target,
timeStamp: new Date().valueOf()
timeStamp: new Date().valueOf(),
...targetInfo
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
} else {
value = this.getValue()
}
this.$emit('change', getCustomEvent('change', { value }, this.$refs.checkboxGroup))
this.$emit('change', getCustomEvent('change', { value }, this))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@
methods: {
submit () {
const value = getFormValue(this.$slots.default)
this.$emit('submit', getCustomEvent('submit', { value }))
this.$emit('submit', getCustomEvent('submit', { value }, this))
},
reset () {
setFormValue(this.$slots.default, this.initialValue)
this.$emit('reset', getCustomEvent('reset', { value: this.initialValue }))
this.$emit('reset', getCustomEvent('reset', { value: this.initialValue }, this))
}
}
}
Expand Down
26 changes: 11 additions & 15 deletions packages/webpack-plugin/lib/runtime/components/web/mpx-image.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import getInnerListeners, { extendEvent } from './getInnerListeners'
import getInnerListeners, { getCustomEvent } from './getInnerListeners'
export default {
name: 'mpx-image',
Expand All @@ -22,18 +22,14 @@
},
beforeCreate () {
this.image = new Image()
this.image.onload = (e) => {
extendEvent(e, {
detail: {
width: this.image.width,
height: this.image.height
}
})
this.$emit('load', e)
this.image.onload = () => {
this.$emit('load', getCustomEvent('load', {
width: this.image.width,
height: this.image.height
}, this))
}
this.image.onerror = (e) => {
this.$emit('error', e)
this.image.onerror = () => {
this.$emit('error', getCustomEvent('error', {}, this))
}
},
watch: {
Expand All @@ -48,9 +44,9 @@
if (this.mode === 'widthFix' || this.mode === 'heightFix') {
let style
if (this.mode === 'widthFix') {
style = {
height: 'auto'
}
style = {
height: 'auto'
}
} else {
style = {
width: 'auto'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
x: this.roundFun(position.x) ? this.roundFun(position.x) : 0,
y: this.roundFun(position.y) ? this.roundFun(position.y) : 0,
source: this.source
}))
}, this))
}
this.lastestX = this.roundFun(position.x)
this.lastestY = this.roundFun(position.y)
Expand Down Expand Up @@ -215,7 +215,7 @@
this.touchEvent = 'vtouchmove'
}
}
this.$emit(this.touchEvent)
this.$emit(this.touchEvent, getCustomEvent(this.touchEvent, {}, this))
this.isFirstTouch = false
})
if (this.inertia) { // movable-view是否带有惯性
Expand All @@ -233,7 +233,7 @@
x: this.roundFun(this.bs.x),
y: this.roundFun(this.bs.y),
scale: this.roundFun(scale)
}))
}, this))
this.lastestScale = this.roundFun(scale)
})
this.bs.on('zoomEnd', ({ scale }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@
},
notifyChange() {
const value = this.getValue()
this.$emit('change', getCustomEvent('change', {value}))
this.$emit('change', getCustomEvent('change', { value }, this))
},
notifyPickstart(value) {
this.$emit('pickstart', getCustomEvent('pickstart', {value}))
notifyPickstart() {
this.$emit('pickstart', getCustomEvent('pickstart', {}, this))
},
notifyPickend(value) {
this.$emit('pickend', getCustomEvent('pickend', {value}))
notifyPickend() {
this.$emit('pickend', getCustomEvent('pickend', {}, this))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@
default:
value = this.selectedIndex[0]
}
this.$emit('change', getCustomEvent('change', {value}))
this.$emit('change', getCustomEvent('change', {value}, this))
},
_cancel () {
this.hide()
this.$emit('cancel', getCustomEvent('cancel'))
this.$emit('cancel', getCustomEvent('cancel', {}, this))
},
_isMoving () {
return this.wheels.some((wheel) => {
Expand Down Expand Up @@ -327,7 +327,7 @@
this.$emit('columnchange', getCustomEvent('columnchange', {
column: i,
value: currentIndex
}))
}, this))
}
}
if (this.mode === 'time' || this.mode === 'date') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@
ref: 'progress',
on: {
transitionend: () => {
this.$emit('activeend', getCustomEvent('activeend'))
this.$emit('activeend', getCustomEvent('activeend', {
curPercent: this.percent
}, this))
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
} else {
value = this.getValue()
}
this.$emit('change', getCustomEvent('change', { value }, this.$refs.radioGroup))
this.$emit('change', getCustomEvent('change', { value }, this))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
refresherTriggered: {
handler (val) {
if (!val) {
this.$emit('refresherrestore')
this.$emit('refresherrestore', getCustomEvent('refresherrestore', {}, this))
this.isLoading = false
this.isAutoPullDown = true
this.bs && this.bs.finishPullDown()
Expand Down Expand Up @@ -182,7 +182,7 @@
scrollHeight: this.bs.scrollerHeight,
deltaX,
deltaY
}))
}, this))
if (this.bs.minScrollX - x < this._upperThreshold && deltaX > 0) {
this.dispatchScrollTo('left')
}
Expand Down Expand Up @@ -212,7 +212,7 @@
this.$emit('dragstart', getCustomEvent('dragstart', {
scrollLeft: this.bs.x ? this.bs.x * -1 : 0,
scrollTop: this.bs.y ? this.bs.y * -1 : 0
}))
}, this))
}
if (this.refresherEnabled) {
this.isAutoPullDown = false
Expand All @@ -223,13 +223,13 @@
this.$emit('dragging', getCustomEvent('dragging', {
scrollLeft: this.bs.x ? this.bs.x * -1 : 0,
scrollTop: this.bs.y ? this.bs.y * -1 : 0
}))
}, this))
}
if (this.refresherEnabled) {
if (this.bs.y > 0 && this.bs.y < this.refresherThreshold && this.bs.movingDirectionY !== 1) {
this.isAutoPullDown = false
this.isLoading = false
this.$emit('refresherpulling')
this.$emit('refresherpulling', getCustomEvent('refresherpulling', {}, this))
}
}
})
Expand All @@ -238,7 +238,7 @@
this.$emit('dragend', getCustomEvent('dragend', {
scrollLeft: this.bs.x ? this.bs.x * -1 : 0,
scrollTop: this.bs.y ? this.bs.y * -1 : 0
}))
}, this))
}
})
if (this.refresherEnabled) {
Expand All @@ -248,12 +248,12 @@
this.isLoading = true
if (this.bs.y < this.refresherThreshold) {
this.isAutoPullDown = true
this.$emit('refresherabort')
this.$emit('refresherabort', getCustomEvent('refresherabort', {}, this))
}
}
})
this.bs.on('pullingDown', () => {
this.$emit('refresherrefresh')
this.$emit('refresherrefresh', getCustomEvent('refresherrefresh', {}, this))
})
}
}
Expand Down Expand Up @@ -312,7 +312,7 @@
dispatchScrollTo: throttle(function (direction) {
let eventName = 'scrolltoupper'
if (direction === 'bottom' || direction === 'right') eventName = 'scrolltolower'
this.$emit(eventName, getCustomEvent(eventName, { direction }))
this.$emit(eventName, getCustomEvent(eventName, { direction }, this))
}, 200, {
leading: true,
trailing: false
Expand Down
Loading

0 comments on commit 926aaa2

Please sign in to comment.