soma-core 1.3.2 → 1.3.4
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 +43 -0
- package/app/SomaPageClient.tsx +22 -68
- 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/bin/soma-lsp.cjs +1 -4
- package/core/build/compiler/full-manifest-builder.ts +19 -23
- package/core/build/compiler/html-include-expander.ts +56 -0
- package/core/build/compiler/page-assets.ts +26 -0
- package/core/build/compiler/page-declaration-compiler.ts +85 -0
- package/core/build/compiler/rollup-plugin-soma.ts +4 -13
- package/core/build/compiler/route-builder.ts +0 -2
- package/core/build/compiler/rspack-plugin-soma.js +1 -10
- package/core/build/compiler/soma-manifest-webpack-plugin.js +54 -9
- package/core/build/compiler/soma-precompile.js +3581 -2387
- package/core/build/compiler/soma-precompile.ts +44 -2
- package/core/build/compiler/soma-rspack-yaml-loader.js +5 -8
- package/core/build/compiler/soma-webpack-loader.js +6 -15
- package/core/build/compiler/vite-plugin-soma.ts +9 -21
- package/core/build/component/pack-from-dir.ts +58 -0
- package/core/build/component/package-loader.ts +281 -0
- package/core/build/eject/apply-eject.ts +133 -0
- package/core/build/eject/plan-eject.ts +133 -0
- package/core/build/lsp/cross-file-diagnostics.cjs +82 -113
- package/core/build/lsp/extra-completion.cjs +14 -8
- package/core/build/lsp/lsp-navigation.cjs +50 -43
- package/core/build/lsp/soma-declaration.cjs +85 -0
- package/core/build/lsp/ui-yaml-completion.cjs +98 -104
- package/core/build/v2/block-compile.ts +200 -0
- package/core/build/v2/block-loader.ts +33 -0
- package/core/build/v2/html-index.ts +120 -0
- package/core/build/v2/migrate-v1.ts +370 -0
- package/core/build/v2/soma-file-loader.ts +216 -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 +277 -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 +445 -0
- package/core/client/component/component-registry.ts +71 -0
- package/core/client/component/contract-compat.ts +132 -0
- package/core/client/component/example-v2.ts +132 -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 +249 -24
- 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 +11 -10
- package/core/client/engine/render-engine.ts +39 -4
- package/core/client/engine/runtime-builder.ts +23 -0
- package/core/client/engine/soma-bootstrap.ts +380 -7
- package/core/client/engine/style-binder.ts +47 -1
- 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/parser/v2/namespace.ts +182 -0
- package/core/client/parser/v2/page-parser.ts +359 -0
- package/core/client/parser/v2/use-parser.ts +412 -0
- package/core/client/parser/value-lang.ts +340 -0
- package/core/client/pipes/pipe-registry.ts +249 -0
- package/core/client/quality/SomaQualityRegistry.ts +3 -0
- package/core/client/registry/declaration-renderer.ts +161 -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/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/harmony.ts +307 -0
- package/core/client/theme/scene-tokens.ts +134 -0
- package/core/client/theme/theme-axes.ts +228 -0
- package/core/client/theme/theme-engine.ts +1196 -0
- package/core/client/theme/tone-solver.ts +118 -0
- package/core/client/typography/typography-base.ts +34 -0
- package/core/client/validation/contract-validator.ts +48 -5
- package/core/index.ts +262 -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 +34 -7
- package/core/server/host/soma-page-compile.ts +33 -0
- package/core/server/index.ts +45 -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 +99 -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 +932 -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 +96 -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 +54 -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 +67 -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 +120 -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 +7811 -1380
- package/dist/types/build/compiler/full-manifest-builder.d.ts +6 -2
- package/dist/types/build/compiler/html-include-expander.d.ts +19 -0
- package/dist/types/build/compiler/page-assets.d.ts +3 -0
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +33 -0
- package/dist/types/build/compiler/rollup-plugin-soma.d.ts +0 -2
- package/dist/types/build/compiler/route-builder.d.ts +0 -1
- package/dist/types/build/compiler/soma-precompile.d.ts +17 -0
- package/dist/types/build/compiler/vite-plugin-soma.d.ts +2 -7
- package/dist/types/build/component/pack-from-dir.d.ts +17 -0
- package/dist/types/build/component/package-loader.d.ts +40 -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/build/v2/block-compile.d.ts +28 -0
- package/dist/types/build/v2/block-loader.d.ts +9 -0
- package/dist/types/build/v2/html-index.d.ts +37 -0
- package/dist/types/build/v2/migrate-v1.d.ts +32 -0
- package/dist/types/build/v2/soma-file-loader.d.ts +45 -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 +110 -0
- package/dist/types/client/component/component-registry.d.ts +12 -0
- package/dist/types/client/component/contract-compat.d.ts +16 -0
- package/dist/types/client/component/example-v2.d.ts +9 -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 +51 -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 +25 -1
- package/dist/types/client/engine/runtime-builder.d.ts +7 -0
- package/dist/types/client/engine/soma-bootstrap.d.ts +118 -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/parser/v2/namespace.d.ts +52 -0
- package/dist/types/client/parser/v2/page-parser.d.ts +21 -0
- package/dist/types/client/parser/v2/use-parser.d.ts +72 -0
- package/dist/types/client/parser/value-lang.d.ts +63 -0
- package/dist/types/client/pipes/pipe-registry.d.ts +38 -0
- package/dist/types/client/registry/declaration-renderer.d.ts +50 -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/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/harmony.d.ts +77 -0
- package/dist/types/client/theme/scene-tokens.d.ts +25 -0
- package/dist/types/client/theme/theme-axes.d.ts +81 -0
- package/dist/types/client/theme/theme-engine.d.ts +77 -0
- package/dist/types/client/theme/tone-solver.d.ts +47 -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 +47 -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 +2 -0
- package/dist/types/server/host/soma-page-compile.d.ts +7 -0
- package/dist/types/server/index.d.ts +6 -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 +12 -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 +78 -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/editor/vscode/package.json +1 -24
- package/global.d.ts +5 -11
- package/next.config.js +85 -28
- package/package.json +33 -11
- package/proxy.ts +62 -0
- package/tailwind.config.ts +0 -1
- package/core/build/lsp/event-yaml-completion.cjs +0 -106
- 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/editor/vscode/syntaxes/soma-event-yaml.tmLanguage.json +0 -30
- package/middleware.ts +0 -33
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import yaml from 'js-yaml';
|
|
2
|
+
import { compileSomaV2 } from '../v2/block-compile';
|
|
3
|
+
import { expandSomaHtmlIncludes } from './html-include-expander';
|
|
4
|
+
import type { SomaDataConfig } from '../../shared/types/data-config.types';
|
|
5
|
+
import type { ParsedEvent } from '../../shared/types/event.types';
|
|
6
|
+
import type { PropertyTrigger } from '../../shared/types/trigger.types';
|
|
7
|
+
import type { StyleConfig } from '../../shared/types/style-config.types';
|
|
8
|
+
import type { ParsedTimer } from '../../shared/types/timer.types';
|
|
9
|
+
import type { UiConfig } from '../../shared/types/ui-config.types';
|
|
10
|
+
import {
|
|
11
|
+
compileDataConfig,
|
|
12
|
+
compileEventConfigFromRaw,
|
|
13
|
+
} from './soma-precompile';
|
|
14
|
+
|
|
15
|
+
export interface SomaPageDeclarationInput {
|
|
16
|
+
html: string;
|
|
17
|
+
uiYaml: string;
|
|
18
|
+
eventYaml?: string;
|
|
19
|
+
styleYaml?: string;
|
|
20
|
+
dataYaml?: string;
|
|
21
|
+
externalBlocks?: ReadonlyMap<string, string>;
|
|
22
|
+
/** 与浏览器运行时一致的共享 HTML 片段;仅在构建锚点校验前展开。 */
|
|
23
|
+
includes?: Readonly<Record<string, string>>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface SomaRuntimeDeclarationAssets {
|
|
27
|
+
uiYaml: string;
|
|
28
|
+
eventYaml: string;
|
|
29
|
+
styleYaml: string;
|
|
30
|
+
dataYaml?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface CompiledPageDeclaration {
|
|
34
|
+
uiConfig: UiConfig;
|
|
35
|
+
eventConfig: ParsedEvent[];
|
|
36
|
+
triggers: PropertyTrigger[];
|
|
37
|
+
timers: ParsedTimer[];
|
|
38
|
+
styleConfig?: StyleConfig;
|
|
39
|
+
dataConfig?: SomaDataConfig;
|
|
40
|
+
runtimeAssets: SomaRuntimeDeclarationAssets;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const dump = (value: unknown): string =>
|
|
44
|
+
yaml.dump(value, { lineWidth: 120, noRefs: true, quotingType: '"' });
|
|
45
|
+
|
|
46
|
+
/** 编译一整页 SOMA DSL 声明。旧页面形状与页面侧车在唯一入口直接拒绝。 */
|
|
47
|
+
export function compilePageDeclaration(input: SomaPageDeclarationInput): CompiledPageDeclaration {
|
|
48
|
+
const eventYaml = input.eventYaml ?? '';
|
|
49
|
+
const styleYaml = input.styleYaml ?? '';
|
|
50
|
+
const dataYaml = input.dataYaml ?? '';
|
|
51
|
+
|
|
52
|
+
const sidecars = [
|
|
53
|
+
eventYaml.trim() ? 'eventYaml / *_event.yaml' : '',
|
|
54
|
+
styleYaml.trim() ? 'styleYaml / *_style.yaml' : '',
|
|
55
|
+
dataYaml.trim() ? 'dataYaml / *_data.yaml' : '',
|
|
56
|
+
].filter(Boolean);
|
|
57
|
+
if (sidecars.length > 0) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`[soma-core][SOMA DSL] 页面侧车已退役:${sidecars.join('、')}。`
|
|
60
|
+
+ '事件、样式状态与数据对象必须写进同一份 SOMA DSL 声明。',
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const compiled = compileSomaV2({
|
|
65
|
+
html: expandSomaHtmlIncludes(input.html, input.includes),
|
|
66
|
+
uiYamlRaw: input.uiYaml,
|
|
67
|
+
...(input.externalBlocks ? { externalBlocks: input.externalBlocks } : {}),
|
|
68
|
+
});
|
|
69
|
+
const eventBundle = compileEventConfigFromRaw(compiled.event);
|
|
70
|
+
const embeddedDataYaml = Object.keys(compiled.data).length > 0 ? dump({ data: compiled.data }) : '';
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
uiConfig: compiled.ui,
|
|
74
|
+
eventConfig: eventBundle.events,
|
|
75
|
+
triggers: eventBundle.triggers,
|
|
76
|
+
timers: eventBundle.timers,
|
|
77
|
+
...(embeddedDataYaml ? { dataConfig: compileDataConfig(embeddedDataYaml) } : {}),
|
|
78
|
+
runtimeAssets: {
|
|
79
|
+
uiYaml: dump(compiled.ui),
|
|
80
|
+
eventYaml: Object.keys(compiled.event).length > 0 ? dump(compiled.event) : '',
|
|
81
|
+
styleYaml: '',
|
|
82
|
+
...(embeddedDataYaml ? { dataYaml: embeddedDataYaml } : {}),
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -2,22 +2,16 @@
|
|
|
2
2
|
// Rollup 预编译插件:构建阶段将 YAML 编译为 JS 模块(与 vite-plugin-soma 对齐)
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
precompileEventYaml,
|
|
7
|
-
precompileStyleYaml,
|
|
5
|
+
precompileUiModule,
|
|
8
6
|
precompileYaml,
|
|
9
7
|
} from './soma-precompile';
|
|
10
8
|
|
|
11
9
|
export interface SomaRollupPluginOptions {
|
|
12
10
|
uiSuffix?: string;
|
|
13
|
-
eventSuffix?: string;
|
|
14
|
-
styleSuffix?: string;
|
|
15
11
|
}
|
|
16
12
|
|
|
17
13
|
export function somaRollupPlugin(options: SomaRollupPluginOptions = {}) {
|
|
18
14
|
const uiSuffix = options.uiSuffix ?? '_ui.yaml';
|
|
19
|
-
const eventSuffix = options.eventSuffix ?? '_event.yaml';
|
|
20
|
-
const styleSuffix = options.styleSuffix ?? '_style.yaml';
|
|
21
15
|
|
|
22
16
|
return {
|
|
23
17
|
name: 'rollup-plugin-soma',
|
|
@@ -28,13 +22,10 @@ export function somaRollupPlugin(options: SomaRollupPluginOptions = {}) {
|
|
|
28
22
|
|
|
29
23
|
try {
|
|
30
24
|
if (id.endsWith(uiSuffix)) {
|
|
31
|
-
return { code: `export default ${
|
|
25
|
+
return { code: `export default ${precompileUiModule(code)};`, map: { mappings: '' } };
|
|
32
26
|
}
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
if (id.endsWith(styleSuffix)) {
|
|
37
|
-
return { code: `export default ${precompileStyleYaml(code)};`, map: { mappings: '' } };
|
|
27
|
+
if (/_((event)|(style)|(data))\.ya?ml$/.test(id)) {
|
|
28
|
+
throw new Error('页面侧车已退役;事件、样式状态与数据对象必须并入同一份 SOMA DSL 声明');
|
|
38
29
|
}
|
|
39
30
|
return { code: `export default ${precompileYaml(code)};`, map: { mappings: '' } };
|
|
40
31
|
} catch (err) {
|
|
@@ -5,7 +5,6 @@ export interface SomaRouteEntry {
|
|
|
5
5
|
path: string;
|
|
6
6
|
htmlFile: string;
|
|
7
7
|
uiFile: string;
|
|
8
|
-
eventFile: string;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -21,7 +20,6 @@ export function buildRouteTable(htmlFiles: string[]): SomaRouteEntry[] {
|
|
|
21
20
|
path: `/${base}`,
|
|
22
21
|
htmlFile,
|
|
23
22
|
uiFile: `${base}_ui.yaml`,
|
|
24
|
-
eventFile: `${base}_event.yaml`,
|
|
25
23
|
};
|
|
26
24
|
});
|
|
27
25
|
}
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
const {
|
|
2
|
-
precompileUiYaml,
|
|
3
|
-
precompileEventYaml,
|
|
4
|
-
precompileStyleYaml,
|
|
5
|
-
precompileYaml,
|
|
6
|
-
} = require('./soma-precompile');
|
|
7
|
-
|
|
8
1
|
function somaRspackPlugin(options = {}) {
|
|
9
2
|
const uiSuffix = options.uiSuffix ?? '_ui.yaml';
|
|
10
|
-
const eventSuffix = options.eventSuffix ?? '_event.yaml';
|
|
11
|
-
const styleSuffix = options.styleSuffix ?? '_style.yaml';
|
|
12
3
|
|
|
13
4
|
return {
|
|
14
5
|
name: 'rspack-plugin-soma',
|
|
@@ -21,7 +12,7 @@ function somaRspackPlugin(options = {}) {
|
|
|
21
12
|
use: [
|
|
22
13
|
{
|
|
23
14
|
loader: require.resolve('./soma-rspack-yaml-loader.js'),
|
|
24
|
-
options: { uiSuffix
|
|
15
|
+
options: { uiSuffix },
|
|
25
16
|
},
|
|
26
17
|
],
|
|
27
18
|
},
|
|
@@ -30,6 +30,13 @@ function readJson(filePath) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
function writeFileIfChanged(filePath, content) {
|
|
34
|
+
if (fs.existsSync(filePath) && fs.readFileSync(filePath, 'utf8') === content) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
fs.writeFileSync(filePath, content);
|
|
38
|
+
}
|
|
39
|
+
|
|
33
40
|
function packagePathInNodeModules(hostDir, packageName) {
|
|
34
41
|
return path.join(hostDir, 'node_modules', ...packageName.split('/'));
|
|
35
42
|
}
|
|
@@ -151,6 +158,40 @@ function collectPageEntries(sources) {
|
|
|
151
158
|
return [...byHtmlFile.values()].sort((a, b) => a.htmlFile.localeCompare(b.htmlFile));
|
|
152
159
|
}
|
|
153
160
|
|
|
161
|
+
/** 与运行期 collectIncludes 保持同一覆盖顺序:包默认值,Host 同名片段覆盖。 */
|
|
162
|
+
function collectIncludes(sources) {
|
|
163
|
+
const includes = {};
|
|
164
|
+
const orderedSources = [
|
|
165
|
+
...sources.filter((source) => source.type === 'package'),
|
|
166
|
+
...sources.filter((source) => source.type === 'host'),
|
|
167
|
+
];
|
|
168
|
+
for (const source of orderedSources) {
|
|
169
|
+
const sharedDir = path.join(source.assetRoot, 'html', 'shared');
|
|
170
|
+
if (!fs.existsSync(sharedDir)) continue;
|
|
171
|
+
for (const entry of fs.readdirSync(sharedDir, { withFileTypes: true })) {
|
|
172
|
+
if (!entry.isFile() || !entry.name.endsWith('.html')) continue;
|
|
173
|
+
includes[`shared/${entry.name}`] = fs.readFileSync(path.join(sharedDir, entry.name), 'utf8');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return includes;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function assertNoPageSidecars(source, base) {
|
|
180
|
+
const uiDir = path.join(source.assetRoot, 'ui');
|
|
181
|
+
const forbidden = [
|
|
182
|
+
path.join(source.assetRoot, 'event', `${base}_event.yaml`),
|
|
183
|
+
path.join(uiDir, `${base}_style.yaml`),
|
|
184
|
+
path.join(source.assetRoot, 'data', `${base}_data.yaml`),
|
|
185
|
+
path.join(uiDir, `${base}_data.yaml`),
|
|
186
|
+
].filter((file) => fs.existsSync(file));
|
|
187
|
+
if (forbidden.length > 0) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
'页面侧车已退役;请把事件、样式状态与数据对象并入同一份 SOMA DSL 声明:'
|
|
190
|
+
+ forbidden.map((file) => path.relative(source.assetRoot, file)).join(', '),
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
154
195
|
class SomaManifestWebpackPlugin {
|
|
155
196
|
constructor(options = {}) {
|
|
156
197
|
this.hostDir = options.hostDir;
|
|
@@ -158,7 +199,7 @@ class SomaManifestWebpackPlugin {
|
|
|
158
199
|
this.jiti = createJiti(__filename, {
|
|
159
200
|
interopDefault: true,
|
|
160
201
|
alias: {
|
|
161
|
-
'@core': path.resolve(__dirname, '
|
|
202
|
+
'@core': path.resolve(__dirname, '../..'),
|
|
162
203
|
},
|
|
163
204
|
});
|
|
164
205
|
}
|
|
@@ -173,8 +214,10 @@ class SomaManifestWebpackPlugin {
|
|
|
173
214
|
|
|
174
215
|
try {
|
|
175
216
|
const { precompileAll } = this.jiti('./full-manifest-builder.ts');
|
|
217
|
+
const { loadExternalBlocks } = this.jiti('../v2/block-loader.ts');
|
|
176
218
|
const sources = getSomaAssetSources(hostDir);
|
|
177
219
|
const pageEntries = collectPageEntries(sources);
|
|
220
|
+
const includes = collectIncludes(sources);
|
|
178
221
|
const htmlFiles = pageEntries.map((entry) => entry.htmlFile);
|
|
179
222
|
const readYaml = (filePath) =>
|
|
180
223
|
fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : '';
|
|
@@ -186,11 +229,15 @@ class SomaManifestWebpackPlugin {
|
|
|
186
229
|
.map(({ source, htmlFile }) => {
|
|
187
230
|
const base = htmlFile.replace(/\.html$/, '');
|
|
188
231
|
const sourceAppConfigPath = resolveAppConfigPath(source.configRoot);
|
|
232
|
+
const uiDir = path.join(source.assetRoot, 'ui');
|
|
233
|
+
assertNoPageSidecars(source, base);
|
|
234
|
+
const externalBlocks = loadExternalBlocks(uiDir, base);
|
|
189
235
|
return {
|
|
190
236
|
path: `/${base}`,
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
237
|
+
html: fs.readFileSync(path.join(source.assetRoot, 'html', htmlFile), 'utf8'),
|
|
238
|
+
uiYaml: readYaml(path.join(uiDir, `${base}_ui.yaml`)),
|
|
239
|
+
...(externalBlocks.size > 0 ? { externalBlocks } : {}),
|
|
240
|
+
...(Object.keys(includes).length > 0 ? { includes } : {}),
|
|
194
241
|
appConfigYaml: sourceAppConfigPath
|
|
195
242
|
? readYaml(sourceAppConfigPath)
|
|
196
243
|
: (hostAppConfigPath ? readYaml(hostAppConfigPath) : ''),
|
|
@@ -203,15 +250,13 @@ class SomaManifestWebpackPlugin {
|
|
|
203
250
|
|
|
204
251
|
const outDir = path.join(hostDir, this.outputDir);
|
|
205
252
|
if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true });
|
|
206
|
-
|
|
253
|
+
writeFileIfChanged(
|
|
207
254
|
path.join(outDir, 'manifest.json'),
|
|
208
255
|
JSON.stringify(manifest, null, 2),
|
|
209
256
|
);
|
|
210
257
|
} catch (e) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
`[soma-manifest] 预编译跳过: ${e.message}`,
|
|
214
|
-
);
|
|
258
|
+
callback(e);
|
|
259
|
+
return;
|
|
215
260
|
}
|
|
216
261
|
|
|
217
262
|
callback();
|