soma-core 2.2.9 → 2.2.11

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 (51) hide show
  1. package/README.md +8 -19
  2. package/bin/service-codegen.cjs +2 -3
  3. package/bin/soma.cjs +2 -2
  4. package/core/build/compiler/soma-precompile.js +19 -6
  5. package/core/client/data/region-scope-port.ts +8 -3
  6. package/core/client/engine/event-engine.ts +1 -1
  7. package/core/client/engine/soma-bootstrap.ts +9 -0
  8. package/core/client/engines/diff/code.ts +205 -0
  9. package/core/client/engines/diff/index.ts +27 -1
  10. package/core/client/engines/diff/port.ts +75 -0
  11. package/core/client/parser/confirm-spec.ts +10 -4
  12. package/core/client/parser/ui-config-parser.ts +14 -2
  13. package/core/index.ts +1 -1
  14. package/core/server/api/load-host-service.ts +0 -1
  15. package/core/server/host/source-packages.cjs +3 -0
  16. package/core/shared/registry-generated/diagnostic-registry-index.ts +16 -0
  17. package/core/shared/registry-generated/diagnostic-registry.ts +130 -0
  18. package/core/shared/registry-generated/limits.ts +6 -2
  19. package/core/shared/registry-generated/std-grammar-views.ts +1 -1
  20. package/core/shared/registry-generated/std-grammar.ts +1 -1
  21. package/core/shared/types/region-scope.types.ts +6 -0
  22. package/dist/browser/runtime-bundle.manifest.json +12 -12
  23. package/dist/browser/soma-runtime.js +752 -489
  24. package/dist/core/index.cjs +752 -489
  25. package/dist/host-native/aot-builder.cjs +366 -226
  26. package/dist/host-native/native-server.cjs +131 -56
  27. package/dist/lsp/component-tree.cjs +23 -10
  28. package/dist/types/client/data/region-scope-port.d.ts +1 -1
  29. package/dist/types/client/engine/soma-bootstrap.d.ts +5 -0
  30. package/dist/types/client/engines/diff/code.d.ts +27 -0
  31. package/dist/types/client/engines/diff/index.d.ts +2 -1
  32. package/dist/types/client/engines/diff/port.d.ts +77 -0
  33. package/dist/types/client/parser/confirm-spec.d.ts +1 -1
  34. package/dist/types/server/host/source-packages.d.cts +5 -0
  35. package/dist/types/shared/registry-generated/diagnostic-registry.d.ts +113 -1
  36. package/dist/types/shared/registry-generated/limits.d.ts +4 -0
  37. package/dist/types/shared/registry-generated/std-grammar-views.d.ts +1 -1
  38. package/dist/types/shared/registry-generated/std-grammar.d.ts +1 -1
  39. package/dist/types/shared/types/region-scope.types.d.ts +6 -0
  40. package/host-native/bin/host-native.cjs +1 -1
  41. package/host-native/client/browser-entry.ts +12 -1
  42. package/host-native/client/first-frame.ts +8 -0
  43. package/host-native/client/router-bridge.ts +8 -2
  44. package/host-native/src/aot-builder.ts +173 -93
  45. package/host-native/src/native-server.ts +131 -25
  46. package/host-native/src/public-packages.cjs +156 -50
  47. package/host-native/styles/globals.css +28 -2
  48. package/package.json +2 -2
  49. package/dist/core/adaptive-pure.cjs +0 -41
  50. package/dist/core/theme-pure.cjs +0 -38
  51. package/dist/preview-export.cjs +0 -3401
