@lark-apaas/client-toolkit 1.2.63 → 1.2.64-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/AppContainer/__test__/standalone.test.d.ts +1 -0
- package/lib/components/AppContainer/__test__/standalone.test.js +36 -0
- package/lib/components/AppContainer/index.js +2 -1
- package/lib/components/AppContainer/standalone.d.ts +17 -0
- package/lib/components/AppContainer/standalone.js +8 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
describe('isStandaloneBuild', ()=>{
|
|
3
|
+
afterEach(()=>{
|
|
4
|
+
delete process.env.MIAODA_BUILD_TARGET;
|
|
5
|
+
vi.resetModules();
|
|
6
|
+
});
|
|
7
|
+
async function load() {
|
|
8
|
+
vi.resetModules();
|
|
9
|
+
return (await import("../standalone.js")).isStandaloneBuild;
|
|
10
|
+
}
|
|
11
|
+
it('MIAODA_BUILD_TARGET=standalone → true', async ()=>{
|
|
12
|
+
process.env.MIAODA_BUILD_TARGET = 'standalone';
|
|
13
|
+
expect((await load())()).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
it('未设置 → false(平台正常构建,徽标照常显示)', async ()=>{
|
|
16
|
+
expect((await load())()).toBe(false);
|
|
17
|
+
});
|
|
18
|
+
it('其它取值 → false(--mode 将来扩展新形态时不误判为 standalone)', async ()=>{
|
|
19
|
+
process.env.MIAODA_BUILD_TARGET = 'something-else';
|
|
20
|
+
expect((await load())()).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
it('精确匹配,不做前缀/包含判断', async ()=>{
|
|
23
|
+
process.env.MIAODA_BUILD_TARGET = 'standalone-v2';
|
|
24
|
+
expect((await load())()).toBe(false);
|
|
25
|
+
});
|
|
26
|
+
it('没有 process 全局时返回 false 而不是抛错', async ()=>{
|
|
27
|
+
const isStandaloneBuild = await load();
|
|
28
|
+
const original = globalThis.process;
|
|
29
|
+
delete globalThis.process;
|
|
30
|
+
try {
|
|
31
|
+
expect(isStandaloneBuild()).toBe(false);
|
|
32
|
+
} finally{
|
|
33
|
+
globalThis.process = original;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -12,6 +12,7 @@ import { useAppInfo } from "../../hooks/index.js";
|
|
|
12
12
|
import { TrackKey } from "../../types/tea.js";
|
|
13
13
|
import { slardar } from "@lark-apaas/internal-slardar";
|
|
14
14
|
import Watermark, { isDoubaoSource } from "./Watermark.js";
|
|
15
|
+
import { isStandaloneBuild } from "./standalone.js";
|
|
15
16
|
import { getAppId } from "../../utils/getAppId.js";
|
|
16
17
|
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
17
18
|
import QueryProvider from "../QueryProvider/index.js";
|
|
@@ -200,7 +201,7 @@ const AppContainer_AppContainer = (props)=>{
|
|
|
200
201
|
};
|
|
201
202
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
202
203
|
children: [
|
|
203
|
-
/*#__PURE__*/ jsx(SafetyErrorBoundary, {
|
|
204
|
+
!isStandaloneBuild() && /*#__PURE__*/ jsx(SafetyErrorBoundary, {
|
|
204
205
|
children: isDoubaoSource() ? /*#__PURE__*/ jsx(Watermark, {}) : /*#__PURE__*/ jsx(Suspense, {
|
|
205
206
|
fallback: null,
|
|
206
207
|
children: /*#__PURE__*/ jsx(Safety, {})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 是否为 standalone 导出构建(`miaoda app pack --mode standalone`)。
|
|
3
|
+
*
|
|
4
|
+
* standalone 产物脱离妙搭平台、以 `file://` 离线打开,平台徽标(Safety「由妙搭搭建」/
|
|
5
|
+
* 豆包水印)在这里既无意义也无从校验 —— 它们的显隐判据全是 **fail-open** 的:
|
|
6
|
+
* `showBadge` 拿不到平台数据就默认 true、接口失败也 catch 成 true,于是离线产物里
|
|
7
|
+
* 徽标必然出现,还附带两个必然失败的 `tenant_info` / `get_published` 请求。
|
|
8
|
+
* 所以 gate 在挂载处,让整棵子树不渲染,连 effect 里的请求一起省掉。
|
|
9
|
+
*
|
|
10
|
+
* `MIAODA_BUILD_TARGET` 由构建 preset 在 standalone 模式下 define 注入。
|
|
11
|
+
*
|
|
12
|
+
* **必须 try/catch**:客户端 bundle 里没有 `process` 全局,所有 `process.env.X` 全靠
|
|
13
|
+
* 构建期 define 做字符串替换。若应用升级了本 SDK 却仍用**旧版 preset**(不认识这个 key),
|
|
14
|
+
* 该表达式不会被替换,运行时直接 `ReferenceError: process is not defined` 把整个应用打挂。
|
|
15
|
+
* 与同目录 `Watermark.tsx` 的 `isDoubaoSource()` 同一防御口径。
|
|
16
|
+
*/
|
|
17
|
+
export declare const isStandaloneBuild: () => boolean;
|