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.
- package/app/SomaPageClient.tsx +11 -20
- package/app/[...path]/page.tsx +21 -0
- package/app/api/[...path]/route.ts +86 -77
- package/app/components/SomaHostPage.tsx +133 -0
- package/app/components/SomaHydrationShell.tsx +1 -1
- package/app/favicon.ico/route.ts +13 -0
- package/app/layout.tsx +10 -6
- package/app/page.tsx +7 -18
- package/app/soma/[...path]/route.ts +9 -0
- package/app/{api/soma-manifest → soma/manifest}/route.ts +3 -3
- package/app/soma/page/route.ts +29 -0
- package/app/soma/page-object/route.ts +158 -0
- package/app/soma/route.ts +9 -0
- package/bin/soma-mock.mjs +38 -0
- package/bin/soma.cjs +1 -1
- package/core/api/load-host-service.ts +5 -2
- package/core/base/SomaHttpClient.ts +5 -3
- package/core/compiler/full-manifest-builder.ts +84 -69
- package/core/compiler/host-config-sync.cjs +32 -6
- package/core/compiler/page-base-resolver.ts +3 -0
- package/core/compiler/soma-manifest-webpack-plugin.js +160 -10
- package/core/engine/dom-renderer.ts +160 -24
- package/core/engine/soma-headless-page.ts +86 -0
- package/core/host/app-config-composer.ts +90 -0
- package/core/host/app-config.stub.ts +2 -0
- package/core/host/host-config-paths.cjs +100 -0
- package/core/host/host-config-paths.ts +132 -0
- package/core/host/invoke-host-request-hook.ts +37 -0
- package/core/host/load-host-domain-class.ts +87 -0
- package/core/host/locale.stub.ts +2 -0
- package/core/host/page-response-mode.cjs +96 -0
- package/core/host/page-response-request.ts +35 -0
- package/core/host/request-origin.ts +18 -0
- package/core/host/resolve-host-request-hook.ts +29 -0
- package/core/host/server-page-assets.ts +193 -0
- package/core/host/soma-domain-loaders.stub.ts +6 -0
- package/core/host/soma-domain-loaders.ts +69 -0
- package/core/host/soma-request-hook-host.stub.ts +4 -0
- package/core/host/source-packages.ts +153 -0
- package/core/index.ts +22 -0
- package/core/infra/http/SomaHttpService.ts +23 -14
- package/core/infra/http/soma-server-request-context.ts +126 -0
- package/core/mock/node/catch-all.mjs +35 -0
- package/core/mock/node/cli.d.mts +58 -0
- package/core/mock/node/cli.mjs +243 -0
- package/core/mock/node/context.mjs +167 -0
- package/core/mock/node/environment-policy.mjs +52 -0
- package/core/mock/node/plugin-loader.mjs +212 -0
- package/core/mock/node/preload.mjs +91 -0
- package/core/mock/node/process-lifecycle.mjs +236 -0
- package/core/mock/node/public.d.mts +110 -0
- package/core/mock/node/public.mjs +4 -0
- package/core/mock/node/registry.mjs +336 -0
- package/core/mock/node/schema-generator.mjs +1310 -0
- package/core/mock/testing/host-harness.d.mts +66 -0
- package/core/mock/testing/host-harness.mjs +276 -0
- package/core/mock/testing/host-runtime.mjs +48 -0
- package/core/runtime/SomaRuntimeServices.ts +5 -1
- package/core/runtime/serialize-page-state.ts +152 -0
- package/dist/cli/soma.js +375 -4
- package/dist/core/index.cjs +2957 -2387
- package/dist/tsconfig.types.tsbuildinfo +1 -1
- package/dist/types/base/SomaHttpClient.d.ts +2 -0
- package/dist/types/compiler/full-manifest-builder.d.ts +2 -0
- package/dist/types/engine/dom-renderer.d.ts +6 -0
- package/dist/types/engine/soma-headless-page.d.ts +10 -0
- package/dist/types/host/app-config-composer.d.ts +6 -0
- package/dist/types/host/app-config.stub.d.ts +3 -0
- package/dist/types/host/host-config-paths.d.ts +23 -0
- package/dist/types/host/invoke-host-request-hook.d.ts +8 -0
- package/dist/types/host/load-host-domain-class.d.ts +12 -0
- package/dist/types/host/locale.stub.d.ts +3 -0
- package/dist/types/host/page-response-request.d.ts +9 -0
- package/dist/types/host/request-origin.d.ts +1 -0
- package/dist/types/host/resolve-host-request-hook.d.ts +16 -0
- package/dist/types/host/server-page-assets.d.ts +29 -0
- package/dist/types/host/soma-domain-loaders.d.ts +19 -0
- package/dist/types/host/soma-domain-loaders.stub.d.ts +4 -0
- package/dist/types/host/soma-request-hook-host.stub.d.ts +2 -0
- package/dist/types/host/source-packages.d.ts +12 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/infra/http/SomaHttpService.d.ts +2 -0
- package/dist/types/infra/http/soma-server-request-context.d.ts +5 -0
- package/dist/types/runtime/serialize-page-state.d.ts +10 -0
- 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
- package/global.d.ts +74 -33
- package/middleware.ts +33 -0
- package/next.config.js +166 -16
- package/package.json +47 -13
- package/tailwind.config.ts +21 -17
- package/tsconfig.json +1 -5
- package/app/api/page/route.ts +0 -99
- package/app/loading.tsx +0 -5
package/next.config.js
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
/** @type {import('next').NextConfig} */
|
|
2
|
+
const fs = require('fs');
|
|
2
3
|
const path = require('path');
|
|
3
4
|
const { SomaManifestWebpackPlugin } = require('./core/compiler/soma-manifest-webpack-plugin');
|
|
5
|
+
const {
|
|
6
|
+
resolveHostConfigRoot,
|
|
7
|
+
resolveHostAppConfigPath,
|
|
8
|
+
} = require('./core/host/host-config-paths.cjs');
|
|
9
|
+
const {
|
|
10
|
+
readSomaPageResponseMode,
|
|
11
|
+
} = require('./core/host/page-response-mode.cjs');
|
|
12
|
+
|
|
13
|
+
function readSomaWebpackCacheMode(env = process.env) {
|
|
14
|
+
const mode = env.SOMA_WEBPACK_CACHE_MODE;
|
|
15
|
+
if (mode === undefined) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
if (mode !== 'memory') {
|
|
19
|
+
throw new Error(
|
|
20
|
+
'[soma-core] Unsupported SOMA_WEBPACK_CACHE_MODE '
|
|
21
|
+
+ JSON.stringify(mode)
|
|
22
|
+
+ '; expected "memory" or leave it unset.',
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return mode;
|
|
26
|
+
}
|
|
4
27
|
|
|
5
28
|
const rawHostDir = process.env.SOMA_HOST_DIR;
|
|
6
29
|
if (!rawHostDir || !String(rawHostDir).trim()) {
|
|
@@ -9,17 +32,157 @@ if (!rawHostDir || !String(rawHostDir).trim()) {
|
|
|
9
32
|
);
|
|
10
33
|
}
|
|
11
34
|
const hostDir = path.resolve(rawHostDir);
|
|
35
|
+
const webpackCacheMode = readSomaWebpackCacheMode();
|
|
36
|
+
const pageResponseConfig = readSomaPageResponseMode(hostDir);
|
|
37
|
+
process.env.SOMA_PAGE_RESPONSE_MODE = pageResponseConfig.mode;
|
|
38
|
+
if (pageResponseConfig.mode === 'json') {
|
|
39
|
+
console.log(
|
|
40
|
+
'[soma-core] pageResponseMode=json enabled from '
|
|
41
|
+
+ (pageResponseConfig.configPath || 'App defaults'),
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function readJson(filePath) {
|
|
46
|
+
try {
|
|
47
|
+
if (!fs.existsSync(filePath)) return null;
|
|
48
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function resolveSafeChildRoot(parent, relativePath) {
|
|
55
|
+
const trimmed = typeof relativePath === 'string' ? relativePath.trim() : '';
|
|
56
|
+
if (!trimmed) return parent;
|
|
57
|
+
|
|
58
|
+
const resolved = path.resolve(parent, trimmed);
|
|
59
|
+
if ((resolved === parent || resolved.startsWith(`${parent}${path.sep}`)) && fs.existsSync(resolved)) {
|
|
60
|
+
return resolved;
|
|
61
|
+
}
|
|
62
|
+
return parent;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function readHostSourceRoot() {
|
|
66
|
+
const packageJson = readJson(path.join(hostDir, 'package.json'));
|
|
67
|
+
return resolveSafeChildRoot(hostDir, packageJson?.soma?.hostRoot);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const hostSourceRoot = readHostSourceRoot();
|
|
71
|
+
const hostConfigRoot = resolveHostConfigRoot(hostDir);
|
|
72
|
+
|
|
73
|
+
function resolveOptionalHostSourceFile(relativePath, fallbackPath) {
|
|
74
|
+
const hostFile = path.resolve(hostSourceRoot, relativePath);
|
|
75
|
+
if (fs.existsSync(hostFile)) {
|
|
76
|
+
return hostFile;
|
|
77
|
+
}
|
|
78
|
+
return path.resolve(__dirname, fallbackPath);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function resolveOptionalHostConfigFile(fileName, fallbackPath) {
|
|
82
|
+
const hostFile = path.resolve(hostConfigRoot, fileName);
|
|
83
|
+
if (fs.existsSync(hostFile)) {
|
|
84
|
+
return hostFile;
|
|
85
|
+
}
|
|
86
|
+
return path.resolve(__dirname, fallbackPath);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function resolveHostAppConfigAlias(fallbackPath) {
|
|
90
|
+
const envConfig = resolveHostAppConfigPath(hostDir);
|
|
91
|
+
if (envConfig) {
|
|
92
|
+
return envConfig;
|
|
93
|
+
}
|
|
94
|
+
return path.resolve(__dirname, fallbackPath);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function readHostFileDependencyEntries() {
|
|
98
|
+
const packageJsonPath = path.join(hostDir, 'package.json');
|
|
99
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
105
|
+
const dependencies = {
|
|
106
|
+
...(packageJson.dependencies ?? {}),
|
|
107
|
+
...(packageJson.devDependencies ?? {}),
|
|
108
|
+
};
|
|
109
|
+
return Object.entries(dependencies)
|
|
110
|
+
.filter(([, version]) => typeof version === 'string' && version.startsWith('file:'))
|
|
111
|
+
.map(([name, version]) => ({
|
|
112
|
+
name,
|
|
113
|
+
root: path.resolve(hostDir, String(version).slice('file:'.length)),
|
|
114
|
+
}))
|
|
115
|
+
.filter((entry) => fs.existsSync(entry.root));
|
|
116
|
+
} catch {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function readEnvTranspilePackages() {
|
|
122
|
+
return String(process.env.SOMA_TRANSPILE_PACKAGES ?? '')
|
|
123
|
+
.split(',')
|
|
124
|
+
.map((item) => item.trim())
|
|
125
|
+
.filter(Boolean);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const hostFileDependencyEntries = readHostFileDependencyEntries();
|
|
129
|
+
const transpilePackages = [
|
|
130
|
+
...new Set(['soma-core', ...hostFileDependencyEntries.map((entry) => entry.name), ...readEnvTranspilePackages()]),
|
|
131
|
+
];
|
|
12
132
|
|
|
13
133
|
const nextConfig = {
|
|
134
|
+
env: {
|
|
135
|
+
SOMA_PAGE_RESPONSE_MODE: pageResponseConfig.mode,
|
|
136
|
+
},
|
|
137
|
+
|
|
14
138
|
experimental: {
|
|
15
139
|
externalDir: true,
|
|
140
|
+
serverComponentsExternalPackages: ['jiti'],
|
|
16
141
|
},
|
|
17
142
|
|
|
18
|
-
|
|
143
|
+
transpilePackages,
|
|
19
144
|
|
|
20
|
-
webpack: (config) => {
|
|
145
|
+
webpack: (config, { dev }) => {
|
|
146
|
+
if (webpackCacheMode === 'memory' && dev) {
|
|
147
|
+
config.cache = { type: 'memory' };
|
|
148
|
+
}
|
|
149
|
+
config.resolve.alias['@'] = __dirname;
|
|
150
|
+
config.resolve.alias['soma-core$'] = path.resolve(__dirname, 'core/index.ts');
|
|
151
|
+
config.resolve.alias['soma-core/base$'] = path.resolve(__dirname, 'core/base/index.ts');
|
|
21
152
|
config.resolve.alias['@core'] = path.resolve(__dirname, 'core');
|
|
22
|
-
|
|
153
|
+
for (const entry of hostFileDependencyEntries) {
|
|
154
|
+
const packageJson = readJson(path.join(entry.root, 'package.json'));
|
|
155
|
+
if (packageJson?.soma?.configRoot) {
|
|
156
|
+
config.resolve.alias[`${entry.name}/config`] = resolveSafeChildRoot(
|
|
157
|
+
entry.root,
|
|
158
|
+
packageJson.soma.configRoot,
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
config.resolve.alias[entry.name] = resolveSafeChildRoot(
|
|
162
|
+
entry.root,
|
|
163
|
+
packageJson?.soma?.hostRoot,
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
config.resolve.alias['@soma-host/bootstrap/soma-bootstrap'] = resolveOptionalHostSourceFile(
|
|
167
|
+
'bootstrap/soma-bootstrap.ts',
|
|
168
|
+
'core/host/soma-bootstrap-host.stub.ts',
|
|
169
|
+
);
|
|
170
|
+
config.resolve.alias['@soma-host/bootstrap/soma-request-hook'] = resolveOptionalHostSourceFile(
|
|
171
|
+
'bootstrap/soma-request-hook.ts',
|
|
172
|
+
'core/host/soma-request-hook-host.stub.ts',
|
|
173
|
+
);
|
|
174
|
+
config.resolve.alias['@soma-host/bootstrap/soma-domain-loaders'] = resolveOptionalHostSourceFile(
|
|
175
|
+
'bootstrap/soma-domain-loaders.ts',
|
|
176
|
+
'core/host/soma-domain-loaders.stub.ts',
|
|
177
|
+
);
|
|
178
|
+
config.resolve.alias['@soma-host/config/locale.yaml'] = resolveOptionalHostConfigFile(
|
|
179
|
+
'locale.yaml',
|
|
180
|
+
'core/host/locale.stub.ts',
|
|
181
|
+
);
|
|
182
|
+
config.resolve.alias['@soma-host/config/app.config.yaml'] = resolveHostAppConfigAlias(
|
|
183
|
+
'core/host/app-config.stub.ts',
|
|
184
|
+
);
|
|
185
|
+
config.resolve.alias['@soma-host'] = hostSourceRoot;
|
|
23
186
|
|
|
24
187
|
config.plugins.push(new SomaManifestWebpackPlugin({ hostDir }));
|
|
25
188
|
|
|
@@ -48,19 +211,6 @@ const nextConfig = {
|
|
|
48
211
|
);
|
|
49
212
|
return config;
|
|
50
213
|
},
|
|
51
|
-
|
|
52
|
-
async rewrites() {
|
|
53
|
-
return [
|
|
54
|
-
{
|
|
55
|
-
source: '/:path*.html',
|
|
56
|
-
destination: '/',
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
source: '/:path((?!api|_next|favicon\\.ico)(?![^/]*\\.[a-zA-Z0-9]+$).*)',
|
|
60
|
-
destination: '/',
|
|
61
|
-
},
|
|
62
|
-
];
|
|
63
|
-
},
|
|
64
214
|
};
|
|
65
215
|
|
|
66
216
|
module.exports = nextConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soma-core",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "SOMA — Semantic Oriented Modular Architecture. A declarative frontend framework runtime built on Next.js 14+ App Router.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"soma",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"directory": "soma-core"
|
|
18
18
|
},
|
|
19
19
|
"main": "./core/index.ts",
|
|
20
|
-
"types": "./
|
|
20
|
+
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"typesVersions": {
|
|
22
22
|
"*": {
|
|
23
23
|
"diagnostics": [
|
|
@@ -27,34 +27,62 @@
|
|
|
27
27
|
},
|
|
28
28
|
"bin": {
|
|
29
29
|
"soma": "bin/soma.cjs",
|
|
30
|
-
"soma-lsp": "bin/soma-lsp.cjs"
|
|
30
|
+
"soma-lsp": "bin/soma-lsp.cjs",
|
|
31
|
+
"soma-mock": "bin/soma-mock.mjs"
|
|
31
32
|
},
|
|
32
33
|
"exports": {
|
|
33
34
|
".": {
|
|
34
|
-
"types": "./
|
|
35
|
+
"types": "./dist/types/index.d.ts",
|
|
35
36
|
"import": "./core/index.ts",
|
|
36
37
|
"require": "./dist/core/index.cjs",
|
|
37
38
|
"default": "./core/index.ts"
|
|
38
39
|
},
|
|
39
|
-
"./base":
|
|
40
|
+
"./base": {
|
|
41
|
+
"types": "./dist/types/base/index.d.ts",
|
|
42
|
+
"import": "./core/base/index.ts",
|
|
43
|
+
"default": "./core/base/index.ts"
|
|
44
|
+
},
|
|
40
45
|
"./compiler/vite": "./core/compiler/vite-plugin-soma.ts",
|
|
41
46
|
"./compiler/webpack-loader": "./core/compiler/soma-webpack-loader.js",
|
|
42
47
|
"./diagnostics": {
|
|
43
|
-
"types": "./
|
|
48
|
+
"types": "./dist/types/diagnostics/SomaTelemetry.d.ts",
|
|
44
49
|
"import": "./core/diagnostics/SomaTelemetry.ts",
|
|
45
50
|
"require": "./dist/diagnostics/telemetry.cjs",
|
|
46
51
|
"default": "./core/diagnostics/SomaTelemetry.ts"
|
|
52
|
+
},
|
|
53
|
+
"./host/request-hook": {
|
|
54
|
+
"types": "./dist/types/host/resolve-host-request-hook.d.ts",
|
|
55
|
+
"import": "./core/host/resolve-host-request-hook.ts",
|
|
56
|
+
"default": "./core/host/resolve-host-request-hook.ts"
|
|
57
|
+
},
|
|
58
|
+
"./mock/node": {
|
|
59
|
+
"types": "./core/mock/node/public.d.mts",
|
|
60
|
+
"import": "./core/mock/node/public.mjs",
|
|
61
|
+
"default": "./core/mock/node/public.mjs"
|
|
62
|
+
},
|
|
63
|
+
"./mock/node/cli": {
|
|
64
|
+
"types": "./core/mock/node/cli.d.mts",
|
|
65
|
+
"import": "./core/mock/node/cli.mjs",
|
|
66
|
+
"default": "./core/mock/node/cli.mjs"
|
|
67
|
+
},
|
|
68
|
+
"./testing/mock-host": {
|
|
69
|
+
"types": "./core/mock/testing/host-harness.d.mts",
|
|
70
|
+
"import": "./core/mock/testing/host-harness.mjs",
|
|
71
|
+
"default": "./core/mock/testing/host-harness.mjs"
|
|
47
72
|
}
|
|
48
73
|
},
|
|
49
74
|
"files": [
|
|
50
75
|
"bin/soma.cjs",
|
|
51
76
|
"bin/soma-lsp.cjs",
|
|
52
77
|
"bin/soma-sync.cjs",
|
|
78
|
+
"bin/soma-mock.mjs",
|
|
53
79
|
"core/",
|
|
80
|
+
"docs/",
|
|
54
81
|
"editor/",
|
|
55
82
|
"app/",
|
|
56
83
|
"dist/",
|
|
57
84
|
"dist/vscode/",
|
|
85
|
+
"middleware.ts",
|
|
58
86
|
"next.config.js",
|
|
59
87
|
"tailwind.config.ts",
|
|
60
88
|
"postcss.config.js",
|
|
@@ -76,14 +104,18 @@
|
|
|
76
104
|
"build": "next build",
|
|
77
105
|
"start": "next start",
|
|
78
106
|
"lint": "next lint",
|
|
79
|
-
"test": "vitest run",
|
|
107
|
+
"test": "vitest run && npm run test:mock",
|
|
108
|
+
"test:mock": "node --test tests/mock/*.test.mjs",
|
|
109
|
+
"verify:mock-pack": "node scripts/verify-mock-pack.mjs",
|
|
80
110
|
"test:watch": "vitest",
|
|
81
111
|
"typecheck": "tsc --noEmit"
|
|
82
112
|
},
|
|
83
113
|
"dependencies": {
|
|
84
|
-
"
|
|
114
|
+
"ajv": "8.20.0",
|
|
115
|
+
"dompurify": "^3.4.12",
|
|
85
116
|
"jiti": "^1.21.7",
|
|
86
|
-
"js-yaml": "^4.
|
|
117
|
+
"js-yaml": "^4.3.0",
|
|
118
|
+
"msw": "2.15.0",
|
|
87
119
|
"reflect-metadata": "^0.2.1"
|
|
88
120
|
},
|
|
89
121
|
"peerDependencies": {
|
|
@@ -97,7 +129,9 @@
|
|
|
97
129
|
"@types/node": "^20.11.0",
|
|
98
130
|
"@types/react": "^18.3.0",
|
|
99
131
|
"@types/react-dom": "^18.3.0",
|
|
100
|
-
"@
|
|
132
|
+
"@types/ws": "^8.5.13",
|
|
133
|
+
"@vitest/coverage-v8": "^3.2.7",
|
|
134
|
+
"ajv-formats": "3.0.1",
|
|
101
135
|
"autoprefixer": "^10.4.17",
|
|
102
136
|
"esbuild": "^0.25.12",
|
|
103
137
|
"jsdom": "^26.1.0",
|
|
@@ -107,8 +141,8 @@
|
|
|
107
141
|
"react-dom": "^18.3.0",
|
|
108
142
|
"tailwindcss": "^3.4.1",
|
|
109
143
|
"typescript": "^5.3.3",
|
|
110
|
-
"
|
|
111
|
-
"
|
|
112
|
-
"
|
|
144
|
+
"vite": "6.4.3",
|
|
145
|
+
"vitest": "^3.2.7",
|
|
146
|
+
"ws": "^8.21.0"
|
|
113
147
|
}
|
|
114
148
|
}
|
package/tailwind.config.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { Config } from 'tailwindcss';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { createRequire } from 'node:module';
|
|
5
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { getSomaAssetSources } from './core/host/source-packages';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Framework Tailwind config (loaded with soma-core / Next).
|
|
9
|
-
* Host theme/plugins come from SOMA_HOST_DIR/tailwind.config.js via presets.
|
|
10
|
+
* Host theme/plugins come from SOMA_HOST_DIR/tailwind.config.cjs/js via presets.
|
|
10
11
|
*/
|
|
11
12
|
if (!process.env.SOMA_HOST_DIR) {
|
|
12
13
|
throw new Error('[soma-core] tailwind: SOMA_HOST_DIR is not set');
|
|
@@ -14,8 +15,8 @@ if (!process.env.SOMA_HOST_DIR) {
|
|
|
14
15
|
const hostDir = path.resolve(process.env.SOMA_HOST_DIR);
|
|
15
16
|
const require = createRequire(fileURLToPath(import.meta.url));
|
|
16
17
|
|
|
17
|
-
function loadHostPreset(): Config | null {
|
|
18
|
-
for (const name of ['tailwind.config.
|
|
18
|
+
function loadHostPreset(): Config | null {
|
|
19
|
+
for (const name of ['tailwind.config.cjs', 'tailwind.config.js']) {
|
|
19
20
|
const cfgPath = path.join(hostDir, name);
|
|
20
21
|
if (!fs.existsSync(cfgPath)) continue;
|
|
21
22
|
const mod = require(cfgPath) as Config | { default: Config };
|
|
@@ -24,17 +25,20 @@ function loadHostPreset(): Config | null {
|
|
|
24
25
|
return null;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
const hostPreset = loadHostPreset();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
28
|
+
const hostPreset = loadHostPreset();
|
|
29
|
+
const sourceContent = getSomaAssetSources(hostDir).flatMap((source) => [
|
|
30
|
+
path.join(source.assetRoot, 'html/**/*.html'),
|
|
31
|
+
path.join(source.assetRoot, 'ui/**/*_style.yaml'),
|
|
32
|
+
path.join(source.assetRoot, 'styles/**/*.css'),
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
const config: Config = {
|
|
36
|
+
...(hostPreset ? { presets: [hostPreset] } : {}),
|
|
37
|
+
content: [
|
|
38
|
+
'./app/**/*.{js,ts,jsx,tsx,mdx}',
|
|
39
|
+
'./core/**/*.{js,ts,jsx,tsx}',
|
|
40
|
+
...sourceContent,
|
|
41
|
+
],
|
|
42
|
+
};
|
|
39
43
|
|
|
40
44
|
export default config;
|
package/tsconfig.json
CHANGED
|
@@ -20,11 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"paths": {
|
|
22
22
|
"@core/*": ["./core/*"],
|
|
23
|
-
"@/*": ["./*"]
|
|
24
|
-
"@soma-host/config/locale.yaml": ["./tests/fixtures/host/config/locale.stub.ts"],
|
|
25
|
-
"@soma-host/config/app.config.yaml": ["./tests/fixtures/host/config/app.config.stub.ts"],
|
|
26
|
-
"@soma-host/bootstrap/soma-bootstrap": ["./tests/fixtures/host/bootstrap/soma-bootstrap.ts"],
|
|
27
|
-
"@soma-host/*": ["./tests/fixtures/host/*"]
|
|
23
|
+
"@/*": ["./*"]
|
|
28
24
|
},
|
|
29
25
|
"baseUrl": "."
|
|
30
26
|
},
|
package/app/api/page/route.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
// URL → html/ui/event files: / → index.html, /a/b → a/b.html; */index.html also maps to short path /a
|
|
2
|
-
|
|
3
|
-
import { existsSync } from 'fs';
|
|
4
|
-
import { join, resolve } from 'path';
|
|
5
|
-
import { NextRequest } from 'next/server';
|
|
6
|
-
import { isSafePageBase, urlPathToCandidates } from '../../../core/compiler/page-base-resolver';
|
|
7
|
-
import { ServerFileCache } from '../../../core/infra/cache/ServerFileCache';
|
|
8
|
-
|
|
9
|
-
const cache = ServerFileCache.getInstance();
|
|
10
|
-
|
|
11
|
-
function getHostDir(): string | undefined {
|
|
12
|
-
return process.env.SOMA_HOST_DIR || undefined;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
let watchedRoot: string | null = null;
|
|
16
|
-
|
|
17
|
-
function ensureWatch(root: string) {
|
|
18
|
-
if (watchedRoot === root) return;
|
|
19
|
-
watchedRoot = root;
|
|
20
|
-
cache.watchAndInvalidate(root);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function resolvePageBase(hostDir: string, urlPath: string): string | null {
|
|
24
|
-
for (const candidate of urlPathToCandidates(urlPath)) {
|
|
25
|
-
if (!isSafePageBase(candidate)) continue;
|
|
26
|
-
const htmlPath = join(hostDir, 'html', `${candidate}.html`);
|
|
27
|
-
if (existsSync(htmlPath)) return candidate;
|
|
28
|
-
}
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function collectIncludes(hostDir: string): Record<string, string> {
|
|
33
|
-
const includes: Record<string, string> = {};
|
|
34
|
-
const sharedDir = join(hostDir, 'html', 'shared');
|
|
35
|
-
try {
|
|
36
|
-
const files = cache.readDirFiles(sharedDir, '.html');
|
|
37
|
-
const names = cache.readDirNames(sharedDir, '.html');
|
|
38
|
-
for (let i = 0; i < names.length; i++) {
|
|
39
|
-
includes[`shared/${names[i]}`] = files[i];
|
|
40
|
-
}
|
|
41
|
-
} catch {}
|
|
42
|
-
return includes;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function GET(req: NextRequest) {
|
|
46
|
-
const hostDir = getHostDir();
|
|
47
|
-
if (!hostDir) {
|
|
48
|
-
return Response.json(
|
|
49
|
-
{ error: 'SOMA_HOST_DIR is not set. Run: npx soma dev from your app root.' },
|
|
50
|
-
{ status: 503 },
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
ensureWatch(hostDir);
|
|
55
|
-
|
|
56
|
-
const urlPath = req.nextUrl.searchParams.get('path') || '/';
|
|
57
|
-
const base = resolvePageBase(hostDir, urlPath);
|
|
58
|
-
|
|
59
|
-
if (!base) {
|
|
60
|
-
return Response.json({ error: `Page not found: ${urlPath}` }, { status: 404 });
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const htmlPath = join(hostDir, 'html', `${base}.html`);
|
|
64
|
-
const resolvedHtml = resolve(htmlPath);
|
|
65
|
-
const resolvedHostHtml = resolve(hostDir, 'html');
|
|
66
|
-
if (!resolvedHtml.startsWith(resolvedHostHtml)) {
|
|
67
|
-
return Response.json({ error: 'Invalid path' }, { status: 400 });
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
try {
|
|
71
|
-
const html = cache.readFile(htmlPath);
|
|
72
|
-
|
|
73
|
-
let ui: string, event: string, style: string, localeYaml: string, appConfigYaml: string;
|
|
74
|
-
try {
|
|
75
|
-
ui = cache.tryReadFile(join(hostDir, 'ui', `${base}_ui.yaml`));
|
|
76
|
-
event = cache.tryReadFile(join(hostDir, 'event', `${base}_event.yaml`));
|
|
77
|
-
style = cache.tryReadFile(join(hostDir, 'ui', `${base}_style.yaml`));
|
|
78
|
-
localeYaml = cache.tryReadFile(join(hostDir, 'config', 'locale.yaml'));
|
|
79
|
-
appConfigYaml = cache.tryReadFile(join(hostDir, 'config', 'app.config.yaml'));
|
|
80
|
-
} catch (e: any) {
|
|
81
|
-
return Response.json({ error: `Asset read error: ${e.message}` }, { status: 500 });
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const includes = collectIncludes(hostDir);
|
|
85
|
-
|
|
86
|
-
return Response.json({
|
|
87
|
-
base,
|
|
88
|
-
html,
|
|
89
|
-
ui,
|
|
90
|
-
event,
|
|
91
|
-
styleYaml: style,
|
|
92
|
-
localeYaml,
|
|
93
|
-
appConfigYaml,
|
|
94
|
-
includes,
|
|
95
|
-
});
|
|
96
|
-
} catch (e: any) {
|
|
97
|
-
return Response.json({ error: `Page not found: ${base}.html` }, { status: 404 });
|
|
98
|
-
}
|
|
99
|
-
}
|