@@ -30,142 +30,6 @@ 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 fs3 = require("node:fs");
38
- var path3 = require("node:path");
39
- function readJson(filePath) {
40
- try {
41
- if (!fs3.existsSync(filePath)) return null;
42
- return JSON.parse(fs3.readFileSync(filePath, "utf8"));
43
- } catch {
44
- return null;
45
- }
46
- }
47
- function isSafePackageChild(packageRoot, candidate) {
48
- return candidate === packageRoot || candidate.startsWith(`${packageRoot}${path3.sep}`);
49
- }
50
- function collectFiles(root) {
51
- if (!fs3.existsSync(root) || !fs3.statSync(root).isDirectory()) return [];
52
- const files = [];
53
- for (const entry of fs3.readdirSync(root, { withFileTypes: true })) {
54
- const fullPath = path3.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 && !path3.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 = path3.resolve(packageRoot, targetPrefix);
72
- if (!isSafePackageChild(packageRoot, sourceRoot)) return {};
73
- const aliases = {};
74
- for (const filePath of collectFiles(sourceRoot)) {
75
- const relative = path3.relative(sourceRoot, filePath).split(path3.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(path3.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 = path3.resolve(packageRoot, target);
112
- if (!isSafePackageChild(packageRoot, resolved) || !fs3.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
- path3.join(repoRoot2, "soma-core"),
124
- path3.join(repoRoot2, "soma-foundation"),
125
- path3.join(repoRoot2, "soma-ui"),
126
- path3.join(repoRoot2, "soma-kit"),
127
- path3.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 (!fs3.existsSync(searchRoot)) continue;
138
- const pkgJsonPath = path3.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 = path3.join(searchRoot, "node_modules");
145
- if (fs3.existsSync(nm)) {
146
- try {
147
- for (const entry of fs3.readdirSync(nm, { withFileTypes: true })) {
148
- if (!entry.isDirectory()) continue;
149
- if (entry.name.startsWith("soma-") && !seenPackages.has(entry.name)) {
150
- const pkgPath = path3.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
33
  // core/server/infra/host-config-paths.cjs
170
34
  var require_host_config_paths = __commonJS({
171
35
  "core/server/infra/host-config-paths.cjs"(exports2, module2) {
@@ -453,6 +317,9 @@ var require_source_packages = __commonJS({
453
317
  }
454
318
  module2.exports = {
455
319
  SOMA_SOURCE_PACKAGES_ENV,
320
+ isSomaSourcePackage,
321
+ readExplicitSourcePackages,
322
+ resolvePackageRoot,
456
323
  getSomaHostSourceRoot: getSomaHostSourceRoot2,
457
324
  getSomaHostApiRoot: getSomaHostApiRoot2,
458
325
  resolveSafeChildRoot,
@@ -467,6 +334,224 @@ var require_source_packages = __commonJS({
467
334
  }
468
335
  });
469
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, linkedRoot) => {
465
+ if (!pkgName || seenPackages.has(pkgName) || !fs3.existsSync(linkedRoot)) return;
466
+ let pkgRoot = linkedRoot;
467
+ try {
468
+ pkgRoot = fs3.realpathSync(linkedRoot);
469
+ } catch {
470
+ }
471
+ if (!shouldIncludePackage(pkgName, pkgRoot)) return;
472
+ seenPackages.add(pkgName);
473
+ Object.assign(aliases, readPublicPackageAliases(pkgName, pkgRoot));
474
+ const nestedNm = path3.join(pkgRoot, "node_modules");
475
+ if (fs3.existsSync(nestedNm)) scanNodeModules(nestedNm);
476
+ };
477
+ const scanNodeModules = (nmDir) => {
478
+ let realNm = path3.resolve(nmDir);
479
+ try {
480
+ realNm = fs3.realpathSync(nmDir);
481
+ } catch {
482
+ }
483
+ if (seenNodeModules.has(realNm)) return;
484
+ seenNodeModules.add(realNm);
485
+ let entries = [];
486
+ try {
487
+ entries = fs3.readdirSync(nmDir, { withFileTypes: true });
488
+ } catch {
489
+ return;
490
+ }
491
+ for (const entry of entries) {
492
+ if (entry.name.startsWith(".")) continue;
493
+ if (!isDirectoryOrSymlinkToDir(nmDir, entry)) continue;
494
+ const entryPath = path3.join(nmDir, entry.name);
495
+ if (entry.name.startsWith("@")) {
496
+ let scopedEntries = [];
497
+ try {
498
+ scopedEntries = fs3.readdirSync(entryPath, { withFileTypes: true });
499
+ } catch {
500
+ scopedEntries = [];
501
+ }
502
+ for (const scoped of scopedEntries) {
503
+ if (scoped.name.startsWith(".")) continue;
504
+ if (!isDirectoryOrSymlinkToDir(entryPath, scoped)) continue;
505
+ registerPackage(`${entry.name}/${scoped.name}`, path3.join(entryPath, scoped.name));
506
+ }
507
+ } else {
508
+ registerPackage(entry.name, entryPath);
509
+ }
510
+ }
511
+ };
512
+ for (const searchRoot of searchRoots) {
513
+ if (!searchRoot || !fs3.existsSync(searchRoot)) continue;
514
+ const pkgJsonPath = path3.join(searchRoot, "package.json");
515
+ const pkgJson = readJson(pkgJsonPath);
516
+ if (pkgJson?.name) {
517
+ registerPackage(pkgJson.name, searchRoot);
518
+ }
519
+ const deps = {
520
+ ...pkgJson?.dependencies ?? {},
521
+ ...pkgJson?.devDependencies ?? {}
522
+ };
523
+ const depNames = /* @__PURE__ */ new Set([...Object.keys(deps), ...explicitPackages]);
524
+ for (const depName of depNames) {
525
+ if (seenPackages.has(depName)) continue;
526
+ const depRoot = resolvePackageRoot(searchRoot, depName, deps[depName]);
527
+ if (depRoot) registerPackage(depName, depRoot);
528
+ }
529
+ const nm = path3.join(searchRoot, "node_modules");
530
+ if (fs3.existsSync(nm)) {
531
+ scanNodeModules(nm);
532
+ }
533
+ }
534
+ return aliases;
535
+ }
536
+ function createPublicAliasesFilter2(aliases) {
537
+ const roots = /* @__PURE__ */ new Set();
538
+ for (const spec of Object.keys(aliases || {})) {
539
+ const root = spec.startsWith("@") ? spec.split("/").slice(0, 2).join("/") : spec.split("/")[0];
540
+ if (root) roots.add(root);
541
+ }
542
+ if (roots.size === 0) return null;
543
+ const escaped = [...roots].sort().map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
544
+ return new RegExp(`^(?:${escaped.join("|")})(?:/.*)?$`);
545
+ }
546
+ module2.exports = {
547
+ readJson,
548
+ readPublicPackageAliases,
549
+ readAllSomaPublicAliases: readAllSomaPublicAliases2,
550
+ createPublicAliasesFilter: createPublicAliasesFilter2
551
+ };
552
+ }
553
+ });
554
+
470
555
  // core/server/host/source-aliases.cjs
471
556
  var require_source_aliases = __commonJS({
472
557
  "core/server/host/source-aliases.cjs"(exports2, module2) {
@@ -739,7 +824,8 @@ var require_source_aliases = __commonJS({
739
824
  var aot_builder_exports = {};
740
825
  __export(aot_builder_exports, {
741
826
  buildBrowserClient: () => buildBrowserClient,
742
- buildServerAot: () => buildServerAot
827
+ buildServerAot: () => buildServerAot,
828
+ clientBuildAffectedBy: () => clientBuildAffectedBy
743
829
  });
744
830
  module.exports = __toCommonJS(aot_builder_exports);
745
831
  var import_node_fs2 = __toESM(require("node:fs"));
@@ -844,6 +930,11 @@ function registerSourceRootResolve(build, hostDir, env) {
844
930
  return { path: resolveModuleFile(hit.dir, hit.subpath) };
845
931
  });
846
932
  }
933
+ var CLIENT_MODULE_EXT = /\.(?:[cm]?[jt]sx?|json|css)$/i;
934
+ function clientBuildAffectedBy(inputs, changedFiles) {
935
+ if (inputs === null || changedFiles.length === 0) return true;
936
+ return changedFiles.some((file) => inputs.has(import_node_path2.default.resolve(file)) || CLIENT_MODULE_EXT.test(file));
937
+ }
847
938
  function resolveModuleFile(baseDir, subpath) {
848
939
  const target = subpath ? import_node_path2.default.resolve(baseDir, subpath) : import_node_path2.default.resolve(baseDir);
849
940
  for (const ext of ["", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"]) {
@@ -866,8 +957,9 @@ var coreRoot = import_node_path2.default.resolve(__dirname, "../..");
866
957
  var hostNativeRoot = import_node_path2.default.join(coreRoot, "host-native");
867
958
  var repoRoot = import_node_path2.default.resolve(coreRoot, "..");
868
959
  function createBrowserClientPlugin(options) {
869
- const { hostDir, webRoot } = options;
870
- const publicAliases = (0, import_public_packages.readAllSomaPublicAliases)(hostDir, repoRoot, [webRoot, coreRoot]);
960
+ const { hostDir, webRoot, env } = options;
961
+ const publicAliases = (0, import_public_packages.readAllSomaPublicAliases)(hostDir, repoRoot, [webRoot, coreRoot], env);
962
+ const publicFilter = (0, import_public_packages.createPublicAliasesFilter)(publicAliases);
871
963
  return {
872
964
  name: "soma-browser-client-plugin",
873
965
  setup(build) {
@@ -935,7 +1027,7 @@ function createBrowserClientPlugin(options) {
935
1027
  }
936
1028
  return { path: target };
937
1029
  });
938
- registerSourceRootResolve(build, hostDir);
1030
+ registerSourceRootResolve(build, hostDir, env);
939
1031
  build.onResolve({ filter: /core\/client\/engine\// }, (args) => {
940
1032
  if (!args.importer.includes("soma-core")) {
941
1033
  throw new Error(
@@ -944,13 +1036,15 @@ function createBrowserClientPlugin(options) {
944
1036
  }
945
1037
  return void 0;
946
1038
  });
947
- build.onResolve({ filter: /^soma-[a-z0-9-]+(?:\/.*)?$/ }, (args) => {
948
- const direct = publicAliases[args.path];
949
- if (direct && import_node_fs2.default.existsSync(direct)) {
950
- return { path: direct };
951
- }
952
- return void 0;
953
- });
1039
+ if (publicFilter) {
1040
+ build.onResolve({ filter: publicFilter }, (args) => {
1041
+ const direct = publicAliases[args.path];
1042
+ if (direct && import_node_fs2.default.existsSync(direct)) {
1043
+ return { path: direct };
1044
+ }
1045
+ return void 0;
1046
+ });
1047
+ }
954
1048
  build.onResolve({ filter: /^echarts(?:\/.*)?$/ }, async (args) => {
955
1049
  if (args.pluginData?.skipEchartsStub) return void 0;
956
1050
  const resolveOpts = {
@@ -1007,7 +1101,7 @@ async function buildBrowserClient(options) {
1007
1101
  const clientOutDir = import_node_path2.default.join(outDir, "client");
1008
1102
  import_node_fs2.default.mkdirSync(clientOutDir, { recursive: true });
1009
1103
  const clientEntry = import_node_path2.default.join(hostNativeRoot, "client/browser-entry.ts");
1010
- const plugin = createBrowserClientPlugin({ hostDir, webRoot });
1104
+ const plugin = createBrowserClientPlugin({ hostDir, webRoot, env: options.env });
1011
1105
  const cssSourcePath = import_node_path2.default.join(hostNativeRoot, "styles/globals.css");
1012
1106
  let rawCss = "";
1013
1107
  try {
@@ -1052,10 +1146,14 @@ async function buildBrowserClient(options) {
1052
1146
  };
1053
1147
  let ctx = null;
1054
1148
  let entryUrl = "/_soma/client/browser-entry.js";
1149
+ let devInputs = null;
1055
1150
  const devRebuild = async () => {
1056
1151
  if (!ctx) return;
1057
1152
  const result = await ctx.rebuild();
1058
- if (result.metafile) collectDevChunks(clientOutDir, outputsRelativeTo(clientOutDir, Object.keys(result.metafile.outputs)));
1153
+ if (result.metafile) {
1154
+ collectDevChunks(clientOutDir, outputsRelativeTo(clientOutDir, Object.keys(result.metafile.outputs)));
1155
+ devInputs = new Set(Object.keys(result.metafile.inputs).map((file) => import_node_path2.default.resolve(file)));
1156
+ }
1059
1157
  };
1060
1158
  if (options.dev) {
1061
1159
  ctx = await import_esbuild.default.context({ ...buildOptions, metafile: true });
@@ -1090,6 +1188,7 @@ async function buildBrowserClient(options) {
1090
1188
  rebuild: async () => {
1091
1189
  await devRebuild();
1092
1190
  },
1191
+ affectedBy: (changedFiles) => clientBuildAffectedBy(devInputs, changedFiles),
1093
1192
  dispose: async () => {
1094
1193
  if (ctx) {
1095
1194
  await ctx.dispose();
@@ -1098,19 +1197,26 @@ async function buildBrowserClient(options) {
1098
1197
  }
1099
1198
  };
1100
1199
  }
1200
+ function sharedPackageSlug(specifier) {
1201
+ const safe = specifier.replace(/^@/, "").replace(/[^a-zA-Z0-9_-]+/g, "__").replace(/^_+|_+$/g, "");
1202
+ const hash = (0, import_node_crypto.createHash)("sha256").update(specifier).digest("hex").slice(0, 8);
1203
+ return `${safe || "pkg"}-${hash}`;
1204
+ }
1101
1205
  async function buildServerAot(options) {
1102
1206
  const hostDir = import_node_path2.default.resolve(options.hostDir);
1103
1207
  const webRoot = import_node_path2.default.resolve(options.webRoot || (0, import_source_packages.getSomaHostSourceRoot)(hostDir, options.env));
1104
1208
  const apiRoot = import_node_path2.default.resolve(options.apiRoot || (0, import_source_packages.getSomaHostApiRoot)(hostDir, options.env));
1105
1209
  const outDir = import_node_path2.default.resolve(options.outDir);
1106
1210
  const aotServerDir = import_node_path2.default.join(outDir, "aot-server");
1211
+ const sharedPackagesDir = import_node_path2.default.join(aotServerDir, "_packages");
1107
1212
  import_node_fs2.default.mkdirSync(aotServerDir, { recursive: true });
1213
+ import_node_fs2.default.rmSync(sharedPackagesDir, { recursive: true, force: true });
1108
1214
  const serviceFiles = scanServiceFiles(apiRoot, webRoot);
1109
- const entryPoints = {};
1215
+ const serviceEntryPoints = {};
1110
1216
  const routes = {};
1111
1217
  for (const item of serviceFiles) {
1112
1218
  const entryName = `services/${item.routeKey.replace(/\//g, "_")}`;
1113
- entryPoints[entryName] = item.filePath;
1219
+ serviceEntryPoints[entryName] = item.filePath;
1114
1220
  routes[item.routeKey] = `${entryName}.cjs`;
1115
1221
  const segments = item.routeKey.split("/");
1116
1222
  const pascalKey = segments.slice(0, -1).concat(toPascalCase(segments[segments.length - 1])).join("/");
@@ -1125,84 +1231,117 @@ async function buildServerAot(options) {
1125
1231
  let hostAppCompiledPath;
1126
1232
  const hostAppPath = import_node_path2.default.resolve(webRoot, "soma.app.ts");
1127
1233
  if (import_node_fs2.default.existsSync(hostAppPath)) {
1128
- entryPoints["host-app"] = hostAppPath;
1129
1234
  hostAppCompiledPath = "host-app.cjs";
1130
1235
  }
1131
- if (Object.keys(entryPoints).length > 0) {
1132
- await import_esbuild.default.build({
1133
- entryPoints,
1134
- outdir: aotServerDir,
1135
- bundle: true,
1136
- platform: "node",
1137
- format: "cjs",
1138
- target: "node20",
1139
- packages: "external",
1140
- nodePaths: [import_node_path2.default.join(apiRoot, "node_modules"), 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)),
1141
- outExtension: { ".js": ".cjs" },
1142
- plugins: [
1143
- {
1144
- name: "soma-server-aot-plugin",
1145
- setup(build) {
1146
- const publicAliases = (0, import_public_packages.readAllSomaPublicAliases)(hostDir, repoRoot, [webRoot, apiRoot, coreRoot]);
1147
- build.onResolve({ filter: /^server-only$/ }, () => {
1148
- return { path: import_node_path2.default.resolve(coreRoot, "core/server/host/server-only-noop.cjs") };
1149
- });
1150
- build.onResolve({ filter: /^@core(?:\/.*)?$/ }, (args) => {
1151
- const subpath = args.path.replace(/^@core\/?/, "");
1152
- return { path: resolveModuleFile(import_node_path2.default.resolve(coreRoot, "core"), subpath) };
1153
- });
1154
- build.onResolve({ filter: /^@soma-host\/bootstrap\/soma-bootstrap$/ }, () => {
1155
- const candidateHostFile = import_node_path2.default.resolve(webRoot, "bootstrap/soma-bootstrap");
1156
- for (const ext of [".ts", ".js", ".mjs"]) {
1157
- if (import_node_fs2.default.existsSync(candidateHostFile + ext)) {
1158
- return { path: candidateHostFile + ext };
1159
- }
1160
- }
1161
- if (import_node_fs2.default.existsSync(import_node_path2.default.resolve(webRoot, "soma.app.ts"))) {
1162
- return { path: import_node_path2.default.resolve(coreRoot, "core/client/host-bridge/soma-bootstrap-from-app.ts") };
1163
- }
1164
- return { path: import_node_path2.default.resolve(coreRoot, "core/client/host-bridge/soma-bootstrap-host.stub.ts") };
1165
- });
1166
- build.onResolve({ filter: /^@soma-host\/bootstrap\/soma-domain-loaders$/ }, () => {
1167
- const candidateLoader = import_node_path2.default.resolve(webRoot, "bootstrap/soma-domain-loaders");
1168
- for (const ext of [".ts", ".js", ".mjs"]) {
1169
- if (import_node_fs2.default.existsSync(candidateLoader + ext)) {
1170
- return { path: candidateLoader + ext };
1171
- }
1172
- }
1173
- return { path: import_node_path2.default.resolve(coreRoot, "core/client/host-bridge/soma-domain-loaders.stub.ts") };
1174
- });
1175
- build.onResolve({ filter: /^@soma-host\/domain\/ui\/.*Class\.ts$/ }, (args) => {
1176
- const baseName = import_node_path2.default.basename(args.path);
1177
- const diskFile = import_node_path2.default.resolve(webRoot, "domain/ui", baseName);
1178
- if (import_node_fs2.default.existsSync(diskFile)) {
1179
- return { path: diskFile };
1180
- }
1181
- return { path: args.path, namespace: "soma-absent-domain" };
1182
- });
1183
- build.onLoad({ filter: /.*/, namespace: "soma-absent-domain" }, (args) => ({
1184
- contents: `const err = new Error("Cannot find module '${args.path}'"); err.code = "MODULE_NOT_FOUND"; throw err;`,
1185
- loader: "js"
1186
- }));
1187
- build.onResolve({ filter: /^@soma-host(?:\/.*)?$/ }, (args) => {
1188
- const subpath = args.path.replace(/^@soma-host\/?/, "");
1189
- return { path: resolveModuleFile(webRoot, subpath) };
1190
- });
1191
- registerSourceRootResolve(build, hostDir, options.env);
1192
- build.onResolve({ filter: /^@soma-api(?:\/.*)?$/ }, (args) => {
1193
- const subpath = args.path.replace(/^@soma-api\/?/, "");
1194
- return { path: resolveModuleFile(apiRoot, subpath) };
1195
- });
1196
- build.onResolve({ filter: /^soma-[a-z0-9-]+(?:\/.*)?$/ }, (args) => {
1197
- const direct = publicAliases[args.path];
1198
- if (direct && import_node_fs2.default.existsSync(direct)) {
1199
- return { path: direct };
1200
- }
1201
- return void 0;
1202
- });
1236
+ const publicAliases = (0, import_public_packages.readAllSomaPublicAliases)(hostDir, repoRoot, [webRoot, apiRoot, coreRoot], options.env);
1237
+ const publicFilter = (0, import_public_packages.createPublicAliasesFilter)(publicAliases);
1238
+ const sharedEntries = /* @__PURE__ */ new Map();
1239
+ const nodePaths = [
1240
+ import_node_path2.default.join(apiRoot, "node_modules"),
1241
+ import_node_path2.default.join(webRoot, "node_modules"),
1242
+ import_node_path2.default.join(hostDir, "node_modules"),
1243
+ import_node_path2.default.join(coreRoot, "node_modules")
1244
+ ].filter((d) => import_node_fs2.default.existsSync(d));
1245
+ const createServerAotPlugin = (mode) => ({
1246
+ name: "soma-server-aot-plugin",
1247
+ setup(build) {
1248
+ build.onResolve({ filter: /^server-only$/ }, () => {
1249
+ return { path: import_node_path2.default.resolve(coreRoot, "core/server/host/server-only-noop.cjs") };
1250
+ });
1251
+ build.onResolve({ filter: /^@core(?:\/.*)?$/ }, (args) => {
1252
+ const subpath = args.path.replace(/^@core\/?/, "");
1253
+ return { path: resolveModuleFile(import_node_path2.default.resolve(coreRoot, "core"), subpath) };
1254
+ });
1255
+ build.onResolve({ filter: /^@soma-host\/bootstrap\/soma-bootstrap$/ }, () => {
1256
+ const candidateHostFile = import_node_path2.default.resolve(webRoot, "bootstrap/soma-bootstrap");
1257
+ for (const ext of [".ts", ".js", ".mjs"]) {
1258
+ if (import_node_fs2.default.existsSync(candidateHostFile + ext)) {
1259
+ return { path: candidateHostFile + ext };
1203
1260
  }
1204
1261
  }
1205
- ]
1262
+ if (import_node_fs2.default.existsSync(import_node_path2.default.resolve(webRoot, "soma.app.ts"))) {
1263
+ return { path: import_node_path2.default.resolve(coreRoot, "core/client/host-bridge/soma-bootstrap-from-app.ts") };
1264
+ }
1265
+ return { path: import_node_path2.default.resolve(coreRoot, "core/client/host-bridge/soma-bootstrap-host.stub.ts") };
1266
+ });
1267
+ build.onResolve({ filter: /^@soma-host\/bootstrap\/soma-domain-loaders$/ }, () => {
1268
+ const candidateLoader = import_node_path2.default.resolve(webRoot, "bootstrap/soma-domain-loaders");
1269
+ for (const ext of [".ts", ".js", ".mjs"]) {
1270
+ if (import_node_fs2.default.existsSync(candidateLoader + ext)) {
1271
+ return { path: candidateLoader + ext };
1272
+ }
1273
+ }
1274
+ return { path: import_node_path2.default.resolve(coreRoot, "core/client/host-bridge/soma-domain-loaders.stub.ts") };
1275
+ });
1276
+ build.onResolve({ filter: /^@soma-host\/domain\/ui\/.*Class\.ts$/ }, (args) => {
1277
+ const baseName = import_node_path2.default.basename(args.path);
1278
+ const diskFile = import_node_path2.default.resolve(webRoot, "domain/ui", baseName);
1279
+ if (import_node_fs2.default.existsSync(diskFile)) {
1280
+ return { path: diskFile };
1281
+ }
1282
+ return { path: args.path, namespace: "soma-absent-domain" };
1283
+ });
1284
+ build.onLoad({ filter: /.*/, namespace: "soma-absent-domain" }, (args) => ({
1285
+ contents: `const err = new Error("Cannot find module '${args.path}'"); err.code = "MODULE_NOT_FOUND"; throw err;`,
1286
+ loader: "js"
1287
+ }));
1288
+ build.onResolve({ filter: /^@soma-host(?:\/.*)?$/ }, (args) => {
1289
+ const subpath = args.path.replace(/^@soma-host\/?/, "");
1290
+ return { path: resolveModuleFile(webRoot, subpath) };
1291
+ });
1292
+ registerSourceRootResolve(build, hostDir, options.env);
1293
+ build.onResolve({ filter: /^@soma-api(?:\/.*)?$/ }, (args) => {
1294
+ const subpath = args.path.replace(/^@soma-api\/?/, "");
1295
+ return { path: resolveModuleFile(apiRoot, subpath) };
1296
+ });
1297
+ if (publicFilter) {
1298
+ build.onResolve({ filter: publicFilter }, (args) => {
1299
+ const direct = publicAliases[args.path];
1300
+ if (!direct || !import_node_fs2.default.existsSync(direct)) {
1301
+ return void 0;
1302
+ }
1303
+ if ("inlinePublic" in mode) {
1304
+ return { path: direct };
1305
+ }
1306
+ const slug = sharedPackageSlug(args.path);
1307
+ sharedEntries.set(slug, direct);
1308
+ return { path: `${mode.sharedOutPrefix}_packages/${slug}.cjs`, external: true };
1309
+ });
1310
+ }
1311
+ }
1312
+ });
1313
+ const baseServerBuildOptions = {
1314
+ bundle: true,
1315
+ platform: "node",
1316
+ format: "cjs",
1317
+ target: "node20",
1318
+ packages: "external",
1319
+ nodePaths,
1320
+ outExtension: { ".js": ".cjs" }
1321
+ };
1322
+ if (Object.keys(serviceEntryPoints).length > 0) {
1323
+ await import_esbuild.default.build({
1324
+ ...baseServerBuildOptions,
1325
+ entryPoints: serviceEntryPoints,
1326
+ outdir: aotServerDir,
1327
+ plugins: [createServerAotPlugin({ sharedOutPrefix: "../" })]
1328
+ });
1329
+ }
1330
+ if (hostAppCompiledPath) {
1331
+ await import_esbuild.default.build({
1332
+ ...baseServerBuildOptions,
1333
+ entryPoints: { "host-app": hostAppPath },
1334
+ outdir: aotServerDir,
1335
+ plugins: [createServerAotPlugin({ sharedOutPrefix: "./" })]
1336
+ });
1337
+ }
1338
+ if (sharedEntries.size > 0) {
1339
+ import_node_fs2.default.mkdirSync(sharedPackagesDir, { recursive: true });
1340
+ await import_esbuild.default.build({
1341
+ ...baseServerBuildOptions,
1342
+ entryPoints: Object.fromEntries(sharedEntries),
1343
+ outdir: sharedPackagesDir,
1344
+ plugins: [createServerAotPlugin({ inlinePublic: true })]
1206
1345
  });
1207
1346
  }
1208
1347
  const manifest = {
@@ -1266,5 +1405,6 @@ function scanServiceFiles(apiRoot, webRoot) {
1266
1405
  // Annotate the CommonJS export names for ESM import in node:
1267
1406
  0 && (module.exports = {
1268
1407
  buildBrowserClient,
1269
- buildServerAot
1408
+ buildServerAot,
1409
+ clientBuildAffectedBy
1270
1410
  });