soma-core 1.0.2 → 1.1.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.
Files changed (93) hide show
  1. package/app/SomaPageClient.tsx +11 -20
  2. package/app/[...path]/page.tsx +21 -0
  3. package/app/api/[...path]/route.ts +86 -77
  4. package/app/components/SomaHostPage.tsx +133 -0
  5. package/app/components/SomaHydrationShell.tsx +1 -1
  6. package/app/favicon.ico/route.ts +13 -0
  7. package/app/layout.tsx +10 -6
  8. package/app/page.tsx +7 -18
  9. package/app/soma/[...path]/route.ts +9 -0
  10. package/app/{api/soma-manifest → soma/manifest}/route.ts +3 -3
  11. package/app/soma/page/route.ts +29 -0
  12. package/app/soma/page-object/route.ts +158 -0
  13. package/app/soma/route.ts +9 -0
  14. package/bin/soma-mock.mjs +38 -0
  15. package/bin/soma.cjs +1 -1
  16. package/core/api/load-host-service.ts +5 -2
  17. package/core/base/SomaHttpClient.ts +5 -3
  18. package/core/compiler/full-manifest-builder.ts +84 -69
  19. package/core/compiler/host-config-sync.cjs +32 -6
  20. package/core/compiler/page-base-resolver.ts +3 -0
  21. package/core/compiler/soma-manifest-webpack-plugin.js +160 -10
  22. package/core/engine/dom-renderer.ts +160 -24
  23. package/core/engine/soma-headless-page.ts +86 -0
  24. package/core/host/app-config-composer.ts +90 -0
  25. package/core/host/app-config.stub.ts +2 -0
  26. package/core/host/host-config-paths.cjs +100 -0
  27. package/core/host/host-config-paths.ts +132 -0
  28. package/core/host/invoke-host-request-hook.ts +37 -0
  29. package/core/host/load-host-domain-class.ts +87 -0
  30. package/core/host/locale.stub.ts +2 -0
  31. package/core/host/page-response-mode.cjs +96 -0
  32. package/core/host/page-response-request.ts +35 -0
  33. package/core/host/request-origin.ts +18 -0
  34. package/core/host/resolve-host-request-hook.ts +29 -0
  35. package/core/host/server-page-assets.ts +193 -0
  36. package/core/host/soma-domain-loaders.stub.ts +6 -0
  37. package/core/host/soma-domain-loaders.ts +69 -0
  38. package/core/host/soma-request-hook-host.stub.ts +4 -0
  39. package/core/host/source-packages.ts +153 -0
  40. package/core/index.ts +22 -0
  41. package/core/infra/http/SomaHttpService.ts +23 -14
  42. package/core/infra/http/soma-server-request-context.ts +126 -0
  43. package/core/mock/node/catch-all.mjs +35 -0
  44. package/core/mock/node/cli.d.mts +58 -0
  45. package/core/mock/node/cli.mjs +243 -0
  46. package/core/mock/node/context.mjs +167 -0
  47. package/core/mock/node/environment-policy.mjs +52 -0
  48. package/core/mock/node/plugin-loader.mjs +212 -0
  49. package/core/mock/node/preload.mjs +91 -0
  50. package/core/mock/node/process-lifecycle.mjs +236 -0
  51. package/core/mock/node/public.d.mts +110 -0
  52. package/core/mock/node/public.mjs +4 -0
  53. package/core/mock/node/registry.mjs +336 -0
  54. package/core/mock/node/schema-generator.mjs +1310 -0
  55. package/core/mock/testing/host-harness.d.mts +66 -0
  56. package/core/mock/testing/host-harness.mjs +276 -0
  57. package/core/mock/testing/host-runtime.mjs +48 -0
  58. package/core/runtime/SomaRuntimeServices.ts +5 -1
  59. package/core/runtime/serialize-page-state.ts +152 -0
  60. package/dist/cli/soma.js +375 -4
  61. package/dist/core/index.cjs +2957 -2387
  62. package/dist/tsconfig.types.tsbuildinfo +1 -1
  63. package/dist/types/base/SomaHttpClient.d.ts +2 -0
  64. package/dist/types/compiler/full-manifest-builder.d.ts +2 -0
  65. package/dist/types/engine/dom-renderer.d.ts +6 -0
  66. package/dist/types/engine/soma-headless-page.d.ts +10 -0
  67. package/dist/types/host/app-config-composer.d.ts +6 -0
  68. package/dist/types/host/app-config.stub.d.ts +3 -0
  69. package/dist/types/host/host-config-paths.d.ts +23 -0
  70. package/dist/types/host/invoke-host-request-hook.d.ts +8 -0
  71. package/dist/types/host/load-host-domain-class.d.ts +12 -0
  72. package/dist/types/host/locale.stub.d.ts +3 -0
  73. package/dist/types/host/page-response-request.d.ts +9 -0
  74. package/dist/types/host/request-origin.d.ts +1 -0
  75. package/dist/types/host/resolve-host-request-hook.d.ts +16 -0
  76. package/dist/types/host/server-page-assets.d.ts +29 -0
  77. package/dist/types/host/soma-domain-loaders.d.ts +19 -0
  78. package/dist/types/host/soma-domain-loaders.stub.d.ts +4 -0
  79. package/dist/types/host/soma-request-hook-host.stub.d.ts +2 -0
  80. package/dist/types/host/source-packages.d.ts +12 -0
  81. package/dist/types/index.d.ts +3 -0
  82. package/dist/types/infra/http/SomaHttpService.d.ts +2 -0
  83. package/dist/types/infra/http/soma-server-request-context.d.ts +5 -0
  84. package/dist/types/runtime/serialize-page-state.d.ts +10 -0
  85. package/docs//351/241/265/351/235/242JSON/346/250/241/345/274/217/346/216/245/345/205/245/346/214/207/345/215/227.md +141 -0
  86. package/global.d.ts +74 -33
  87. package/middleware.ts +33 -0
  88. package/next.config.js +166 -16
  89. package/package.json +47 -13
  90. package/tailwind.config.ts +21 -17
  91. package/tsconfig.json +1 -5
  92. package/app/api/page/route.ts +0 -99
  93. package/app/loading.tsx +0 -5
