soma-core 1.3.1 → 1.3.3
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/README.md +42 -0
- package/app/SomaPageClient.tsx +39 -2
- package/app/[...path]/page.tsx +7 -6
- package/app/api/[...path]/route.ts +3 -3
- package/app/api/soma-registry/[...path]/route.ts +67 -0
- package/app/components/SomaHostPage.tsx +3 -8
- package/app/components/SomaPageClientBoundary.tsx +13 -0
- package/app/layout.tsx +6 -1
- package/app/page.tsx +3 -3
- package/app/soma/manifest/route.ts +1 -0
- package/app/soma/page-object/route.ts +1 -1
- package/core/build/compiler/full-manifest-builder.ts +6 -1
- package/core/build/compiler/rollup-plugin-soma.ts +6 -0
- package/core/build/compiler/soma-manifest-webpack-plugin.js +4 -0
- package/core/build/compiler/soma-precompile.js +3507 -2387
- package/core/build/compiler/soma-precompile.ts +31 -2
- package/core/build/compiler/soma-rspack-yaml-loader.js +3 -0
- package/core/build/compiler/soma-webpack-loader.js +7 -1
- package/core/build/compiler/vite-plugin-soma.ts +11 -1
- package/core/build/component/package-loader.ts +135 -0
- package/core/build/eject/apply-eject.ts +133 -0
- package/core/build/eject/plan-eject.ts +139 -0
- package/core/client/adaptive/flush-scheduler.ts +96 -0
- package/core/client/adaptive/hysteresis.ts +56 -0
- package/core/client/adaptive/index.ts +23 -0
- package/core/client/adaptive/observer-pool.ts +90 -0
- package/core/client/base/SomaPageRootBase.ts +50 -0
- package/core/client/compiler/adaptive-compile.ts +136 -0
- package/core/client/compiler/manifest-compiler.ts +155 -27
- package/core/client/component/ai-catalog.ts +262 -0
- package/core/client/component/component-definition.types.ts +65 -0
- package/core/client/component/component-expander.ts +119 -0
- package/core/client/component/component-manager.ts +933 -0
- package/core/client/component/component-pack.ts +271 -0
- package/core/client/component/component-registry.ts +71 -0
- package/core/client/component/pack-styles.ts +94 -0
- package/core/client/component/scoped-adapter.ts +85 -0
- package/core/client/component/verify-pack.ts +247 -0
- package/core/client/container/MiniProgramContainerAdapter.ts +15 -1
- package/core/client/container/ReactNativeContainerAdapter.ts +15 -1
- package/core/client/container/SomaContainerAdapter.ts +186 -180
- package/core/client/data/data-object-resolver.ts +417 -0
- package/core/client/diagnostics/SomaDiagnostics.ts +187 -186
- package/core/client/diagnostics/boot-timings.ts +152 -0
- package/core/client/engine/asset-resolver.ts +12 -2
- package/core/client/engine/dom-renderer.ts +235 -16
- package/core/client/engine/emit-event.ts +21 -0
- package/core/client/engine/event-engine.ts +34 -4
- package/core/client/engine/on-change-engine.ts +1 -1
- package/core/client/engine/property-watcher.ts +1 -1
- package/core/client/engine/reactive-proxy.ts +3 -3
- package/core/client/engine/render-engine.ts +43 -4
- package/core/client/engine/runtime-builder.ts +23 -0
- package/core/client/engine/soma-bootstrap.ts +389 -5
- package/core/client/engine/style-binder.ts +47 -1
- package/core/client/host-bridge/empty-host/data/README.md +17 -0
- package/core/client/infra/http/SomaHttpService.ts +5 -0
- package/core/client/observability/error-reporter.ts +173 -0
- package/core/client/parser/adaptive-parser.ts +264 -0
- package/core/client/parser/data-config-parser.ts +396 -0
- package/core/client/parser/pipeline-parser.ts +15 -3
- package/core/client/parser/style-config-parser.ts +65 -2
- package/core/client/parser/ui-config-parser.ts +52 -3
- package/core/client/pipes/pipe-registry.ts +249 -0
- package/core/client/quality/SomaQualityRegistry.ts +3 -0
- package/core/client/registry/declaration-renderer.ts +159 -0
- package/core/client/registry/index.ts +28 -0
- package/core/client/registry/page-lifecycle.ts +171 -0
- package/core/client/registry/remote-page.ts +139 -0
- package/core/client/runtime/SomaRuntimeServices.ts +24 -0
- package/core/client/scheduler/SomaScheduler.ts +29 -1
- package/core/client/security/attribute-presence.ts +70 -0
- package/core/client/security/html-sanitizer.ts +113 -0
- package/core/client/security/url-guard.ts +0 -0
- package/core/client/theme/theme-engine.ts +936 -0
- package/core/client/typography/typography-base.ts +34 -0
- package/core/client/validation/contract-validator.ts +48 -5
- package/core/index.ts +190 -2
- package/core/server/api/IService.ts +18 -6
- package/core/server/api/load-host-service.ts +3 -3
- package/core/server/host/content-security-policy.ts +190 -0
- package/core/server/host/csp-nonce-metadata.ts +75 -0
- package/core/server/host/resolve-host-request-hook.ts +5 -0
- package/core/server/host/server-page-assets.ts +10 -0
- package/core/server/index.ts +30 -1
- package/core/server/infra/cache/ServerFileCache.ts +1 -1
- package/core/server/mock/node/cli.mjs +2 -2
- package/core/server/registry/api-registry-store.ts +518 -0
- package/core/server/registry/conditional-object-store.ts +29 -0
- package/core/server/registry/declaration-precompiler.ts +129 -0
- package/core/server/registry/in-memory-conditional-object-store.ts +43 -0
- package/core/server/registry/index.ts +142 -0
- package/core/server/registry/page-registry-repository.ts +373 -0
- package/core/server/registry/page-registry-store.ts +903 -0
- package/core/server/registry/registry-error.ts +17 -0
- package/core/server/registry/registry-file-lock.ts +173 -0
- package/core/server/registry/registry-response.ts +71 -0
- package/core/server/registry/registry-subjects.ts +194 -0
- package/core/server/registry/registry-write-pipeline.ts +240 -0
- package/core/server/registry/request-body-limit.ts +99 -0
- package/core/server/registry/services/apis/Get.ts +25 -0
- package/core/server/registry/services/apis/List.ts +41 -0
- package/core/server/registry/services/apis/Register.ts +39 -0
- package/core/server/registry/services/apis/Unregister.ts +24 -0
- package/core/server/registry/services/index.ts +40 -0
- package/core/server/registry/services/pages/Get.ts +86 -0
- package/core/server/registry/services/pages/List.ts +53 -0
- package/core/server/registry/services/pages/Register.ts +49 -0
- package/core/server/registry/services/pages/Rollback.ts +36 -0
- package/core/server/registry/services/pages/Unregister.ts +23 -0
- package/core/server/registry/services/service-utils.ts +21 -0
- package/core/server/registry/validation/compile-gate.ts +71 -0
- package/core/server/registry/validation/component-existence.ts +55 -0
- package/core/server/registry/validation/credential-ban.ts +86 -0
- package/core/server/registry/validation/cross-check.ts +77 -0
- package/core/server/registry/validation/declaration-safety-scan.ts +102 -0
- package/core/shared/types/adaptive.types.ts +109 -0
- package/core/shared/types/component-contract.types.ts +110 -0
- package/core/shared/types/data-config.types.ts +105 -0
- package/core/shared/types/domain.types.ts +6 -0
- package/core/shared/types/engine.types.ts +41 -35
- package/core/shared/types/manifest.types.ts +55 -32
- package/core/shared/types/scope-manifest.types.ts +96 -0
- package/core/shared/types/style-config.types.ts +9 -0
- package/core/shared/types/ui-config.types.ts +118 -98
- package/dist/cli/soma.js +20 -5
- package/dist/core/index.cjs +5388 -888
- package/dist/types/build/compiler/full-manifest-builder.d.ts +4 -0
- package/dist/types/build/compiler/rollup-plugin-soma.d.ts +1 -0
- package/dist/types/build/compiler/soma-precompile.d.ts +9 -0
- package/dist/types/build/compiler/vite-plugin-soma.d.ts +3 -0
- package/dist/types/build/component/package-loader.d.ts +9 -0
- package/dist/types/build/eject/apply-eject.d.ts +22 -0
- package/dist/types/build/eject/plan-eject.d.ts +32 -0
- package/dist/types/client/adaptive/flush-scheduler.d.ts +13 -0
- package/dist/types/client/adaptive/hysteresis.d.ts +16 -0
- package/dist/types/client/adaptive/index.d.ts +5 -0
- package/dist/types/client/adaptive/observer-pool.d.ts +15 -0
- package/dist/types/client/base/SomaPageRootBase.d.ts +33 -0
- package/dist/types/client/compiler/adaptive-compile.d.ts +26 -0
- package/dist/types/client/compiler/manifest-compiler.d.ts +13 -2
- package/dist/types/client/component/ai-catalog.d.ts +73 -0
- package/dist/types/client/component/component-definition.types.d.ts +54 -0
- package/dist/types/client/component/component-expander.d.ts +25 -0
- package/dist/types/client/component/component-manager.d.ts +160 -0
- package/dist/types/client/component/component-pack.d.ts +90 -0
- package/dist/types/client/component/component-registry.d.ts +12 -0
- package/dist/types/client/component/pack-styles.d.ts +22 -0
- package/dist/types/client/component/scoped-adapter.d.ts +18 -0
- package/dist/types/client/component/verify-pack.d.ts +14 -0
- package/dist/types/client/data/data-object-resolver.d.ts +71 -0
- package/dist/types/client/diagnostics/SomaDiagnostics.d.ts +2 -1
- package/dist/types/client/diagnostics/boot-timings.d.ts +30 -0
- package/dist/types/client/engine/asset-resolver.d.ts +7 -1
- package/dist/types/client/engine/dom-renderer.d.ts +49 -1
- package/dist/types/client/engine/emit-event.d.ts +6 -0
- package/dist/types/client/engine/event-engine.d.ts +6 -0
- package/dist/types/client/engine/render-engine.d.ts +26 -1
- package/dist/types/client/engine/runtime-builder.d.ts +7 -0
- package/dist/types/client/engine/soma-bootstrap.d.ts +122 -0
- package/dist/types/client/infra/http/SomaHttpService.d.ts +2 -0
- package/dist/types/client/observability/error-reporter.d.ts +51 -0
- package/dist/types/client/parser/adaptive-parser.d.ts +28 -0
- package/dist/types/client/parser/data-config-parser.d.ts +34 -0
- package/dist/types/client/parser/pipeline-parser.d.ts +2 -0
- package/dist/types/client/parser/style-config-parser.d.ts +5 -3
- package/dist/types/client/parser/ui-config-parser.d.ts +22 -1
- package/dist/types/client/pipes/pipe-registry.d.ts +38 -0
- package/dist/types/client/registry/declaration-renderer.d.ts +51 -0
- package/dist/types/client/registry/index.d.ts +10 -0
- package/dist/types/client/registry/page-lifecycle.d.ts +61 -0
- package/dist/types/client/registry/remote-page.d.ts +52 -0
- package/dist/types/client/runtime/SomaRuntimeServices.d.ts +16 -0
- package/dist/types/client/scheduler/SomaScheduler.d.ts +8 -0
- package/dist/types/client/security/attribute-presence.d.ts +7 -0
- package/dist/types/client/security/html-sanitizer.d.ts +37 -0
- package/dist/types/client/security/url-guard.d.ts +11 -0
- package/dist/types/client/theme/theme-engine.d.ts +49 -0
- package/dist/types/client/typography/typography-base.d.ts +15 -0
- package/dist/types/client/validation/contract-validator.d.ts +2 -0
- package/dist/types/index.d.ts +36 -2
- package/dist/types/server/api/IService.d.ts +18 -6
- package/dist/types/server/host/content-security-policy.d.ts +53 -0
- package/dist/types/server/host/csp-nonce-metadata.d.ts +32 -0
- package/dist/types/server/host/resolve-host-request-hook.d.ts +5 -0
- package/dist/types/server/host/server-page-assets.d.ts +5 -0
- package/dist/types/server/index.d.ts +4 -1
- package/dist/types/server/registry/api-registry-store.d.ts +141 -0
- package/dist/types/server/registry/conditional-object-store.d.ts +27 -0
- package/dist/types/server/registry/declaration-precompiler.d.ts +30 -0
- package/dist/types/server/registry/in-memory-conditional-object-store.d.ts +8 -0
- package/dist/types/server/registry/index.d.ts +29 -0
- package/dist/types/server/registry/page-registry-repository.d.ts +58 -0
- package/dist/types/server/registry/page-registry-store.d.ts +259 -0
- package/dist/types/server/registry/registry-error.d.ts +12 -0
- package/dist/types/server/registry/registry-file-lock.d.ts +20 -0
- package/dist/types/server/registry/registry-response.d.ts +18 -0
- package/dist/types/server/registry/registry-subjects.d.ts +59 -0
- package/dist/types/server/registry/registry-write-pipeline.d.ts +48 -0
- package/dist/types/server/registry/request-body-limit.d.ts +31 -0
- package/dist/types/server/registry/services/apis/Get.d.ts +10 -0
- package/dist/types/server/registry/services/apis/List.d.ts +10 -0
- package/dist/types/server/registry/services/apis/Register.d.ts +13 -0
- package/dist/types/server/registry/services/apis/Unregister.d.ts +12 -0
- package/dist/types/server/registry/services/index.d.ts +3 -0
- package/dist/types/server/registry/services/pages/Get.d.ts +10 -0
- package/dist/types/server/registry/services/pages/List.d.ts +13 -0
- package/dist/types/server/registry/services/pages/Register.d.ts +11 -0
- package/dist/types/server/registry/services/pages/Rollback.d.ts +9 -0
- package/dist/types/server/registry/services/pages/Unregister.d.ts +9 -0
- package/dist/types/server/registry/services/service-utils.d.ts +10 -0
- package/dist/types/server/registry/validation/compile-gate.d.ts +10 -0
- package/dist/types/server/registry/validation/component-existence.d.ts +14 -0
- package/dist/types/server/registry/validation/credential-ban.d.ts +15 -0
- package/dist/types/server/registry/validation/cross-check.d.ts +16 -0
- package/dist/types/server/registry/validation/declaration-safety-scan.d.ts +15 -0
- package/dist/types/shared/types/adaptive.types.d.ts +88 -0
- package/dist/types/shared/types/component-contract.types.d.ts +68 -0
- package/dist/types/shared/types/data-config.types.d.ts +81 -0
- package/dist/types/shared/types/domain.types.d.ts +6 -0
- package/dist/types/shared/types/engine.types.d.ts +6 -0
- package/dist/types/shared/types/manifest.types.d.ts +23 -0
- package/dist/types/shared/types/scope-manifest.types.d.ts +82 -0
- package/dist/types/shared/types/style-config.types.d.ts +8 -0
- package/dist/types/shared/types/ui-config.types.d.ts +20 -0
- package/global.d.ts +12 -0
- package/next.config.js +76 -1
- package/package.json +32 -11
- package/proxy.ts +62 -0
- package/core/client/engine/theme-variables.ts +0 -37
- package/dist/tsconfig.types.tsbuildinfo +0 -1
- package/dist/types/client/engine/theme-variables.d.ts +0 -3
- package/middleware.ts +0 -33
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** 声明的可扫描面(与 PageRegistryDeclaration / PageDeclarations 同构的子集) */
|
|
2
|
+
export interface ScannableDeclaration {
|
|
3
|
+
html: string;
|
|
4
|
+
uiYaml?: string;
|
|
5
|
+
eventYaml?: string;
|
|
6
|
+
styleYaml?: string;
|
|
7
|
+
dataYaml?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 扫描声明的注入面,返回中文问题清单(空数组 = 通过)。
|
|
11
|
+
*
|
|
12
|
+
* 清单同时喂两处:发布管线用它拒绝落库,生成链闸门用它回喂模型自修复——
|
|
13
|
+
* 一把尺子量两处,规则不会各写一份而漂移。
|
|
14
|
+
*/
|
|
15
|
+
export declare function scanDeclarationSafety(declaration: ScannableDeclaration): string[];
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 版式画像:唯一封闭取值集。
|
|
3
|
+
* 只标注页面的信息形态,不携带任何几何档位(档位语义在 soma-ui)。
|
|
4
|
+
*/
|
|
5
|
+
export declare const SOMA_ADAPTIVE_PROFILES: readonly ["dashboard", "form", "list", "console"];
|
|
6
|
+
export type SomaAdaptiveProfile = (typeof SOMA_ADAPTIVE_PROFILES)[number];
|
|
7
|
+
/**
|
|
8
|
+
* 阶梯级数上限。
|
|
9
|
+
* 取 5 不是性能阈值:超过五级说明页面本身过载,正确做法是拆页而不是加级。
|
|
10
|
+
*/
|
|
11
|
+
export declare const SOMA_ADAPTIVE_MAX_LADDER = 5;
|
|
12
|
+
/**
|
|
13
|
+
* 阶梯的一级。
|
|
14
|
+
* YAML 上是单键对象 `{ 槽名: 级值 }`,解析后拍平为二元组——
|
|
15
|
+
* 单键对象在类型层无法表达"恰好一个键",拍平后级序才是可枚举、可快照的。
|
|
16
|
+
*/
|
|
17
|
+
export interface SomaAdaptiveLevel {
|
|
18
|
+
/** 槽名,同时是展开目标锚点的 data-soma-id */
|
|
19
|
+
slot: string;
|
|
20
|
+
/** 级值;必须落在注册词汇表内,core 不解释其含义 */
|
|
21
|
+
value: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* `_ui.yaml` 顶层保留键 `adaptive` 的解析结果。
|
|
25
|
+
* 整个键可选:未声明时编译产物与迁移前字节级一致(零破坏保证的类型锚点)。
|
|
26
|
+
*/
|
|
27
|
+
export interface SomaAdaptiveConfig {
|
|
28
|
+
profile: SomaAdaptiveProfile;
|
|
29
|
+
/** 声明即全量覆盖默认阶梯,不深合并——深合并会让"实际生效的阶梯"失去单一可读处 */
|
|
30
|
+
ladder?: SomaAdaptiveLevel[];
|
|
31
|
+
/** 记名豁免槽:不参与降级 */
|
|
32
|
+
pin?: string[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 级的展开方式。
|
|
36
|
+
* breakpoint:纯 CSS 作用域类,L1 自足,不经运行时解算;
|
|
37
|
+
* measure:需要测量,展开为执行器配置交 soma-ui 接线层消费。
|
|
38
|
+
*/
|
|
39
|
+
export type SomaAdaptiveLevelKind = 'breakpoint' | 'measure';
|
|
40
|
+
export interface SomaAdaptiveLevelDefinition {
|
|
41
|
+
kind: SomaAdaptiveLevelKind;
|
|
42
|
+
/**
|
|
43
|
+
* 断点型级的触发档值,由词汇提供方声明,core 只透传不解释。
|
|
44
|
+
*
|
|
45
|
+
* 测量型级没有静态触发点,通常省略此字段;若宿主需要为调试/审计标注
|
|
46
|
+
* 一个业务触发标签,也只能作为不透明字符串携带,不能让 core 据此做布局决策。
|
|
47
|
+
*/
|
|
48
|
+
trigger?: string;
|
|
49
|
+
/**
|
|
50
|
+
* 展开目标:断点型是预置作用域类名,测量型是执行器名。
|
|
51
|
+
* core 只做透传,不解释其内容(解释即等于把组件行为搬进引擎)。
|
|
52
|
+
*/
|
|
53
|
+
target: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 阶梯词汇表:槽名 → 级值 → 定义。
|
|
57
|
+
* 由 `bootstrap` 与组件注册同点注入(`adaptiveVocabulary: createSomaUiAdaptiveVocabulary()`)。
|
|
58
|
+
* core 侧恒为空:未注册而页面声明 ladder 时按 ERR-02 快速失败。
|
|
59
|
+
*/
|
|
60
|
+
export type SomaAdaptiveVocabulary = Readonly<Record<string, Readonly<Record<string, SomaAdaptiveLevelDefinition>>>>;
|
|
61
|
+
/** 断点型级的展开产物:目标锚点挂一个预置作用域类 */
|
|
62
|
+
export interface SomaAdaptiveScopeClass {
|
|
63
|
+
/** 目标锚点 data-soma-id(等于槽名) */
|
|
64
|
+
slot: string;
|
|
65
|
+
className: string;
|
|
66
|
+
/** 原始断点档值;core 只透传,供宿主闸门/调试工具观察,不参与运行期决策。 */
|
|
67
|
+
trigger?: string;
|
|
68
|
+
}
|
|
69
|
+
/** 测量型级的展开产物:交 soma-ui 接线层消费的执行器配置 */
|
|
70
|
+
export interface SomaAdaptiveExecutorConfig {
|
|
71
|
+
/** 目标锚点 data-soma-id(等于槽名) */
|
|
72
|
+
slot: string;
|
|
73
|
+
/** 原始级值,用于 ui 侧回溯声明 */
|
|
74
|
+
value: string;
|
|
75
|
+
/** 执行器名,由词汇表给出;core 不认识它做什么 */
|
|
76
|
+
executor: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 阶梯编译产物:确定性映射(同输入同输出,可快照)。
|
|
80
|
+
* 运行期不再做任何展开判断——这是"运行期零决策"的兑现处。
|
|
81
|
+
*/
|
|
82
|
+
export interface SomaCompiledAdaptive {
|
|
83
|
+
profile: SomaAdaptiveProfile;
|
|
84
|
+
scopeClasses: SomaAdaptiveScopeClass[];
|
|
85
|
+
executors: SomaAdaptiveExecutorConfig[];
|
|
86
|
+
/** 记名豁免槽的原样透传(ui 侧仲裁链据此跳过) */
|
|
87
|
+
pinned: string[];
|
|
88
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export type SomaComponentLayer = 'atom' | 'composite' | 'solution' | 'template';
|
|
2
|
+
/**
|
|
3
|
+
* 组件的主几何族。
|
|
4
|
+
*
|
|
5
|
+
* 这是生成链与组件目录之间的结构契约:页面生成器只根据族义务决定包裹方式,
|
|
6
|
+
* 不读取组件实现细节。字段保持可选以兼容尚未迁移的外部组件契约;目录编译器会
|
|
7
|
+
* 为缺省值生成一次性迁移归族结果,待组件逐步补齐后即可删掉该兼容路径。
|
|
8
|
+
*/
|
|
9
|
+
export type SomaGeometryFamily = 'control' | 'surface' | 'message' | 'data' | 'overlay' | 'layout' | 'display';
|
|
10
|
+
export type SomaContractPropType = 'number' | 'string' | 'boolean' | 'enum' | 'object' | 'array';
|
|
11
|
+
export interface SomaContractProp {
|
|
12
|
+
type: SomaContractPropType;
|
|
13
|
+
required?: boolean;
|
|
14
|
+
/** 非 required 的 prop 必须有默认值(契约规则 C4:零 props 可渲染) */
|
|
15
|
+
default?: unknown;
|
|
16
|
+
desc?: string;
|
|
17
|
+
/** type === 'enum' 时的取值集合 */
|
|
18
|
+
values?: (string | number)[];
|
|
19
|
+
/** 绑定模式:oneway(默认)| model(双向,一个组件最多一个) */
|
|
20
|
+
mode?: 'oneway' | 'model';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 找出契约默认值中第二层及更深的引用型值。
|
|
24
|
+
*
|
|
25
|
+
* 运行时只隔离默认值的最外层数组/普通对象,避免擅自克隆 Date、类实例等带语义的值。
|
|
26
|
+
* 因而默认值允许 `[]`、`{}` 与一层标量字段,却不能再嵌套数组/对象;否则实例仍会
|
|
27
|
+
* 共享内部引用,组件控制器或 model 写入会跨实例、跨页面污染状态且不会报错。
|
|
28
|
+
*
|
|
29
|
+
* 返回相对 default 的首个违规路径;`null` 表示最外层浅拷贝已足够隔离。
|
|
30
|
+
*/
|
|
31
|
+
export declare function findNestedMutableContractDefault(value: unknown): string | null;
|
|
32
|
+
export interface SomaContractEmitPayloadField {
|
|
33
|
+
type: SomaContractPropType;
|
|
34
|
+
desc?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface SomaContractEmit {
|
|
37
|
+
payload?: Record<string, SomaContractEmitPayloadField>;
|
|
38
|
+
desc?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface SomaContractSlot {
|
|
41
|
+
desc?: string;
|
|
42
|
+
required?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* AI 目录段(契约规范第 11 章):AI 生成页面前查表选组件的依据。
|
|
46
|
+
* when_to_use / example 为目录质量线;when_not_to_use 用于同族组件消歧。
|
|
47
|
+
*/
|
|
48
|
+
export interface SomaContractAiSection {
|
|
49
|
+
when_to_use: string;
|
|
50
|
+
when_not_to_use?: string;
|
|
51
|
+
/** 三行真实用法:html / ui / event 各一行 */
|
|
52
|
+
example: string;
|
|
53
|
+
anti_patterns?: string[];
|
|
54
|
+
}
|
|
55
|
+
export interface SomaComponentContract {
|
|
56
|
+
/** 契约名,PascalCase,注册域内唯一 */
|
|
57
|
+
name: string;
|
|
58
|
+
layer: SomaComponentLayer;
|
|
59
|
+
/** semver;破坏性变更必须升 major(契约规则 C8) */
|
|
60
|
+
version: string;
|
|
61
|
+
description: string;
|
|
62
|
+
/** 主几何族;旧契约缺省时由目录编译器按组件层与名称推导迁移值。 */
|
|
63
|
+
geometry?: SomaGeometryFamily;
|
|
64
|
+
props?: Record<string, SomaContractProp>;
|
|
65
|
+
emits?: Record<string, SomaContractEmit>;
|
|
66
|
+
slots?: Record<string, SomaContractSlot>;
|
|
67
|
+
ai?: SomaContractAiSection;
|
|
68
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** 字段类型枚举(决定 soma-ui 双态映射走哪个渲染组件) */
|
|
2
|
+
export type SomaDataFieldType = 'text' | 'int' | 'float' | 'money' | 'bool' | 'enum' | 'date' | 'datetime' | 'image' | 'url' | 'richtext';
|
|
3
|
+
/** 字段权限:r 只读 / w 可写(决定双态映射走 show 还是 edit 形态) */
|
|
4
|
+
export type SomaDataFieldPermission = 'r' | 'w';
|
|
5
|
+
/** 枚举字段候选项(type: enum 专用) */
|
|
6
|
+
export interface SomaDataFieldOption {
|
|
7
|
+
/** 枚举值 */
|
|
8
|
+
key: string;
|
|
9
|
+
/** 展示文案(缺省用 key) */
|
|
10
|
+
label?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 字段校验规则:required / max_len / min_len / pattern / min / max 六种之一,
|
|
14
|
+
* 每条规则必须携带校验失败时的提示文案 message。
|
|
15
|
+
*/
|
|
16
|
+
export interface SomaDataFieldRule {
|
|
17
|
+
/** 必填 */
|
|
18
|
+
required?: boolean;
|
|
19
|
+
/** 最大长度(字符串) */
|
|
20
|
+
max_len?: number;
|
|
21
|
+
/** 最小长度(字符串) */
|
|
22
|
+
min_len?: number;
|
|
23
|
+
/** 正则表达式(字符串形式) */
|
|
24
|
+
pattern?: string;
|
|
25
|
+
/** 最小值(数字) */
|
|
26
|
+
min?: number;
|
|
27
|
+
/** 最大值(数字) */
|
|
28
|
+
max?: number;
|
|
29
|
+
/** 校验失败提示文案 */
|
|
30
|
+
message: string;
|
|
31
|
+
}
|
|
32
|
+
/** 字段字典条目(驱动 UI 的元数据,全部可选;字典缺失时由 shape-infer 推断兜底) */
|
|
33
|
+
export interface SomaDataFieldConfig {
|
|
34
|
+
/** 业务名称(如「订单号」),速记列 label 的第一优先来源 */
|
|
35
|
+
name?: string;
|
|
36
|
+
/** 字段类型(缺省按 text 处理) */
|
|
37
|
+
type?: SomaDataFieldType;
|
|
38
|
+
/** 字段权限(缺省按只读处理) */
|
|
39
|
+
permission?: SomaDataFieldPermission;
|
|
40
|
+
/** 校验规则集 */
|
|
41
|
+
rules?: SomaDataFieldRule[];
|
|
42
|
+
/** 枚举候选项 */
|
|
43
|
+
options?: SomaDataFieldOption[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 单个取数来源:一个后端接口 + 参数 + 聚合位置。
|
|
47
|
+
* params 值支持三源 `$` 引用:$query.*(URL 参数)、$page.*(Domain 字段)、
|
|
48
|
+
* $<数据对象>.*(依赖编排,决定对象间取数顺序)。
|
|
49
|
+
*/
|
|
50
|
+
export interface SomaDataSourceConfig {
|
|
51
|
+
/** 后端接口路径(后端接口是唯一数据边界) */
|
|
52
|
+
api: string;
|
|
53
|
+
/** 取数参数:字面量或 `$` 引用(支持嵌套对象/数组) */
|
|
54
|
+
params?: Record<string, unknown>;
|
|
55
|
+
/** 结果聚合到对象子键(如 order.trace);缺省浅合并进对象根 */
|
|
56
|
+
into?: string;
|
|
57
|
+
}
|
|
58
|
+
/** 数据对象声明(*_data.yaml 中 data.<对象名> 的解析产物) */
|
|
59
|
+
export interface SomaDataObjectConfig {
|
|
60
|
+
/** 对象名(页面内唯一,即 data 下的键名) */
|
|
61
|
+
name: string;
|
|
62
|
+
/** 取数来源列表(mock 预览对象可为空数组) */
|
|
63
|
+
from: SomaDataSourceConfig[];
|
|
64
|
+
/**
|
|
65
|
+
* 派生字段:值为 "源字段路径 | 管道链"(复用 pipe-registry)。
|
|
66
|
+
* 解析期已归一化为标准管道语法(`date: 'x'` → `date('x')`)。
|
|
67
|
+
*/
|
|
68
|
+
transform?: Record<string, string>;
|
|
69
|
+
/** 字段字典(字段名 → 字典条目) */
|
|
70
|
+
fields?: Record<string, SomaDataFieldConfig>;
|
|
71
|
+
/** mock 样本:SOMA_MOCK_ENABLED / 接口失败兜底 / 无接口预览 */
|
|
72
|
+
mock?: unknown;
|
|
73
|
+
/** 解析期提取:params 引用到的其他数据对象名(DAG 拓扑排序输入,不含自引用) */
|
|
74
|
+
deps: string[];
|
|
75
|
+
}
|
|
76
|
+
/** *_data.yaml 整体解析产物(对象名 → 声明) */
|
|
77
|
+
export interface SomaDataConfig {
|
|
78
|
+
objects: Record<string, SomaDataObjectConfig>;
|
|
79
|
+
}
|
|
80
|
+
/** 字段字典集合(对象名 → 字段名 → 字典条目),解析器产物 dicts 的形状 */
|
|
81
|
+
export type SomaDataDicts = Record<string, Record<string, SomaDataFieldConfig>>;
|
|
@@ -9,6 +9,12 @@ export interface SomaPageRoot {
|
|
|
9
9
|
_config?: unknown;
|
|
10
10
|
/** 运行时基础设施(引擎在 mount 时注入) */
|
|
11
11
|
_services?: import('../../client/runtime/SomaRuntimeServices').SomaRuntimeServices;
|
|
12
|
+
/** 数据对象层解析产物挂载点(*_data.yaml 可选件;引擎解析完成后注入) */
|
|
13
|
+
data?: Record<string, unknown>;
|
|
14
|
+
/** 数据对象重取钩子(引擎在存在 *_data.yaml 声明时注入) */
|
|
15
|
+
_reloadData?: () => Promise<void>;
|
|
16
|
+
/** 重新执行数据对象取数(无声明时为空操作) */
|
|
17
|
+
reloadData?(): Promise<void>;
|
|
12
18
|
/** 页面初始化(引擎在渲染完成后调用) */
|
|
13
19
|
onMount?(): void | Promise<void>;
|
|
14
20
|
/** 页面销毁前(引擎在卸载时调用) */
|
|
@@ -11,6 +11,12 @@ export interface BindingEntry {
|
|
|
11
11
|
attrName?: string;
|
|
12
12
|
negate?: boolean;
|
|
13
13
|
classRules?: Record<string, string>;
|
|
14
|
+
/** 展示格式化管道链(text/attr 绑定,来自 SomaCompiledBinding.pipes) */
|
|
15
|
+
pipes?: import('./scope-manifest.types').SomaPipeCall[];
|
|
16
|
+
/** 异构列表模板选择器(行相对路径) */
|
|
17
|
+
roleBy?: string;
|
|
18
|
+
/** 变体模板表:'item' 默认 + 'item:变体'(异构列表用;同构列表仅 templateCache) */
|
|
19
|
+
templatesByRole?: Record<string, DocumentFragment>;
|
|
14
20
|
/** 预编译的属性访问器:消除 path.split + 循环 */
|
|
15
21
|
compiledGetter?: (root: any) => any;
|
|
16
22
|
/** 预编译的渲染函数:消除 switch 分支 + 类型判断 */
|
|
@@ -2,6 +2,8 @@ import type { BindingType } from './engine.types';
|
|
|
2
2
|
import type { ParsedEvent } from './event.types';
|
|
3
3
|
import type { SomaTaskPriority } from './scheduler.types';
|
|
4
4
|
import type { ShowMapping } from './ui-config.types';
|
|
5
|
+
import type { SomaPipeCall } from './scope-manifest.types';
|
|
6
|
+
import type { SomaCompiledAdaptive } from './adaptive.types';
|
|
5
7
|
export interface SomaCompiledBinding {
|
|
6
8
|
id: string;
|
|
7
9
|
somaId: string;
|
|
@@ -14,10 +16,25 @@ export interface SomaCompiledBinding {
|
|
|
14
16
|
childShowConfig?: ShowMapping;
|
|
15
17
|
/** 静态提升标记:值在初始化后不会变化,不需要注册 watchPaths */
|
|
16
18
|
static?: boolean;
|
|
19
|
+
/** 展示格式化管道链(text/attr 绑定专用,见 pipe-registry) */
|
|
20
|
+
pipes?: SomaPipeCall[];
|
|
21
|
+
/** 异构列表模板选择器(行相对路径,list 绑定专用) */
|
|
22
|
+
roleBy?: string;
|
|
17
23
|
}
|
|
18
24
|
export interface SomaCompiledEvent extends ParsedEvent {
|
|
25
|
+
/**
|
|
26
|
+
* 同锚点同 DOM 事件的多按键候选(仅当一个锚点绑了多个 keyModifier 时出现)。
|
|
27
|
+
* 派发侧按 event.key 从中挑一条;单绑定时不存在此字段,零额外开销。
|
|
28
|
+
*/
|
|
29
|
+
keyVariants?: SomaCompiledEvent[];
|
|
19
30
|
eventKey: string;
|
|
20
31
|
priority: SomaTaskPriority;
|
|
32
|
+
/**
|
|
33
|
+
* 组件 emit 路由标记:somaId 为组件实例、domEvent 为契约 emit 名。
|
|
34
|
+
* 标记后不注册 DOM 监听、不响应冒泡 DOM 事件,仅由组件管理器 dispatchEmit 触发;
|
|
35
|
+
* Domain 处理器第二实参为 emit payload(DOM 路由保持 originalEvent)。
|
|
36
|
+
*/
|
|
37
|
+
emitRoute?: boolean;
|
|
21
38
|
}
|
|
22
39
|
export interface SomaRuntimeManifest {
|
|
23
40
|
bindings: SomaCompiledBinding[];
|
|
@@ -26,4 +43,10 @@ export interface SomaRuntimeManifest {
|
|
|
26
43
|
eventIndex: Map<string, SomaCompiledEvent>;
|
|
27
44
|
/** 启动时一次性初始化的属性(来自 _ui.yaml initProps) */
|
|
28
45
|
initProps?: Record<string, unknown>;
|
|
46
|
+
/**
|
|
47
|
+
* 阶梯编译产物(来自 _ui.yaml adaptive)。
|
|
48
|
+
* 未声明 adaptive 时**此字段不存在**(不是空对象、不是 null)——
|
|
49
|
+
* 零破坏保证要求产物字节级不变,写一个空壳就已经破了。
|
|
50
|
+
*/
|
|
51
|
+
adaptive?: SomaCompiledAdaptive;
|
|
29
52
|
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { SomaCompiledBinding, SomaCompiledEvent, SomaRuntimeManifest } from './manifest.types';
|
|
2
|
+
/**
|
|
3
|
+
* v2 作用域清单树(组件体系 P0)。
|
|
4
|
+
*
|
|
5
|
+
* 设计规范:soma-core/doc/soma 作用域清单树.md
|
|
6
|
+
* 兼容承诺:v1 清单(SomaRuntimeManifest)长期保留;无组件页面继续走 v1 原路径,
|
|
7
|
+
* 本文件只做类型新增,不修改任何既有类型。
|
|
8
|
+
*
|
|
9
|
+
* 节点结构保持可 JSON 序列化(仅数组/普通对象,无 Map)——构建期产物与
|
|
10
|
+
* 运行期客户端编译产物必须深度相等(规范 7.4),索引一律在运行时装配。
|
|
11
|
+
*/
|
|
12
|
+
export type SomaScopeKind = 'page' | 'list' | 'component';
|
|
13
|
+
export type SomaPropMode = 'oneway' | 'model';
|
|
14
|
+
/** 管道实参:字面量,或取值自绑定路径 */
|
|
15
|
+
export interface SomaPipeArg {
|
|
16
|
+
kind: 'literal' | 'binding';
|
|
17
|
+
value: string | number | boolean;
|
|
18
|
+
}
|
|
19
|
+
/** 格式化管道调用(DSL 扩展规范第 3 章),按声明顺序从左到右执行 */
|
|
20
|
+
export interface SomaPipeCall {
|
|
21
|
+
name: string;
|
|
22
|
+
args?: Record<string, SomaPipeArg>;
|
|
23
|
+
}
|
|
24
|
+
/** 页面表达式 → 组件契约 prop 的绑定(下行通道) */
|
|
25
|
+
export interface SomaPropBinding {
|
|
26
|
+
prop: string;
|
|
27
|
+
/** 已解析的绑定路径;与 literal 二选一 */
|
|
28
|
+
source?: string;
|
|
29
|
+
literal?: unknown;
|
|
30
|
+
/** 布尔 prop 的 `!` 前缀(沿用 when 语义,不引入其他运算) */
|
|
31
|
+
negate?: boolean;
|
|
32
|
+
mode: SomaPropMode;
|
|
33
|
+
pipes?: SomaPipeCall[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 契约 emit → 页面 Pipeline 的路由(上行通道)。
|
|
37
|
+
*
|
|
38
|
+
* 处理器分型(作用域清单树规范 1.1 R2):
|
|
39
|
+
* emit 路由的 Domain 处理器收 (currentVar, payload);
|
|
40
|
+
* DOM 事件路由保持既有 (currentVar, originalEvent),运行时按 kind 分发,不做猜测。
|
|
41
|
+
*/
|
|
42
|
+
export interface SomaEmitRoute {
|
|
43
|
+
kind: 'emit';
|
|
44
|
+
emit: string;
|
|
45
|
+
/** 复用既有 Pipeline 编译产物;somaId 为实例锚点 id */
|
|
46
|
+
pipeline: SomaCompiledEvent;
|
|
47
|
+
}
|
|
48
|
+
/** 组件实例元数据(kind === 'component' 的节点持有) */
|
|
49
|
+
export interface SomaComponentInstanceMeta {
|
|
50
|
+
/** 契约名(PascalCase) */
|
|
51
|
+
name: string;
|
|
52
|
+
/** 契约 semver,升级破坏点定位用(契约规范 C8) */
|
|
53
|
+
version: string;
|
|
54
|
+
props: SomaPropBinding[];
|
|
55
|
+
emits: SomaEmitRoute[];
|
|
56
|
+
/**
|
|
57
|
+
* 插槽内容子树。插槽内容归父(页面/外层)作用域:其 bindings 的数据路径
|
|
58
|
+
* 相对父作用域求值,组件只决定投影位置与显隐(契约规范第 5 章)。
|
|
59
|
+
*/
|
|
60
|
+
slots?: Record<string, SomaScopeNode>;
|
|
61
|
+
}
|
|
62
|
+
export interface SomaScopeNode {
|
|
63
|
+
kind: SomaScopeKind;
|
|
64
|
+
/** page: 页面 base;list/component: 宿主锚点 data-soma-id */
|
|
65
|
+
id: string;
|
|
66
|
+
component?: SomaComponentInstanceMeta;
|
|
67
|
+
/** kind === 'list':行变量名(currentVar 语义与既有列表一致) */
|
|
68
|
+
listVar?: string;
|
|
69
|
+
/** 异构列表模板选择器的绑定路径(DSL 扩展规范 2.1,行模板后缀 = 该路径取值) */
|
|
70
|
+
roleBy?: string;
|
|
71
|
+
/** 本作用域直属锚点的绑定(结构与 v1 逐字段同构) */
|
|
72
|
+
bindings: SomaCompiledBinding[];
|
|
73
|
+
events: SomaCompiledEvent[];
|
|
74
|
+
children: SomaScopeNode[];
|
|
75
|
+
}
|
|
76
|
+
export interface SomaRuntimeManifestV2 {
|
|
77
|
+
version: 2;
|
|
78
|
+
root: SomaScopeNode;
|
|
79
|
+
initProps?: Record<string, unknown>;
|
|
80
|
+
}
|
|
81
|
+
export type SomaAnyRuntimeManifest = SomaRuntimeManifest | SomaRuntimeManifestV2;
|
|
82
|
+
export declare function isManifestV2(manifest: SomaAnyRuntimeManifest): manifest is SomaRuntimeManifestV2;
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 样式声明的违规类别(解析期硬校验用)。
|
|
3
|
+
*
|
|
4
|
+
* `layout-class`:`_style.yaml` 里出现了布局组装类。
|
|
5
|
+
* 布局的合法归宿是 HTML 骨架与布局原语;样式配置只承载视觉与显隐。
|
|
6
|
+
* 该类别不设 warn 档、不设开关——开关会立刻制造两份事实("开了的项目"与"没开的项目")。
|
|
7
|
+
*/
|
|
8
|
+
export type SomaStyleViolationKind = 'layout-class';
|
|
1
9
|
/**
|
|
2
10
|
* 状态驱动的样式规则
|
|
3
11
|
* 当 condition 路径的值等于 value 时,将 apply 中的类名应用到对应 DOM 节点
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { OnChangeRule } from './watcher.types';
|
|
2
|
+
import type { SomaAdaptiveConfig } from './adaptive.types';
|
|
2
3
|
/**
|
|
3
4
|
* 作用域声明
|
|
4
5
|
* 定义数据源路径和当前作用域别名
|
|
@@ -10,6 +11,11 @@ export interface BindDeclaration {
|
|
|
10
11
|
var: string;
|
|
11
12
|
/** 属性变化时触发的 Domain 方法(声明式 watch) */
|
|
12
13
|
onChange?: OnChangeRule[];
|
|
14
|
+
/**
|
|
15
|
+
* 异构列表模板选择器(行相对路径,如 msg.type):
|
|
16
|
+
* 取值匹配 <template data-soma-role="item:取值">,无匹配回落 item 默认模板。
|
|
17
|
+
*/
|
|
18
|
+
role_by?: string;
|
|
13
19
|
}
|
|
14
20
|
/**
|
|
15
21
|
* 展示映射值 - 支持多种绑定类型
|
|
@@ -29,6 +35,8 @@ export interface NestedShowMapping {
|
|
|
29
35
|
bind: BindDeclaration;
|
|
30
36
|
/** 子级展示映射 */
|
|
31
37
|
show: ShowMapping;
|
|
38
|
+
/** 整块显隐:与 bind 同处一个配置对象(另起同名键会覆盖列表绑定) */
|
|
39
|
+
when?: string;
|
|
32
40
|
}
|
|
33
41
|
/**
|
|
34
42
|
* 扩展绑定值
|
|
@@ -45,6 +53,12 @@ export interface ExtendedShowValue {
|
|
|
45
53
|
class?: Record<string, string>;
|
|
46
54
|
/** 子级展示映射 */
|
|
47
55
|
show?: ShowMapping;
|
|
56
|
+
/**
|
|
57
|
+
* 组件实例 props(键为契约 prop 名)。
|
|
58
|
+
* 值:绑定路径字符串 / 字面量 / 一层嵌套对象与数组(字段值递归同规则)。
|
|
59
|
+
* 仅当锚点元素带 data-soma-component 时生效。
|
|
60
|
+
*/
|
|
61
|
+
props?: Record<string, unknown>;
|
|
48
62
|
}
|
|
49
63
|
/**
|
|
50
64
|
* 展示映射
|
|
@@ -70,6 +84,12 @@ export interface UiConfig {
|
|
|
70
84
|
* 键为 var 别名路径(如 page.title),值为初始值
|
|
71
85
|
*/
|
|
72
86
|
initProps?: Record<string, unknown>;
|
|
87
|
+
/**
|
|
88
|
+
* 降级阶梯声明(保留键,可选)。
|
|
89
|
+
* **未声明时编译产物与迁移前字节级一致**——这是零破坏保证的实现锚点,
|
|
90
|
+
* 所以此键必须保持可选,且缺席时不得在下游产生任何默认值。
|
|
91
|
+
*/
|
|
92
|
+
adaptive?: SomaAdaptiveConfig;
|
|
73
93
|
}
|
|
74
94
|
/**
|
|
75
95
|
* 解析后的 show 条目
|
package/global.d.ts
CHANGED
|
@@ -63,6 +63,8 @@ interface SomaDevConsole {
|
|
|
63
63
|
getDiagnosticsSnapshot: () => import('./core/client/diagnostics/SomaDiagnostics').SomaDiagnosticsSnapshot | null;
|
|
64
64
|
getTelemetrySnapshot: () => Record<string, { count: number; avg: number; max: number; min: number }> | null;
|
|
65
65
|
getAvailableThemes?: () => string[];
|
|
66
|
+
/** 首屏三段耗时(未开启打点时为 null,开启方式见 boot-timings.ts) */
|
|
67
|
+
getBootTimings?: () => import('./core/client/diagnostics/boot-timings').SomaBootTimings | null;
|
|
66
68
|
getDomainInstance: () => unknown;
|
|
67
69
|
captureSnapshot: () => number | null;
|
|
68
70
|
restoreSnapshot: (id: number) => void;
|
|
@@ -71,4 +73,14 @@ interface SomaDevConsole {
|
|
|
71
73
|
|
|
72
74
|
interface Window {
|
|
73
75
|
__SOMA__?: SomaDevConsole;
|
|
76
|
+
__SOMA_READY__?: boolean;
|
|
77
|
+
__SOMA_DIAGNOSTICS__?: SomaReadinessDiagnostics;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
interface SomaReadinessDiagnostics {
|
|
81
|
+
isSettled: () => boolean;
|
|
82
|
+
getDomainValue: (path: string) => unknown;
|
|
83
|
+
getRegisteredSomaIds: () => string[];
|
|
84
|
+
/** 只读 CSP nonce 链(meta 为 meta[name=csp-nonce];styles 为带 nonce 的运行期样式元素) */
|
|
85
|
+
getCspNonceChain: () => { meta: string; styles: string[] };
|
|
74
86
|
}
|
package/next.config.js
CHANGED
|
@@ -94,6 +94,25 @@ function resolveHostAppConfigAlias(fallbackPath) {
|
|
|
94
94
|
return path.resolve(__dirname, fallbackPath);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
/**
|
|
98
|
+
* 目录别名的可选解析:宿主有这个目录就用宿主的,没有就落到 soma-core 里的空目录。
|
|
99
|
+
*
|
|
100
|
+
* 数据对象层是可选能力(`*_data.yaml`),不用它的宿主根本不会有 `data/`。
|
|
101
|
+
* 但 SomaPageClient 对四件套 + data 是一次性并发 import,webpack 要为
|
|
102
|
+
* `@soma-host/data/${base}_data.yaml` 建 context——目录不存在时它不会安静跳过,
|
|
103
|
+
* 而是每次页面加载都报 `Module not found: Can't resolve '@soma-host/data'`。
|
|
104
|
+
* 运行时有 `.catch(() => null)` 兜底所以页面照常渲染,于是这条错误既不影响功能、
|
|
105
|
+
* 又永远刷在控制台上,把真正该看见的错误淹掉。
|
|
106
|
+
* 空目录让 context 成立且为空,import 走 catch 返回 null,与"宿主没有数据层"语义一致。
|
|
107
|
+
*/
|
|
108
|
+
function resolveOptionalHostSourceDir(relativePath, fallbackPath) {
|
|
109
|
+
const hostDirCandidate = path.resolve(hostSourceRoot, relativePath);
|
|
110
|
+
if (fs.existsSync(hostDirCandidate)) {
|
|
111
|
+
return hostDirCandidate;
|
|
112
|
+
}
|
|
113
|
+
return path.resolve(__dirname, fallbackPath);
|
|
114
|
+
}
|
|
115
|
+
|
|
97
116
|
function readHostFileDependencyEntries() {
|
|
98
117
|
const packageJsonPath = path.join(hostDir, 'package.json');
|
|
99
118
|
if (!fs.existsSync(packageJsonPath)) {
|
|
@@ -151,14 +170,58 @@ const transpilePackages = [
|
|
|
151
170
|
]),
|
|
152
171
|
];
|
|
153
172
|
|
|
173
|
+
/**
|
|
174
|
+
* 构建期是否再跑一遍类型检查 / lint。
|
|
175
|
+
*
|
|
176
|
+
* 缺省跑(单机开发时这是最后一道拦截)。设 SOMA_BUILD_SKIP_CHECKS=1 可跳过——
|
|
177
|
+
* 两种场景需要它:
|
|
178
|
+
* 1. CI 里 `npm run verify` 已经按包跑过 `tsc --noEmit` 与 eslint,构建期重复一遍
|
|
179
|
+
* 只是把同一件事做两次;
|
|
180
|
+
* 2. **小内存机器**:实测本仓在 2GB 机器上做生产构建,编译阶段能过,
|
|
181
|
+
* 到"Linting and checking validity of types"时可用内存掉到 197MB,
|
|
182
|
+
* 构建 worker 直接被 SIGTERM(而 Next 只留下一句
|
|
183
|
+
* `build worker exited with code: null and signal: SIGTERM`,很容易被当成玄学)。
|
|
184
|
+
*/
|
|
185
|
+
const skipBuildChecks = process.env.SOMA_BUILD_SKIP_CHECKS === '1';
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* dev 服务器允许的访问来源。
|
|
189
|
+
*
|
|
190
|
+
* Next 16 起 dev 资源(HMR 与按需 chunk)默认只认 `localhost`,从 `127.0.0.1` 打开同一台
|
|
191
|
+
* 机器上的同一个服务会被判为跨 origin 而拦截。症状很有欺骗性:页面本身 200,
|
|
192
|
+
* 但 `next/dynamic` 的 chunk 永远拿不到,整页停在 "Loading page…",看起来像 SOMA 没挂载。
|
|
193
|
+
* 回环地址与 localhost 指向同一主机,这里补齐;反代域名等额外来源用
|
|
194
|
+
* `SOMA_DEV_ORIGINS`(逗号分隔)追加,不放宽到通配。
|
|
195
|
+
*/
|
|
196
|
+
const allowedDevOrigins = [
|
|
197
|
+
...new Set([
|
|
198
|
+
'localhost',
|
|
199
|
+
'127.0.0.1',
|
|
200
|
+
'[::1]',
|
|
201
|
+
...String(process.env.SOMA_DEV_ORIGINS ?? '')
|
|
202
|
+
.split(',')
|
|
203
|
+
.map((item) => item.trim())
|
|
204
|
+
.filter(Boolean),
|
|
205
|
+
]),
|
|
206
|
+
];
|
|
207
|
+
|
|
154
208
|
const nextConfig = {
|
|
155
209
|
env: {
|
|
156
210
|
SOMA_PAGE_RESPONSE_MODE: pageResponseConfig.mode,
|
|
157
211
|
},
|
|
158
212
|
|
|
213
|
+
allowedDevOrigins,
|
|
214
|
+
|
|
215
|
+
...(skipBuildChecks
|
|
216
|
+
? { typescript: { ignoreBuildErrors: true } }
|
|
217
|
+
: {}),
|
|
218
|
+
|
|
219
|
+
serverExternalPackages: ['jiti'],
|
|
220
|
+
|
|
159
221
|
experimental: {
|
|
160
222
|
externalDir: true,
|
|
161
|
-
|
|
223
|
+
// 低内存构建:并行 worker 是构建期内存的主要来源,小内存机器上把它压到 1
|
|
224
|
+
...(skipBuildChecks ? { cpus: 1, workerThreads: false } : {}),
|
|
162
225
|
},
|
|
163
226
|
|
|
164
227
|
transpilePackages,
|
|
@@ -169,6 +232,13 @@ const nextConfig = {
|
|
|
169
232
|
}
|
|
170
233
|
config.resolve.alias['@'] = __dirname;
|
|
171
234
|
config.resolve.alias['soma-core$'] = path.resolve(__dirname, 'core/index.ts');
|
|
235
|
+
// Webpack 不会对指向源码 `.ts` 的 package-export 子路径稳定做条件解析;
|
|
236
|
+
// 自适应布局词汇是 soma-ui 唯一需要的纯共享模块,显式落到同一份 core 源文件,
|
|
237
|
+
// 避免宿主开发服务器在首次编译时把 `soma-core/adaptive-vocabulary` 判成缺失。
|
|
238
|
+
config.resolve.alias['soma-core/adaptive-vocabulary$'] = path.resolve(
|
|
239
|
+
__dirname,
|
|
240
|
+
'core/shared/types/adaptive.types.ts',
|
|
241
|
+
);
|
|
172
242
|
config.resolve.alias['soma-core/base$'] = path.resolve(__dirname, 'core/client/base/index.ts');
|
|
173
243
|
config.resolve.alias['@core'] = path.resolve(__dirname, 'core');
|
|
174
244
|
for (const entry of hostFileDependencyEntries) {
|
|
@@ -203,6 +273,11 @@ const nextConfig = {
|
|
|
203
273
|
config.resolve.alias['@soma-host/config/app.config.yaml'] = resolveHostAppConfigAlias(
|
|
204
274
|
'core/server/host/app-config.stub.ts',
|
|
205
275
|
);
|
|
276
|
+
// 必须排在 '@soma-host' 之前:数据对象层可选,宿主没有 data/ 时落到空目录
|
|
277
|
+
config.resolve.alias['@soma-host/data'] = resolveOptionalHostSourceDir(
|
|
278
|
+
'data',
|
|
279
|
+
'core/client/host-bridge/empty-host/data',
|
|
280
|
+
);
|
|
206
281
|
config.resolve.alias['@soma-host'] = hostSourceRoot;
|
|
207
282
|
|
|
208
283
|
config.plugins.push(new SomaManifestWebpackPlugin({ hostDir }));
|