Commit 004711a5 by 张立顺

test: gate miniprogram npm pruning

1 parent 469c62cd
# miniprogram_npm 体积优化接口清单
## 业务接口
本次迁移不新增、删除或修改任何业务 API、请求参数、响应结构或页面路由。
## 构建接口
- `project.config.json.setting.packNpmManually = true`
- `project.config.json.setting.packNpmRelationList[0] = { "packageJsonPath": "./package.json", "miniprogramNpmDistDir": "./" }`
- `pruneGeneratedNpmArtifacts(projectRoot)` 返回 `{ removedNestedNpm: boolean, removedSourceMaps: number }`。
- `scripts/wx-upload-guard.js` 在静态依赖闭包检查前调用裁剪函数。
## 运行时依赖
- 保留:`glsk-applet-component/GlsxPrivacy/index`。
- 删除:仓库业务源码无引用的 `glsx-applet-component`。
{
"id": "miniprogram-npm-size-reduction",
"title": "miniprogram_npm 插件与上传产物体积优化",
"sourceProject": "dj-car-boutique-work-wechat",
"affectedPaths": [
"package.json",
"package-lock.json",
"yarn.lock",
"project.config.json",
"project.private.config.json",
"scripts/wx-upload-guard.js",
"scripts/prune-miniprogram-npm.js",
"tests/work-order-migration/upload-config.test.mjs",
"tests/work-order-migration/npm-upload-prune.test.mjs",
"tests/work-order-migration/npm-dependency-prune.test.mjs",
"docs/migrations/miniprogram-npm-size-reduction"
],
"interfaces": [
"WeChat DevTools manual npm packaging configuration",
"pruneGeneratedNpmArtifacts(projectRoot)"
],
"tests": [
{
"id": "npm-dependency-prune",
"file": "tests/work-order-migration/npm-dependency-prune.test.mjs",
"level": "unit",
"expectedBefore": "fail"
},
{
"id": "npm-artifact-prune",
"file": "tests/work-order-migration/npm-upload-prune.test.mjs",
"level": "unit",
"expectedBefore": "pass"
},
{
"id": "upload-config-boundary",
"file": "tests/work-order-migration/upload-config.test.mjs",
"level": "integration",
"expectedBefore": "pass"
}
],
"baseline": {
"command": "git rev-parse --short 70c239a",
"result": "70c239a"
},
"apiInventory": "docs/migrations/miniprogram-npm-size-reduction/api-inventory.md",
"acceptance": "docs/migrations/miniprogram-npm-size-reduction/test-acceptance.md"
}
# miniprogram_npm 体积优化验收
## 基线
| 指标 | 基线值 |
| --- | --- |
| `miniprogram_npm` 文件数 | 712 |
| `miniprogram_npm` 字节数 | 1,648,929 |
| source map 数量 | 49 |
| source map 字节数 | 540,083 |
| `glsx-applet-component` 文件数 | 118 |
| `glsx-applet-component` 字节数 | 423,591 |
## 预期后置状态
- `miniprogram_npm` 中 source map 数量为 0。
- 不再生成 `miniprogram_npm/glsx-applet-component`。
- 保留隐私组件 `glsk-applet-component/GlsxPrivacy/index` 及其 `app.json` 注册。
## 验证命令
```powershell
npm run test:workOrderMigration
npm run check:workOrderClosure
```
import assert from 'node:assert/strict'
import { 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('mini-program npm dependency pruning', () => {
it('removes the unused glsx component plugin from every dependency manifest', async () => {
const packageJson = JSON.parse(
await readFile(path.join(projectRoot, 'package.json'), 'utf8')
)
const packageLock = JSON.parse(
await readFile(path.join(projectRoot, 'package-lock.json'), 'utf8')
)
const yarnLock = await readFile(path.join(projectRoot, 'yarn.lock'), 'utf8')
assert.equal(packageJson.dependencies['glsx-applet-component'], undefined)
assert.equal(
packageLock.packages[''].dependencies['glsx-applet-component'],
undefined
)
assert.equal(
packageLock.packages['node_modules/glsx-applet-component'],
undefined
)
assert.doesNotMatch(yarnLock, /^glsx-applet-component@/m)
})
it('keeps the privacy component dependency used by app.json', async () => {
const packageJson = JSON.parse(
await readFile(path.join(projectRoot, 'package.json'), 'utf8')
)
const appConfig = JSON.parse(
await readFile(path.join(projectRoot, 'app.json'), 'utf8')
)
assert.equal(packageJson.dependencies['glsk-applet-component'], '^1.0.0')
assert.equal(
appConfig.usingComponents['glsx-privacy'],
'glsk-applet-component/GlsxPrivacy/index'
)
})
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!