@@ -0,0 +1,158 @@
1
+ import { NextRequest } from 'next/server';
2
+ import { runSomaHeadlessPage } from '../../../core/engine/soma-headless-page';
3
+ import { SomaDomainLoadError, loadHostDomainClass } from '../../../core/host/load-host-domain-class';
4
+ import {
5
+ SOMA_PAGE_REQUEST_URL_HEADER,
6
+ isJsonPageResponseMode,
7
+ isSomaPageRequestPath,
8
+ } from '../../../core/host/page-response-request';
9
+ import { resolveSomaRequestOrigin } from '../../../core/host/request-origin';
10
+ import {
11
+ SomaPageAssetError,
12
+ loadSomaServerPageAssets,
13
+ } from '../../../core/host/server-page-assets';
14
+ import { invokeHostRequestHook } from '../../../core/host/invoke-host-request-hook';
15
+ import { withSomaServerRequestContext } from '../../../core/infra/http/soma-server-request-context';
16
+ import { SomaPageSerializationError } from '../../../core/runtime/serialize-page-state';
17
+
18
+ export const runtime = 'nodejs';
19
+ export const dynamic = 'force-dynamic';
20
+
21
+ function jsonHeaders(): HeadersInit {
22
+ return {
23
+ 'cache-control': 'no-store',
24
+ 'x-content-type-options': 'nosniff',
25
+ };
26
+ }
27
+
28
+ function errorResponse(error: unknown, pagePath: string): Response {
29
+ const status = error instanceof SomaPageAssetError ? error.status : 500;
30
+ const code = error instanceof SomaPageAssetError
31
+ || error instanceof SomaDomainLoadError
32
+ || error instanceof SomaPageSerializationError
33
+ ? error.code
34
+ : 'SOMA_HEADLESS_PAGE_FAILED';
35
+ const message = error instanceof Error ? error.message : String(error);
36
+ if (status >= 500) {
37
+ console.error('[soma-headless] ' + pagePath + ': ' + message);
38
+ }
39
+ return Response.json(
40
+ {
41
+ error: {
42
+ code,
43
+ message: message || 'Headless page request failed',
44
+ path: pagePath,
45
+ },
46
+ },
47
+ { status, headers: jsonHeaders() },
48
+ );
49
+ }
50
+
51
+ /**
52
+ * Only relative Host page paths are accepted (must start with `/`).
53
+ * Absolute / protocol-relative URLs are rejected so Origin/Cookie cannot be hijacked.
54
+ */
55
+ function resolveOriginalPageUrl(request: NextRequest): URL {
56
+ const rawPageUrl = (
57
+ request.headers.get(SOMA_PAGE_REQUEST_URL_HEADER)
58
+ || request.nextUrl.searchParams.get('path')
59
+ || '/'
60
+ ).trim() || '/';
61
+ if (
62
+ !rawPageUrl.startsWith('/')
63
+ || rawPageUrl.startsWith('//')
64
+ || rawPageUrl.includes('://')
65
+ ) {
66
+ throw new SomaPageAssetError(
67
+ 'SOMA_PAGE_PATH_INVALID',
68
+ 400,
69
+ `Absolute or protocol-relative page path is not allowed: ${rawPageUrl}`,
70
+ );
71
+ }
72
+ const requestHeaders = new Headers(request.headers);
73
+ return new URL(rawPageUrl, resolveSomaRequestOrigin(requestHeaders));
74
+ }
75
+
76
+ /** Internally rewritten Host page request. Direct access is disabled outside JSON mode. */
77
+ export async function GET(request: NextRequest): Promise<Response> {
78
+ if (!isJsonPageResponseMode(process.env.SOMA_PAGE_RESPONSE_MODE)) {
79
+ return Response.json(
80
+ {
81
+ error: {
82
+ code: 'SOMA_PAGE_RESPONSE_MODE_DISABLED',
83
+ message: 'JSON page response mode is disabled',
84
+ path: request.nextUrl.pathname,
85
+ },
86
+ },
87
+ { status: 404, headers: jsonHeaders() },
88
+ );
89
+ }
90
+
91
+ let pageUrl: URL;
92
+ try {
93
+ pageUrl = resolveOriginalPageUrl(request);
94
+ } catch (error) {
95
+ return errorResponse(error, request.nextUrl.pathname);
96
+ }
97
+ if (!isSomaPageRequestPath(pageUrl.pathname)) {
98
+ return Response.json(
99
+ {
100
+ error: {
101
+ code: 'SOMA_PAGE_PATH_INVALID',
102
+ message: 'Not a Host page path: ' + pageUrl.pathname,
103
+ path: pageUrl.pathname,
104
+ },
105
+ },
106
+ { status: 400, headers: jsonHeaders() },
107
+ );
108
+ }
109
+
110
+ const requestHeaders = new Headers(request.headers);
111
+ requestHeaders.delete(SOMA_PAGE_REQUEST_URL_HEADER);
112
+ const pageRequest = new Request(pageUrl, {
113
+ method: request.method,
114
+ headers: requestHeaders,
115
+ });
116
+ try {
117
+ const rejected = await invokeHostRequestHook(pageRequest, {
118
+ kind: 'page',
119
+ path: pageUrl.pathname,
120
+ pageHref: pageUrl.pathname,
121
+ });
122
+ if (rejected) return rejected;
123
+
124
+ const assets = loadSomaServerPageAssets({
125
+ hostDir: process.env.SOMA_HOST_DIR,
126
+ urlPath: pageUrl.pathname,
127
+ profile: 'headless',
128
+ });
129
+ const routerPath = pageUrl.pathname + pageUrl.search;
130
+ const state = await withSomaServerRequestContext(
131
+ pageRequest,
132
+ async () => {
133
+ const DomainClass = await loadHostDomainClass(
134
+ {
135
+ base: assets.base,
136
+ sourcePackage: assets.sourcePackage,
137
+ },
138
+ { allowLocaleOnlyFallback: false },
139
+ );
140
+ return runSomaHeadlessPage({
141
+ DomainClass,
142
+ uiYaml: assets.ui,
143
+ localeYaml: assets.localeYaml,
144
+ appConfigYaml: assets.appConfigYaml,
145
+ routerPath,
146
+ });
147
+ },
148
+ { pageHref: routerPath },
149
+ );
150
+
151
+ return Response.json(state, {
152
+ status: 200,
153
+ headers: jsonHeaders(),
154
+ });
155
+ } catch (error) {
156
+ return errorResponse(error, pageUrl.pathname);
157
+ }
158
+ }
@@ -0,0 +1,9 @@
1
+ function somaRouteNotFound(): Response {
2
+ return Response.json({ error: 'SOMA internal endpoint not found' }, { status: 404 });
3
+ }
4
+
5
+ export const GET = somaRouteNotFound;
6
+ export const POST = somaRouteNotFound;
7
+ export const PUT = somaRouteNotFound;
8
+ export const PATCH = somaRouteNotFound;
9
+ export const DELETE = somaRouteNotFound;
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Optional Mock capability CLI for plain SOMA Hosts.
4
+ * Does not change the regular `soma` lifecycle; callers must invoke soma-mock
5
+ * explicitly. Hosts that already use an upper-framework Mock switch should keep
6
+ * using that switch instead of this bin.
7
+ */
8
+ import path from 'node:path';
9
+ import process from 'node:process';
10
+ import { fileURLToPath } from 'node:url';
11
+ import { runSomaMockCli, SomaMockCliError } from '../core/mock/node/cli.mjs';
12
+
13
+ const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
14
+ const SOMA_BIN = path.join(PACKAGE_ROOT, 'bin', 'soma.cjs');
15
+
16
+ runSomaMockCli(process.argv.slice(2), {
17
+ enabled: true,
18
+ appRoot: process.cwd(),
19
+ commandName: 'soma-mock',
20
+ env: process.env,
21
+ delegate: {
22
+ executable: process.execPath,
23
+ argsPrefix: [SOMA_BIN],
24
+ cwd: process.cwd(),
25
+ },
26
+ }).then(
27
+ (code) => {
28
+ process.exitCode = code;
29
+ },
30
+ (error) => {
31
+ const code = error instanceof SomaMockCliError && error.code
32
+ ? error.code
33
+ : (typeof error?.code === 'string' && error.code.trim() ? error.code.trim() : 'UNEXPECTED_ERROR');
34
+ const message = error instanceof Error ? error.message : String(error);
35
+ console.error(`[soma-mock][${code}] ${message}`);
36
+ process.exitCode = 1;
37
+ },
38
+ );
package/bin/soma.cjs CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  /**
3
3
  * SOMA CLI 薄入口 — 优先委托 dist/cli/soma.js,回退到内联实现
4
4
  */
