soma-core 2.1.6 → 2.2.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/README.md +2 -2
- package/bin/soma.cjs +1 -1
- package/bin/soma.ts +64 -15
- package/core/server/api/dispatch-service-api.ts +212 -0
- package/core/server/api/load-host-service.ts +230 -56
- package/core/server/api/service-path.ts +78 -14
- package/core/server/engines/style/candidate-guard.ts +57 -0
- package/core/server/engines/style/index.ts +1 -1
- package/core/server/engines/style/tailwind-adapter.ts +83 -16
- package/core/server/host/source-packages.cjs +96 -30
- package/core/server/host/source-packages.ts +12 -5
- package/core/server/index.ts +39 -17
- package/core/server/infra/cache/ServerFileCache.ts +138 -25
- package/core/server/node.ts +32 -8
- package/dist/cli/soma.js +68 -14
- package/dist/host-native/aot-builder.cjs +850 -0
- package/dist/host-native/native-server.cjs +15338 -0
- package/dist/types/server/api/dispatch-service-api.d.ts +18 -0
- package/dist/types/server/api/load-host-service.d.ts +7 -2
- package/dist/types/server/api/service-path.d.ts +21 -1
- package/dist/types/server/engines/style/candidate-guard.d.ts +10 -0
- package/dist/types/server/engines/style/index.d.ts +1 -1
- package/dist/types/server/engines/style/tailwind-adapter.d.ts +12 -0
- package/dist/types/server/host/source-packages.d.cts +13 -1
- package/dist/types/server/host/source-packages.d.ts +7 -4
- package/dist/types/server/index.d.ts +18 -17
- package/dist/types/server/infra/cache/ServerFileCache.d.ts +28 -5
- package/dist/types/server/node.d.ts +10 -7
- package/host-native/bin/host-native.cjs +204 -0
- package/host-native/client/browser-entry.ts +499 -0
- package/{host-next/app → host-native/client}/page-access.ts +12 -0
- package/host-native/client/router-bridge.ts +120 -0
- package/host-native/src/aot-builder.ts +486 -0
- package/host-native/src/csp-headers.ts +75 -0
- package/host-native/src/host-prepare.ts +123 -0
- package/{host-next/app/soma/manifest/route.ts → host-native/src/manifest-http.ts} +10 -10
- package/host-native/src/native-server.ts +691 -0
- package/host-native/src/page-http.ts +223 -0
- package/host-native/src/public-packages.cjs +167 -0
- package/{host-next/app/api/soma-registry/[...path]/route.ts → host-native/src/registry-handler.ts} +17 -19
- package/{host-next → host-native}/src/shell-routes.cjs +23 -13
- package/host-native/src/static-file.ts +172 -0
- package/host-native/src/workspace.ts +185 -0
- package/{host-next/app → host-native/styles}/globals.css +2 -2
- package/package.json +12 -31
- package/tsconfig.json +1 -1
- package/host-next/app/SomaPageClient.tsx +0 -359
- package/host-next/app/[...path]/page.tsx +0 -22
- package/host-next/app/api/[...path]/route.ts +0 -98
- package/host-next/app/components/SomaHostPage.tsx +0 -128
- package/host-next/app/components/SomaHydrationShell.tsx +0 -20
- package/host-next/app/components/SomaPageClientBoundary.tsx +0 -13
- package/host-next/app/components/SomaPageForbidden.tsx +0 -19
- package/host-next/app/favicon.ico/route.ts +0 -13
- package/host-next/app/layout.tsx +0 -27
- package/host-next/app/page.tsx +0 -9
- package/host-next/app/router-bridge.ts +0 -42
- package/host-next/app/soma/[...path]/route.ts +0 -9
- package/host-next/app/soma/_shared/host-prepare.ts +0 -33
- package/host-next/app/soma/_shared/page-http.ts +0 -86
- package/host-next/app/soma/page/route.ts +0 -36
- package/host-next/app/soma/route.ts +0 -9
- package/host-next/app/soma-runtime/[...file]/route.ts +0 -21
- package/host-next/app/soma-runtime/_shared/static-file.ts +0 -89
- package/host-next/bin/host-next.cjs +0 -60
- package/host-next/instrumentation.ts +0 -18
- package/host-next/next-env.d.ts +0 -7
- package/host-next/next.config.js +0 -410
- package/host-next/proxy.ts +0 -43
- package/host-next/src/workspace.ts +0 -543
|
@@ -0,0 +1,850 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
|
|
33
|
+
// host-native/src/public-packages.cjs
|
|
34
|
+
var require_public_packages = __commonJS({
|
|
35
|
+
"host-native/src/public-packages.cjs"(exports2, module2) {
|
|
36
|
+
"use strict";
|
|
37
|
+
var fs2 = require("node:fs");
|
|
38
|
+
var path2 = require("node:path");
|
|
39
|
+
function readJson(filePath) {
|
|
40
|
+
try {
|
|
41
|
+
if (!fs2.existsSync(filePath)) return null;
|
|
42
|
+
return JSON.parse(fs2.readFileSync(filePath, "utf8"));
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function isSafePackageChild(packageRoot, candidate) {
|
|
48
|
+
return candidate === packageRoot || candidate.startsWith(`${packageRoot}${path2.sep}`);
|
|
49
|
+
}
|
|
50
|
+
function collectFiles(root) {
|
|
51
|
+
if (!fs2.existsSync(root) || !fs2.statSync(root).isDirectory()) return [];
|
|
52
|
+
const files = [];
|
|
53
|
+
for (const entry of fs2.readdirSync(root, { withFileTypes: true })) {
|
|
54
|
+
const fullPath = path2.join(root, entry.name);
|
|
55
|
+
if (entry.isDirectory()) files.push(...collectFiles(fullPath));
|
|
56
|
+
else if (entry.isFile()) files.push(fullPath);
|
|
57
|
+
}
|
|
58
|
+
return files;
|
|
59
|
+
}
|
|
60
|
+
function isSafeExportWildcardValue(value) {
|
|
61
|
+
return value.length > 0 && !path2.isAbsolute(value) && value.split(/[\\/]/).every((segment) => segment !== "" && segment !== "." && segment !== "..");
|
|
62
|
+
}
|
|
63
|
+
function expandWildcardExportAliases(packageName, packageRoot, entry, target) {
|
|
64
|
+
if ((entry.match(/\*/g) ?? []).length !== 1 || (target.match(/\*/g) ?? []).length !== 1) return {};
|
|
65
|
+
const entryStar = entry.indexOf("*");
|
|
66
|
+
const targetStar = target.indexOf("*");
|
|
67
|
+
const entryPrefix = entry.slice(0, entryStar);
|
|
68
|
+
const entrySuffix = entry.slice(entryStar + 1);
|
|
69
|
+
const targetPrefix = target.slice(0, targetStar);
|
|
70
|
+
const targetSuffix = target.slice(targetStar + 1);
|
|
71
|
+
const sourceRoot = path2.resolve(packageRoot, targetPrefix);
|
|
72
|
+
if (!isSafePackageChild(packageRoot, sourceRoot)) return {};
|
|
73
|
+
const aliases = {};
|
|
74
|
+
for (const filePath of collectFiles(sourceRoot)) {
|
|
75
|
+
const relative = path2.relative(sourceRoot, filePath).split(path2.sep).join("/");
|
|
76
|
+
if (!relative.endsWith(targetSuffix)) continue;
|
|
77
|
+
const wildcardValue = relative.slice(0, relative.length - targetSuffix.length);
|
|
78
|
+
if (!isSafeExportWildcardValue(wildcardValue)) continue;
|
|
79
|
+
const publicPath = `${entryPrefix.slice(2)}${wildcardValue}${entrySuffix}`;
|
|
80
|
+
if (!isSafeExportWildcardValue(publicPath)) continue;
|
|
81
|
+
aliases[`${packageName}/${publicPath}`] = filePath;
|
|
82
|
+
}
|
|
83
|
+
return aliases;
|
|
84
|
+
}
|
|
85
|
+
function readPublicPackageAliases(packageName, packageRoot) {
|
|
86
|
+
const exportsMap = readJson(path2.join(packageRoot, "package.json"))?.exports;
|
|
87
|
+
if (!exportsMap || typeof exportsMap !== "object") return {};
|
|
88
|
+
const exactAliases = {};
|
|
89
|
+
const wildcardAliases = {};
|
|
90
|
+
for (const [entry, descriptor] of Object.entries(exportsMap)) {
|
|
91
|
+
if (entry !== "." && !entry.startsWith("./")) continue;
|
|
92
|
+
let target = null;
|
|
93
|
+
if (typeof descriptor === "string") {
|
|
94
|
+
target = descriptor;
|
|
95
|
+
} else if (descriptor && typeof descriptor === "object") {
|
|
96
|
+
target = descriptor.import?.default ?? descriptor.import ?? descriptor.default ?? descriptor.require?.default ?? descriptor.require;
|
|
97
|
+
if (typeof target === "object" && target !== null) {
|
|
98
|
+
target = target.default;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (typeof target !== "string" || !target.startsWith("./")) continue;
|
|
102
|
+
const isWildcard = entry.includes("*") || target.includes("*");
|
|
103
|
+
if (entry.includes("*") !== target.includes("*")) continue;
|
|
104
|
+
if (isWildcard) {
|
|
105
|
+
Object.assign(
|
|
106
|
+
wildcardAliases,
|
|
107
|
+
expandWildcardExportAliases(packageName, packageRoot, entry, target)
|
|
108
|
+
);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const resolved = path2.resolve(packageRoot, target);
|
|
112
|
+
if (!isSafePackageChild(packageRoot, resolved) || !fs2.existsSync(resolved)) continue;
|
|
113
|
+
const publicPath = entry === "." ? "" : entry.slice(2);
|
|
114
|
+
const specifier = publicPath ? `${packageName}/${publicPath}` : packageName;
|
|
115
|
+
exactAliases[specifier] = resolved;
|
|
116
|
+
}
|
|
117
|
+
return { ...wildcardAliases, ...exactAliases };
|
|
118
|
+
}
|
|
119
|
+
function readAllSomaPublicAliases2(hostDir, repoRoot2, extraRoots = []) {
|
|
120
|
+
const aliases = {};
|
|
121
|
+
const searchRoots = [
|
|
122
|
+
repoRoot2,
|
|
123
|
+
path2.join(repoRoot2, "soma-core"),
|
|
124
|
+
path2.join(repoRoot2, "soma-foundation"),
|
|
125
|
+
path2.join(repoRoot2, "soma-ui"),
|
|
126
|
+
path2.join(repoRoot2, "soma-lite"),
|
|
127
|
+
path2.join(repoRoot2, "soma-kit"),
|
|
128
|
+
path2.join(repoRoot2, "soma-ai")
|
|
129
|
+
];
|
|
130
|
+
for (const r of extraRoots) {
|
|
131
|
+
if (r) searchRoots.unshift(r);
|
|
132
|
+
}
|
|
133
|
+
if (hostDir) {
|
|
134
|
+
searchRoots.unshift(hostDir);
|
|
135
|
+
}
|
|
136
|
+
const seenPackages = /* @__PURE__ */ new Set();
|
|
137
|
+
for (const searchRoot of searchRoots) {
|
|
138
|
+
if (!fs2.existsSync(searchRoot)) continue;
|
|
139
|
+
const pkgJsonPath = path2.join(searchRoot, "package.json");
|
|
140
|
+
const pkgJson = readJson(pkgJsonPath);
|
|
141
|
+
if (pkgJson?.name && pkgJson.name.startsWith("soma-") && !seenPackages.has(pkgJson.name)) {
|
|
142
|
+
seenPackages.add(pkgJson.name);
|
|
143
|
+
Object.assign(aliases, readPublicPackageAliases(pkgJson.name, searchRoot));
|
|
144
|
+
}
|
|
145
|
+
const nm = path2.join(searchRoot, "node_modules");
|
|
146
|
+
if (fs2.existsSync(nm)) {
|
|
147
|
+
try {
|
|
148
|
+
for (const entry of fs2.readdirSync(nm, { withFileTypes: true })) {
|
|
149
|
+
if (!entry.isDirectory()) continue;
|
|
150
|
+
if (entry.name.startsWith("soma-") && !seenPackages.has(entry.name)) {
|
|
151
|
+
const pkgPath = path2.join(nm, entry.name);
|
|
152
|
+
seenPackages.add(entry.name);
|
|
153
|
+
Object.assign(aliases, readPublicPackageAliases(entry.name, pkgPath));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
} catch {
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return aliases;
|
|
161
|
+
}
|
|
162
|
+
module2.exports = {
|
|
163
|
+
readJson,
|
|
164
|
+
readPublicPackageAliases,
|
|
165
|
+
readAllSomaPublicAliases: readAllSomaPublicAliases2
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// core/server/host/host-config-paths.cjs
|
|
171
|
+
var require_host_config_paths = __commonJS({
|
|
172
|
+
"core/server/host/host-config-paths.cjs"(exports2, module2) {
|
|
173
|
+
"use strict";
|
|
174
|
+
var fs2 = require("node:fs");
|
|
175
|
+
var path2 = require("node:path");
|
|
176
|
+
function readJson(filePath) {
|
|
177
|
+
try {
|
|
178
|
+
if (!fs2.existsSync(filePath)) return null;
|
|
179
|
+
return JSON.parse(fs2.readFileSync(filePath, "utf8"));
|
|
180
|
+
} catch {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function resolveSafeChildRoot(parent, relativePath, options = {}) {
|
|
185
|
+
const trimmed = typeof relativePath === "string" ? relativePath.trim() : "";
|
|
186
|
+
if (!trimmed) return parent;
|
|
187
|
+
const resolved = path2.resolve(parent, trimmed);
|
|
188
|
+
const normalizedParent = path2.resolve(parent);
|
|
189
|
+
if (resolved === normalizedParent || resolved.startsWith(`${normalizedParent}${path2.sep}`)) {
|
|
190
|
+
if (options.requireExists && !fs2.existsSync(resolved)) {
|
|
191
|
+
return normalizedParent;
|
|
192
|
+
}
|
|
193
|
+
return resolved;
|
|
194
|
+
}
|
|
195
|
+
return options.fallback ?? normalizedParent;
|
|
196
|
+
}
|
|
197
|
+
function normalizeSomaEnv(raw) {
|
|
198
|
+
const value = String(raw ?? "").trim().toLowerCase();
|
|
199
|
+
if (!value) return "test";
|
|
200
|
+
if (["test", "testing", "dev", "development", "local", "qa", "staging", "pre", "prepub", "uat"].includes(value)) {
|
|
201
|
+
return "test";
|
|
202
|
+
}
|
|
203
|
+
return "prod";
|
|
204
|
+
}
|
|
205
|
+
function readSomaEnv(env = process.env) {
|
|
206
|
+
return normalizeSomaEnv(env.SOMA_ENV ?? env.APP_ENV ?? env.NODE_ENV);
|
|
207
|
+
}
|
|
208
|
+
function resolveHostConfigRoot(hostDir) {
|
|
209
|
+
const normalizedHostDir = path2.resolve(hostDir);
|
|
210
|
+
const packageJson = readJson(path2.join(normalizedHostDir, "package.json"));
|
|
211
|
+
const configured = packageJson?.soma?.configRoot?.trim();
|
|
212
|
+
if (configured) {
|
|
213
|
+
return resolveSafeChildRoot(normalizedHostDir, configured, {
|
|
214
|
+
fallback: path2.join(normalizedHostDir, "config")
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
const hostSourceRoot = resolveSafeChildRoot(normalizedHostDir, packageJson?.soma?.hostRoot, {
|
|
218
|
+
requireExists: true
|
|
219
|
+
});
|
|
220
|
+
const candidates = [
|
|
221
|
+
path2.join(normalizedHostDir, "config"),
|
|
222
|
+
path2.join(hostSourceRoot, "config")
|
|
223
|
+
];
|
|
224
|
+
for (const candidate of candidates) {
|
|
225
|
+
if (fs2.existsSync(candidate)) {
|
|
226
|
+
return candidate;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return path2.join(hostSourceRoot, "config");
|
|
230
|
+
}
|
|
231
|
+
function getSomaHostConfigRoot(hostDir) {
|
|
232
|
+
return resolveHostConfigRoot(hostDir);
|
|
233
|
+
}
|
|
234
|
+
function resolveAppConfigPath(configRoot, envName) {
|
|
235
|
+
const env = envName ?? readSomaEnv();
|
|
236
|
+
const candidates = [
|
|
237
|
+
path2.join(configRoot, `app.config.${env}.yaml`),
|
|
238
|
+
path2.join(configRoot, "app.config.yaml")
|
|
239
|
+
];
|
|
240
|
+
for (const candidate of candidates) {
|
|
241
|
+
if (fs2.existsSync(candidate)) {
|
|
242
|
+
return candidate;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
function resolveHostAppConfigPath(hostDir, envName) {
|
|
248
|
+
return resolveAppConfigPath(resolveHostConfigRoot(hostDir), envName);
|
|
249
|
+
}
|
|
250
|
+
module2.exports = {
|
|
251
|
+
normalizeSomaEnv,
|
|
252
|
+
readSomaEnv,
|
|
253
|
+
resolveHostConfigRoot,
|
|
254
|
+
getSomaHostConfigRoot,
|
|
255
|
+
resolveAppConfigPath,
|
|
256
|
+
resolveHostAppConfigPath
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
// core/server/host/source-packages.cjs
|
|
262
|
+
var require_source_packages = __commonJS({
|
|
263
|
+
"core/server/host/source-packages.cjs"(exports2, module2) {
|
|
264
|
+
"use strict";
|
|
265
|
+
var fs2 = require("node:fs");
|
|
266
|
+
var path2 = require("node:path");
|
|
267
|
+
var { getSomaHostConfigRoot } = require_host_config_paths();
|
|
268
|
+
var SOMA_SOURCE_PACKAGES_ENV = "SOMA_SOURCE_PACKAGES";
|
|
269
|
+
var MAX_ASSET_SOURCE_CACHE = 64;
|
|
270
|
+
var assetSourcesCache = /* @__PURE__ */ new Map();
|
|
271
|
+
function clearSomaAssetSourcesCache() {
|
|
272
|
+
assetSourcesCache.clear();
|
|
273
|
+
}
|
|
274
|
+
function readJson(filePath) {
|
|
275
|
+
try {
|
|
276
|
+
if (!fs2.existsSync(filePath)) return null;
|
|
277
|
+
return JSON.parse(fs2.readFileSync(filePath, "utf8"));
|
|
278
|
+
} catch {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function packagePathInNodeModules(hostDir, packageName) {
|
|
283
|
+
return path2.join(hostDir, "node_modules", ...packageName.split("/"));
|
|
284
|
+
}
|
|
285
|
+
function resolvePackageRoot(hostDir, packageName, version) {
|
|
286
|
+
const nodeModulesPath = packagePathInNodeModules(hostDir, packageName);
|
|
287
|
+
if (fs2.existsSync(nodeModulesPath)) return nodeModulesPath;
|
|
288
|
+
if (typeof version === "string" && version.startsWith("file:")) {
|
|
289
|
+
const fileRoot = path2.resolve(hostDir, version.slice("file:".length));
|
|
290
|
+
if (fs2.existsSync(fileRoot)) return fileRoot;
|
|
291
|
+
}
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
function readExplicitSourcePackages(env = process.env) {
|
|
295
|
+
return String(env?.[SOMA_SOURCE_PACKAGES_ENV] ?? "").split(",").map((item) => item.trim()).filter(Boolean);
|
|
296
|
+
}
|
|
297
|
+
function readHostDependencies(hostDir) {
|
|
298
|
+
const packageJson = readJson(path2.join(hostDir, "package.json"));
|
|
299
|
+
return {
|
|
300
|
+
...packageJson?.dependencies ?? {},
|
|
301
|
+
...packageJson?.devDependencies ?? {}
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
function resolveSafeChildRoot(parent, relativePath) {
|
|
305
|
+
const normalizedParent = path2.resolve(parent);
|
|
306
|
+
const trimmed = typeof relativePath === "string" ? relativePath.trim() : "";
|
|
307
|
+
if (!trimmed) return normalizedParent;
|
|
308
|
+
const resolved = path2.resolve(normalizedParent, trimmed);
|
|
309
|
+
if (resolved === normalizedParent || resolved.startsWith(`${normalizedParent}${path2.sep}`)) {
|
|
310
|
+
return fs2.existsSync(resolved) ? resolved : normalizedParent;
|
|
311
|
+
}
|
|
312
|
+
return normalizedParent;
|
|
313
|
+
}
|
|
314
|
+
function resolveExplicitHostPath(baseDir, rawPath, options = {}) {
|
|
315
|
+
if (typeof rawPath !== "string") return null;
|
|
316
|
+
const trimmed = rawPath.trim();
|
|
317
|
+
if (!trimmed || trimmed.includes("\0")) return null;
|
|
318
|
+
const resolved = path2.resolve(baseDir, trimmed);
|
|
319
|
+
if (resolved === path2.parse(resolved).root) return null;
|
|
320
|
+
if (options.requireExists && !fs2.existsSync(resolved)) return null;
|
|
321
|
+
return resolved;
|
|
322
|
+
}
|
|
323
|
+
function getSomaHostSourceRoot2(hostDir, env = process.env) {
|
|
324
|
+
const normalizedHostDir = path2.resolve(hostDir);
|
|
325
|
+
if (env && typeof env.SOMA_WEB_DIR === "string" && env.SOMA_WEB_DIR.trim()) {
|
|
326
|
+
const explicit = resolveExplicitHostPath(normalizedHostDir, env.SOMA_WEB_DIR, { requireExists: false });
|
|
327
|
+
if (explicit) return explicit;
|
|
328
|
+
}
|
|
329
|
+
const packageJson = readJson(path2.join(normalizedHostDir, "package.json"));
|
|
330
|
+
if (typeof packageJson?.soma?.webRoot === "string" && packageJson.soma.webRoot.trim()) {
|
|
331
|
+
const explicit = resolveExplicitHostPath(normalizedHostDir, packageJson.soma.webRoot, { requireExists: true });
|
|
332
|
+
if (explicit) return explicit;
|
|
333
|
+
}
|
|
334
|
+
return resolveSafeChildRoot(normalizedHostDir, packageJson?.soma?.hostRoot);
|
|
335
|
+
}
|
|
336
|
+
function getSomaHostApiRoot2(hostDir, env = process.env) {
|
|
337
|
+
const normalizedHostDir = path2.resolve(hostDir);
|
|
338
|
+
if (env && typeof env.SOMA_API_DIR === "string" && env.SOMA_API_DIR.trim()) {
|
|
339
|
+
const explicit = resolveExplicitHostPath(normalizedHostDir, env.SOMA_API_DIR, { requireExists: false });
|
|
340
|
+
if (explicit) return explicit;
|
|
341
|
+
}
|
|
342
|
+
const packageJson = readJson(path2.join(normalizedHostDir, "package.json"));
|
|
343
|
+
const candidate = typeof packageJson?.soma?.apiRoot === "string" && packageJson.soma.apiRoot.trim() ? packageJson.soma.apiRoot : typeof packageJson?.soma?.serviceRoot === "string" && packageJson.soma.serviceRoot.trim() ? packageJson.soma.serviceRoot : null;
|
|
344
|
+
if (candidate) {
|
|
345
|
+
const explicit = resolveExplicitHostPath(normalizedHostDir, candidate, { requireExists: true });
|
|
346
|
+
if (explicit) return explicit;
|
|
347
|
+
}
|
|
348
|
+
return getSomaHostSourceRoot2(normalizedHostDir, env);
|
|
349
|
+
}
|
|
350
|
+
function isSomaSourcePackage(packageRoot, explicit) {
|
|
351
|
+
if (explicit) return true;
|
|
352
|
+
const packageJson = readJson(path2.join(packageRoot, "package.json"));
|
|
353
|
+
return packageJson?.soma?.source === true;
|
|
354
|
+
}
|
|
355
|
+
function toPackageSource(packageName, packageRoot) {
|
|
356
|
+
const packageJson = readJson(path2.join(packageRoot, "package.json"));
|
|
357
|
+
const codeRoot = resolveSafeChildRoot(packageRoot, packageJson?.soma?.hostRoot);
|
|
358
|
+
const configRoot = resolveSafeChildRoot(packageRoot, packageJson?.soma?.configRoot);
|
|
359
|
+
return {
|
|
360
|
+
type: "package",
|
|
361
|
+
name: packageName,
|
|
362
|
+
packageName,
|
|
363
|
+
assetRoot: codeRoot,
|
|
364
|
+
codeRoot,
|
|
365
|
+
apiRoot: codeRoot,
|
|
366
|
+
configRoot
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
function getSomaAssetSources(hostDir, env = process.env) {
|
|
370
|
+
const normalizedHostDir = path2.resolve(hostDir);
|
|
371
|
+
const pkgStat = fs2.statSync(path2.join(normalizedHostDir, "package.json"), { throwIfNoEntry: false });
|
|
372
|
+
const pkgStatKey = pkgStat ? `${pkgStat.mtimeMs}:${pkgStat.size}` : "none";
|
|
373
|
+
const cacheKey = `${normalizedHostDir}\0${env?.[SOMA_SOURCE_PACKAGES_ENV] ?? ""}\0${env?.SOMA_WEB_DIR ?? ""}\0${env?.SOMA_API_DIR ?? ""}\0${pkgStatKey}`;
|
|
374
|
+
const cached = assetSourcesCache.get(cacheKey);
|
|
375
|
+
if (cached) {
|
|
376
|
+
return cached.slice();
|
|
377
|
+
}
|
|
378
|
+
const hostSourceRoot = getSomaHostSourceRoot2(normalizedHostDir, env);
|
|
379
|
+
const hostApiRoot = getSomaHostApiRoot2(normalizedHostDir, env);
|
|
380
|
+
const dependencies = readHostDependencies(normalizedHostDir);
|
|
381
|
+
const explicitPackages = new Set(readExplicitSourcePackages(env));
|
|
382
|
+
const packageNames = /* @__PURE__ */ new Set([...Object.keys(dependencies), ...explicitPackages]);
|
|
383
|
+
const sources = [
|
|
384
|
+
{
|
|
385
|
+
type: "host",
|
|
386
|
+
name: "host",
|
|
387
|
+
assetRoot: hostSourceRoot,
|
|
388
|
+
codeRoot: hostSourceRoot,
|
|
389
|
+
apiRoot: hostApiRoot,
|
|
390
|
+
configRoot: getSomaHostConfigRoot(normalizedHostDir)
|
|
391
|
+
}
|
|
392
|
+
];
|
|
393
|
+
for (const packageName of packageNames) {
|
|
394
|
+
const packageRoot = resolvePackageRoot(normalizedHostDir, packageName, dependencies[packageName]);
|
|
395
|
+
if (!packageRoot || !isSomaSourcePackage(packageRoot, explicitPackages.has(packageName))) continue;
|
|
396
|
+
sources.push(toPackageSource(packageName, packageRoot));
|
|
397
|
+
}
|
|
398
|
+
if (assetSourcesCache.size >= MAX_ASSET_SOURCE_CACHE) {
|
|
399
|
+
assetSourcesCache.delete(assetSourcesCache.keys().next().value);
|
|
400
|
+
}
|
|
401
|
+
assetSourcesCache.set(cacheKey, sources);
|
|
402
|
+
return sources.slice();
|
|
403
|
+
}
|
|
404
|
+
function listSomaSourcePackageNames(hostDir, env = process.env) {
|
|
405
|
+
return getSomaAssetSources(hostDir, env).filter((source) => source.type === "package").map((source) => source.packageName);
|
|
406
|
+
}
|
|
407
|
+
function orderSourcesForOverride(sources) {
|
|
408
|
+
return [
|
|
409
|
+
...sources.filter((source) => source.type === "package"),
|
|
410
|
+
...sources.filter((source) => source.type === "host")
|
|
411
|
+
];
|
|
412
|
+
}
|
|
413
|
+
function collectHtmlFiles(dir, prefix = "", acc = []) {
|
|
414
|
+
if (!fs2.existsSync(dir)) return acc;
|
|
415
|
+
for (const entry of fs2.readdirSync(dir, { withFileTypes: true })) {
|
|
416
|
+
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
417
|
+
const full = path2.join(dir, entry.name);
|
|
418
|
+
if (entry.isDirectory()) collectHtmlFiles(full, rel, acc);
|
|
419
|
+
else if (entry.name.endsWith(".html")) acc.push(rel);
|
|
420
|
+
}
|
|
421
|
+
return acc;
|
|
422
|
+
}
|
|
423
|
+
function collectPageEntries(sources) {
|
|
424
|
+
const byHtmlFile = /* @__PURE__ */ new Map();
|
|
425
|
+
for (const source of orderSourcesForOverride(sources)) {
|
|
426
|
+
const htmlRoot = path2.join(source.assetRoot, "html");
|
|
427
|
+
for (const htmlFile of collectHtmlFiles(htmlRoot).sort()) {
|
|
428
|
+
byHtmlFile.set(htmlFile, { source, htmlFile });
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return [...byHtmlFile.values()].sort((a, b) => a.htmlFile.localeCompare(b.htmlFile));
|
|
432
|
+
}
|
|
433
|
+
function collectIncludes(sources) {
|
|
434
|
+
const includes = {};
|
|
435
|
+
for (const source of orderSourcesForOverride(sources)) {
|
|
436
|
+
const sharedDir = path2.join(source.assetRoot, "html", "shared");
|
|
437
|
+
if (!fs2.existsSync(sharedDir)) continue;
|
|
438
|
+
for (const entry of fs2.readdirSync(sharedDir, { withFileTypes: true })) {
|
|
439
|
+
if (!entry.isFile() || !entry.name.endsWith(".html")) continue;
|
|
440
|
+
includes[`shared/${entry.name}`] = fs2.readFileSync(path2.join(sharedDir, entry.name), "utf8");
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return includes;
|
|
444
|
+
}
|
|
445
|
+
module2.exports = {
|
|
446
|
+
SOMA_SOURCE_PACKAGES_ENV,
|
|
447
|
+
getSomaHostSourceRoot: getSomaHostSourceRoot2,
|
|
448
|
+
getSomaHostApiRoot: getSomaHostApiRoot2,
|
|
449
|
+
clearSomaAssetSourcesCache,
|
|
450
|
+
getSomaAssetSources,
|
|
451
|
+
listSomaSourcePackageNames,
|
|
452
|
+
orderSourcesForOverride,
|
|
453
|
+
collectHtmlFiles,
|
|
454
|
+
collectPageEntries,
|
|
455
|
+
collectIncludes
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
// host-native/src/aot-builder.ts
|
|
461
|
+
var aot_builder_exports = {};
|
|
462
|
+
__export(aot_builder_exports, {
|
|
463
|
+
buildBrowserClient: () => buildBrowserClient,
|
|
464
|
+
buildServerAot: () => buildServerAot
|
|
465
|
+
});
|
|
466
|
+
module.exports = __toCommonJS(aot_builder_exports);
|
|
467
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
468
|
+
var import_node_path = __toESM(require("node:path"));
|
|
469
|
+
var import_node_crypto = require("node:crypto");
|
|
470
|
+
var import_esbuild = __toESM(require("esbuild"));
|
|
471
|
+
var import_public_packages = __toESM(require_public_packages());
|
|
472
|
+
|
|
473
|
+
// core/server/api/service-path.ts
|
|
474
|
+
function toPascalCase(str) {
|
|
475
|
+
return str.split(/[-_]/).map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join("");
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// host-native/src/aot-builder.ts
|
|
479
|
+
var import_source_packages = __toESM(require_source_packages());
|
|
480
|
+
function resolveModuleFile(baseDir, subpath) {
|
|
481
|
+
const target = subpath ? import_node_path.default.resolve(baseDir, subpath) : import_node_path.default.resolve(baseDir);
|
|
482
|
+
for (const ext of ["", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"]) {
|
|
483
|
+
const candidate = target + ext;
|
|
484
|
+
if (import_node_fs.default.existsSync(candidate) && import_node_fs.default.statSync(candidate).isFile()) {
|
|
485
|
+
return candidate;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
if (import_node_fs.default.existsSync(target) && import_node_fs.default.statSync(target).isDirectory()) {
|
|
489
|
+
for (const index of ["index.ts", "index.tsx", "index.js", "index.mjs", "index.cjs"]) {
|
|
490
|
+
const candidate = import_node_path.default.join(target, index);
|
|
491
|
+
if (import_node_fs.default.existsSync(candidate) && import_node_fs.default.statSync(candidate).isFile()) {
|
|
492
|
+
return candidate;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return target;
|
|
497
|
+
}
|
|
498
|
+
var coreRoot = import_node_path.default.resolve(__dirname, "../..");
|
|
499
|
+
var hostNativeRoot = import_node_path.default.join(coreRoot, "host-native");
|
|
500
|
+
var repoRoot = import_node_path.default.resolve(coreRoot, "..");
|
|
501
|
+
function createBrowserClientPlugin(options) {
|
|
502
|
+
const { hostDir, webRoot } = options;
|
|
503
|
+
const publicAliases = (0, import_public_packages.readAllSomaPublicAliases)(hostDir, repoRoot, [webRoot, coreRoot]);
|
|
504
|
+
return {
|
|
505
|
+
name: "soma-browser-client-plugin",
|
|
506
|
+
setup(build) {
|
|
507
|
+
build.onResolve({ filter: /^server-only$/ }, (args) => {
|
|
508
|
+
throw new Error(
|
|
509
|
+
`[soma] Client bundle must not import 'server-only'! Boundary violation detected from ${args.importer}`
|
|
510
|
+
);
|
|
511
|
+
});
|
|
512
|
+
build.onResolve({ filter: /^@soma-host\/bootstrap\/soma-bootstrap$/ }, () => {
|
|
513
|
+
const candidateHostFile = import_node_path.default.resolve(webRoot, "bootstrap/soma-bootstrap");
|
|
514
|
+
for (const ext of [".ts", ".js", ".mjs"]) {
|
|
515
|
+
if (import_node_fs.default.existsSync(candidateHostFile + ext)) {
|
|
516
|
+
return { path: candidateHostFile + ext };
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
if (import_node_fs.default.existsSync(import_node_path.default.resolve(webRoot, "soma.app.ts"))) {
|
|
520
|
+
return { path: import_node_path.default.resolve(coreRoot, "core/client/host-bridge/soma-bootstrap-from-app.ts") };
|
|
521
|
+
}
|
|
522
|
+
return { path: import_node_path.default.resolve(coreRoot, "core/client/host-bridge/soma-bootstrap-host.stub.ts") };
|
|
523
|
+
});
|
|
524
|
+
build.onResolve({ filter: /^@soma-host\/bootstrap\/soma-domain-loaders$/ }, () => {
|
|
525
|
+
const candidateLoader = import_node_path.default.resolve(webRoot, "bootstrap/soma-domain-loaders");
|
|
526
|
+
for (const ext of [".ts", ".js", ".mjs"]) {
|
|
527
|
+
if (import_node_fs.default.existsSync(candidateLoader + ext)) {
|
|
528
|
+
return { path: candidateLoader + ext };
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
return { path: import_node_path.default.resolve(coreRoot, "core/client/host-bridge/soma-domain-loaders.stub.ts") };
|
|
532
|
+
});
|
|
533
|
+
build.onResolve({ filter: /^@soma-host\/domain\/ui\/.*Class\.ts$/ }, (args) => {
|
|
534
|
+
const baseName = import_node_path.default.basename(args.path);
|
|
535
|
+
const diskFile = import_node_path.default.resolve(webRoot, "domain/ui", baseName);
|
|
536
|
+
if (import_node_fs.default.existsSync(diskFile)) {
|
|
537
|
+
return { path: diskFile };
|
|
538
|
+
}
|
|
539
|
+
return {
|
|
540
|
+
path: args.path,
|
|
541
|
+
namespace: "soma-absent-domain"
|
|
542
|
+
};
|
|
543
|
+
});
|
|
544
|
+
build.onLoad({ filter: /.*/, namespace: "soma-absent-domain" }, (args) => {
|
|
545
|
+
return {
|
|
546
|
+
contents: `
|
|
547
|
+
const err = new Error("Cannot find module '${args.path}'");
|
|
548
|
+
err.code = "MODULE_NOT_FOUND";
|
|
549
|
+
throw err;
|
|
550
|
+
`,
|
|
551
|
+
loader: "js"
|
|
552
|
+
};
|
|
553
|
+
});
|
|
554
|
+
build.onResolve({ filter: /^@soma-host(?:\/.*)?$/ }, (args) => {
|
|
555
|
+
const subpath = args.path.replace(/^@soma-host\/?/, "");
|
|
556
|
+
const target = import_node_path.default.resolve(webRoot, subpath);
|
|
557
|
+
for (const ext of ["", ".ts", ".tsx", ".js", ".jsx", ".mjs"]) {
|
|
558
|
+
if (import_node_fs.default.existsSync(target + ext) && import_node_fs.default.statSync(target + ext).isFile()) {
|
|
559
|
+
return { path: target + ext };
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
if (import_node_fs.default.existsSync(target) && import_node_fs.default.statSync(target).isDirectory()) {
|
|
563
|
+
for (const index of ["index.ts", "index.tsx", "index.js", "index.jsx"]) {
|
|
564
|
+
if (import_node_fs.default.existsSync(import_node_path.default.join(target, index))) {
|
|
565
|
+
return { path: import_node_path.default.join(target, index) };
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
return { path: target };
|
|
570
|
+
});
|
|
571
|
+
build.onResolve({ filter: /core\/client\/engine\// }, (args) => {
|
|
572
|
+
if (!args.importer.includes("soma-core")) {
|
|
573
|
+
throw new Error(
|
|
574
|
+
`[soma] Deep import forbidden: '${args.path}' from '${args.importer}'. Import from 'soma-core/runtime' instead.`
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
return void 0;
|
|
578
|
+
});
|
|
579
|
+
build.onResolve({ filter: /^soma-[a-z0-9-]+(?:\/.*)?$/ }, (args) => {
|
|
580
|
+
const direct = publicAliases[args.path];
|
|
581
|
+
if (direct && import_node_fs.default.existsSync(direct)) {
|
|
582
|
+
return { path: direct };
|
|
583
|
+
}
|
|
584
|
+
return void 0;
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
async function buildBrowserClient(options) {
|
|
590
|
+
const hostDir = import_node_path.default.resolve(options.hostDir);
|
|
591
|
+
const webRoot = import_node_path.default.resolve(options.webRoot || (0, import_source_packages.getSomaHostSourceRoot)(hostDir, options.env));
|
|
592
|
+
const outDir = import_node_path.default.resolve(options.outDir);
|
|
593
|
+
const clientOutDir = import_node_path.default.join(outDir, "client");
|
|
594
|
+
import_node_fs.default.mkdirSync(clientOutDir, { recursive: true });
|
|
595
|
+
const clientEntry = import_node_path.default.join(hostNativeRoot, "client/browser-entry.ts");
|
|
596
|
+
const plugin = createBrowserClientPlugin({ hostDir, webRoot });
|
|
597
|
+
const cssSourcePath = import_node_path.default.join(hostNativeRoot, "styles/globals.css");
|
|
598
|
+
let rawCss = "";
|
|
599
|
+
try {
|
|
600
|
+
rawCss = import_node_fs.default.readFileSync(cssSourcePath, "utf8");
|
|
601
|
+
} catch {
|
|
602
|
+
rawCss = "/* soma globals */\n";
|
|
603
|
+
}
|
|
604
|
+
let finalCss = rawCss;
|
|
605
|
+
if (!options.dev) {
|
|
606
|
+
const minifiedCss = await import_esbuild.default.transform(rawCss, {
|
|
607
|
+
loader: "css",
|
|
608
|
+
minify: true
|
|
609
|
+
});
|
|
610
|
+
finalCss = minifiedCss.code;
|
|
611
|
+
}
|
|
612
|
+
let cssFileName = "globals.css";
|
|
613
|
+
if (!options.dev) {
|
|
614
|
+
const hash = (0, import_node_crypto.createHash)("sha256").update(finalCss).digest("hex").slice(0, 8);
|
|
615
|
+
cssFileName = `globals-${hash}.css`;
|
|
616
|
+
}
|
|
617
|
+
import_node_fs.default.writeFileSync(import_node_path.default.join(clientOutDir, cssFileName), finalCss, "utf8");
|
|
618
|
+
const cssUrl = `/_soma/client/${cssFileName}`;
|
|
619
|
+
const buildOptions = {
|
|
620
|
+
entryPoints: {
|
|
621
|
+
"browser-entry": clientEntry
|
|
622
|
+
},
|
|
623
|
+
outdir: clientOutDir,
|
|
624
|
+
bundle: true,
|
|
625
|
+
format: "esm",
|
|
626
|
+
splitting: true,
|
|
627
|
+
platform: "browser",
|
|
628
|
+
target: ["es2022"],
|
|
629
|
+
minify: !options.dev,
|
|
630
|
+
sourcemap: options.dev ? "inline" : false,
|
|
631
|
+
entryNames: options.dev ? "[name]" : "[name]-[hash]",
|
|
632
|
+
chunkNames: options.dev ? "chunks/[name]" : "chunks/[name]-[hash]",
|
|
633
|
+
nodePaths: [import_node_path.default.join(webRoot, "node_modules"), import_node_path.default.join(hostDir, "node_modules"), import_node_path.default.join(coreRoot, "node_modules")].filter((d) => import_node_fs.default.existsSync(d)),
|
|
634
|
+
plugins: [plugin],
|
|
635
|
+
define: {
|
|
636
|
+
"process.env.NODE_ENV": JSON.stringify(options.dev ? "development" : "production")
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
let ctx = null;
|
|
640
|
+
let entryUrl = "/_soma/client/browser-entry.js";
|
|
641
|
+
if (options.dev) {
|
|
642
|
+
ctx = await import_esbuild.default.context(buildOptions);
|
|
643
|
+
await ctx.rebuild();
|
|
644
|
+
entryUrl = "/_soma/client/browser-entry.js";
|
|
645
|
+
} else {
|
|
646
|
+
const result = await import_esbuild.default.build({
|
|
647
|
+
...buildOptions,
|
|
648
|
+
metafile: true
|
|
649
|
+
});
|
|
650
|
+
if (result.metafile) {
|
|
651
|
+
for (const [outputPath, meta] of Object.entries(result.metafile.outputs)) {
|
|
652
|
+
if (meta.entryPoint && (meta.entryPoint.endsWith("browser-entry.ts") || import_node_path.default.basename(outputPath).startsWith("browser-entry")) && outputPath.endsWith(".js")) {
|
|
653
|
+
const fileName = import_node_path.default.basename(outputPath);
|
|
654
|
+
entryUrl = `/_soma/client/${fileName}`;
|
|
655
|
+
break;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
if (!options.dev) {
|
|
661
|
+
import_node_fs.default.writeFileSync(
|
|
662
|
+
import_node_path.default.join(clientOutDir, "client-manifest.json"),
|
|
663
|
+
JSON.stringify({ entryUrl, cssUrl, cssText: finalCss }, null, 2) + "\n",
|
|
664
|
+
"utf8"
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
return {
|
|
668
|
+
entryUrl,
|
|
669
|
+
cssUrl,
|
|
670
|
+
cssText: finalCss,
|
|
671
|
+
rebuild: async () => {
|
|
672
|
+
if (ctx) {
|
|
673
|
+
await ctx.rebuild();
|
|
674
|
+
}
|
|
675
|
+
},
|
|
676
|
+
dispose: async () => {
|
|
677
|
+
if (ctx) {
|
|
678
|
+
await ctx.dispose();
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
async function buildServerAot(options) {
|
|
684
|
+
const hostDir = import_node_path.default.resolve(options.hostDir);
|
|
685
|
+
const webRoot = import_node_path.default.resolve(options.webRoot || (0, import_source_packages.getSomaHostSourceRoot)(hostDir, options.env));
|
|
686
|
+
const apiRoot = import_node_path.default.resolve(options.apiRoot || (0, import_source_packages.getSomaHostApiRoot)(hostDir, options.env));
|
|
687
|
+
const outDir = import_node_path.default.resolve(options.outDir);
|
|
688
|
+
const aotServerDir = import_node_path.default.join(outDir, "aot-server");
|
|
689
|
+
import_node_fs.default.mkdirSync(aotServerDir, { recursive: true });
|
|
690
|
+
const serviceFiles = scanServiceFiles(apiRoot, webRoot);
|
|
691
|
+
const entryPoints = {};
|
|
692
|
+
const routes = {};
|
|
693
|
+
for (const item of serviceFiles) {
|
|
694
|
+
const entryName = `services/${item.routeKey.replace(/\//g, "_")}`;
|
|
695
|
+
entryPoints[entryName] = item.filePath;
|
|
696
|
+
routes[item.routeKey] = `${entryName}.cjs`;
|
|
697
|
+
const segments = item.routeKey.split("/");
|
|
698
|
+
const pascalKey = segments.slice(0, -1).concat(toPascalCase(segments[segments.length - 1])).join("/");
|
|
699
|
+
if (pascalKey !== item.routeKey) {
|
|
700
|
+
routes[pascalKey] = `${entryName}.cjs`;
|
|
701
|
+
}
|
|
702
|
+
const lowerKey = item.routeKey.toLowerCase();
|
|
703
|
+
if (lowerKey !== item.routeKey) {
|
|
704
|
+
routes[lowerKey] = `${entryName}.cjs`;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
let hostAppCompiledPath;
|
|
708
|
+
const hostAppPath = import_node_path.default.resolve(webRoot, "soma.app.ts");
|
|
709
|
+
if (import_node_fs.default.existsSync(hostAppPath)) {
|
|
710
|
+
entryPoints["host-app"] = hostAppPath;
|
|
711
|
+
hostAppCompiledPath = "host-app.cjs";
|
|
712
|
+
}
|
|
713
|
+
if (Object.keys(entryPoints).length > 0) {
|
|
714
|
+
await import_esbuild.default.build({
|
|
715
|
+
entryPoints,
|
|
716
|
+
outdir: aotServerDir,
|
|
717
|
+
bundle: true,
|
|
718
|
+
platform: "node",
|
|
719
|
+
format: "cjs",
|
|
720
|
+
target: "node20",
|
|
721
|
+
packages: "external",
|
|
722
|
+
nodePaths: [import_node_path.default.join(apiRoot, "node_modules"), import_node_path.default.join(webRoot, "node_modules"), import_node_path.default.join(hostDir, "node_modules"), import_node_path.default.join(coreRoot, "node_modules")].filter((d) => import_node_fs.default.existsSync(d)),
|
|
723
|
+
outExtension: { ".js": ".cjs" },
|
|
724
|
+
plugins: [
|
|
725
|
+
{
|
|
726
|
+
name: "soma-server-aot-plugin",
|
|
727
|
+
setup(build) {
|
|
728
|
+
const publicAliases = (0, import_public_packages.readAllSomaPublicAliases)(hostDir, repoRoot, [webRoot, apiRoot, coreRoot]);
|
|
729
|
+
build.onResolve({ filter: /^server-only$/ }, () => {
|
|
730
|
+
return { path: import_node_path.default.resolve(coreRoot, "core/server/host/server-only-noop.cjs") };
|
|
731
|
+
});
|
|
732
|
+
build.onResolve({ filter: /^@core(?:\/.*)?$/ }, (args) => {
|
|
733
|
+
const subpath = args.path.replace(/^@core\/?/, "");
|
|
734
|
+
return { path: resolveModuleFile(import_node_path.default.resolve(coreRoot, "core"), subpath) };
|
|
735
|
+
});
|
|
736
|
+
build.onResolve({ filter: /^@soma-host\/bootstrap\/soma-bootstrap$/ }, () => {
|
|
737
|
+
const candidateHostFile = import_node_path.default.resolve(webRoot, "bootstrap/soma-bootstrap");
|
|
738
|
+
for (const ext of [".ts", ".js", ".mjs"]) {
|
|
739
|
+
if (import_node_fs.default.existsSync(candidateHostFile + ext)) {
|
|
740
|
+
return { path: candidateHostFile + ext };
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
if (import_node_fs.default.existsSync(import_node_path.default.resolve(webRoot, "soma.app.ts"))) {
|
|
744
|
+
return { path: import_node_path.default.resolve(coreRoot, "core/client/host-bridge/soma-bootstrap-from-app.ts") };
|
|
745
|
+
}
|
|
746
|
+
return { path: import_node_path.default.resolve(coreRoot, "core/client/host-bridge/soma-bootstrap-host.stub.ts") };
|
|
747
|
+
});
|
|
748
|
+
build.onResolve({ filter: /^@soma-host\/bootstrap\/soma-domain-loaders$/ }, () => {
|
|
749
|
+
const candidateLoader = import_node_path.default.resolve(webRoot, "bootstrap/soma-domain-loaders");
|
|
750
|
+
for (const ext of [".ts", ".js", ".mjs"]) {
|
|
751
|
+
if (import_node_fs.default.existsSync(candidateLoader + ext)) {
|
|
752
|
+
return { path: candidateLoader + ext };
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
return { path: import_node_path.default.resolve(coreRoot, "core/client/host-bridge/soma-domain-loaders.stub.ts") };
|
|
756
|
+
});
|
|
757
|
+
build.onResolve({ filter: /^@soma-host\/domain\/ui\/.*Class\.ts$/ }, (args) => {
|
|
758
|
+
const baseName = import_node_path.default.basename(args.path);
|
|
759
|
+
const diskFile = import_node_path.default.resolve(webRoot, "domain/ui", baseName);
|
|
760
|
+
if (import_node_fs.default.existsSync(diskFile)) {
|
|
761
|
+
return { path: diskFile };
|
|
762
|
+
}
|
|
763
|
+
return { path: args.path, namespace: "soma-absent-domain" };
|
|
764
|
+
});
|
|
765
|
+
build.onLoad({ filter: /.*/, namespace: "soma-absent-domain" }, (args) => ({
|
|
766
|
+
contents: `const err = new Error("Cannot find module '${args.path}'"); err.code = "MODULE_NOT_FOUND"; throw err;`,
|
|
767
|
+
loader: "js"
|
|
768
|
+
}));
|
|
769
|
+
build.onResolve({ filter: /^@soma-host(?:\/.*)?$/ }, (args) => {
|
|
770
|
+
const subpath = args.path.replace(/^@soma-host\/?/, "");
|
|
771
|
+
return { path: resolveModuleFile(webRoot, subpath) };
|
|
772
|
+
});
|
|
773
|
+
build.onResolve({ filter: /^@soma-api(?:\/.*)?$/ }, (args) => {
|
|
774
|
+
const subpath = args.path.replace(/^@soma-api\/?/, "");
|
|
775
|
+
return { path: resolveModuleFile(apiRoot, subpath) };
|
|
776
|
+
});
|
|
777
|
+
build.onResolve({ filter: /^soma-[a-z0-9-]+(?:\/.*)?$/ }, (args) => {
|
|
778
|
+
const direct = publicAliases[args.path];
|
|
779
|
+
if (direct && import_node_fs.default.existsSync(direct)) {
|
|
780
|
+
return { path: direct };
|
|
781
|
+
}
|
|
782
|
+
return void 0;
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
]
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
const manifest = {
|
|
790
|
+
hostDir,
|
|
791
|
+
webRoot,
|
|
792
|
+
apiRoot,
|
|
793
|
+
builtAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
794
|
+
routes,
|
|
795
|
+
...hostAppCompiledPath ? { hostAppCompiledPath } : {}
|
|
796
|
+
};
|
|
797
|
+
const manifestPath = import_node_path.default.join(aotServerDir, "aot-manifest.json");
|
|
798
|
+
import_node_fs.default.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + "\n", "utf8");
|
|
799
|
+
return manifest;
|
|
800
|
+
}
|
|
801
|
+
function scanServiceFiles(apiRoot, webRoot) {
|
|
802
|
+
const items = [];
|
|
803
|
+
const scannedPaths = /* @__PURE__ */ new Set();
|
|
804
|
+
const baseCandidates = [
|
|
805
|
+
{ base: import_node_path.default.join(apiRoot, "api", "service"), isDirect: false },
|
|
806
|
+
{ base: import_node_path.default.join(apiRoot, "service"), isDirect: false }
|
|
807
|
+
];
|
|
808
|
+
if (apiRoot !== webRoot) {
|
|
809
|
+
baseCandidates.push({ base: apiRoot, isDirect: true });
|
|
810
|
+
}
|
|
811
|
+
for (const { base, isDirect } of baseCandidates) {
|
|
812
|
+
if (!import_node_fs.default.existsSync(base)) continue;
|
|
813
|
+
walk(base, base, isDirect);
|
|
814
|
+
}
|
|
815
|
+
function walk(currentDir, baseDir, isDirect) {
|
|
816
|
+
let entries = [];
|
|
817
|
+
try {
|
|
818
|
+
entries = import_node_fs.default.readdirSync(currentDir, { withFileTypes: true });
|
|
819
|
+
} catch {
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
for (const entry of entries) {
|
|
823
|
+
const name = entry.name;
|
|
824
|
+
if (name.startsWith(".") || name.startsWith("_")) continue;
|
|
825
|
+
if (name === "node_modules" || name === "dist" || name === ".soma" || name === ".next") continue;
|
|
826
|
+
const fullPath = import_node_path.default.join(currentDir, name);
|
|
827
|
+
if (entry.isDirectory()) {
|
|
828
|
+
walk(fullPath, baseDir, isDirect);
|
|
829
|
+
} else if (entry.isFile()) {
|
|
830
|
+
if (!/\.(?:ts|js|mjs|cjs)$/.test(name)) continue;
|
|
831
|
+
if (name.endsWith(".d.ts") || name.includes(".test.") || name.includes(".spec.")) continue;
|
|
832
|
+
if (scannedPaths.has(fullPath)) continue;
|
|
833
|
+
scannedPaths.add(fullPath);
|
|
834
|
+
const rel = import_node_path.default.relative(baseDir, fullPath).replace(/\\/g, "/");
|
|
835
|
+
const segments = rel.replace(/\.[^.]+$/, "").split("/");
|
|
836
|
+
const last = segments[segments.length - 1];
|
|
837
|
+
const lowerLast = last.charAt(0).toLowerCase() + last.slice(1);
|
|
838
|
+
segments[segments.length - 1] = lowerLast;
|
|
839
|
+
const routeKey = segments.join("/");
|
|
840
|
+
items.push({ routeKey, filePath: fullPath });
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
return items;
|
|
845
|
+
}
|
|
846
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
847
|
+
0 && (module.exports = {
|
|
848
|
+
buildBrowserClient,
|
|
849
|
+
buildServerAot
|
|
850
|
+
});
|