修复 项目名称和版本号获取

This commit is contained in:
2025-12-01 22:40:41 +08:00
parent b08d955049
commit 6ad59a6ae7
2 changed files with 29 additions and 34 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "uniapp-error-monitor", "name": "uniapp-error-monitor",
"version": "1.0.0", "version": "1.0.1",
"description": "专门为UniApp环境设计的错误监控和上报工具支持全局错误捕获、Promise错误捕获、网络错误捕获等", "description": "专门为UniApp环境设计的错误监控和上报工具支持全局错误捕获、Promise错误捕获、网络错误捕获等",
"main": "dist/index.js", "main": "dist/index.js",
"module": "dist/index.esm.js", "module": "dist/index.esm.js",
@@ -28,12 +28,9 @@
"license": "MIT", "license": "MIT",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/iflow-dev/uniapp-error-monitor.git" "url": "hhttps://git.pandorastudio.cn/product/uniapp-error-monitor.git"
}, },
"bugs": { "homepage": "https://git.pandorastudio.cn",
"url": "https://github.com/iflow-dev/uniapp-error-monitor/issues"
},
"homepage": "https://github.com/iflow-dev/uniapp-error-monitor#readme",
"engines": { "engines": {
"node": ">=14.0.0", "node": ">=14.0.0",
"npm": ">=6.0.0" "npm": ">=6.0.0"
@@ -42,11 +39,9 @@
"build": "rollup -c", "build": "rollup -c",
"dev": "rollup -c -w", "dev": "rollup -c -w",
"clean": "rimraf dist", "clean": "rimraf dist",
"test": "jest",
"test:watch": "jest --watch",
"lint": "eslint src/**/*.js", "lint": "eslint src/**/*.js",
"lint:fix": "eslint src/**/*.js --fix", "lint:fix": "eslint src/**/*.js --fix",
"prepublishOnly": "npm run clean && npm run build && npm test" "prepublishOnly": "npm run clean && npm run build"
}, },
"devDependencies": { "devDependencies": {
"@rollup/plugin-commonjs": "^25.0.0", "@rollup/plugin-commonjs": "^25.0.0",
@@ -55,7 +50,6 @@
"rollup": "^3.0.0", "rollup": "^3.0.0",
"rollup-plugin-terser": "^7.0.0", "rollup-plugin-terser": "^7.0.0",
"typescript": "^5.0.0", "typescript": "^5.0.0",
"jest": "^29.0.0",
"eslint": "^8.0.0", "eslint": "^8.0.0",
"rimraf": "^5.0.0" "rimraf": "^5.0.0"
}, },

View File

@@ -248,23 +248,25 @@ class ErrorMonitor {
_setupMiniProgramErrorHandlers() { _setupMiniProgramErrorHandlers() {
if (typeof uni !== 'undefined') { if (typeof uni !== 'undefined') {
// 监听小程序错误事件 // 监听小程序错误事件
uni.onError && uni.onError(error => { uni.onError &&
this._handleMiniProgramError({ uni.onError(error => {
type: 'miniProgram', this._handleMiniProgramError({
error, type: 'miniProgram',
timestamp: Date.now(), error,
timestamp: Date.now(),
})
}) })
})
// 监听小程序页面错误 // 监听小程序页面错误
uni.onPageNotFound && uni.onPageNotFound(result => { uni.onPageNotFound &&
this._handleMiniProgramError({ uni.onPageNotFound(result => {
type: 'pageNotFound', this._handleMiniProgramError({
path: result.path, type: 'pageNotFound',
query: result.query, path: result.path,
timestamp: Date.now(), query: result.query,
timestamp: Date.now(),
})
}) })
})
// 监听小程序网络请求错误 // 监听小程序网络请求错误
const originalRequest = uni.request const originalRequest = uni.request
@@ -408,9 +410,7 @@ class ErrorMonitor {
} }
// 格式化错误信息 // 格式化错误信息
const message = this.config?.customFormatter const message = this.config?.customFormatter ? this.config.customFormatter(errorInfo) : this._formatErrorMessage(errorInfo)
? this.config.customFormatter(errorInfo)
: this._formatErrorMessage(errorInfo)
// 使用uni.request发送POST请求适配uniapp环境 // 使用uni.request发送POST请求适配uniapp环境
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
@@ -439,10 +439,11 @@ class ErrorMonitor {
*/ */
_formatErrorMessage(errorInfo) { _formatErrorMessage(errorInfo) {
const timestamp = new Date(errorInfo.timestamp).toLocaleString('zh-CN') const timestamp = new Date(errorInfo.timestamp).toLocaleString('zh-CN')
const systemInfo = uni.getSystemInfoSync?.()
let message = `🚨 JavaScript错误报告\n` let message = `🚨 JavaScript错误报告\n`
message += `📦 项目: ${this.projectInfo.name}\n` message += `📦 项目: ${systemInfo.appName || this.projectInfo.name}\n`
message += `🏷️ 版本: ${this.projectInfo.version}\n` message += `🏷️ 版本: ${systemInfo.appVersion || this.projectInfo.version}\n`
message += `⏰ 时间: ${timestamp}\n` message += `⏰ 时间: ${timestamp}\n`
message += `📱 页面: ${errorInfo.page || '未知页面'}\n` message += `📱 页面: ${errorInfo.page || '未知页面'}\n`
message += `🌐 链接: ${errorInfo.url || '未知链接'}\n\n` message += `🌐 链接: ${errorInfo.url || '未知链接'}\n\n`
@@ -644,12 +645,12 @@ class ErrorMonitor {
* @private * @private
*/ */
_getMode() { _getMode() {
if (typeof import !== 'undefined' && import.meta?.env?.MODE) { try {
try { if (import.meta?.env?.MODE) {
return import.meta.env.MODE return import.meta.env.MODE
} catch (error) {
// 忽略访问错误
} }
} catch (error) {
// 忽略访问错误
} }
return 'unknown' return 'unknown'
} }