@@ -3,6 +3,7 @@ import path from 'node:path';
3
3
  import createJiti from 'jiti';
4
4
  import type { IService } from './IService';
5
5
  import { resolveServiceFilePath } from './service-path';
6
+ import { getSomaAssetSources } from '../host/source-packages';
6
7
 
7
8
  function isService(obj: unknown): obj is IService {
8
9
  if (!obj || typeof obj !== 'object') return false;
@@ -40,8 +41,10 @@ export function loadHostService(segments: string[]): IService | null {
40
41
  const hostDir = process.env.SOMA_HOST_DIR;
41
42
  if (!hostDir) return null;
42
43
 
43
- const filePath = resolveServiceFilePath(hostDir, segments);
44
- if (!filePath || !fs.existsSync(filePath)) return null;
44
+ const filePath = getSomaAssetSources(hostDir)
45
+ .map((source) => resolveServiceFilePath(source.codeRoot, segments))
46
+ .find((candidate): candidate is string => Boolean(candidate && fs.existsSync(candidate)));
47
+ if (!filePath) return null;
45
48
 
46
49
  const isDev = process.env.NODE_ENV !== 'production';
47
50
  if (!isDev && instanceCache.has(filePath)) {
@@ -6,12 +6,14 @@
6
6
  /**
7
7
  * HTTP 客户端配置
8
8
  */
9
- export interface SomaHttpClientConfig {
9
+ export interface SomaHttpClientConfig {
10
10
  /** API 基础地址(如 "https://api.example.com") */
11
11
  baseURL: string;
12
12
  /** 请求超时时间(毫秒),默认 30000 */
13
- timeout?: number;
14
- }
13
+ timeout?: number;
14
+ /** Generic headers supplied by the host runtime, such as page context. */
15
+ defaultHeaders?: Record<string, string> | (() => Record<string, string>);
16
+ }
15
17
 
16
18
  /**
17
19
  * SomaHttpClient — API 请求封装
@@ -1,69 +1,84 @@
1
- // core/compiler/full-manifest-builder.ts
2
- // 职责:全量预编译项目所有声明式配置
3
-
4
- import type { UiConfig } from '../types/ui-config.types';
5
- import type { ParsedEvent } from '../types/event.types';
6
- import type { PropertyTrigger } from '../types/trigger.types';
7
- import type { ParsedTimer } from '../types/timer.types';
8
- import type { StyleConfig } from '../types/style-config.types';
9
- import { compileUiConfig, compileStyleConfig, precompileYaml } from '@core/compiler/soma-precompile';
10
- import { parseEventConfig } from '../parser/pipeline-parser';
11
- import { splitEventConfigRaw } from '../parser/trigger-parser';
12
- import { buildRouteTable, type SomaRouteEntry } from './route-builder';
13
- import yaml from 'js-yaml';
14
-
15
- function compileEventBundle(eventYaml: string) {
16
- if (!eventYaml.trim()) {
17
- return { events: [], triggers: [] as PropertyTrigger[], timers: [] as ParsedTimer[] };
18
- }
19
- const { eventsRaw, triggers, timers } = splitEventConfigRaw(yaml.load(eventYaml));
20
- return {
21
- events: parseEventConfig(eventsRaw as any),
22
- triggers,
23
- timers,
24
- };
25
- }
26
-
27
- export interface SomaPrecompiledPage {
28
- path: string;
29
- uiConfig: UiConfig;
30
- eventConfig: ParsedEvent[];
31
- triggers: PropertyTrigger[];
32
- timers: ParsedTimer[];
33
- styleConfig?: StyleConfig;
34
- }
35
-
36
- export interface SomaPrecompiledManifest {
37
- routes: SomaRouteEntry[];
38
- locale: Record<string, unknown>;
39
- appConfig: unknown;
40
- pages: SomaPrecompiledPage[];
41
- }
42
-
43
- /**
44
- * 全量预编译整个项目的所有声明式配置。
45
- * 构建产物是一个 JS 模块,运行时 import 即可使用,零解析。
46
- */
47
- export function precompileAll(inputs: {
48
- htmlFiles: string[];
49
- localeYaml: string;
50
- appConfigYaml: string;
51
- pages: Array<{ path: string; uiYaml: string; eventYaml: string; styleYaml?: string }>;
52
- }): SomaPrecompiledManifest {
53
- return {
54
- routes: buildRouteTable(inputs.htmlFiles),
55
- locale: (yaml.load(inputs.localeYaml) as Record<string, unknown>) || {},
56
- appConfig: yaml.load(inputs.appConfigYaml) ?? {},
57
- pages: inputs.pages.map(p => {
58
- const eventBundle = compileEventBundle(p.eventYaml);
59
- return {
60
- path: p.path,
61
- uiConfig: compileUiConfig(p.uiYaml),
62
- eventConfig: eventBundle.events,
63
- triggers: eventBundle.triggers,
64
- timers: eventBundle.timers,
65
- styleConfig: p.styleYaml ? compileStyleConfig(p.styleYaml) : undefined,
66
- };
67
- }),
68
- };
69
- }
1
+ // core/compiler/full-manifest-builder.ts
2
+ // 职责:全量预编译项目所有声明式配置
3
+
4
+ import type { UiConfig } from '../types/ui-config.types';
5
+ import type { ParsedEvent } from '../types/event.types';
6
+ import type { PropertyTrigger } from '../types/trigger.types';
7
+ import type { ParsedTimer } from '../types/timer.types';
8
+ import type { StyleConfig } from '../types/style-config.types';
9
+ import { compileUiConfig, compileStyleConfig, precompileYaml } from '@core/compiler/soma-precompile';
10
+ import { parseEventConfig } from '../parser/pipeline-parser';
11
+ import { splitEventConfigRaw } from '../parser/trigger-parser';
12
+ import { buildRouteTable, type SomaRouteEntry } from './route-builder';
13
+ import yaml from 'js-yaml';
14
+ import {
15
+ mergeSourcePackageAppConfig,
16
+ parseAppConfigYaml,
17
+ } from '../host/app-config-composer';
18
+
19
+ function compileEventBundle(eventYaml: string) {
20
+ if (!eventYaml.trim()) {
21
+ return { events: [], triggers: [] as PropertyTrigger[], timers: [] as ParsedTimer[] };
22
+ }
23
+ const { eventsRaw, triggers, timers } = splitEventConfigRaw(yaml.load(eventYaml));
24
+ return {
25
+ events: parseEventConfig(eventsRaw as any),
26
+ triggers,
27
+ timers,
28
+ };
29
+ }
30
+
31
+ export interface SomaPrecompiledPage {
32
+ path: string;
33
+ uiConfig: UiConfig;
34
+ eventConfig: ParsedEvent[];
35
+ triggers: PropertyTrigger[];
36
+ timers: ParsedTimer[];
37
+ styleConfig?: StyleConfig;
38
+ appConfig?: unknown;
39
+ }
40
+
41
+ export interface SomaPrecompiledManifest {
42
+ routes: SomaRouteEntry[];
43
+ locale: Record<string, unknown>;
44
+ appConfig: unknown;
45
+ pages: SomaPrecompiledPage[];
46
+ }
47
+
48
+ /**
49
+ * 全量预编译整个项目的所有声明式配置。
50
+ * 构建产物是一个 JS 模块,运行时 import 即可使用,零解析。
51
+ */
52
+ export function precompileAll(inputs: {
53
+ htmlFiles: string[];
54
+ localeYaml: string;
55
+ appConfigYaml: string;
56
+ pages: Array<{
57
+ path: string;
58
+ uiYaml: string;
59
+ eventYaml: string;
60
+ styleYaml?: string;
61
+ appConfigYaml?: string;
62
+ }>;
63
+ }): SomaPrecompiledManifest {
64
+ const hostAppConfig = parseAppConfigYaml(inputs.appConfigYaml);
65
+ return {
66
+ routes: buildRouteTable(inputs.htmlFiles),
67
+ locale: (yaml.load(inputs.localeYaml) as Record<string, unknown>) || {},
68
+ appConfig: hostAppConfig,
69
+ pages: inputs.pages.map(p => {
70
+ const eventBundle = compileEventBundle(p.eventYaml);
71
+ return {
72
+ path: p.path,
73
+ uiConfig: compileUiConfig(p.uiYaml),
74
+ eventConfig: eventBundle.events,
75
+ triggers: eventBundle.triggers,
76
+ timers: eventBundle.timers,
77
+ styleConfig: p.styleYaml ? compileStyleConfig(p.styleYaml) : undefined,
78
+ appConfig: p.appConfigYaml
79
+ ? mergeSourcePackageAppConfig(parseAppConfigYaml(p.appConfigYaml), hostAppConfig)
80
+ : undefined,
81
+ };
82
+ }),
83
+ };
84
+ }
@@ -1,32 +1,58 @@
1
1
  /** HOST 配置同步 — 供 bin/soma-sync.cjs 使用 */
2
2
  const fs = require('node:fs');
3
3
  const path = require('node:path');
4
+ const { resolveHostConfigRoot } = require('../host/host-config-paths.cjs');
4
5
 
5
6
  const SYNC_FILES = [
6
- 'config/locale.yaml',
7
- 'config/app.config.yaml',
7
+ 'locale.yaml',
8
+ 'app.config.yaml',
8
9
  'tailwind.config.js',
9
10
  ];
10
11
 
12
+ function listEnvAppConfigFiles(configRoot) {
13
+ if (!fs.existsSync(configRoot)) {
14
+ return [];
15
+ }
16
+ return fs
17
+ .readdirSync(configRoot)
18
+ .filter((name) => /^app\.config\.[a-zA-Z0-9_-]+\.ya?ml$/i.test(name))
19
+ .map((name) => path.join(configRoot, name));
20
+ }
21
+
11
22
  function syncHostConfig(hostDir, outputDir) {
12
23
  const target = outputDir ?? path.join(hostDir, '.soma-sync');
13
24
  const copied = [];
14
25
  const skipped = [];
26
+ const configRoot = resolveHostConfigRoot(hostDir);
15
27
 
16
28
  if (!fs.existsSync(target)) fs.mkdirSync(target, { recursive: true });
17
29
 
18
30
  for (const rel of SYNC_FILES) {
19
- const src = path.join(hostDir, rel);
20
- const dest = path.join(target, rel);
21
- if (!fs.existsSync(src)) {
31
+ const resolvedSrc =
32
+ rel === 'tailwind.config.js'
33
+ ? path.join(hostDir, rel)
34
+ : path.join(configRoot, rel);
35
+ const dest =
36
+ rel === 'tailwind.config.js'
37
+ ? path.join(target, rel)
38
+ : path.join(target, 'config', rel);
39
+ if (!fs.existsSync(resolvedSrc)) {
22
40
  skipped.push(rel);
23
41
  continue;
24
42
  }
25
43
  fs.mkdirSync(path.dirname(dest), { recursive: true });
26
- fs.copyFileSync(src, dest);
44
+ fs.copyFileSync(resolvedSrc, dest);
27
45
  copied.push(rel);
28
46
  }
29
47
 
48
+ for (const appConfigPath of listEnvAppConfigFiles(configRoot)) {
49
+ const name = path.basename(appConfigPath);
50
+ const dest = path.join(target, 'config', name);
51
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
52
+ fs.copyFileSync(appConfigPath, dest);
53
+ copied.push(name);
54
+ }
55
+
30
56
  fs.writeFileSync(
31
57
  path.join(target, 'sync-manifest.json'),
32
58
  JSON.stringify({ syncedAt: new Date().toISOString(), hostDir, files: copied }, null, 2),
@@ -7,6 +7,9 @@ export function urlPathToCandidates(urlPath: string): string[] {
7
7
  const clean = withoutQuery.replace(/^\//, '').replace(/\.html$/i, '');
8
8
  const base = clean || 'index';
9
9
  const candidates = [base];
10
+ if (base.endsWith('/index')) {
11
+ candidates.push(base.slice(0, -'/index'.length));
12
+ }
10
13
  if (!base.includes('/') && base !== 'index') {
11
14
  candidates.push(`${base}/index`);
12
15
  }