soma-core 2.2.9 → 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.
- package/core/build/compiler/soma-precompile.js +6 -2
- package/core/client/engines/diff/code.ts +205 -0
- package/core/client/engines/diff/index.ts +27 -1
- package/core/client/engines/diff/port.ts +75 -0
- package/core/server/host/source-packages.cjs +3 -0
- package/core/shared/registry-generated/limits.ts +6 -2
- package/dist/browser/runtime-bundle.manifest.json +1 -0
- package/dist/browser/soma-runtime.js +1211 -963
- package/dist/core/index.cjs +1211 -963
- package/dist/host-native/aot-builder.cjs +346 -223
- package/dist/host-native/native-server.cjs +9 -2
- package/dist/lsp/component-tree.cjs +6 -2
- package/dist/types/client/engines/diff/code.d.ts +27 -0
- package/dist/types/client/engines/diff/index.d.ts +2 -1
- package/dist/types/client/engines/diff/port.d.ts +77 -0
- package/dist/types/server/host/source-packages.d.cts +5 -0
- package/dist/types/shared/registry-generated/limits.d.ts +4 -0
- package/host-native/src/aot-builder.ts +147 -91
- package/host-native/src/public-packages.cjs +147 -50
- package/package.json +1 -1
|
@@ -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,219 @@ 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, 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
|
+
|
|
470
550
|
// core/server/host/source-aliases.cjs
|
|
471
551
|
var require_source_aliases = __commonJS({
|
|
472
552
|
"core/server/host/source-aliases.cjs"(exports2, module2) {
|
|
@@ -866,8 +946,9 @@ var coreRoot = import_node_path2.default.resolve(__dirname, "../..");
|
|
|
866
946
|
var hostNativeRoot = import_node_path2.default.join(coreRoot, "host-native");
|
|
867
947
|
var repoRoot = import_node_path2.default.resolve(coreRoot, "..");
|
|
868
948
|
function createBrowserClientPlugin(options) {
|
|
869
|
-
const { hostDir, webRoot } = options;
|
|
870
|
-
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);
|
|
871
952
|
return {
|
|
872
953
|
name: "soma-browser-client-plugin",
|
|
873
954
|
setup(build) {
|
|
@@ -935,7 +1016,7 @@ function createBrowserClientPlugin(options) {
|
|
|
935
1016
|
}
|
|
936
1017
|
return { path: target };
|
|
937
1018
|
});
|
|
938
|
-
registerSourceRootResolve(build, hostDir);
|
|
1019
|
+
registerSourceRootResolve(build, hostDir, env);
|
|
939
1020
|
build.onResolve({ filter: /core\/client\/engine\// }, (args) => {
|
|
940
1021
|
if (!args.importer.includes("soma-core")) {
|
|
941
1022
|
throw new Error(
|
|
@@ -944,13 +1025,15 @@ function createBrowserClientPlugin(options) {
|
|
|
944
1025
|
}
|
|
945
1026
|
return void 0;
|
|
946
1027
|
});
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
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
|
+
}
|
|
954
1037
|
build.onResolve({ filter: /^echarts(?:\/.*)?$/ }, async (args) => {
|
|
955
1038
|
if (args.pluginData?.skipEchartsStub) return void 0;
|
|
956
1039
|
const resolveOpts = {
|
|
@@ -1007,7 +1090,7 @@ async function buildBrowserClient(options) {
|
|
|
1007
1090
|
const clientOutDir = import_node_path2.default.join(outDir, "client");
|
|
1008
1091
|
import_node_fs2.default.mkdirSync(clientOutDir, { recursive: true });
|
|
1009
1092
|
const clientEntry = import_node_path2.default.join(hostNativeRoot, "client/browser-entry.ts");
|
|
1010
|
-
const plugin = createBrowserClientPlugin({ hostDir, webRoot });
|
|
1093
|
+
const plugin = createBrowserClientPlugin({ hostDir, webRoot, env: options.env });
|
|
1011
1094
|
const cssSourcePath = import_node_path2.default.join(hostNativeRoot, "styles/globals.css");
|
|
1012
1095
|
let rawCss = "";
|
|
1013
1096
|
try {
|
|
@@ -1098,19 +1181,26 @@ async function buildBrowserClient(options) {
|
|
|
1098
1181
|
}
|
|
1099
1182
|
};
|
|
1100
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
|
+
}
|
|
1101
1189
|
async function buildServerAot(options) {
|
|
1102
1190
|
const hostDir = import_node_path2.default.resolve(options.hostDir);
|
|
1103
1191
|
const webRoot = import_node_path2.default.resolve(options.webRoot || (0, import_source_packages.getSomaHostSourceRoot)(hostDir, options.env));
|
|
1104
1192
|
const apiRoot = import_node_path2.default.resolve(options.apiRoot || (0, import_source_packages.getSomaHostApiRoot)(hostDir, options.env));
|
|
1105
1193
|
const outDir = import_node_path2.default.resolve(options.outDir);
|
|
1106
1194
|
const aotServerDir = import_node_path2.default.join(outDir, "aot-server");
|
|
1195
|
+
const sharedPackagesDir = import_node_path2.default.join(aotServerDir, "_packages");
|
|
1107
1196
|
import_node_fs2.default.mkdirSync(aotServerDir, { recursive: true });
|
|
1197
|
+
import_node_fs2.default.rmSync(sharedPackagesDir, { recursive: true, force: true });
|
|
1108
1198
|
const serviceFiles = scanServiceFiles(apiRoot, webRoot);
|
|
1109
|
-
const
|
|
1199
|
+
const serviceEntryPoints = {};
|
|
1110
1200
|
const routes = {};
|
|
1111
1201
|
for (const item of serviceFiles) {
|
|
1112
1202
|
const entryName = `services/${item.routeKey.replace(/\//g, "_")}`;
|
|
1113
|
-
|
|
1203
|
+
serviceEntryPoints[entryName] = item.filePath;
|
|
1114
1204
|
routes[item.routeKey] = `${entryName}.cjs`;
|
|
1115
1205
|
const segments = item.routeKey.split("/");
|
|
1116
1206
|
const pascalKey = segments.slice(0, -1).concat(toPascalCase(segments[segments.length - 1])).join("/");
|
|
@@ -1125,84 +1215,117 @@ async function buildServerAot(options) {
|
|
|
1125
1215
|
let hostAppCompiledPath;
|
|
1126
1216
|
const hostAppPath = import_node_path2.default.resolve(webRoot, "soma.app.ts");
|
|
1127
1217
|
if (import_node_fs2.default.existsSync(hostAppPath)) {
|
|
1128
|
-
entryPoints["host-app"] = hostAppPath;
|
|
1129
1218
|
hostAppCompiledPath = "host-app.cjs";
|
|
1130
1219
|
}
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
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
|
-
});
|
|
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 };
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
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 };
|
|
1203
1256
|
}
|
|
1204
1257
|
}
|
|
1205
|
-
|
|
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 })]
|
|
1206
1329
|
});
|
|
1207
1330
|
}
|
|
1208
1331
|
const manifest = {
|