feat: 遮蔽产物中的 Taro 指纹

H5 预览与小程序产物会带出 taro_tmpl、taro-*-core、taro.js、--taro-button-height、
project.config.json 的 projectname 等指纹,而 Taro 4.3 没有隐藏这些名称的配置。
改为在 build:h5、build:weapp、build:preview 之后按 apps/taro/config/mask.config.json
做构建后处理:

- 同一张替换表同时作用于文件名与文本内容,重命名后引用保持同步,长度 ≥ 40 的 base64/哈希片段原样保留;
- 遮蔽后仍命中 forbidden 词表时构建失败,并把 project.config.json 的 projectname/description 中性化;
- dev:h5、dev:preview 保持原始命名,便于本地调试;改架构名只改 mask.config.json;
- 产物契约测试先用 unmask() 还原再断言,浏览器测试选择器写成 :is(<源码名>, <遮蔽名>)。

取舍与迁移见 docs/adr/0025-build-output-stack-masking.md。
This commit is contained in:
que01 committed 2026-10-13 23:03:32 +08:00
1 parent 53713e5935
commit 9ad2776515
13 files changed
+382 -10

No files matched your search

+9 -5
View File
@@ -1,4 +1,8 @@
import { test, expect } from "@playwright/test";
// 产物会遮蔽 Taro 运行时命名,选择器同时接受源码名称与遮蔽名称。
const BUTTON_CORE = ":is(taro-button-core, appkit-button-core)";
const TABBAR = ":is(.taro-tabbar__tabbar, .appkit-tabbar__tabbar)";
test("真实 API 驱动首页、出摊和主理人视觉槽位", async ({ page }) => {
const errors: string[] = [];
page.on("pageerror", (error) => errors.push(error.message));
@@ -57,7 +61,7 @@ test("餐品搜索、详情和咨询目标传递", async ({ page }) => {
const name = await page.locator(".dish-name").first().textContent();
await page.locator(".offering-card").first().click();
await expect(page.locator(".hero-copy")).toContainText(name!);
await page.locator(".bar taro-button-core").click();
await page.locator(`.bar ${BUTTON_CORE}`).click();
await expect(page.locator(".inquiry-form")).toBeVisible();
await expect(page.locator(".half-field")).toHaveCount(4);
});
@@ -124,17 +128,17 @@ for (const width of [375, 430, 768, 1280]) {
await page.goto("/");
await expect(page.locator(".food-home .name")).toBeVisible();
const expectedWidth = Math.min(width, 430);
const bounds = await page.evaluate(() => {
const bounds = await page.evaluate((tabSelector) => {
const rect = (selector: string) => {
const box = document.querySelector(selector)!.getBoundingClientRect();
return { width: box.width, left: box.left };
};
return {
page: rect(".food-home .page"),
tab: rect(".taro-tabbar__tabbar"),
tab: rect(tabSelector),
overflow: document.documentElement.scrollWidth > window.innerWidth,
};
});
}, TABBAR);
expect(bounds.page.width).toBeCloseTo(expectedWidth, 0);
expect(bounds.tab.width).toBeCloseTo(expectedWidth, 0);
expect(bounds.tab.left).toBeCloseTo(bounds.page.left, 0);
@@ -167,7 +171,7 @@ for (const width of [375, 1280]) {
};
const aboveNavigation = async (selector: string) => {
const bottom = await page.locator(selector).last().boundingBox();
const nav = await page.locator(".taro-tabbar__tabbar").boundingBox();
const nav = await page.locator(TABBAR).boundingBox();
expect(bottom!.y + bottom!.height).toBeLessThan(nav!.y - 8);
};
await page.goto("/");