Commit 701241a2 by 张立顺

perf: trim privacy component and remove sentry

1 parent 5c17d02b
//app.js
// 初始化sentry
import sentryInit from '~/utils/sentryConfig/sentryInit'
const sentry = sentryInit()
wx.$sendSentry = function (e) {
sentry.captureException(e)
}
// 解决showLoading 和 showToast显示异常的问题
import fixWxShowToast from './utils/lib/fixWxShowToast'
fixWxShowToast()
......
......@@ -87,8 +87,6 @@ export const ALIYUN = ALIYUN_LIST[1];
// 报价单图片地址
export const quotedImgUrl = createQuotedUrl[target[envIndex]];
export const scoket_url = scoketURL[target[envIndex]];
// sentry Dsn 地址
export const dsnUrl = "https://6b10bd312d154ff3a4664772bb4e50f5@sentry.glsx.com.cn/49";
// 图片基地址
export const ImgUrl = "https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat";
......
......@@ -4,8 +4,8 @@
## 规模
- 节点:4240
- 关系:8117
- 节点:4236
- 关系:8106
- 未解析:88
## 节点类型
......@@ -17,11 +17,11 @@
| document | 83 |
| domain | 6 |
| endpoint | 234 |
| globalState | 33 |
| method | 2928 |
| module | 366 |
| globalState | 32 |
| method | 2926 |
| module | 364 |
| page | 71 |
| test | 78 |
| test | 79 |
## 关系类型
......@@ -31,14 +31,14 @@
| calls | 885 |
| callsApi | 221 |
| callsEndpoint | 332 |
| contains | 710 |
| contains | 708 |
| coveredBy | 63 |
| declares | 2929 |
| declares | 2927 |
| definesApi | 332 |
| documentedBy | 53 |
| imports | 440 |
| imports | 437 |
| navigatesTo | 71 |
| readsState | 777 |
| readsState | 773 |
| usesComponent | 314 |
| writesState | 51 |
......
......@@ -4,8 +4,8 @@
| 来源 | 目标页面 | 证据 |
| --- | --- | --- |
| `app.js` | `pages/wxLogin/wxLogin` | `app.js:207` |
| `app.js` | `pages/wxLogin/wxLogin` | `app.js:227` |
| `app.js` | `pages/wxLogin/wxLogin` | `app.js:201` |
| `app.js` | `pages/wxLogin/wxLogin` | `app.js:221` |
| `packageStudy/pages/aiCheck/detail/components/fluent/fluent.js` | `packageStudy/pages/aiCheck/redundance/redundance` | `packageStudy/pages/aiCheck/detail/components/fluent/fluent.js:77` |
| `packageStudy/pages/aiCheck/detail/detail.js` | `packageStudy/pages/aiCheck/scene/scene` | `packageStudy/pages/aiCheck/detail/detail.js:36` |
| `packageStudy/pages/aiCheck/detail/detail.js` | `packageStudy/pages/aiCheck/scene/scene` | `packageStudy/pages/aiCheck/detail/detail.js:40` |
......
......@@ -22,7 +22,7 @@
| page | 18 |
| component | 23 |
| apiOperation | 0 |
| globalState | 1 |
| globalState | 0 |
| test | 0 |
| document | 1 |
......@@ -54,7 +54,6 @@
| component | `packageStudy/pages/sceneMarket/components/material/material` |
| component | `packageStudy/pages/sceneMarket/components/materialTab/materialTab` |
| document | `docs/README.md` |
| globalState | `wx.$sendSentry` |
| page | `packageStudy/pages/aiCheck/chat/chat` |
| page | `packageStudy/pages/aiCheck/defense/defense` |
| page | `packageStudy/pages/aiCheck/detail/detail` |
......
......@@ -634,7 +634,7 @@ Page({
// 如果重试次数小于1,则重试一次
this.getEnhancement(last_message, idx, retryCount + 1);
}
wx.$sendSentry(name + "获取改进建议和润色表达" + JSON.stringify(e));
console.error(name + "获取改进建议和润色表达" + JSON.stringify(e));
});
},
getHistory() {
......@@ -1021,4 +1021,4 @@ Page({
}
});
},
});
\ No newline at end of file
});
......@@ -84,7 +84,7 @@ Component({
const {
name
} = wx.$util.getUserInfo();
wx.$sendSentry(name+'语音识别连接失败')
console.error(name+'语音识别连接失败')
console.log("sr is null")
return
}
......@@ -112,7 +112,7 @@ Component({
await sr.start(param)
this.data.srStart = true
} catch (e) {
wx.$sendSentry('语音转文字连接失败' + JSON.stringify(e))
console.error('语音转文字连接失败' + JSON.stringify(e))
console.log("start failed:" + e)
return
}
......@@ -152,7 +152,7 @@ Component({
})
wx.getRecorderManager().onError((res) => {
console.log("recording failed:" + res)
wx.$sendSentry('语音转文字失败' + JSON.stringify(res))
console.error('语音转文字失败' + JSON.stringify(res))
// this.connectSr()
})
try {
......@@ -248,4 +248,4 @@ Component({
})
},1500),
}
})
\ No newline at end of file
})
const fs = require('node:fs')
const path = require('node:path')
const packageEntryAllowlists = new Map([
['glsk-applet-component', new Set(['GlsxPrivacy'])]
])
function collectSourceMaps(directory, result = []) {
if (!fs.existsSync(directory)) return result
......@@ -19,11 +23,26 @@ function pruneGeneratedNpmArtifacts(projectRoot) {
const npmRoot = path.resolve(projectRoot, 'miniprogram_npm')
const nestedNpmRoot = path.join(npmRoot, 'miniprogram_npm')
const removedNestedNpm = fs.existsSync(nestedNpmRoot)
let removedUnusedPackageEntries = 0
if (removedNestedNpm) {
fs.rmSync(nestedNpmRoot, { recursive: true, force: true })
}
for (const [packageName, allowedEntries] of packageEntryAllowlists) {
const packageRoot = path.join(npmRoot, packageName)
if (!fs.existsSync(packageRoot)) continue
for (const entry of fs.readdirSync(packageRoot, { withFileTypes: true })) {
if (allowedEntries.has(entry.name)) continue
fs.rmSync(path.join(packageRoot, entry.name), {
recursive: entry.isDirectory(),
force: true
})
removedUnusedPackageEntries += 1
}
}
const sourceMaps = collectSourceMaps(npmRoot)
for (const sourceMap of sourceMaps) {
fs.rmSync(sourceMap, { force: true })
......@@ -31,7 +50,8 @@ function pruneGeneratedNpmArtifacts(projectRoot) {
return {
removedNestedNpm,
removedSourceMaps: sourceMaps.length
removedSourceMaps: sourceMaps.length,
removedUnusedPackageEntries
}
}
......
......@@ -14,7 +14,7 @@ if (nodeMajor < 24) {
const pruneResult = pruneGeneratedNpmArtifacts(projectRoot)
console.log(
`[wx-upload-guard] npm artifacts pruned; nested=${pruneResult.removedNestedNpm}; sourceMaps=${pruneResult.removedSourceMaps}`
`[wx-upload-guard] npm artifacts pruned; nested=${pruneResult.removedNestedNpm}; sourceMaps=${pruneResult.removedSourceMaps}; packageEntries=${pruneResult.removedUnusedPackageEntries}`
)
function runGuard(scriptName, label) {
......
......@@ -12,6 +12,72 @@ const testDir = path.dirname(fileURLToPath(import.meta.url))
const projectRoot = path.resolve(testDir, '../..')
describe('npm upload artifact pruning', () => {
it('keeps only the used privacy component from glsk-applet-component', async t => {
const fixtureRoot = await mkdtemp(path.join(os.tmpdir(), 'wx-npm-prune-'))
t.after(() => rm(fixtureRoot, { recursive: true, force: true }))
const privacyRoot = path.join(
fixtureRoot,
'miniprogram_npm',
'glsk-applet-component',
'GlsxPrivacy'
)
const unusedComponentRoot = path.join(
fixtureRoot,
'miniprogram_npm',
'glsk-applet-component',
'GLIcon'
)
const unrelatedPackageRoot = path.join(
fixtureRoot,
'miniprogram_npm',
'unrelated-package'
)
await Promise.all([
mkdir(privacyRoot, { recursive: true }),
mkdir(unusedComponentRoot, { recursive: true }),
mkdir(unrelatedPackageRoot, { recursive: true })
])
await Promise.all([
writeFile(path.join(privacyRoot, 'index.js'), 'Component({})'),
writeFile(path.join(unusedComponentRoot, 'index.js'), 'Component({})'),
writeFile(
path.join(
fixtureRoot,
'miniprogram_npm',
'glsk-applet-component',
'utils.js'
),
'module.exports = {}'
),
writeFile(
path.join(unrelatedPackageRoot, 'index.js'),
'module.exports = {}'
)
])
const { pruneGeneratedNpmArtifacts } = require(
'../../scripts/prune-miniprogram-npm.js'
)
const result = pruneGeneratedNpmArtifacts(fixtureRoot)
assert.equal(existsSync(path.join(privacyRoot, 'index.js')), true)
assert.equal(existsSync(unusedComponentRoot), false)
assert.equal(
existsSync(
path.join(
fixtureRoot,
'miniprogram_npm',
'glsk-applet-component',
'utils.js'
)
),
false
)
assert.equal(existsSync(path.join(unrelatedPackageRoot, 'index.js')), true)
assert.equal(result.removedUnusedPackageEntries, 2)
})
it('removes only nested npm output and source maps', async t => {
const fixtureRoot = await mkdtemp(path.join(os.tmpdir(), 'wx-npm-prune-'))
t.after(() => rm(fixtureRoot, { recursive: true, force: true }))
......@@ -45,7 +111,8 @@ describe('npm upload artifact pruning', () => {
)
assert.deepEqual(pruneGeneratedNpmArtifacts(fixtureRoot), {
removedNestedNpm: false,
removedSourceMaps: 0
removedSourceMaps: 0,
removedUnusedPackageEntries: 0
})
})
......
import assert from 'node:assert/strict'
import { access, readFile } from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { describe, it } from 'node:test'
const projectRoot = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'../..'
)
describe('Sentry removal boundary', () => {
it('ships no Sentry SDK, bootstrap, DSN, or runtime reporter calls', async () => {
const removedArtifacts = [
'utils/lib/sentry-miniapp.js',
'utils/sentryConfig/sentryInit.js'
]
for (const relativePath of removedArtifacts) {
await assert.rejects(
access(path.join(projectRoot, relativePath)),
error => error?.code === 'ENOENT',
`Sentry artifact must not ship: ${relativePath}`
)
}
const runtimeFiles = [
'app.js',
'config.js',
'packageStudy/pages/aiCheck/chat/chat.js',
'packageStudy/pages/aiCheck/components/SpeechPopup/SpeechPopup.js'
]
const runtimeSource = (
await Promise.all(
runtimeFiles.map(relativePath =>
readFile(path.join(projectRoot, relativePath), 'utf8')
)
)
).join('\n')
assert.doesNotMatch(runtimeSource, /sentry|\$sendSentry|dsnUrl/i)
})
})
import { dsnUrl } from '~/config'
import * as Sentry from '~/utils/lib/sentry-miniapp'
import { env } from '~/config'
// console.log(env, 'env')
export default function sentryInit() {
//测试和生产才开启sentry
const envNameList = ['trial', 'release']
envNameList.includes(env) &&
Sentry.init({
dsn: dsnUrl
})
return Sentry
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!