提交 29b404ee 编写于 作者: fxy060608's avatar fxy060608

feat(ext-api): add warning

上级 397f6324
......@@ -7,7 +7,7 @@ exports.parseInject = exports.parseInjects = exports.parseUniExtApis = void 0;
const path_1 = __importDefault(require("path"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const merge_1 = require("merge");
function parseUniExtApis() {
function parseUniExtApis(vite = true) {
const uniModulesDir = path_1.default.resolve(process.env.UNI_INPUT_DIR, 'uni_modules');
if (!fs_extra_1.default.existsSync(uniModulesDir)) {
return {};
......@@ -25,7 +25,10 @@ function parseUniExtApis() {
}
const exports = (_b = (_a = JSON.parse(fs_extra_1.default.readFileSync(pkgPath, 'utf8'))) === null || _a === void 0 ? void 0 : _a.uni_modules) === null || _b === void 0 ? void 0 : _b['uni-ext-api'];
if (exports) {
Object.assign(injects, parseInjects(process.env.UNI_PLATFORM === 'h5' ? 'web' : process.env.UNI_PLATFORM, `@/uni_modules/${uniModuleDir}`, exports));
Object.assign(injects, parseInjects(vite, process.env.UNI_PLATFORM === 'h5' ? 'web' : process.env.UNI_PLATFORM, `@/uni_modules/${uniModuleDir}` +
(vite || !process.env.UNI_UTS_PLATFORM
? ''
: `/utssdk/${process.env.UNI_UTS_PLATFORM}/index`), exports));
}
});
return injects;
......@@ -52,7 +55,7 @@ exports.parseUniExtApis = parseUniExtApis;
* @param define
* @returns
*/
function parseInjects(platform, source, exports = {}) {
function parseInjects(vite = true, platform, source, exports = {}) {
let rootDefines = {};
Object.keys(exports).forEach((name) => {
if (name.startsWith('uni')) {
......@@ -69,18 +72,18 @@ function parseInjects(platform, source, exports = {}) {
}
const injects = {};
for (const key in rootDefines) {
Object.assign(injects, parseInject(source, 'uni', rootDefines[key]));
Object.assign(injects, parseInject(vite, source, 'uni', rootDefines[key]));
}
return injects;
}
exports.parseInjects = parseInjects;
function parseInject(source, globalObject, define) {
function parseInject(vite = true, source, globalObject, define) {
const injects = {};
if (define === false) {
}
else if (typeof define === 'string') {
// {'uni.getBatteryInfo' : '@dcloudio/uni-getbatteryinfo'}
injects[globalObject + '.' + define] = source;
injects[globalObject + '.' + define] = vite ? source : [source, 'default'];
}
else if (Array.isArray(define)) {
// {'uni.getBatteryInfo' : ['@dcloudio/uni-getbatteryinfo','getBatteryInfo]}
......
......@@ -230,10 +230,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
webpackConfig.resolve.modules = webpackConfig.resolve.modules.filter(module => module !== 'node_modules')
}
const plugins = [
new webpack.ProvidePlugin(require('@dcloudio/uni-cli-shared/lib/uni_modules/uni_modules')
.parseUniExtApis())
]
const plugins = []
const isAppView = process.env.UNI_PLATFORM === 'app-plus' &&
vueOptions.pluginOptions &&
......@@ -245,6 +242,19 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
plugins.push(new CopyWebpackPlugin(CopyWebpackPluginVersion > 5 ? {
patterns
} : patterns))
const uniExtApis = require('@dcloudio/uni-cli-shared/lib/uni_modules/uni_modules')
.parseUniExtApis(false)
const keys = Object.keys(uniExtApis)
if (keys.length) {
if (process.env.UNI_PLATFORM === 'app-plus') {
keys.forEach(key => {
console.warn(`[${uniExtApis[key][0].split('/')[2]}]: uts目前仅支持vue3`)
})
} else {
plugins.push(new webpack.ProvidePlugin(uniExtApis))
}
}
}
if (!process.env.UNI_SUBPACKGE || !process.env.UNI_MP_PLUGIN) {
try {
......
......@@ -148,6 +148,23 @@ if (process.env.UNI_OUTPUT_DIR && process.env.UNI_OUTPUT_DIR.indexOf('./') === 0
process.env.UNI_PLATFORM = process.env.UNI_PLATFORM || 'h5'
process.env.VUE_APP_PLATFORM = process.env.UNI_PLATFORM
process.env.UNI_OUTPUT_DIR = process.env.UNI_OUTPUT_DIR || process.env.UNI_OUTPUT_DEFAULT_DIR
initUtsPlatform()
function initUtsPlatform () {
if (process.env.UNI_APP_PLATFORM === 'android') {
process.env.UNI_UTS_PLATFORM = 'app-android'
}
if (process.env.UNI_APP_PLATFORM === 'ios') {
process.env.UNI_UTS_PLATFORM = 'app-ios'
}
if (process.env.UNI_PLATFORM === 'h5') {
process.env.UNI_UTS_PLATFORM = 'web'
} else {
if (!process.env.UNI_UTS_PLATFORM) {
process.env.UNI_UTS_PLATFORM = process.env.UNI_PLATFORM
}
}
}
if (process.env.UNI_PLATFORM === 'app-plus') {
process.env.UNI_OUTPUT_TMP_DIR = path.resolve(process.env.UNI_OUTPUT_DIR, '../.tmp/app-plus')
......@@ -367,7 +384,9 @@ if (
} else {
uniStatLog(`已开启 uni统计${uniStatistics.version}.0 版本`)
if (version === '2') {
uniStatLog('【重要】因 HBuilderX 3.4.9 版本起,uni统计2.0 调整了安卓端 deviceId 获取方式,导致 uni统计2.0 App-Android平台部分统计数据不准确。如使用了HBuilderX 3.4.9 - 3.6.4版本且开通了uni统计2.0的应用,需要使用HBuilderX3.6.7及以上版本重新发布应用并升级 uniAdmin 云函数解决,详见:https://ask.dcloud.net.cn/article/40097')
uniStatLog(
'【重要】因 HBuilderX 3.4.9 版本起,uni统计2.0 调整了安卓端 deviceId 获取方式,导致 uni统计2.0 App-Android平台部分统计数据不准确。如使用了HBuilderX 3.4.9 - 3.6.4版本且开通了uni统计2.0的应用,需要使用HBuilderX3.6.7及以上版本重新发布应用并升级 uniAdmin 云函数解决,详见:https://ask.dcloud.net.cn/article/40097'
)
}
}
}
......@@ -379,7 +398,9 @@ if (
} else {
uniStatLog(`已开启 uni统计${uniStatistics.version}.0 版本`)
if (version === '2') {
uniStatLog('【重要】因 HBuilderX 3.4.9 版本起,uni统计2.0 调整了安卓端 deviceId 获取方式,导致 uni统计2.0 App-Android平台部分统计数据不准确。如使用了HBuilderX 3.4.9 - 3.6.4版本且开通了uni统计2.0的应用,需要使用HBuilderX3.6.7及以上版本重新发布应用并升级 uniAdmin 云函数解决,详见:https://ask.dcloud.net.cn/article/40097')
uniStatLog(
'【重要】因 HBuilderX 3.4.9 版本起,uni统计2.0 调整了安卓端 deviceId 获取方式,导致 uni统计2.0 App-Android平台部分统计数据不准确。如使用了HBuilderX 3.4.9 - 3.6.4版本且开通了uni统计2.0的应用,需要使用HBuilderX3.6.7及以上版本重新发布应用并升级 uniAdmin 云函数解决,详见:https://ask.dcloud.net.cn/article/40097'
)
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册