Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:white_check_mark: Guard export renderer platform branches https://github.com/siyuan-note/siyuan/issues/20229

Daniel3e566bb222cf
diff --git a/app/tests/exportDependencyBoundary.test.js b/app/tests/exportDependencyBoundary.test.js
index 2005316508..5ec4789fca 100644
--- a/app/tests/exportDependencyBoundary.test.js
+++ b/app/tests/exportDependencyBoundary.test.js
@@ -14,7 +14,7 @@ const options = {...loaders.find(loader => loader.loader === "ifdef-loader").opt
delete options["ifdef-verbose"];
// 按导出包的条件编译与类型擦除流程检查静态和动态依赖,不生成构建产物。
-const getExportDependencies = () => {
+const getExportDependencies = (compileOptions = options) => {
const visited = new Set();
const pending = [path.join(root, "protyle/method.ts")];
while (pending.length) {
@@ -24,7 +24,7 @@ const getExportDependencies = () => {
}
visited.add(file);
const original = readFileSync(file, "utf8");
- const code = file.endsWith(".ts") ? transformSync(parse(original, options, false), {
+ const code = file.endsWith(".ts") ? transformSync(parse(original, compileOptions, false), {
loader: "ts", target: "es6", format: "esm",
}).code : original;
const source = ts.createSourceFile(file, code, ts.ScriptTarget.Latest, true);
@@ -66,3 +66,13 @@ test("export rendering keeps application UI outside its runtime dependency graph
assert.ok(dependencies.includes("protyle/render/listMindmap/legacy.ts"), "Legacy mind map rendering must remain available");
t.diagnostic(`Export renderer runtime dependency graph: ${dependencies.length} modules`);
});
+
+test("export rendering has no desktop-only branches or platform-dependent dependencies", () => {
+ const dependencies = getExportDependencies();
+ const desktopDependencies = getExportDependencies({...options, MOBILE: false});
+ assert.deepEqual([...dependencies].sort(), [...desktopDependencies].sort(),
+ "Export rendering dependencies must not depend on the MOBILE flag");
+ const desktopBranches = dependencies.filter(file =>
+ /^\s*\/\/\/\s*#(?:if|elif)\b[^\r\n]*!\s*MOBILE\b/m.test(readFileSync(path.join(root, file), "utf8")));
+ assert.deepEqual(desktopBranches, [], "Export rendering must not silently discard desktop-only branches");
+});
diff --git a/app/webpack.export.js b/app/webpack.export.js
index 4bf0e8352e..b4e9545814 100644
--- a/app/webpack.export.js
+++ b/app/webpack.export.js
@@ -59,6 +59,8 @@ module.exports = (env, argv) => {
options: {
"ifdef-verbose": false,
BROWSER: true,
+ // 用于隔离应用界面依赖,不表示导出页的运行平台,见 #5326、#20219。
+ // 导出依赖边界测试同时检查桌面分支,防止渲染逻辑被静默裁剪。
MOBILE: true,
},
},