提交 777dac29 编写于 作者: 雪洛's avatar 雪洛

fix: require hooks error

上级 82c75412
const path = require('path')
const fs = require('fs')
const { const {
getWeixinPlatform getWeixinPlatform
} = require('./weixin') } = require('./weixin')
const createConfig = require('uni-config-center')
const requiredConfig = { const requiredConfig = {
'web.h5-weixin': ['appid', 'appsecret'], 'web.h5-weixin': ['appid', 'appsecret'],
...@@ -13,6 +12,11 @@ const requiredConfig = { ...@@ -13,6 +12,11 @@ const requiredConfig = {
'mp-alipay.alipay': ['appid', 'privateKey'], 'mp-alipay.alipay': ['appid', 'privateKey'],
'app.apple': ['bundleId'] 'app.apple': ['bundleId']
} }
const uniIdConfig = createConfig({
pluginId: 'uni-id'
})
class ConfigUtils { class ConfigUtils {
constructor ({ constructor ({
context context
...@@ -61,14 +65,17 @@ class ConfigUtils { ...@@ -61,14 +65,17 @@ class ConfigUtils {
getPlatformConfig () { getPlatformConfig () {
const appConfig = this.getAppConfig() const appConfig = this.getAppConfig()
if (!appConfig) { if (!appConfig) {
throw new Error(`Config for current app (${this.appId}) was not found, please check your config file or client appId`) throw new Error(
`Config for current app (${this.appId}) was not found, please check your config file or client appId`)
} }
const platform = this.platform const platform = this.platform
if ( if (
(this.platform === 'app' && appConfig['app-plus']) || (this.platform === 'app' && appConfig['app-plus']) ||
(this.platform === 'web' && appConfig.h5) (this.platform === 'web' && appConfig.h5)
) { ) {
throw new Error(`Client platform is ${this.platform}, but ${this.platform === 'web' ? 'h5' : 'app-plus'} was found in config. Please refer to: https://uniapp.dcloud.net.cn/uniCloud/uni-id-summary?id=m-to-co`) throw new Error(
`Client platform is ${this.platform}, but ${this.platform === 'web' ? 'h5' : 'app-plus'} was found in config. Please refer to: https://uniapp.dcloud.net.cn/uniCloud/uni-id-summary?id=m-to-co`
)
} }
const defaultConfig = { const defaultConfig = {
...@@ -116,10 +123,10 @@ class ConfigUtils { ...@@ -116,10 +123,10 @@ class ConfigUtils {
} }
getHooks () { getHooks () {
const configPath = require.resolve('uni-config-center/uni-id') if (uniIdConfig.hasFile('hooks/index.js')) {
const hookPath = path.resolve(configPath, 'hooks/index.js') return require(
if (fs.existsSync(hookPath)) { uniIdConfig.resolve('hooks/index.js')
return require(hookPath) )
} }
return {} return {}
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册