Skip to content

Commit

Permalink
Merge pull request #1819 from AdamCaoQAQ/feat_hummer_mode
Browse files Browse the repository at this point in the history
bugfix: 修改hummer运行时报错(prop缺失)&API util缺失
  • Loading branch information
Blackgan3 authored Jan 17, 2025
2 parents 6aa26fa + 7fab7fb commit 18003c8
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/api-proxy/src/common/js/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './web'
export * from './utils'
export * from './toPromise'
export * from './toPromise'
80 changes: 80 additions & 0 deletions packages/api-proxy/src/platform/api/request/tenonUtil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
function typeEqual (obj, type) {
return Object.prototype.toString.call(obj) === '[object ' + type + ']'
}

function isStr (obj) {
return typeEqual(obj, 'String')
}

export function queryParse (search = '') {
const arr = search.split(/(\?|&)/)
const parmsObj = {}

for (let i = 0; i < arr.length; i++) {
if (arr[i].indexOf('=') !== -1) {
const keyValue = arr[i].match(/([^=]*)=(.*)/)
parmsObj[keyValue[1]] = decodeURIComponent(keyValue[2])
}
}

if (JSON.stringify(parmsObj) === '{}') {
// 如果解析失败,返回原值
return search
}

return parmsObj
}

export function tryJsonParse (some) {
// 这里eslint提示也先别删除\[\]
// eslint-disable-next-line no-useless-escape
if (isStr(some) && /[\{\[].*[\}\]]/.test(some)) {
try {
some = JSON.parse(some)
} catch (err) {}
}

return some
}

export function parseHeader (headers) {
// fetch中的headers value为数组形式,其他端为字符串形式, 统一为字符串
// header的key值统一为小写
const result = {}
Object.keys(headers).forEach(key => {
let value = headers[key]

if (value instanceof Array) {
value = value[0]
}

result[key.toLowerCase()] = value
})
return JSON.stringify(result)
}

export function queryStringify (obj) {
const strArr = []
let keys = null

if (obj && Object.keys(obj).length > 0) {
keys = Object.keys(obj)

for (let i = 0; i < keys.length; i++) {
const key = keys[i]
strArr.push(`${key}=${encodeURIComponent(obj[key])}`)
}
}

return strArr.join('&')
}
export function buildQueryStringUrl (params, url = '') {
if (!url) return queryStringify(params)
let retUrl = url

if (queryStringify(params)) {
retUrl = url.indexOf('?') > -1 ? `${url}&${queryStringify(params)}` : `${url}?${queryStringify(params)}`
}

return retUrl
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function initProxy (context, rawOptions) {
}
}

export function getDefaultOptions ({type, rawOptions = {}, currentInject }) {
export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
const rawSetup = rawOptions.setup
if (rawSetup) {
rawOptions.setup = (props) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-plugin/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,7 @@ try {
if (tenonStyleLoaderIndex > -1 && !isPitcherRequest) {
loaders.splice(tenonStyleLoaderIndex + 1, 0, {
loader: normalize.lib('style-compiler/index.js'),
options: (mpxStyleOptions && JSON.parse(mpxStyleOptions)) || {}
options: (queryObj.mpxStyleOptions && JSON.parse(queryObj.mpxStyleOptions)) || {}
})
}
} else if (mpxStyleLoaderIndex === -1) {
Expand Down
1 change: 0 additions & 1 deletion packages/webpack-plugin/lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ module.exports = function (content) {
const hasComment = templateAttrs && templateAttrs.comments
const isNative = false


if (mode === 'tenon') {
let output = ''
if (ctorType === 'app' && !queryObj.app) {
Expand Down
6 changes: 3 additions & 3 deletions packages/webpack-plugin/lib/runtime/optionProcessor.tenon.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function processComponentOption (
componentGenerics,
genericsInfo,
wxsMixin,
hasApp,
hasApp
}
) {
if (ctorType === 'app') {
Expand Down Expand Up @@ -48,9 +48,9 @@ export function processComponentOption (

if (wxsMixin) {
if (option.mixins) {
option.mixins.push(mixin)
option.mixins.push(wxsMixin)
} else {
option.mixins = [mixin]
option.mixins = [wxsMixin]
}
}

Expand Down
9 changes: 2 additions & 7 deletions packages/webpack-plugin/lib/tenon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ const processTemplate = require('./processTemplate')
const processStyles = require('./processStyles')
const processScript = require('./processScript')
const RecordLoaderContentDependency = require('../dependencies/RecordLoaderContentDependency')
const {stringifyRequest} = require('./script-helper')
const { stringifyRequest } = require('./script-helper')
const addQuery = require('../utils/add-query')
const parseRequest = require('../utils/parse-request')



module.exports = function ({
parts,
jsonContent,
Expand All @@ -30,15 +28,12 @@ module.exports = function ({
autoScope,
callback
}) {

let output = ''


const mpx = loaderContext.getMpx()
// const hasComment = parts.template && parts.template.attrs && parts.template.attrs.comments
// const isNative = false
const mode = mpx.mode
// const srcMode = mpx.srcMode
srcMode = mpx.srcMode
const env = mpx.env
const defs = mpx.defs
const resolveMode = mpx.resolveMode
Expand Down
5 changes: 0 additions & 5 deletions packages/webpack-plugin/lib/tenon/processScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const async = require('async')
const createJSONHelper = require('../json-compiler/helper')
const addQuery = require('../utils/add-query')



const {
buildComponentsMap,
getRequireScript,
Expand All @@ -33,7 +31,6 @@ module.exports = function (script, {
}, callback) {
const { projectRoot, appInfo, webConfig } = loaderContext.getMpx()


// add entry
// const checkEntryDeps = (callback) => {
// callback = callback || cacheCallback
Expand Down Expand Up @@ -146,10 +143,8 @@ module.exports = function (script, {
hasApp = false
}


// 获取组件集合
const componentsMap = buildComponentsMap({ localComponentsMap, builtInComponentsMap, loaderContext, jsonConfig })

// 获取pageConfig
const pageConfig = {}
if (ctorType === 'page') {
Expand Down
3 changes: 1 addition & 2 deletions packages/webpack-plugin/lib/tenon/processTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const addQuery = require('../utils/add-query')
const path = require('path')
const parseRequest = require('../utils/parse-request')


module.exports = function (template, {
loaderContext,
hasScoped,
Expand Down Expand Up @@ -84,7 +83,7 @@ module.exports = function (template, {
// web模式下全局组件不会被合入usingComponents中,故globalComponents可以传空
globalComponents: [],
// web模式下实现抽象组件
componentGenerics,
componentGenerics
})
// if (parsed.meta.wxsModuleMap) {
// wxsModuleMap = parsed.meta.wxsModuleMap
Expand Down

0 comments on commit 18003c8

Please sign in to comment.