soma-core 2.2.8 → 2.2.10

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 (98) hide show
  1. package/core/build/compiler/full-manifest-builder.ts +1 -1
  2. package/core/build/compiler/host-config-sync.cjs +1 -1
  3. package/core/build/compiler/soma-manifest-webpack-plugin.js +2 -6
  4. package/core/build/compiler/soma-precompile.js +84 -4
  5. package/core/client/a11y/announcer.ts +2 -16
  6. package/core/client/base/SomaPageRootBase.ts +2 -2
  7. package/core/client/base/defineSomaView.ts +11 -2
  8. package/core/client/base/runtime-services.types.ts +57 -0
  9. package/core/client/data/role-gate.ts +2 -8
  10. package/core/client/engine/event-engine.ts +1 -0
  11. package/core/client/engines/diff/adapter-jsdiff.ts +27 -8
  12. package/core/client/engines/diff/code.ts +205 -0
  13. package/core/client/engines/diff/index.ts +107 -6
  14. package/core/client/engines/diff/items.ts +212 -0
  15. package/core/client/engines/diff/port.ts +215 -3
  16. package/core/client/engines/diff/prose.ts +443 -0
  17. package/core/client/engines/engine-adapters.ts +6 -0
  18. package/core/client/engines/highlight/adapter-lezer.ts +109 -0
  19. package/core/client/engines/highlight/index.ts +135 -0
  20. package/core/client/engines/highlight/port.ts +92 -0
  21. package/core/client/engines/markdown/adapter-markdown-it.ts +65 -0
  22. package/core/client/engines/markdown/blocks.ts +335 -0
  23. package/core/client/engines/markdown/index.ts +51 -0
  24. package/core/client/engines/markdown/port.ts +94 -0
  25. package/core/client/engines/markdown/vendor-modules.d.ts +6 -0
  26. package/core/client/engines/structured/adapter-js-yaml.ts +33 -0
  27. package/core/client/engines/structured/index.ts +139 -0
  28. package/core/client/engines/structured/port.ts +59 -0
  29. package/core/client/infra/http/SomaHttpService.ts +2 -4
  30. package/core/client/infra/notify/DefaultNotifyService.ts +2 -3
  31. package/core/client/infra/permission/SomaPermission.ts +1 -1
  32. package/core/client/render-ports/notify-renderer.ts +2 -46
  33. package/core/client/runtime/SomaRuntimeServices.ts +16 -45
  34. package/core/server/host/app-config-composer.ts +6 -52
  35. package/core/server/host/host-config-paths.cjs +2 -100
  36. package/core/server/host/precompiled-manifest.ts +69 -0
  37. package/core/server/host/source-packages.cjs +3 -0
  38. package/core/server/infra/host-config-paths.cjs +100 -0
  39. package/core/server/page-assets.ts +2 -70
  40. package/core/server/runtime-space/bindings.ts +33 -4
  41. package/core/server/runtime-space/store.ts +16 -1
  42. package/core/shared/app-config-merge.ts +59 -0
  43. package/core/shared/registry-generated/limits.ts +84 -4
  44. package/core/shared/types/announcer.types.ts +18 -0
  45. package/core/shared/types/notify.types.ts +26 -0
  46. package/core/shared/types/role-gate.types.ts +11 -0
  47. package/dist/browser/runtime-bundle.manifest.json +51 -7
  48. package/dist/browser/soma-runtime.js +120952 -104762
  49. package/dist/core/index.cjs +113613 -97412
  50. package/dist/host-native/aot-builder.cjs +582 -371
  51. package/dist/host-native/native-server.cjs +203 -72
  52. package/dist/lsp/component-tree.cjs +84 -4
  53. package/dist/types/build/compiler/full-manifest-builder.d.ts +1 -1
  54. package/dist/types/client/a11y/announcer.d.ts +2 -14
  55. package/dist/types/client/base/SomaPageRootBase.d.ts +2 -2
  56. package/dist/types/client/base/runtime-services.types.d.ts +50 -0
  57. package/dist/types/client/data/role-gate.d.ts +2 -8
  58. package/dist/types/client/engines/diff/code.d.ts +27 -0
  59. package/dist/types/client/engines/diff/index.d.ts +2 -1
  60. package/dist/types/client/engines/diff/items.d.ts +24 -0
  61. package/dist/types/client/engines/diff/port.d.ts +201 -2
  62. package/dist/types/client/engines/diff/prose.d.ts +80 -0
  63. package/dist/types/client/engines/engine-adapters.d.ts +6 -0
  64. package/dist/types/client/engines/highlight/adapter-lezer.d.ts +6 -0
  65. package/dist/types/client/engines/highlight/index.d.ts +15 -0
  66. package/dist/types/client/engines/highlight/port.d.ts +64 -0
  67. package/dist/types/client/engines/markdown/adapter-markdown-it.d.ts +6 -0
  68. package/dist/types/client/engines/markdown/blocks.d.ts +29 -0
  69. package/dist/types/client/engines/markdown/index.d.ts +9 -0
  70. package/dist/types/client/engines/markdown/port.d.ts +166 -0
  71. package/dist/types/client/engines/structured/adapter-js-yaml.d.ts +6 -0
  72. package/dist/types/client/engines/structured/index.d.ts +29 -0
  73. package/dist/types/client/engines/structured/port.d.ts +45 -0
  74. package/dist/types/client/infra/http/SomaHttpService.d.ts +1 -1
  75. package/dist/types/client/infra/notify/DefaultNotifyService.d.ts +2 -3
  76. package/dist/types/client/infra/permission/SomaPermission.d.ts +1 -1
  77. package/dist/types/client/render-ports/notify-renderer.d.ts +1 -56
  78. package/dist/types/client/runtime/SomaRuntimeServices.d.ts +9 -44
  79. package/dist/types/server/host/app-config-composer.d.ts +2 -3
  80. package/dist/types/server/host/host-config-paths.d.cts +2 -7
  81. package/dist/types/server/host/precompiled-manifest.d.ts +5 -0
  82. package/dist/types/server/host/source-packages.d.cts +5 -0
  83. package/dist/types/server/infra/host-config-paths.d.cts +7 -0
  84. package/dist/types/server/page-assets.d.ts +2 -5
  85. package/dist/types/server/runtime-space/store.d.ts +4 -0
  86. package/dist/types/shared/app-config-merge.d.ts +3 -0
  87. package/dist/types/shared/registry-generated/limits.d.ts +82 -4
  88. package/dist/types/shared/types/announcer.types.d.ts +14 -0
  89. package/dist/types/shared/types/notify.types.d.ts +36 -0
  90. package/dist/types/shared/types/role-gate.types.d.ts +8 -0
  91. package/host-native/src/aot-builder.ts +159 -96
  92. package/host-native/src/dev-chunk-gc.ts +104 -0
  93. package/host-native/src/host-prepare.ts +1 -1
  94. package/host-native/src/manifest-http.ts +1 -1
  95. package/host-native/src/page-http.ts +2 -67
  96. package/host-native/src/page-payload-cache.ts +68 -0
  97. package/host-native/src/public-packages.cjs +147 -50
  98. package/package.json +16 -2
@@ -30,152 +30,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
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-kit"),
127
- path2.join(repoRoot2, "soma-ai")
128
- ];
129
- for (const r of extraRoots) {
130
- if (r) searchRoots.unshift(r);
131
- }
132
- if (hostDir) {
133
- searchRoots.unshift(hostDir);
134
- }
135
- const seenPackages = /* @__PURE__ */ new Set();
136
- for (const searchRoot of searchRoots) {
137
- if (!fs2.existsSync(searchRoot)) continue;
138
- const pkgJsonPath = path2.join(searchRoot, "package.json");
139
- const pkgJson = readJson(pkgJsonPath);
140
- if (pkgJson?.name && pkgJson.name.startsWith("soma-") && !seenPackages.has(pkgJson.name)) {
141
- seenPackages.add(pkgJson.name);
142
- Object.assign(aliases, readPublicPackageAliases(pkgJson.name, searchRoot));
143
- }
144
- const nm = path2.join(searchRoot, "node_modules");
145
- if (fs2.existsSync(nm)) {
146
- try {
147
- for (const entry of fs2.readdirSync(nm, { withFileTypes: true })) {
148
- if (!entry.isDirectory()) continue;
149
- if (entry.name.startsWith("soma-") && !seenPackages.has(entry.name)) {
150
- const pkgPath = path2.join(nm, entry.name);
151
- seenPackages.add(entry.name);
152
- Object.assign(aliases, readPublicPackageAliases(entry.name, pkgPath));
153
- }
154
- }
155
- } catch {
156
- }
157
- }
158
- }
159
- return aliases;
160
- }
161
- module2.exports = {
162
- readJson,
163
- readPublicPackageAliases,
164
- readAllSomaPublicAliases: readAllSomaPublicAliases2
165
- };
166
- }
167
- });
168
-
169
- // core/server/host/host-config-paths.cjs
33
+ // core/server/infra/host-config-paths.cjs
170
34
  var require_host_config_paths = __commonJS({
171
- "core/server/host/host-config-paths.cjs"(exports2, module2) {
35
+ "core/server/infra/host-config-paths.cjs"(exports2, module2) {
172
36
  "use strict";
173
- var fs2 = require("node:fs");
174
- var path2 = require("node:path");
37
+ var fs3 = require("node:fs");
38
+ var path3 = require("node:path");
175
39
  function readJson(filePath) {
176
40
  try {
177
- if (!fs2.existsSync(filePath)) return null;
178
- return JSON.parse(fs2.readFileSync(filePath, "utf8"));
41
+ if (!fs3.existsSync(filePath)) return null;
42
+ return JSON.parse(fs3.readFileSync(filePath, "utf8"));
179
43
  } catch {
180
44
  return null;
181
45
  }
@@ -183,10 +47,10 @@ var require_host_config_paths = __commonJS({
183
47
  function resolveSafeChildRoot(parent, relativePath, options = {}) {
184
48
  const trimmed = typeof relativePath === "string" ? relativePath.trim() : "";
185
49
  if (!trimmed) return parent;
186
- const resolved = path2.resolve(parent, trimmed);
187
- const normalizedParent = path2.resolve(parent);
188
- if (resolved === normalizedParent || resolved.startsWith(`${normalizedParent}${path2.sep}`)) {
189
- if (options.requireExists && !fs2.existsSync(resolved)) {
50
+ const resolved = path3.resolve(parent, trimmed);
51
+ const normalizedParent = path3.resolve(parent);
52
+ if (resolved === normalizedParent || resolved.startsWith(`${normalizedParent}${path3.sep}`)) {
53
+ if (options.requireExists && !fs3.existsSync(resolved)) {
190
54
  return normalizedParent;
191
55
  }
192
56
  return resolved;
@@ -205,27 +69,27 @@ var require_host_config_paths = __commonJS({
205
69
  return normalizeSomaEnv(env.SOMA_ENV ?? env.APP_ENV ?? env.NODE_ENV);
206
70
  }
207
71
  function resolveHostConfigRoot(hostDir) {
208
- const normalizedHostDir = path2.resolve(hostDir);
209
- const packageJson = readJson(path2.join(normalizedHostDir, "package.json"));
72
+ const normalizedHostDir = path3.resolve(hostDir);
73
+ const packageJson = readJson(path3.join(normalizedHostDir, "package.json"));
210
74
  const configured = packageJson?.soma?.configRoot?.trim();
211
75
  if (configured) {
212
76
  return resolveSafeChildRoot(normalizedHostDir, configured, {
213
- fallback: path2.join(normalizedHostDir, "config")
77
+ fallback: path3.join(normalizedHostDir, "config")
214
78
  });
215
79
  }
216
80
  const hostSourceRoot = resolveSafeChildRoot(normalizedHostDir, packageJson?.soma?.hostRoot, {
217
81
  requireExists: true
218
82
  });
219
83
  const candidates = [
220
- path2.join(normalizedHostDir, "config"),
221
- path2.join(hostSourceRoot, "config")
84
+ path3.join(normalizedHostDir, "config"),
85
+ path3.join(hostSourceRoot, "config")
222
86
  ];
223
87
  for (const candidate of candidates) {
224
- if (fs2.existsSync(candidate)) {
88
+ if (fs3.existsSync(candidate)) {
225
89
  return candidate;
226
90
  }
227
91
  }
228
- return path2.join(hostSourceRoot, "config");
92
+ return path3.join(hostSourceRoot, "config");
229
93
  }
230
94
  function getSomaHostConfigRoot(hostDir) {
231
95
  return resolveHostConfigRoot(hostDir);
@@ -233,11 +97,11 @@ var require_host_config_paths = __commonJS({
233
97
  function resolveAppConfigPath(configRoot, envName) {
234
98
  const env = envName ?? readSomaEnv();
235
99
  const candidates = [
236
- path2.join(configRoot, `app.config.${env}.yaml`),
237
- path2.join(configRoot, "app.config.yaml")
100
+ path3.join(configRoot, `app.config.${env}.yaml`),
101
+ path3.join(configRoot, "app.config.yaml")
238
102
  ];
239
103
  for (const candidate of candidates) {
240
- if (fs2.existsSync(candidate)) {
104
+ if (fs3.existsSync(candidate)) {
241
105
  return candidate;
242
106
  }
243
107
  }
@@ -257,13 +121,21 @@ var require_host_config_paths = __commonJS({
257
121
  }
258
122
  });
259
123
 
124
+ // core/server/host/host-config-paths.cjs
125
+ var require_host_config_paths2 = __commonJS({
126
+ "core/server/host/host-config-paths.cjs"(exports2, module2) {
127
+ "use strict";
128
+ module2.exports = require_host_config_paths();
129
+ }
130
+ });
131
+
260
132
  // core/server/host/source-packages.cjs
261
133
  var require_source_packages = __commonJS({
262
134
  "core/server/host/source-packages.cjs"(exports2, module2) {
263
135
  "use strict";
264
- var fs2 = require("node:fs");
265
- var path2 = require("node:path");
266
- var { getSomaHostConfigRoot } = require_host_config_paths();
136
+ var fs3 = require("node:fs");
137
+ var path3 = require("node:path");
138
+ var { getSomaHostConfigRoot } = require_host_config_paths2();
267
139
  var SOMA_SOURCE_PACKAGES_ENV = "SOMA_SOURCE_PACKAGES";
268
140
  var MAX_ASSET_SOURCE_CACHE = 64;
269
141
  var assetSourcesCache = /* @__PURE__ */ new Map();
@@ -272,21 +144,21 @@ var require_source_packages = __commonJS({
272
144
  }
273
145
  function readJson(filePath) {
274
146
  try {
275
- if (!fs2.existsSync(filePath)) return null;
276
- return JSON.parse(fs2.readFileSync(filePath, "utf8"));
147
+ if (!fs3.existsSync(filePath)) return null;
148
+ return JSON.parse(fs3.readFileSync(filePath, "utf8"));
277
149
  } catch {
278
150
  return null;
279
151
  }
280
152
  }
281
153
  function packagePathInNodeModules(hostDir, packageName) {
282
- return path2.join(hostDir, "node_modules", ...packageName.split("/"));
154
+ return path3.join(hostDir, "node_modules", ...packageName.split("/"));
283
155
  }
284
156
  function resolvePackageRoot(hostDir, packageName, version) {
285
157
  const nodeModulesPath = packagePathInNodeModules(hostDir, packageName);
286
- if (fs2.existsSync(nodeModulesPath)) return nodeModulesPath;
158
+ if (fs3.existsSync(nodeModulesPath)) return nodeModulesPath;
287
159
  if (typeof version === "string" && version.startsWith("file:")) {
288
- const fileRoot = path2.resolve(hostDir, version.slice("file:".length));
289
- if (fs2.existsSync(fileRoot)) return fileRoot;
160
+ const fileRoot = path3.resolve(hostDir, version.slice("file:".length));
161
+ if (fs3.existsSync(fileRoot)) return fileRoot;
290
162
  }
291
163
  return null;
292
164
  }
@@ -294,19 +166,19 @@ var require_source_packages = __commonJS({
294
166
  return String(env?.[SOMA_SOURCE_PACKAGES_ENV] ?? "").split(",").map((item) => item.trim()).filter(Boolean);
295
167
  }
296
168
  function readHostDependencies(hostDir) {
297
- const packageJson = readJson(path2.join(hostDir, "package.json"));
169
+ const packageJson = readJson(path3.join(hostDir, "package.json"));
298
170
  return {
299
171
  ...packageJson?.dependencies ?? {},
300
172
  ...packageJson?.devDependencies ?? {}
301
173
  };
302
174
  }
303
175
  function resolveSafeChildRoot(parent, relativePath) {
304
- const normalizedParent = path2.resolve(parent);
176
+ const normalizedParent = path3.resolve(parent);
305
177
  const trimmed = typeof relativePath === "string" ? relativePath.trim() : "";
306
178
  if (!trimmed) return normalizedParent;
307
- const resolved = path2.resolve(normalizedParent, trimmed);
308
- if (resolved === normalizedParent || resolved.startsWith(`${normalizedParent}${path2.sep}`)) {
309
- return fs2.existsSync(resolved) ? resolved : normalizedParent;
179
+ const resolved = path3.resolve(normalizedParent, trimmed);
180
+ if (resolved === normalizedParent || resolved.startsWith(`${normalizedParent}${path3.sep}`)) {
181
+ return fs3.existsSync(resolved) ? resolved : normalizedParent;
310
182
  }
311
183
  return normalizedParent;
312
184
  }
@@ -314,18 +186,18 @@ var require_source_packages = __commonJS({
314
186
  if (typeof rawPath !== "string") return null;
315
187
  const trimmed = rawPath.trim();
316
188
  if (!trimmed || trimmed.includes("\0")) return null;
317
- const resolved = path2.resolve(baseDir, trimmed);
318
- if (resolved === path2.parse(resolved).root) return null;
319
- if (options.requireExists && !fs2.existsSync(resolved)) return null;
189
+ const resolved = path3.resolve(baseDir, trimmed);
190
+ if (resolved === path3.parse(resolved).root) return null;
191
+ if (options.requireExists && !fs3.existsSync(resolved)) return null;
320
192
  return resolved;
321
193
  }
322
194
  function getSomaHostSourceRoot2(hostDir, env = process.env) {
323
- const normalizedHostDir = path2.resolve(hostDir);
195
+ const normalizedHostDir = path3.resolve(hostDir);
324
196
  if (env && typeof env.SOMA_WEB_DIR === "string" && env.SOMA_WEB_DIR.trim()) {
325
197
  const explicit = resolveExplicitHostPath(normalizedHostDir, env.SOMA_WEB_DIR, { requireExists: false });
326
198
  if (explicit) return explicit;
327
199
  }
328
- const packageJson = readJson(path2.join(normalizedHostDir, "package.json"));
200
+ const packageJson = readJson(path3.join(normalizedHostDir, "package.json"));
329
201
  if (typeof packageJson?.soma?.webRoot === "string" && packageJson.soma.webRoot.trim()) {
330
202
  const explicit = resolveExplicitHostPath(normalizedHostDir, packageJson.soma.webRoot, { requireExists: true });
331
203
  if (explicit) return explicit;
@@ -333,12 +205,12 @@ var require_source_packages = __commonJS({
333
205
  return resolveSafeChildRoot(normalizedHostDir, packageJson?.soma?.hostRoot);
334
206
  }
335
207
  function getSomaHostApiRoot2(hostDir, env = process.env) {
336
- const normalizedHostDir = path2.resolve(hostDir);
208
+ const normalizedHostDir = path3.resolve(hostDir);
337
209
  if (env && typeof env.SOMA_API_DIR === "string" && env.SOMA_API_DIR.trim()) {
338
210
  const explicit = resolveExplicitHostPath(normalizedHostDir, env.SOMA_API_DIR, { requireExists: false });
339
211
  if (explicit) return explicit;
340
212
  }
341
- const packageJson = readJson(path2.join(normalizedHostDir, "package.json"));
213
+ const packageJson = readJson(path3.join(normalizedHostDir, "package.json"));
342
214
  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;
343
215
  if (candidate) {
344
216
  const explicit = resolveExplicitHostPath(normalizedHostDir, candidate, { requireExists: true });
@@ -348,14 +220,14 @@ var require_source_packages = __commonJS({
348
220
  }
349
221
  function isSomaSourcePackage(packageRoot, explicit) {
350
222
  if (explicit) return true;
351
- const packageJson = readJson(path2.join(packageRoot, "package.json"));
223
+ const packageJson = readJson(path3.join(packageRoot, "package.json"));
352
224
  return packageJson?.soma?.source === true;
353
225
  }
354
226
  function toPackageSource(packageName, packageRoot) {
355
- const packageJson = readJson(path2.join(packageRoot, "package.json"));
227
+ const packageJson = readJson(path3.join(packageRoot, "package.json"));
356
228
  const codeRoot = resolveSafeChildRoot(packageRoot, packageJson?.soma?.hostRoot);
357
229
  const configRoot = resolveSafeChildRoot(packageRoot, packageJson?.soma?.configRoot);
358
- const hasRootApiService = fs2.existsSync(path2.join(packageRoot, "api", "service"));
230
+ const hasRootApiService = fs3.existsSync(path3.join(packageRoot, "api", "service"));
359
231
  const apiRoot = hasRootApiService ? packageRoot : codeRoot;
360
232
  return {
361
233
  type: "package",
@@ -368,8 +240,8 @@ var require_source_packages = __commonJS({
368
240
  };
369
241
  }
370
242
  function getSomaAssetSources(hostDir, env = process.env) {
371
- const normalizedHostDir = path2.resolve(hostDir);
372
- const pkgStat = fs2.statSync(path2.join(normalizedHostDir, "package.json"), { throwIfNoEntry: false });
243
+ const normalizedHostDir = path3.resolve(hostDir);
244
+ const pkgStat = fs3.statSync(path3.join(normalizedHostDir, "package.json"), { throwIfNoEntry: false });
373
245
  const pkgStatKey = pkgStat ? `${pkgStat.mtimeMs}:${pkgStat.size}` : "none";
374
246
  const cacheKey = `${normalizedHostDir}\0${env?.[SOMA_SOURCE_PACKAGES_ENV] ?? ""}\0${env?.SOMA_WEB_DIR ?? ""}\0${env?.SOMA_API_DIR ?? ""}\0${pkgStatKey}`;
375
247
  const cached = assetSourcesCache.get(cacheKey);
@@ -412,10 +284,10 @@ var require_source_packages = __commonJS({
412
284
  ];
413
285
  }
414
286
  function collectHtmlFiles(dir, prefix = "", acc = []) {
415
- if (!fs2.existsSync(dir)) return acc;
416
- for (const entry of fs2.readdirSync(dir, { withFileTypes: true })) {
287
+ if (!fs3.existsSync(dir)) return acc;
288
+ for (const entry of fs3.readdirSync(dir, { withFileTypes: true })) {
417
289
  const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
418
- const full = path2.join(dir, entry.name);
290
+ const full = path3.join(dir, entry.name);
419
291
  if (entry.isDirectory()) collectHtmlFiles(full, rel, acc);
420
292
  else if (entry.name.endsWith(".html")) acc.push(rel);
421
293
  }
@@ -424,7 +296,7 @@ var require_source_packages = __commonJS({
424
296
  function collectPageEntries(sources) {
425
297
  const byHtmlFile = /* @__PURE__ */ new Map();
426
298
  for (const source of orderSourcesForOverride(sources)) {
427
- const htmlRoot = path2.join(source.assetRoot, "html");
299
+ const htmlRoot = path3.join(source.assetRoot, "html");
428
300
  for (const htmlFile of collectHtmlFiles(htmlRoot).sort()) {
429
301
  byHtmlFile.set(htmlFile, { source, htmlFile });
430
302
  }
@@ -434,17 +306,20 @@ var require_source_packages = __commonJS({
434
306
  function collectIncludes(sources) {
435
307
  const includes = {};
436
308
  for (const source of orderSourcesForOverride(sources)) {
437
- const sharedDir = path2.join(source.assetRoot, "html", "shared");
438
- if (!fs2.existsSync(sharedDir)) continue;
439
- for (const entry of fs2.readdirSync(sharedDir, { withFileTypes: true })) {
309
+ const sharedDir = path3.join(source.assetRoot, "html", "shared");
310
+ if (!fs3.existsSync(sharedDir)) continue;
311
+ for (const entry of fs3.readdirSync(sharedDir, { withFileTypes: true })) {
440
312
  if (!entry.isFile() || !entry.name.endsWith(".html")) continue;
441
- includes[`shared/${entry.name}`] = fs2.readFileSync(path2.join(sharedDir, entry.name), "utf8");
313
+ includes[`shared/${entry.name}`] = fs3.readFileSync(path3.join(sharedDir, entry.name), "utf8");
442
314
  }
443
315
  }
444
316
  return includes;
445
317
  }
446
318
  module2.exports = {
447
319
  SOMA_SOURCE_PACKAGES_ENV,
320
+ isSomaSourcePackage,
321
+ readExplicitSourcePackages,
322
+ resolvePackageRoot,
448
323
  getSomaHostSourceRoot: getSomaHostSourceRoot2,
449
324
  getSomaHostApiRoot: getSomaHostApiRoot2,
450
325
  resolveSafeChildRoot,
@@ -459,12 +334,225 @@ var require_source_packages = __commonJS({
459
334
  }
460
335
  });
461
336
 
337
+ // host-native/src/public-packages.cjs
338
+ var require_public_packages = __commonJS({
339
+ "host-native/src/public-packages.cjs"(exports2, module2) {
340
+ "use strict";
341
+ var fs3 = require("node:fs");
342
+ var path3 = require("node:path");
343
+ var {
344
+ isSomaSourcePackage,
345
+ readExplicitSourcePackages,
346
+ resolvePackageRoot
347
+ } = require_source_packages();
348
+ function readJson(filePath) {
349
+ try {
350
+ if (!fs3.existsSync(filePath)) return null;
351
+ return JSON.parse(fs3.readFileSync(filePath, "utf8"));
352
+ } catch {
353
+ return null;
354
+ }
355
+ }
356
+ function isSafePackageChild(packageRoot, candidate) {
357
+ return candidate === packageRoot || candidate.startsWith(`${packageRoot}${path3.sep}`);
358
+ }
359
+ function isDirectoryOrSymlinkToDir(baseDir, entry) {
360
+ if (entry.isDirectory()) return true;
361
+ if (!entry.isSymbolicLink()) return false;
362
+ try {
363
+ return fs3.statSync(path3.join(baseDir, entry.name)).isDirectory();
364
+ } catch {
365
+ return false;
366
+ }
367
+ }
368
+ function collectFiles(root) {
369
+ if (!fs3.existsSync(root) || !fs3.statSync(root).isDirectory()) return [];
370
+ const files = [];
371
+ for (const entry of fs3.readdirSync(root, { withFileTypes: true })) {
372
+ const fullPath = path3.join(root, entry.name);
373
+ if (entry.isDirectory()) files.push(...collectFiles(fullPath));
374
+ else if (entry.isFile()) files.push(fullPath);
375
+ }
376
+ return files;
377
+ }
378
+ function isSafeExportWildcardValue(value) {
379
+ return value.length > 0 && !path3.isAbsolute(value) && value.split(/[\\/]/).every((segment) => segment !== "" && segment !== "." && segment !== "..");
380
+ }
381
+ function expandWildcardExportAliases(packageName, packageRoot, entry, target) {
382
+ if ((entry.match(/\*/g) ?? []).length !== 1 || (target.match(/\*/g) ?? []).length !== 1) return {};
383
+ const entryStar = entry.indexOf("*");
384
+ const targetStar = target.indexOf("*");
385
+ const entryPrefix = entry.slice(0, entryStar);
386
+ const entrySuffix = entry.slice(entryStar + 1);
387
+ const targetPrefix = target.slice(0, targetStar);
388
+ const targetSuffix = target.slice(targetStar + 1);
389
+ const sourceRoot = path3.resolve(packageRoot, targetPrefix);
390
+ if (!isSafePackageChild(packageRoot, sourceRoot)) return {};
391
+ const aliases = {};
392
+ for (const filePath of collectFiles(sourceRoot)) {
393
+ const relative = path3.relative(sourceRoot, filePath).split(path3.sep).join("/");
394
+ if (!relative.endsWith(targetSuffix)) continue;
395
+ const wildcardValue = relative.slice(0, relative.length - targetSuffix.length);
396
+ if (!isSafeExportWildcardValue(wildcardValue)) continue;
397
+ const publicPath = `${entryPrefix.slice(2)}${wildcardValue}${entrySuffix}`;
398
+ if (!isSafeExportWildcardValue(publicPath)) continue;
399
+ aliases[`${packageName}/${publicPath}`] = filePath;
400
+ }
401
+ return aliases;
402
+ }
403
+ function readPublicPackageAliases(packageName, packageRoot) {
404
+ const pkgJson = readJson(path3.join(packageRoot, "package.json"));
405
+ const exportsMap = pkgJson?.exports;
406
+ const exactAliases = {};
407
+ const wildcardAliases = {};
408
+ if (exportsMap && typeof exportsMap === "object") {
409
+ for (const [entry, descriptor] of Object.entries(exportsMap)) {
410
+ if (entry !== "." && !entry.startsWith("./")) continue;
411
+ let target = null;
412
+ if (typeof descriptor === "string") {
413
+ target = descriptor;
414
+ } else if (descriptor && typeof descriptor === "object") {
415
+ target = descriptor.import?.default ?? descriptor.import ?? descriptor.default ?? descriptor.require?.default ?? descriptor.require;
416
+ if (typeof target === "object" && target !== null) {
417
+ target = target.default;
418
+ }
419
+ }
420
+ if (typeof target !== "string" || !target.startsWith("./")) continue;
421
+ const isWildcard = entry.includes("*") || target.includes("*");
422
+ if (entry.includes("*") !== target.includes("*")) continue;
423
+ if (isWildcard) {
424
+ Object.assign(
425
+ wildcardAliases,
426
+ expandWildcardExportAliases(packageName, packageRoot, entry, target)
427
+ );
428
+ continue;
429
+ }
430
+ const resolved = path3.resolve(packageRoot, target);
431
+ if (!isSafePackageChild(packageRoot, resolved) || !fs3.existsSync(resolved)) continue;
432
+ const publicPath = entry === "." ? "" : entry.slice(2);
433
+ const specifier = publicPath ? `${packageName}/${publicPath}` : packageName;
434
+ exactAliases[specifier] = resolved;
435
+ }
436
+ } else if (typeof pkgJson?.main === "string" && pkgJson.main.trim()) {
437
+ const resolved = path3.resolve(packageRoot, pkgJson.main.trim());
438
+ if (isSafePackageChild(packageRoot, resolved) && fs3.existsSync(resolved) && fs3.statSync(resolved).isFile()) {
439
+ exactAliases[packageName] = resolved;
440
+ }
441
+ }
442
+ return { ...wildcardAliases, ...exactAliases };
443
+ }
444
+ function readAllSomaPublicAliases2(hostDir, repoRoot2, extraRoots = [], env = process.env) {
445
+ const aliases = {};
446
+ const explicitPackages = new Set(readExplicitSourcePackages(env));
447
+ const searchRoots = [
448
+ repoRoot2,
449
+ path3.join(repoRoot2, "soma-core"),
450
+ path3.join(repoRoot2, "soma-foundation"),
451
+ path3.join(repoRoot2, "soma-ui"),
452
+ path3.join(repoRoot2, "soma-kit"),
453
+ path3.join(repoRoot2, "soma-ai")
454
+ ];
455
+ for (const r of extraRoots) {
456
+ if (r) searchRoots.unshift(r);
457
+ }
458
+ if (hostDir) {
459
+ searchRoots.unshift(hostDir);
460
+ }
461
+ const seenPackages = /* @__PURE__ */ new Set();
462
+ const seenNodeModules = /* @__PURE__ */ new Set();
463
+ const shouldIncludePackage = (pkgName, pkgRoot) => Boolean(pkgName) && (pkgName.startsWith("soma-") || isSomaSourcePackage(pkgRoot, explicitPackages.has(pkgName)));
464
+ const registerPackage = (pkgName, pkgRoot) => {
465
+ if (!pkgName || seenPackages.has(pkgName) || !fs3.existsSync(pkgRoot)) return;
466
+ if (!shouldIncludePackage(pkgName, pkgRoot)) return;
467
+ seenPackages.add(pkgName);
468
+ Object.assign(aliases, readPublicPackageAliases(pkgName, pkgRoot));
469
+ const nestedNm = path3.join(pkgRoot, "node_modules");
470
+ if (fs3.existsSync(nestedNm)) scanNodeModules(nestedNm);
471
+ };
472
+ const scanNodeModules = (nmDir) => {
473
+ let realNm = path3.resolve(nmDir);
474
+ try {
475
+ realNm = fs3.realpathSync(nmDir);
476
+ } catch {
477
+ }
478
+ if (seenNodeModules.has(realNm)) return;
479
+ seenNodeModules.add(realNm);
480
+ let entries = [];
481
+ try {
482
+ entries = fs3.readdirSync(nmDir, { withFileTypes: true });
483
+ } catch {
484
+ return;
485
+ }
486
+ for (const entry of entries) {
487
+ if (entry.name.startsWith(".")) continue;
488
+ if (!isDirectoryOrSymlinkToDir(nmDir, entry)) continue;
489
+ const entryPath = path3.join(nmDir, entry.name);
490
+ if (entry.name.startsWith("@")) {
491
+ let scopedEntries = [];
492
+ try {
493
+ scopedEntries = fs3.readdirSync(entryPath, { withFileTypes: true });
494
+ } catch {
495
+ scopedEntries = [];
496
+ }
497
+ for (const scoped of scopedEntries) {
498
+ if (scoped.name.startsWith(".")) continue;
499
+ if (!isDirectoryOrSymlinkToDir(entryPath, scoped)) continue;
500
+ registerPackage(`${entry.name}/${scoped.name}`, path3.join(entryPath, scoped.name));
501
+ }
502
+ } else {
503
+ registerPackage(entry.name, entryPath);
504
+ }
505
+ }
506
+ };
507
+ for (const searchRoot of searchRoots) {
508
+ if (!searchRoot || !fs3.existsSync(searchRoot)) continue;
509
+ const pkgJsonPath = path3.join(searchRoot, "package.json");
510
+ const pkgJson = readJson(pkgJsonPath);
511
+ if (pkgJson?.name) {
512
+ registerPackage(pkgJson.name, searchRoot);
513
+ }
514
+ const deps = {
515
+ ...pkgJson?.dependencies ?? {},
516
+ ...pkgJson?.devDependencies ?? {}
517
+ };
518
+ const depNames = /* @__PURE__ */ new Set([...Object.keys(deps), ...explicitPackages]);
519
+ for (const depName of depNames) {
520
+ if (seenPackages.has(depName)) continue;
521
+ const depRoot = resolvePackageRoot(searchRoot, depName, deps[depName]);
522
+ if (depRoot) registerPackage(depName, depRoot);
523
+ }
524
+ const nm = path3.join(searchRoot, "node_modules");
525
+ if (fs3.existsSync(nm)) {
526
+ scanNodeModules(nm);
527
+ }
528
+ }
529
+ return aliases;
530
+ }
531
+ function createPublicAliasesFilter2(aliases) {
532
+ const roots = /* @__PURE__ */ new Set();
533
+ for (const spec of Object.keys(aliases || {})) {
534
+ const root = spec.startsWith("@") ? spec.split("/").slice(0, 2).join("/") : spec.split("/")[0];
535
+ if (root) roots.add(root);
536
+ }
537
+ if (roots.size === 0) return null;
538
+ const escaped = [...roots].sort().map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
539
+ return new RegExp(`^(?:${escaped.join("|")})(?:/.*)?$`);
540
+ }
541
+ module2.exports = {
542
+ readJson,
543
+ readPublicPackageAliases,
544
+ readAllSomaPublicAliases: readAllSomaPublicAliases2,
545
+ createPublicAliasesFilter: createPublicAliasesFilter2
546
+ };
547
+ }
548
+ });
549
+
462
550
  // core/server/host/source-aliases.cjs
463
551
  var require_source_aliases = __commonJS({
464
552
  "core/server/host/source-aliases.cjs"(exports2, module2) {
465
553
  "use strict";
466
- var fs2 = require("node:fs");
467
- var path2 = require("node:path");
554
+ var fs3 = require("node:fs");
555
+ var path3 = require("node:path");
468
556
  var nodeModule = require("node:module");
469
557
  var { getSomaHostApiRoot: getSomaHostApiRoot2, getSomaHostSourceRoot: getSomaHostSourceRoot2, resolveSafeChildRoot } = require_source_packages();
470
558
  var CODE_INVALID = "CORE-HOST-ALIAS-INVALID";
@@ -486,8 +574,8 @@ var require_source_aliases = __commonJS({
486
574
  }
487
575
  function readJson(filePath) {
488
576
  try {
489
- if (!fs2.existsSync(filePath)) return null;
490
- return JSON.parse(fs2.readFileSync(filePath, "utf8"));
577
+ if (!fs3.existsSync(filePath)) return null;
578
+ return JSON.parse(fs3.readFileSync(filePath, "utf8"));
491
579
  } catch {
492
580
  return null;
493
581
  }
@@ -495,7 +583,7 @@ var require_source_aliases = __commonJS({
495
583
  function readTsconfig(filePath) {
496
584
  let raw;
497
585
  try {
498
- raw = fs2.readFileSync(filePath, "utf8");
586
+ raw = fs3.readFileSync(filePath, "utf8");
499
587
  } catch {
500
588
  return null;
501
589
  }
@@ -514,26 +602,26 @@ var require_source_aliases = __commonJS({
514
602
  }
515
603
  function realInside(parent, child) {
516
604
  try {
517
- const p = fs2.realpathSync(parent);
518
- const c = fs2.realpathSync(child);
519
- return c === p || c.startsWith(`${p}${path2.sep}`);
605
+ const p = fs3.realpathSync(parent);
606
+ const c = fs3.realpathSync(child);
607
+ return c === p || c.startsWith(`${p}${path3.sep}`);
520
608
  } catch {
521
609
  return false;
522
610
  }
523
611
  }
524
612
  function resolveSomaSourceRoots(hostDir, env = process.env) {
525
- let normalizedHostDir = path2.resolve(hostDir);
526
- if (!fs2.existsSync(path2.join(normalizedHostDir, "package.json"))) {
527
- for (let dir = path2.dirname(normalizedHostDir); ; dir = path2.dirname(dir)) {
528
- if (fs2.existsSync(path2.join(dir, "package.json"))) {
613
+ let normalizedHostDir = path3.resolve(hostDir);
614
+ if (!fs3.existsSync(path3.join(normalizedHostDir, "package.json"))) {
615
+ for (let dir = path3.dirname(normalizedHostDir); ; dir = path3.dirname(dir)) {
616
+ if (fs3.existsSync(path3.join(dir, "package.json"))) {
529
617
  normalizedHostDir = dir;
530
618
  break;
531
619
  }
532
- if (path2.dirname(dir) === dir) break;
620
+ if (path3.dirname(dir) === dir) break;
533
621
  }
534
622
  }
535
- const packageJsonPath = path2.join(normalizedHostDir, "package.json");
536
- const stat = fs2.statSync(packageJsonPath, { throwIfNoEntry: false });
623
+ const packageJsonPath = path3.join(normalizedHostDir, "package.json");
624
+ const stat = fs3.statSync(packageJsonPath, { throwIfNoEntry: false });
537
625
  const cacheKey = `${normalizedHostDir}\0${env?.SOMA_API_DIR ?? ""}\0${env?.SOMA_WEB_DIR ?? ""}\0${stat ? `${stat.mtimeMs}:${stat.size}` : "none"}`;
538
626
  const cached = resolveCache.get(cacheKey);
539
627
  if (cached) return cached;
@@ -554,14 +642,14 @@ var require_source_aliases = __commonJS({
554
642
  if (firstRoot === null) firstRoot = rootDir;
555
643
  let children;
556
644
  try {
557
- children = fs2.readdirSync(rootDir, { withFileTypes: true });
645
+ children = fs3.readdirSync(rootDir, { withFileTypes: true });
558
646
  } catch {
559
647
  invalid(`\u7684\u6E90\u7801\u6839\u4E0D\u53EF\u8BFB\uFF1A${rootDir}`);
560
648
  return;
561
649
  }
562
650
  for (const entry of children.sort((a, b) => a.name.localeCompare(b.name))) {
563
- const full = path2.join(rootDir, entry.name);
564
- const isDir = entry.isDirectory() || entry.isSymbolicLink() && fs2.statSync(full, { throwIfNoEntry: false })?.isDirectory();
651
+ const full = path3.join(rootDir, entry.name);
652
+ const isDir = entry.isDirectory() || entry.isSymbolicLink() && fs3.statSync(full, { throwIfNoEntry: false })?.isDirectory();
565
653
  if (!isDir || entry.name.startsWith(".") || entry.name === "node_modules" || !ALIAS_NAME_RE.test(entry.name)) continue;
566
654
  candidates.push({ name: entry.name, dir: full });
567
655
  }
@@ -571,9 +659,9 @@ var require_source_aliases = __commonJS({
571
659
  invalid("\u7684\u8DEF\u5F84\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32");
572
660
  return null;
573
661
  }
574
- const resolved = path2.resolve(hostDir, rel.trim());
662
+ const resolved = path3.resolve(hostDir, rel.trim());
575
663
  const safe = resolveSafeChildRoot(hostDir, rel);
576
- if (safe !== resolved || !fs2.existsSync(safe) || !fs2.statSync(safe).isDirectory() || !realInside(hostDir, safe)) {
664
+ if (safe !== resolved || !fs3.existsSync(safe) || !fs3.statSync(safe).isDirectory() || !realInside(hostDir, safe)) {
577
665
  invalid(`\u7684\u8DEF\u5F84 "${rel}" \u5FC5\u987B\u662F\u5BBF\u4E3B\u76EE\u5F55\u5185\u5DF2\u5B58\u5728\u7684\u76EE\u5F55`);
578
666
  return null;
579
667
  }
@@ -626,12 +714,12 @@ var require_source_aliases = __commonJS({
626
714
  entries.push(candidate);
627
715
  }
628
716
  for (const { name, dir } of entries) {
629
- const installed = path2.join(hostDir, "node_modules", name);
630
- const installedStat = fs2.lstatSync(installed, { throwIfNoEntry: false });
717
+ const installed = path3.join(hostDir, "node_modules", name);
718
+ const installedStat = fs3.lstatSync(installed, { throwIfNoEntry: false });
631
719
  if (!installedStat) continue;
632
720
  let same = false;
633
721
  try {
634
- same = fs2.realpathSync(installed) === fs2.realpathSync(dir);
722
+ same = fs3.realpathSync(installed) === fs3.realpathSync(dir);
635
723
  } catch {
636
724
  same = false;
637
725
  }
@@ -645,13 +733,13 @@ var require_source_aliases = __commonJS({
645
733
  }
646
734
  }
647
735
  if (firstRoot !== null) {
648
- const tsconfig = readTsconfig(path2.join(hostDir, "tsconfig.json"));
736
+ const tsconfig = readTsconfig(path3.join(hostDir, "tsconfig.json"));
649
737
  const baseUrl = tsconfig?.compilerOptions?.baseUrl;
650
- if (typeof baseUrl === "string" && path2.resolve(hostDir, baseUrl) !== path2.resolve(firstRoot)) {
738
+ if (typeof baseUrl === "string" && path3.resolve(hostDir, baseUrl) !== path3.resolve(firstRoot)) {
651
739
  diagnostics.push({
652
740
  code: CODE_TSCONFIG_DRIFT,
653
741
  severity: "warning",
654
- message: `tsconfig.json \u7684 baseUrl\uFF08${baseUrl}\uFF09\u4E0E soma.sourceRoots \u7684\u6E90\u7801\u6839\uFF08${path2.relative(hostDir, firstRoot) || "."}\uFF09\u4E0D\u4E00\u81F4\uFF1A\u7F16\u8F91\u5668\u4E0E\u8FD0\u884C\u671F\u4F1A\u89E3\u6790\u5230\u4E0D\u540C\u76EE\u5F55`
742
+ message: `tsconfig.json \u7684 baseUrl\uFF08${baseUrl}\uFF09\u4E0E soma.sourceRoots \u7684\u6E90\u7801\u6839\uFF08${path3.relative(hostDir, firstRoot) || "."}\uFF09\u4E0D\u4E00\u81F4\uFF1A\u7F16\u8F91\u5668\u4E0E\u8FD0\u884C\u671F\u4F1A\u89E3\u6790\u5230\u4E0D\u540C\u76EE\u5F55`
655
743
  });
656
744
  }
657
745
  }
@@ -672,7 +760,7 @@ var require_source_aliases = __commonJS({
672
760
  throw error;
673
761
  }
674
762
  for (const d of resolved.diagnostics) {
675
- const key = `${path2.resolve(hostDir)}\0${d.code}\0${d.name ?? ""}\0${d.message}`;
763
+ const key = `${path3.resolve(hostDir)}\0${d.code}\0${d.name ?? ""}\0${d.message}`;
676
764
  if (warned.has(key)) continue;
677
765
  warned.add(key);
678
766
  console.warn(`[soma-core][\u5F15\u64CE] ${d.code} ${d.message}`);
@@ -696,18 +784,18 @@ var require_source_aliases = __commonJS({
696
784
  function somaViteAliases(hostDir, env = process.env) {
697
785
  return Object.entries(getSomaSourceRootAliases2(hostDir, env)).map(([name, dir]) => ({
698
786
  find: new RegExp(`^${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/`),
699
- replacement: `${dir.split(path2.sep).join("/")}/`
787
+ replacement: `${dir.split(path3.sep).join("/")}/`
700
788
  }));
701
789
  }
702
790
  var HOST_BOOTSTRAP_SPECIFIER = "@soma-host/bootstrap/soma-bootstrap";
703
791
  var HOST_BOOTSTRAP_CANDIDATES = ["soma-bootstrap.ts", "soma-bootstrap.js", "soma-bootstrap.mjs"];
704
792
  function somaViteHostAliases(hostDir, env = process.env) {
705
- const sourceRoot = getSomaHostSourceRoot2(path2.resolve(hostDir), env);
706
- const found = HOST_BOOTSTRAP_CANDIDATES.map((name) => path2.join(sourceRoot, "bootstrap", name)).find((file) => fs2.existsSync(file));
707
- const target = found ?? path2.join(__dirname, "empty-host-bootstrap.mjs");
793
+ const sourceRoot = getSomaHostSourceRoot2(path3.resolve(hostDir), env);
794
+ const found = HOST_BOOTSTRAP_CANDIDATES.map((name) => path3.join(sourceRoot, "bootstrap", name)).find((file) => fs3.existsSync(file));
795
+ const target = found ?? path3.join(__dirname, "empty-host-bootstrap.mjs");
708
796
  return [
709
797
  ...somaViteAliases(hostDir, env),
710
- { find: new RegExp(`^${HOST_BOOTSTRAP_SPECIFIER}$`), replacement: target.split(path2.sep).join("/") }
798
+ { find: new RegExp(`^${HOST_BOOTSTRAP_SPECIFIER}$`), replacement: target.split(path3.sep).join("/") }
711
799
  ];
712
800
  }
713
801
  module2.exports = {
@@ -734,12 +822,88 @@ __export(aot_builder_exports, {
734
822
  buildServerAot: () => buildServerAot
735
823
  });
736
824
  module.exports = __toCommonJS(aot_builder_exports);
737
- var import_node_fs = __toESM(require("node:fs"));
738
- var import_node_path = __toESM(require("node:path"));
825
+ var import_node_fs2 = __toESM(require("node:fs"));
826
+ var import_node_path2 = __toESM(require("node:path"));
739
827
  var import_node_crypto = require("node:crypto");
740
828
  var import_esbuild = __toESM(require("esbuild"));
741
829
  var import_public_packages = __toESM(require_public_packages());
742
830
 
831
+ // host-native/src/dev-chunk-gc.ts
832
+ var import_node_fs = __toESM(require("node:fs"));
833
+ var import_node_path = __toESM(require("node:path"));
834
+ var LIVE_DIR = ".live";
835
+ var CHUNKS_DIR = "chunks";
836
+ function isAlive(pid) {
837
+ if (!Number.isInteger(pid) || pid <= 0) return false;
838
+ if (pid === process.pid) return true;
839
+ try {
840
+ process.kill(pid, 0);
841
+ return true;
842
+ } catch (error) {
843
+ return error.code === "EPERM";
844
+ }
845
+ }
846
+ function readLiveSet(file) {
847
+ try {
848
+ const parsed = JSON.parse(import_node_fs.default.readFileSync(file, "utf8"));
849
+ return Array.isArray(parsed) ? parsed.filter((v) => typeof v === "string") : [];
850
+ } catch {
851
+ return [];
852
+ }
853
+ }
854
+ function outputsRelativeTo(clientOutDir, outputs) {
855
+ const rel = [];
856
+ for (const out of outputs) {
857
+ const abs = import_node_path.default.resolve(out);
858
+ const r = import_node_path.default.relative(clientOutDir, abs);
859
+ if (r === "" || r.startsWith("..") || import_node_path.default.isAbsolute(r)) continue;
860
+ rel.push(r.split(import_node_path.default.sep).join("/"));
861
+ }
862
+ return rel;
863
+ }
864
+ function collectDevChunks(clientOutDir, ownOutputs) {
865
+ let removed = 0;
866
+ try {
867
+ const liveDir = import_node_path.default.join(clientOutDir, LIVE_DIR);
868
+ import_node_fs.default.mkdirSync(liveDir, { recursive: true });
869
+ import_node_fs.default.writeFileSync(import_node_path.default.join(liveDir, `${process.pid}.json`), JSON.stringify(ownOutputs), "utf8");
870
+ const keep = new Set(ownOutputs);
871
+ for (const name of import_node_fs.default.readdirSync(liveDir)) {
872
+ if (!name.endsWith(".json")) continue;
873
+ const pid = Number(name.slice(0, -".json".length));
874
+ const file = import_node_path.default.join(liveDir, name);
875
+ if (pid === process.pid) continue;
876
+ if (!isAlive(pid)) {
877
+ import_node_fs.default.rmSync(file, { force: true });
878
+ continue;
879
+ }
880
+ for (const rel of readLiveSet(file)) keep.add(rel);
881
+ }
882
+ const chunksDir = import_node_path.default.join(clientOutDir, CHUNKS_DIR);
883
+ if (!import_node_fs.default.existsSync(chunksDir)) return { removed };
884
+ for (const name of import_node_fs.default.readdirSync(chunksDir)) {
885
+ const rel = `${CHUNKS_DIR}/${name}`;
886
+ if (keep.has(rel)) continue;
887
+ const abs = import_node_path.default.join(chunksDir, name);
888
+ try {
889
+ if (import_node_fs.default.statSync(abs).isFile()) {
890
+ import_node_fs.default.rmSync(abs, { force: true });
891
+ removed += 1;
892
+ }
893
+ } catch {
894
+ }
895
+ }
896
+ } catch {
897
+ }
898
+ return { removed };
899
+ }
900
+ function releaseDevChunks(clientOutDir) {
901
+ try {
902
+ import_node_fs.default.rmSync(import_node_path.default.join(clientOutDir, LIVE_DIR, `${process.pid}.json`), { force: true });
903
+ } catch {
904
+ }
905
+ }
906
+
743
907
  // core/server/api/service-path.ts
744
908
  function toPascalCase(str) {
745
909
  return str.split(/[-_]/).map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join("");
@@ -752,7 +916,7 @@ function registerSourceRootResolve(build, hostDir, env) {
752
916
  const aliases = (0, import_source_aliases.getSomaSourceRootAliases)(hostDir, env);
753
917
  const filter = (0, import_source_aliases.somaSourceRootFilter)(aliases);
754
918
  if (!filter) return;
755
- const nodeModulesSegment = `${import_node_path.default.sep}node_modules${import_node_path.default.sep}`;
919
+ const nodeModulesSegment = `${import_node_path2.default.sep}node_modules${import_node_path2.default.sep}`;
756
920
  build.onResolve({ filter }, (args) => {
757
921
  if (args.importer.includes(nodeModulesSegment)) return void 0;
758
922
  const hit = (0, import_source_aliases.matchSomaSourceRoot)(aliases, args.path);
@@ -761,29 +925,30 @@ function registerSourceRootResolve(build, hostDir, env) {
761
925
  });
762
926
  }
763
927
  function resolveModuleFile(baseDir, subpath) {
764
- const target = subpath ? import_node_path.default.resolve(baseDir, subpath) : import_node_path.default.resolve(baseDir);
928
+ const target = subpath ? import_node_path2.default.resolve(baseDir, subpath) : import_node_path2.default.resolve(baseDir);
765
929
  for (const ext of ["", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"]) {
766
930
  const candidate = target + ext;
767
- if (import_node_fs.default.existsSync(candidate) && import_node_fs.default.statSync(candidate).isFile()) {
931
+ if (import_node_fs2.default.existsSync(candidate) && import_node_fs2.default.statSync(candidate).isFile()) {
768
932
  return candidate;
769
933
  }
770
934
  }
771
- if (import_node_fs.default.existsSync(target) && import_node_fs.default.statSync(target).isDirectory()) {
935
+ if (import_node_fs2.default.existsSync(target) && import_node_fs2.default.statSync(target).isDirectory()) {
772
936
  for (const index of ["index.ts", "index.tsx", "index.js", "index.mjs", "index.cjs"]) {
773
- const candidate = import_node_path.default.join(target, index);
774
- if (import_node_fs.default.existsSync(candidate) && import_node_fs.default.statSync(candidate).isFile()) {
937
+ const candidate = import_node_path2.default.join(target, index);
938
+ if (import_node_fs2.default.existsSync(candidate) && import_node_fs2.default.statSync(candidate).isFile()) {
775
939
  return candidate;
776
940
  }
777
941
  }
778
942
  }
779
943
  return target;
780
944
  }
781
- var coreRoot = import_node_path.default.resolve(__dirname, "../..");
782
- var hostNativeRoot = import_node_path.default.join(coreRoot, "host-native");
783
- var repoRoot = import_node_path.default.resolve(coreRoot, "..");
945
+ var coreRoot = import_node_path2.default.resolve(__dirname, "../..");
946
+ var hostNativeRoot = import_node_path2.default.join(coreRoot, "host-native");
947
+ var repoRoot = import_node_path2.default.resolve(coreRoot, "..");
784
948
  function createBrowserClientPlugin(options) {
785
- const { hostDir, webRoot } = options;
786
- const publicAliases = (0, import_public_packages.readAllSomaPublicAliases)(hostDir, repoRoot, [webRoot, coreRoot]);
949
+ const { hostDir, webRoot, env } = options;
950
+ const publicAliases = (0, import_public_packages.readAllSomaPublicAliases)(hostDir, repoRoot, [webRoot, coreRoot], env);
951
+ const publicFilter = (0, import_public_packages.createPublicAliasesFilter)(publicAliases);
787
952
  return {
788
953
  name: "soma-browser-client-plugin",
789
954
  setup(build) {
@@ -793,30 +958,30 @@ function createBrowserClientPlugin(options) {
793
958
  );
794
959
  });
795
960
  build.onResolve({ filter: /^@soma-host\/bootstrap\/soma-bootstrap$/ }, () => {
796
- const candidateHostFile = import_node_path.default.resolve(webRoot, "bootstrap/soma-bootstrap");
961
+ const candidateHostFile = import_node_path2.default.resolve(webRoot, "bootstrap/soma-bootstrap");
797
962
  for (const ext of [".ts", ".js", ".mjs"]) {
798
- if (import_node_fs.default.existsSync(candidateHostFile + ext)) {
963
+ if (import_node_fs2.default.existsSync(candidateHostFile + ext)) {
799
964
  return { path: candidateHostFile + ext };
800
965
  }
801
966
  }
802
- if (import_node_fs.default.existsSync(import_node_path.default.resolve(webRoot, "soma.app.ts"))) {
803
- return { path: import_node_path.default.resolve(coreRoot, "core/client/host-bridge/soma-bootstrap-from-app.ts") };
967
+ if (import_node_fs2.default.existsSync(import_node_path2.default.resolve(webRoot, "soma.app.ts"))) {
968
+ return { path: import_node_path2.default.resolve(coreRoot, "core/client/host-bridge/soma-bootstrap-from-app.ts") };
804
969
  }
805
- return { path: import_node_path.default.resolve(coreRoot, "core/client/host-bridge/soma-bootstrap-host.stub.ts") };
970
+ return { path: import_node_path2.default.resolve(coreRoot, "core/client/host-bridge/soma-bootstrap-host.stub.ts") };
806
971
  });
807
972
  build.onResolve({ filter: /^@soma-host\/bootstrap\/soma-domain-loaders$/ }, () => {
808
- const candidateLoader = import_node_path.default.resolve(webRoot, "bootstrap/soma-domain-loaders");
973
+ const candidateLoader = import_node_path2.default.resolve(webRoot, "bootstrap/soma-domain-loaders");
809
974
  for (const ext of [".ts", ".js", ".mjs"]) {
810
- if (import_node_fs.default.existsSync(candidateLoader + ext)) {
975
+ if (import_node_fs2.default.existsSync(candidateLoader + ext)) {
811
976
  return { path: candidateLoader + ext };
812
977
  }
813
978
  }
814
- return { path: import_node_path.default.resolve(coreRoot, "core/client/host-bridge/soma-domain-loaders.stub.ts") };
979
+ return { path: import_node_path2.default.resolve(coreRoot, "core/client/host-bridge/soma-domain-loaders.stub.ts") };
815
980
  });
816
981
  build.onResolve({ filter: /^@soma-host\/domain\/ui\/.*Class\.ts$/ }, (args) => {
817
- const baseName = import_node_path.default.basename(args.path);
818
- const diskFile = import_node_path.default.resolve(webRoot, "domain/ui", baseName);
819
- if (import_node_fs.default.existsSync(diskFile)) {
982
+ const baseName = import_node_path2.default.basename(args.path);
983
+ const diskFile = import_node_path2.default.resolve(webRoot, "domain/ui", baseName);
984
+ if (import_node_fs2.default.existsSync(diskFile)) {
820
985
  return { path: diskFile };
821
986
  }
822
987
  return {
@@ -836,22 +1001,22 @@ function createBrowserClientPlugin(options) {
836
1001
  });
837
1002
  build.onResolve({ filter: /^@soma-host(?:\/.*)?$/ }, (args) => {
838
1003
  const subpath = args.path.replace(/^@soma-host\/?/, "");
839
- const target = import_node_path.default.resolve(webRoot, subpath);
1004
+ const target = import_node_path2.default.resolve(webRoot, subpath);
840
1005
  for (const ext of ["", ".ts", ".tsx", ".js", ".jsx", ".mjs"]) {
841
- if (import_node_fs.default.existsSync(target + ext) && import_node_fs.default.statSync(target + ext).isFile()) {
1006
+ if (import_node_fs2.default.existsSync(target + ext) && import_node_fs2.default.statSync(target + ext).isFile()) {
842
1007
  return { path: target + ext };
843
1008
  }
844
1009
  }
845
- if (import_node_fs.default.existsSync(target) && import_node_fs.default.statSync(target).isDirectory()) {
1010
+ if (import_node_fs2.default.existsSync(target) && import_node_fs2.default.statSync(target).isDirectory()) {
846
1011
  for (const index of ["index.ts", "index.tsx", "index.js", "index.jsx"]) {
847
- if (import_node_fs.default.existsSync(import_node_path.default.join(target, index))) {
848
- return { path: import_node_path.default.join(target, index) };
1012
+ if (import_node_fs2.default.existsSync(import_node_path2.default.join(target, index))) {
1013
+ return { path: import_node_path2.default.join(target, index) };
849
1014
  }
850
1015
  }
851
1016
  }
852
1017
  return { path: target };
853
1018
  });
854
- registerSourceRootResolve(build, hostDir);
1019
+ registerSourceRootResolve(build, hostDir, env);
855
1020
  build.onResolve({ filter: /core\/client\/engine\// }, (args) => {
856
1021
  if (!args.importer.includes("soma-core")) {
857
1022
  throw new Error(
@@ -860,13 +1025,15 @@ function createBrowserClientPlugin(options) {
860
1025
  }
861
1026
  return void 0;
862
1027
  });
863
- build.onResolve({ filter: /^soma-[a-z0-9-]+(?:\/.*)?$/ }, (args) => {
864
- const direct = publicAliases[args.path];
865
- if (direct && import_node_fs.default.existsSync(direct)) {
866
- return { path: direct };
867
- }
868
- return void 0;
869
- });
1028
+ if (publicFilter) {
1029
+ build.onResolve({ filter: publicFilter }, (args) => {
1030
+ const direct = publicAliases[args.path];
1031
+ if (direct && import_node_fs2.default.existsSync(direct)) {
1032
+ return { path: direct };
1033
+ }
1034
+ return void 0;
1035
+ });
1036
+ }
870
1037
  build.onResolve({ filter: /^echarts(?:\/.*)?$/ }, async (args) => {
871
1038
  if (args.pluginData?.skipEchartsStub) return void 0;
872
1039
  const resolveOpts = {
@@ -917,17 +1084,17 @@ export default { SVGRenderer, use, init };
917
1084
  };
918
1085
  }
919
1086
  async function buildBrowserClient(options) {
920
- const hostDir = import_node_path.default.resolve(options.hostDir);
921
- const webRoot = import_node_path.default.resolve(options.webRoot || (0, import_source_packages.getSomaHostSourceRoot)(hostDir, options.env));
922
- const outDir = import_node_path.default.resolve(options.outDir);
923
- const clientOutDir = import_node_path.default.join(outDir, "client");
924
- import_node_fs.default.mkdirSync(clientOutDir, { recursive: true });
925
- const clientEntry = import_node_path.default.join(hostNativeRoot, "client/browser-entry.ts");
926
- const plugin = createBrowserClientPlugin({ hostDir, webRoot });
927
- const cssSourcePath = import_node_path.default.join(hostNativeRoot, "styles/globals.css");
1087
+ const hostDir = import_node_path2.default.resolve(options.hostDir);
1088
+ const webRoot = import_node_path2.default.resolve(options.webRoot || (0, import_source_packages.getSomaHostSourceRoot)(hostDir, options.env));
1089
+ const outDir = import_node_path2.default.resolve(options.outDir);
1090
+ const clientOutDir = import_node_path2.default.join(outDir, "client");
1091
+ import_node_fs2.default.mkdirSync(clientOutDir, { recursive: true });
1092
+ const clientEntry = import_node_path2.default.join(hostNativeRoot, "client/browser-entry.ts");
1093
+ const plugin = createBrowserClientPlugin({ hostDir, webRoot, env: options.env });
1094
+ const cssSourcePath = import_node_path2.default.join(hostNativeRoot, "styles/globals.css");
928
1095
  let rawCss = "";
929
1096
  try {
930
- rawCss = import_node_fs.default.readFileSync(cssSourcePath, "utf8");
1097
+ rawCss = import_node_fs2.default.readFileSync(cssSourcePath, "utf8");
931
1098
  } catch {
932
1099
  rawCss = "/* soma globals */\n";
933
1100
  }
@@ -944,7 +1111,7 @@ async function buildBrowserClient(options) {
944
1111
  const hash = (0, import_node_crypto.createHash)("sha256").update(finalCss).digest("hex").slice(0, 8);
945
1112
  cssFileName = `globals-${hash}.css`;
946
1113
  }
947
- import_node_fs.default.writeFileSync(import_node_path.default.join(clientOutDir, cssFileName), finalCss, "utf8");
1114
+ import_node_fs2.default.writeFileSync(import_node_path2.default.join(clientOutDir, cssFileName), finalCss, "utf8");
948
1115
  const cssUrl = `/_soma/client/${cssFileName}`;
949
1116
  const buildOptions = {
950
1117
  entryPoints: {
@@ -960,7 +1127,7 @@ async function buildBrowserClient(options) {
960
1127
  sourcemap: options.dev ? "inline" : false,
961
1128
  entryNames: options.dev ? "[name]" : "[name]-[hash]",
962
1129
  chunkNames: "chunks/[name]-[hash]",
963
- 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)),
1130
+ nodePaths: [import_node_path2.default.join(webRoot, "node_modules"), import_node_path2.default.join(hostDir, "node_modules"), import_node_path2.default.join(coreRoot, "node_modules")].filter((d) => import_node_fs2.default.existsSync(d)),
964
1131
  plugins: [plugin],
965
1132
  define: {
966
1133
  "process.env.NODE_ENV": JSON.stringify(options.dev ? "development" : "production")
@@ -968,9 +1135,14 @@ async function buildBrowserClient(options) {
968
1135
  };
969
1136
  let ctx = null;
970
1137
  let entryUrl = "/_soma/client/browser-entry.js";
1138
+ const devRebuild = async () => {
1139
+ if (!ctx) return;
1140
+ const result = await ctx.rebuild();
1141
+ if (result.metafile) collectDevChunks(clientOutDir, outputsRelativeTo(clientOutDir, Object.keys(result.metafile.outputs)));
1142
+ };
971
1143
  if (options.dev) {
972
- ctx = await import_esbuild.default.context(buildOptions);
973
- await ctx.rebuild();
1144
+ ctx = await import_esbuild.default.context({ ...buildOptions, metafile: true });
1145
+ await devRebuild();
974
1146
  entryUrl = "/_soma/client/browser-entry.js";
975
1147
  } else {
976
1148
  const result = await import_esbuild.default.build({
@@ -979,8 +1151,8 @@ async function buildBrowserClient(options) {
979
1151
  });
980
1152
  if (result.metafile) {
981
1153
  for (const [outputPath, meta] of Object.entries(result.metafile.outputs)) {
982
- if (meta.entryPoint && (meta.entryPoint.endsWith("browser-entry.ts") || import_node_path.default.basename(outputPath).startsWith("browser-entry")) && outputPath.endsWith(".js")) {
983
- const fileName = import_node_path.default.basename(outputPath);
1154
+ if (meta.entryPoint && (meta.entryPoint.endsWith("browser-entry.ts") || import_node_path2.default.basename(outputPath).startsWith("browser-entry")) && outputPath.endsWith(".js")) {
1155
+ const fileName = import_node_path2.default.basename(outputPath);
984
1156
  entryUrl = `/_soma/client/${fileName}`;
985
1157
  break;
986
1158
  }
@@ -988,8 +1160,8 @@ async function buildBrowserClient(options) {
988
1160
  }
989
1161
  }
990
1162
  if (!options.dev) {
991
- import_node_fs.default.writeFileSync(
992
- import_node_path.default.join(clientOutDir, "client-manifest.json"),
1163
+ import_node_fs2.default.writeFileSync(
1164
+ import_node_path2.default.join(clientOutDir, "client-manifest.json"),
993
1165
  JSON.stringify({ entryUrl, cssUrl, cssText: finalCss }, null, 2) + "\n",
994
1166
  "utf8"
995
1167
  );
@@ -999,30 +1171,36 @@ async function buildBrowserClient(options) {
999
1171
  cssUrl,
1000
1172
  cssText: finalCss,
1001
1173
  rebuild: async () => {
1002
- if (ctx) {
1003
- await ctx.rebuild();
1004
- }
1174
+ await devRebuild();
1005
1175
  },
1006
1176
  dispose: async () => {
1007
1177
  if (ctx) {
1008
1178
  await ctx.dispose();
1179
+ releaseDevChunks(clientOutDir);
1009
1180
  }
1010
1181
  }
1011
1182
  };
1012
1183
  }
1184
+ function sharedPackageSlug(specifier) {
1185
+ const safe = specifier.replace(/^@/, "").replace(/[^a-zA-Z0-9_-]+/g, "__").replace(/^_+|_+$/g, "");
1186
+ const hash = (0, import_node_crypto.createHash)("sha256").update(specifier).digest("hex").slice(0, 8);
1187
+ return `${safe || "pkg"}-${hash}`;
1188
+ }
1013
1189
  async function buildServerAot(options) {
1014
- const hostDir = import_node_path.default.resolve(options.hostDir);
1015
- const webRoot = import_node_path.default.resolve(options.webRoot || (0, import_source_packages.getSomaHostSourceRoot)(hostDir, options.env));
1016
- const apiRoot = import_node_path.default.resolve(options.apiRoot || (0, import_source_packages.getSomaHostApiRoot)(hostDir, options.env));
1017
- const outDir = import_node_path.default.resolve(options.outDir);
1018
- const aotServerDir = import_node_path.default.join(outDir, "aot-server");
1019
- import_node_fs.default.mkdirSync(aotServerDir, { recursive: true });
1190
+ const hostDir = import_node_path2.default.resolve(options.hostDir);
1191
+ const webRoot = import_node_path2.default.resolve(options.webRoot || (0, import_source_packages.getSomaHostSourceRoot)(hostDir, options.env));
1192
+ const apiRoot = import_node_path2.default.resolve(options.apiRoot || (0, import_source_packages.getSomaHostApiRoot)(hostDir, options.env));
1193
+ const outDir = import_node_path2.default.resolve(options.outDir);
1194
+ const aotServerDir = import_node_path2.default.join(outDir, "aot-server");
1195
+ const sharedPackagesDir = import_node_path2.default.join(aotServerDir, "_packages");
1196
+ import_node_fs2.default.mkdirSync(aotServerDir, { recursive: true });
1197
+ import_node_fs2.default.rmSync(sharedPackagesDir, { recursive: true, force: true });
1020
1198
  const serviceFiles = scanServiceFiles(apiRoot, webRoot);
1021
- const entryPoints = {};
1199
+ const serviceEntryPoints = {};
1022
1200
  const routes = {};
1023
1201
  for (const item of serviceFiles) {
1024
1202
  const entryName = `services/${item.routeKey.replace(/\//g, "_")}`;
1025
- entryPoints[entryName] = item.filePath;
1203
+ serviceEntryPoints[entryName] = item.filePath;
1026
1204
  routes[item.routeKey] = `${entryName}.cjs`;
1027
1205
  const segments = item.routeKey.split("/");
1028
1206
  const pascalKey = segments.slice(0, -1).concat(toPascalCase(segments[segments.length - 1])).join("/");
@@ -1035,86 +1213,119 @@ async function buildServerAot(options) {
1035
1213
  }
1036
1214
  }
1037
1215
  let hostAppCompiledPath;
1038
- const hostAppPath = import_node_path.default.resolve(webRoot, "soma.app.ts");
1039
- if (import_node_fs.default.existsSync(hostAppPath)) {
1040
- entryPoints["host-app"] = hostAppPath;
1216
+ const hostAppPath = import_node_path2.default.resolve(webRoot, "soma.app.ts");
1217
+ if (import_node_fs2.default.existsSync(hostAppPath)) {
1041
1218
  hostAppCompiledPath = "host-app.cjs";
1042
1219
  }
1043
- if (Object.keys(entryPoints).length > 0) {
1044
- await import_esbuild.default.build({
1045
- entryPoints,
1046
- outdir: aotServerDir,
1047
- bundle: true,
1048
- platform: "node",
1049
- format: "cjs",
1050
- target: "node20",
1051
- packages: "external",
1052
- 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)),
1053
- outExtension: { ".js": ".cjs" },
1054
- plugins: [
1055
- {
1056
- name: "soma-server-aot-plugin",
1057
- setup(build) {
1058
- const publicAliases = (0, import_public_packages.readAllSomaPublicAliases)(hostDir, repoRoot, [webRoot, apiRoot, coreRoot]);
1059
- build.onResolve({ filter: /^server-only$/ }, () => {
1060
- return { path: import_node_path.default.resolve(coreRoot, "core/server/host/server-only-noop.cjs") };
1061
- });
1062
- build.onResolve({ filter: /^@core(?:\/.*)?$/ }, (args) => {
1063
- const subpath = args.path.replace(/^@core\/?/, "");
1064
- return { path: resolveModuleFile(import_node_path.default.resolve(coreRoot, "core"), subpath) };
1065
- });
1066
- build.onResolve({ filter: /^@soma-host\/bootstrap\/soma-bootstrap$/ }, () => {
1067
- const candidateHostFile = import_node_path.default.resolve(webRoot, "bootstrap/soma-bootstrap");
1068
- for (const ext of [".ts", ".js", ".mjs"]) {
1069
- if (import_node_fs.default.existsSync(candidateHostFile + ext)) {
1070
- return { path: candidateHostFile + ext };
1071
- }
1072
- }
1073
- if (import_node_fs.default.existsSync(import_node_path.default.resolve(webRoot, "soma.app.ts"))) {
1074
- return { path: import_node_path.default.resolve(coreRoot, "core/client/host-bridge/soma-bootstrap-from-app.ts") };
1075
- }
1076
- return { path: import_node_path.default.resolve(coreRoot, "core/client/host-bridge/soma-bootstrap-host.stub.ts") };
1077
- });
1078
- build.onResolve({ filter: /^@soma-host\/bootstrap\/soma-domain-loaders$/ }, () => {
1079
- const candidateLoader = import_node_path.default.resolve(webRoot, "bootstrap/soma-domain-loaders");
1080
- for (const ext of [".ts", ".js", ".mjs"]) {
1081
- if (import_node_fs.default.existsSync(candidateLoader + ext)) {
1082
- return { path: candidateLoader + ext };
1083
- }
1084
- }
1085
- return { path: import_node_path.default.resolve(coreRoot, "core/client/host-bridge/soma-domain-loaders.stub.ts") };
1086
- });
1087
- build.onResolve({ filter: /^@soma-host\/domain\/ui\/.*Class\.ts$/ }, (args) => {
1088
- const baseName = import_node_path.default.basename(args.path);
1089
- const diskFile = import_node_path.default.resolve(webRoot, "domain/ui", baseName);
1090
- if (import_node_fs.default.existsSync(diskFile)) {
1091
- return { path: diskFile };
1092
- }
1093
- return { path: args.path, namespace: "soma-absent-domain" };
1094
- });
1095
- build.onLoad({ filter: /.*/, namespace: "soma-absent-domain" }, (args) => ({
1096
- contents: `const err = new Error("Cannot find module '${args.path}'"); err.code = "MODULE_NOT_FOUND"; throw err;`,
1097
- loader: "js"
1098
- }));
1099
- build.onResolve({ filter: /^@soma-host(?:\/.*)?$/ }, (args) => {
1100
- const subpath = args.path.replace(/^@soma-host\/?/, "");
1101
- return { path: resolveModuleFile(webRoot, subpath) };
1102
- });
1103
- registerSourceRootResolve(build, hostDir, options.env);
1104
- build.onResolve({ filter: /^@soma-api(?:\/.*)?$/ }, (args) => {
1105
- const subpath = args.path.replace(/^@soma-api\/?/, "");
1106
- return { path: resolveModuleFile(apiRoot, subpath) };
1107
- });
1108
- build.onResolve({ filter: /^soma-[a-z0-9-]+(?:\/.*)?$/ }, (args) => {
1109
- const direct = publicAliases[args.path];
1110
- if (direct && import_node_fs.default.existsSync(direct)) {
1111
- return { path: direct };
1112
- }
1113
- return void 0;
1114
- });
1220
+ const publicAliases = (0, import_public_packages.readAllSomaPublicAliases)(hostDir, repoRoot, [webRoot, apiRoot, coreRoot], options.env);
1221
+ const publicFilter = (0, import_public_packages.createPublicAliasesFilter)(publicAliases);
1222
+ const sharedEntries = /* @__PURE__ */ new Map();
1223
+ const nodePaths = [
1224
+ import_node_path2.default.join(apiRoot, "node_modules"),
1225
+ import_node_path2.default.join(webRoot, "node_modules"),
1226
+ import_node_path2.default.join(hostDir, "node_modules"),
1227
+ import_node_path2.default.join(coreRoot, "node_modules")
1228
+ ].filter((d) => import_node_fs2.default.existsSync(d));
1229
+ const createServerAotPlugin = (mode) => ({
1230
+ name: "soma-server-aot-plugin",
1231
+ setup(build) {
1232
+ build.onResolve({ filter: /^server-only$/ }, () => {
1233
+ return { path: import_node_path2.default.resolve(coreRoot, "core/server/host/server-only-noop.cjs") };
1234
+ });
1235
+ build.onResolve({ filter: /^@core(?:\/.*)?$/ }, (args) => {
1236
+ const subpath = args.path.replace(/^@core\/?/, "");
1237
+ return { path: resolveModuleFile(import_node_path2.default.resolve(coreRoot, "core"), subpath) };
1238
+ });
1239
+ build.onResolve({ filter: /^@soma-host\/bootstrap\/soma-bootstrap$/ }, () => {
1240
+ const candidateHostFile = import_node_path2.default.resolve(webRoot, "bootstrap/soma-bootstrap");
1241
+ for (const ext of [".ts", ".js", ".mjs"]) {
1242
+ if (import_node_fs2.default.existsSync(candidateHostFile + ext)) {
1243
+ return { path: candidateHostFile + ext };
1115
1244
  }
1116
1245
  }
1117
- ]
1246
+ if (import_node_fs2.default.existsSync(import_node_path2.default.resolve(webRoot, "soma.app.ts"))) {
1247
+ return { path: import_node_path2.default.resolve(coreRoot, "core/client/host-bridge/soma-bootstrap-from-app.ts") };
1248
+ }
1249
+ return { path: import_node_path2.default.resolve(coreRoot, "core/client/host-bridge/soma-bootstrap-host.stub.ts") };
1250
+ });
1251
+ build.onResolve({ filter: /^@soma-host\/bootstrap\/soma-domain-loaders$/ }, () => {
1252
+ const candidateLoader = import_node_path2.default.resolve(webRoot, "bootstrap/soma-domain-loaders");
1253
+ for (const ext of [".ts", ".js", ".mjs"]) {
1254
+ if (import_node_fs2.default.existsSync(candidateLoader + ext)) {
1255
+ return { path: candidateLoader + ext };
1256
+ }
1257
+ }
1258
+ return { path: import_node_path2.default.resolve(coreRoot, "core/client/host-bridge/soma-domain-loaders.stub.ts") };
1259
+ });
1260
+ build.onResolve({ filter: /^@soma-host\/domain\/ui\/.*Class\.ts$/ }, (args) => {
1261
+ const baseName = import_node_path2.default.basename(args.path);
1262
+ const diskFile = import_node_path2.default.resolve(webRoot, "domain/ui", baseName);
1263
+ if (import_node_fs2.default.existsSync(diskFile)) {
1264
+ return { path: diskFile };
1265
+ }
1266
+ return { path: args.path, namespace: "soma-absent-domain" };
1267
+ });
1268
+ build.onLoad({ filter: /.*/, namespace: "soma-absent-domain" }, (args) => ({
1269
+ contents: `const err = new Error("Cannot find module '${args.path}'"); err.code = "MODULE_NOT_FOUND"; throw err;`,
1270
+ loader: "js"
1271
+ }));
1272
+ build.onResolve({ filter: /^@soma-host(?:\/.*)?$/ }, (args) => {
1273
+ const subpath = args.path.replace(/^@soma-host\/?/, "");
1274
+ return { path: resolveModuleFile(webRoot, subpath) };
1275
+ });
1276
+ registerSourceRootResolve(build, hostDir, options.env);
1277
+ build.onResolve({ filter: /^@soma-api(?:\/.*)?$/ }, (args) => {
1278
+ const subpath = args.path.replace(/^@soma-api\/?/, "");
1279
+ return { path: resolveModuleFile(apiRoot, subpath) };
1280
+ });
1281
+ if (publicFilter) {
1282
+ build.onResolve({ filter: publicFilter }, (args) => {
1283
+ const direct = publicAliases[args.path];
1284
+ if (!direct || !import_node_fs2.default.existsSync(direct)) {
1285
+ return void 0;
1286
+ }
1287
+ if ("inlinePublic" in mode) {
1288
+ return { path: direct };
1289
+ }
1290
+ const slug = sharedPackageSlug(args.path);
1291
+ sharedEntries.set(slug, direct);
1292
+ return { path: `${mode.sharedOutPrefix}_packages/${slug}.cjs`, external: true };
1293
+ });
1294
+ }
1295
+ }
1296
+ });
1297
+ const baseServerBuildOptions = {
1298
+ bundle: true,
1299
+ platform: "node",
1300
+ format: "cjs",
1301
+ target: "node20",
1302
+ packages: "external",
1303
+ nodePaths,
1304
+ outExtension: { ".js": ".cjs" }
1305
+ };
1306
+ if (Object.keys(serviceEntryPoints).length > 0) {
1307
+ await import_esbuild.default.build({
1308
+ ...baseServerBuildOptions,
1309
+ entryPoints: serviceEntryPoints,
1310
+ outdir: aotServerDir,
1311
+ plugins: [createServerAotPlugin({ sharedOutPrefix: "../" })]
1312
+ });
1313
+ }
1314
+ if (hostAppCompiledPath) {
1315
+ await import_esbuild.default.build({
1316
+ ...baseServerBuildOptions,
1317
+ entryPoints: { "host-app": hostAppPath },
1318
+ outdir: aotServerDir,
1319
+ plugins: [createServerAotPlugin({ sharedOutPrefix: "./" })]
1320
+ });
1321
+ }
1322
+ if (sharedEntries.size > 0) {
1323
+ import_node_fs2.default.mkdirSync(sharedPackagesDir, { recursive: true });
1324
+ await import_esbuild.default.build({
1325
+ ...baseServerBuildOptions,
1326
+ entryPoints: Object.fromEntries(sharedEntries),
1327
+ outdir: sharedPackagesDir,
1328
+ plugins: [createServerAotPlugin({ inlinePublic: true })]
1118
1329
  });
1119
1330
  }
1120
1331
  const manifest = {
@@ -1125,29 +1336,29 @@ async function buildServerAot(options) {
1125
1336
  routes,
1126
1337
  ...hostAppCompiledPath ? { hostAppCompiledPath } : {}
1127
1338
  };
1128
- const manifestPath = import_node_path.default.join(aotServerDir, "aot-manifest.json");
1129
- import_node_fs.default.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + "\n", "utf8");
1339
+ const manifestPath = import_node_path2.default.join(aotServerDir, "aot-manifest.json");
1340
+ import_node_fs2.default.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + "\n", "utf8");
1130
1341
  return manifest;
1131
1342
  }
1132
1343
  function scanServiceFiles(apiRoot, webRoot) {
1133
1344
  const items = [];
1134
1345
  const scannedPaths = /* @__PURE__ */ new Set();
1135
1346
  const baseCandidates = [
1136
- { base: import_node_path.default.join(apiRoot, "api", "service"), isDirect: false },
1137
- { base: import_node_path.default.join(apiRoot, "service"), isDirect: false }
1347
+ { base: import_node_path2.default.join(apiRoot, "api", "service"), isDirect: false },
1348
+ { base: import_node_path2.default.join(apiRoot, "service"), isDirect: false }
1138
1349
  ];
1139
1350
  if (apiRoot !== webRoot) {
1140
1351
  baseCandidates.push({ base: apiRoot, isDirect: true });
1141
1352
  }
1142
1353
  for (const { base, isDirect } of baseCandidates) {
1143
- if (!import_node_fs.default.existsSync(base) || !import_node_fs.default.statSync(base).isDirectory()) continue;
1354
+ if (!import_node_fs2.default.existsSync(base) || !import_node_fs2.default.statSync(base).isDirectory()) continue;
1144
1355
  walk(base, base, isDirect);
1145
1356
  break;
1146
1357
  }
1147
1358
  function walk(currentDir, baseDir, isDirect) {
1148
1359
  let entries = [];
1149
1360
  try {
1150
- entries = import_node_fs.default.readdirSync(currentDir, { withFileTypes: true });
1361
+ entries = import_node_fs2.default.readdirSync(currentDir, { withFileTypes: true });
1151
1362
  } catch {
1152
1363
  return;
1153
1364
  }
@@ -1155,7 +1366,7 @@ function scanServiceFiles(apiRoot, webRoot) {
1155
1366
  const name = entry.name;
1156
1367
  if (name.startsWith(".") || name.startsWith("_")) continue;
1157
1368
  if (name === "node_modules" || name === "dist" || name === ".soma" || name === ".next") continue;
1158
- const fullPath = import_node_path.default.join(currentDir, name);
1369
+ const fullPath = import_node_path2.default.join(currentDir, name);
1159
1370
  if (entry.isDirectory()) {
1160
1371
  walk(fullPath, baseDir, isDirect);
1161
1372
  } else if (entry.isFile()) {
@@ -1163,7 +1374,7 @@ function scanServiceFiles(apiRoot, webRoot) {
1163
1374
  if (name.endsWith(".d.ts") || name.includes(".test.") || name.includes(".spec.")) continue;
1164
1375
  if (scannedPaths.has(fullPath)) continue;
1165
1376
  scannedPaths.add(fullPath);
1166
- const rel = import_node_path.default.relative(baseDir, fullPath).replace(/\\/g, "/");
1377
+ const rel = import_node_path2.default.relative(baseDir, fullPath).replace(/\\/g, "/");
1167
1378
  const segments = rel.replace(/\.[^.]+$/, "").split("/");
1168
1379
  const last = segments[segments.length - 1];
1169
1380
  const lowerLast = last.charAt(0).toLowerCase() + last.slice(1);