@mono-lit/utility 0.0.0-stage → 0.0.2

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 (54) hide show
  1. package/LICENSE.md +54 -0
  2. package/README.md +157 -3
  3. package/dist/app-roots-CvJnmXcs.js +128 -0
  4. package/dist/app-roots-DK41xMWj.d.ts +90 -0
  5. package/dist/config-node-UzJrXg0Z.js +76 -0
  6. package/dist/config-node.d.ts +923 -0
  7. package/dist/config-node.js +7 -0
  8. package/dist/config.d.ts +2 -0
  9. package/dist/config.js +3 -0
  10. package/dist/create-config-B8IhX4ht.d.ts +735 -0
  11. package/dist/create-config-DdL3Fh6T.js +357 -0
  12. package/dist/fetching.d.ts +244 -0
  13. package/dist/fetching.js +1015 -0
  14. package/dist/generate-CJ7MtcDd.js +291 -0
  15. package/dist/index-BAy6tbOG.d.ts +371 -0
  16. package/dist/index-DYlzhHq7.d.ts +514 -0
  17. package/dist/index.d.ts +25 -0
  18. package/dist/index.js +941 -0
  19. package/dist/merge-file-CLc3wxY4.d.ts +99 -0
  20. package/dist/merge-file-CtyKTu5L.js +133 -0
  21. package/dist/mock-db-4tTWrF-P.js +1282 -0
  22. package/dist/mock-db.d.ts +2 -0
  23. package/dist/mock-db.js +4 -0
  24. package/dist/mono-alias-DNDm-jB_.js +508 -0
  25. package/dist/mono-clone.mjs +958 -0
  26. package/dist/mono-db.d.ts +1 -0
  27. package/dist/mono-db.js +158 -0
  28. package/dist/mono-env.mjs +231 -0
  29. package/dist/mono-git.mjs +798 -0
  30. package/dist/mono-link-YlOQ2PVS.js +488 -0
  31. package/dist/mono-prepare.d.ts +1 -0
  32. package/dist/mono-prepare.js +28 -0
  33. package/dist/mono-skills.d.ts +1 -0
  34. package/dist/mono-skills.js +837 -0
  35. package/dist/mono-tsconfig-D2qRL9_R.js +204 -0
  36. package/dist/mono.mjs +34 -0
  37. package/dist/nuxt-layers-DP1m7f1-.js +176 -0
  38. package/dist/nuxt-layers.d.ts +36 -0
  39. package/dist/nuxt-layers.js +3 -0
  40. package/dist/nuxt-runtime.d.ts +17 -0
  41. package/dist/nuxt-runtime.js +102 -0
  42. package/dist/nuxt.d.ts +390 -0
  43. package/dist/nuxt.js +737 -0
  44. package/dist/runtime-vs7U9Ed4.js +6054 -0
  45. package/dist/runtime.d.ts +2518 -0
  46. package/dist/runtime.js +4 -0
  47. package/dist/session-Bcig-rPi.js +1721 -0
  48. package/dist/types-B6FdB7LJ.d.ts +57 -0
  49. package/dist/universal-BR0O7Qwk.d.ts +59 -0
  50. package/dist/universal-DIVEzCvN.js +600 -0
  51. package/dist/virtual-mono-apps.d.ts +16 -0
  52. package/dist/vite.d.ts +943 -0
  53. package/dist/vite.js +1132 -0
  54. package/package.json +141 -3
@@ -0,0 +1,2 @@
1
+ import { A as parseFilter, B as MonoMockSchemaError, C as FilterContext, D as evaluateFilter, E as ODataResult, F as MonoMockField, H as normalizeSegment, I as MonoMockFieldType, L as MonoMockParsedEntity, M as parseQuery, N as toODataEnvelope, O as executeQuery, P as tokenize, R as MonoMockParsedSchema, S as ExpandItem, T as ODataQuery, U as parseField, V as matchMockRoute, W as parseMockSchema, _ as ApplyTransform, a as monoMockDb, b as applyTransforms, c as createMockStore, d as GenerateOptions, f as createRandom, g as AggregateSpec, h as AggregateMethod, i as createMockDb, j as parseKeySegment, k as parseExpand, l as isIndexedDbAvailable, m as orderEntitiesByDependency, n as MonoMockRequest, o as resetMonoMockDb, p as generateSeed, r as MonoMockResponse, s as MonoMockStore, t as MonoMockDb, u as openMockDb, v as CompileFilter, w as FilterNode, x as parseApply, y as ReadValue, z as MonoMockRelation } from "./index-BAy6tbOG.js";
2
+ export { AggregateMethod, AggregateSpec, ApplyTransform, CompileFilter, ExpandItem, FilterContext, FilterNode, GenerateOptions, MonoMockDb, MonoMockField, MonoMockFieldType, MonoMockParsedEntity, MonoMockParsedSchema, MonoMockRelation, MonoMockRequest, MonoMockResponse, MonoMockSchemaError, MonoMockStore, ODataQuery, ODataResult, ReadValue, applyTransforms, createMockDb, createMockStore, createRandom, evaluateFilter, executeQuery, generateSeed, isIndexedDbAvailable, matchMockRoute, monoMockDb, normalizeSegment, openMockDb, orderEntitiesByDependency, parseApply, parseExpand, parseField, parseFilter, parseKeySegment, parseMockSchema, parseQuery, resetMonoMockDb, toODataEnvelope, tokenize };
@@ -0,0 +1,4 @@
1
+ import { a as normalizeSegment, i as matchMockRoute, n as generateSeed, o as parseField, r as orderEntitiesByDependency, s as parseMockSchema, t as createRandom } from "./generate-CJ7MtcDd.js";
2
+ import { a as isIndexedDbAvailable, c as executeQuery, d as parseKeySegment, f as parseQuery, g as parseApply, h as applyTransforms, i as createMockStore, l as parseExpand, m as tokenize, n as monoMockDb, o as openMockDb, p as toODataEnvelope, r as resetMonoMockDb, s as evaluateFilter, t as createMockDb, u as parseFilter } from "./mock-db-4tTWrF-P.js";
3
+
4
+ export { applyTransforms, createMockDb, createMockStore, createRandom, evaluateFilter, executeQuery, generateSeed, isIndexedDbAvailable, matchMockRoute, monoMockDb, normalizeSegment, openMockDb, orderEntitiesByDependency, parseApply, parseExpand, parseField, parseFilter, parseKeySegment, parseMockSchema, parseQuery, resetMonoMockDb, toODataEnvelope, tokenize };
@@ -0,0 +1,508 @@
1
+ import { c as resolveAppRoots } from "./app-roots-CvJnmXcs.js";
2
+ import { l as srcDirForType } from "./create-config-DdL3Fh6T.js";
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+
6
+ //#region src/composables/mono-alias.ts
7
+ /**
8
+ * Strip `//` and `/* *​/` comments without touching string contents, so a
9
+ * commented-out `name:` never shadows the real one.
10
+ *
11
+ * Ported verbatim from `bin/mono-clone.mjs`.
12
+ */
13
+ function stripCommentsSafe(code) {
14
+ let out = "";
15
+ let quote = null;
16
+ let escaped = false;
17
+ let inLineComment = false;
18
+ let inBlockComment = false;
19
+ for (let i = 0; i < code.length; i++) {
20
+ const ch = code[i];
21
+ const next = code[i + 1];
22
+ if (inLineComment) {
23
+ if (ch === "\n") {
24
+ inLineComment = false;
25
+ out += ch;
26
+ }
27
+ continue;
28
+ }
29
+ if (inBlockComment) {
30
+ if (ch === "*" && next === "/") {
31
+ inBlockComment = false;
32
+ i++;
33
+ }
34
+ continue;
35
+ }
36
+ if (quote) {
37
+ out += ch;
38
+ if (escaped) {
39
+ escaped = false;
40
+ continue;
41
+ }
42
+ if (ch === "\\") {
43
+ escaped = true;
44
+ continue;
45
+ }
46
+ if (ch === quote) quote = null;
47
+ continue;
48
+ }
49
+ if (ch === "\"" || ch === "'" || ch === "`") {
50
+ quote = ch;
51
+ out += ch;
52
+ continue;
53
+ }
54
+ if (ch === "/" && next === "/") {
55
+ inLineComment = true;
56
+ i++;
57
+ continue;
58
+ }
59
+ if (ch === "/" && next === "*") {
60
+ inBlockComment = true;
61
+ i++;
62
+ continue;
63
+ }
64
+ out += ch;
65
+ }
66
+ return out;
67
+ }
68
+ /**
69
+ * Absolute path of the mono config file in `dir`, or `null`. The same lookup
70
+ * order every static reader here uses.
71
+ */
72
+ function monoConfigFileFor(dir) {
73
+ return findMonoConfigFile(dir);
74
+ }
75
+ function findMonoConfigFile(dir) {
76
+ for (const name of [
77
+ "mono.config.ts",
78
+ "mono.config.js",
79
+ "mono.config.mjs",
80
+ "mono.config.cjs"
81
+ ]) {
82
+ const file = path.resolve(dir, name);
83
+ if (fs.existsSync(file)) return file;
84
+ }
85
+ return null;
86
+ }
87
+ /**
88
+ * Read the top-level `name: '...'` literal from mono.config.ts text without
89
+ * executing it. The first lowercase `name:` string literal is the config name —
90
+ * `apps[].name` entries appear later in the file.
91
+ */
92
+ function extractConfigName(dir) {
93
+ const file = findMonoConfigFile(dir);
94
+ if (!file) return null;
95
+ const clean = stripCommentsSafe(fs.readFileSync(file, "utf8"));
96
+ return /\bname\s*:\s*(['"`])([^'"`]+)\1/.exec(clean)?.[2] ?? null;
97
+ }
98
+ /**
99
+ * Read the top-level `template: 'host' | 'remote'` literal from mono.config.ts
100
+ * text without executing it — the same trick `extractConfigName` uses, and for
101
+ * the same reason: `monoNuxtLayers()` runs while `nuxt.config` is being loaded,
102
+ * where the config's `extends` chain (which imports the host's own config
103
+ * through an alias that does not exist yet) cannot be resolved.
104
+ *
105
+ * Only the text BEFORE `apps:` is searched, so a per-app key can never be
106
+ * mistaken for the top-level one. `null` when absent — which, per `MonoTemplate`,
107
+ * reads as `'remote'`.
108
+ */
109
+ function extractTemplate(dir) {
110
+ const file = findMonoConfigFile(dir);
111
+ if (!file) return null;
112
+ const clean = stripCommentsSafe(fs.readFileSync(file, "utf8"));
113
+ const head = clean.slice(0, /\bapps\s*:/.exec(clean)?.index ?? clean.length);
114
+ return /\btemplate\s*:\s*(['"`])(host|remote)\1/.exec(head)?.[2] ?? null;
115
+ }
116
+ /**
117
+ * Index of the bracket that closes the one opened at `startIndex`, ignoring
118
+ * brackets inside strings. Ported from `bin/mono-clone.mjs`.
119
+ */
120
+ function findMatchingBracket(code, startIndex, openChar, closeChar) {
121
+ let depth = 0;
122
+ let quote = null;
123
+ let escaped = false;
124
+ for (let i = startIndex; i < code.length; i++) {
125
+ const ch = code[i];
126
+ if (quote) {
127
+ if (escaped) {
128
+ escaped = false;
129
+ continue;
130
+ }
131
+ if (ch === "\\") {
132
+ escaped = true;
133
+ continue;
134
+ }
135
+ if (ch === quote) quote = null;
136
+ continue;
137
+ }
138
+ if (ch === "\"" || ch === "'" || ch === "`") {
139
+ quote = ch;
140
+ continue;
141
+ }
142
+ if (ch === openChar) depth++;
143
+ if (ch === closeChar) {
144
+ depth--;
145
+ if (depth === 0) return i;
146
+ }
147
+ }
148
+ return -1;
149
+ }
150
+ /** Slice the `apps: [...]` array literal text out of comment-stripped config code. */
151
+ function extractAppsArrayText(clean) {
152
+ const appsMatch = /\bapps\s*:/.exec(clean);
153
+ if (!appsMatch) return null;
154
+ const arrayStart = clean.indexOf("[", appsMatch.index + appsMatch[0].length);
155
+ if (arrayStart === -1) return null;
156
+ const arrayEnd = findMatchingBracket(clean, arrayStart, "[", "]");
157
+ if (arrayEnd === -1) return null;
158
+ return clean.slice(arrayStart, arrayEnd + 1);
159
+ }
160
+ /**
161
+ * Read a mono.config.ts's own `name`/`type` and its `apps[]` (name + type)
162
+ * WITHOUT executing it — `monoAlias` runs before the config is loaded, so it
163
+ * can only parse the source text. The apps array is eval'd in isolation (same
164
+ * approach as `bin/mono-clone.mjs`), so keep apps static (no variables/fns).
165
+ *
166
+ * The top-level `type` is read from the text BEFORE `apps:` so it can't be
167
+ * shadowed by an `apps[].type` (or a `fetching.api.*.type`). Declare the
168
+ * config's own `type` above `apps`.
169
+ */
170
+ function extractConfig(dir) {
171
+ const file = findMonoConfigFile(dir);
172
+ if (!file) return {
173
+ name: null,
174
+ type: "vue",
175
+ apps: []
176
+ };
177
+ const clean = stripCommentsSafe(fs.readFileSync(file, "utf8"));
178
+ const name = /\bname\s*:\s*(['"`])([^'"`]+)\1/.exec(clean)?.[2] ?? null;
179
+ const appsIndex = /\bapps\s*:/.exec(clean)?.index ?? clean.length;
180
+ const head = clean.slice(0, appsIndex);
181
+ const type = /\btype\s*:\s*(['"`])(vue|nuxt)\1/.exec(head)?.[2] ?? "vue";
182
+ let apps = [];
183
+ try {
184
+ const text = extractAppsArrayText(clean);
185
+ if (text) {
186
+ const parsed = Function(`"use strict"; return (${text});`)();
187
+ if (Array.isArray(parsed)) apps = parsed;
188
+ }
189
+ } catch {
190
+ apps = [];
191
+ }
192
+ return {
193
+ name,
194
+ type,
195
+ apps
196
+ };
197
+ }
198
+ /**
199
+ * Statically read the top-level `skill: { url, envToken? }` literal of a
200
+ * mono.config.ts WITHOUT executing it — the `mono skills` CLI runs in a bare
201
+ * checkout where the config's `extends` imports (other apps' aliases) may not be
202
+ * resolvable, so it can only parse the source text, exactly like `extractConfig`.
203
+ *
204
+ * Read from THIS file only: `skill` is never inherited through `extends` (see
205
+ * `MonoConfig.skill`). The object literal is eval'd in isolation, so keep it
206
+ * static — no variables, no template expressions.
207
+ *
208
+ * `null` when the key is absent (the feature is off). THROWS when the key is
209
+ * present but is not a static object literal with a string `url` — a present
210
+ * but broken `skill` must surface as an error, not silently read as "off".
211
+ */
212
+ function extractSkill(dir) {
213
+ const file = findMonoConfigFile(dir);
214
+ if (!file) return null;
215
+ const clean = stripCommentsSafe(fs.readFileSync(file, "utf8"));
216
+ const keyMatch = /\bskill\s*:\s*\{/.exec(clean);
217
+ if (!keyMatch) return null;
218
+ const objStart = keyMatch.index + keyMatch[0].length - 1;
219
+ const objEnd = findMatchingBracket(clean, objStart, "{", "}");
220
+ if (objEnd === -1) throw new Error(`mono.config.ts: unterminated \`skill: {\` literal in ${file}`);
221
+ let parsed;
222
+ try {
223
+ parsed = Function(`"use strict"; return (${clean.slice(objStart, objEnd + 1)});`)();
224
+ } catch (e) {
225
+ throw new Error(`mono.config.ts: \`skill\` must be a static object literal ({ url, envToken? }) — ${e.message}`);
226
+ }
227
+ const obj = parsed;
228
+ if (!obj || typeof obj !== "object" || Array.isArray(obj)) throw new Error("mono.config.ts: `skill` must be an object literal ({ url, envToken? })");
229
+ if (typeof obj.url !== "string" || !obj.url.trim()) throw new Error("mono.config.ts: `skill.url` must be a non-empty string literal");
230
+ if (obj.envToken != null && (typeof obj.envToken !== "string" || !obj.envToken.trim())) throw new Error("mono.config.ts: `skill.envToken` must be a non-empty string (the env var NAME)");
231
+ return {
232
+ url: obj.url.trim(),
233
+ ...typeof obj.envToken === "string" ? { envToken: obj.envToken.trim() } : {}
234
+ };
235
+ }
236
+ /**
237
+ * Every `apps[]` entry must say where it comes from: a `url` (`mono sync`
238
+ * clones it), a `path` (read in place), or both (`path` wins, `url` is the
239
+ * fallback when the directory is absent). An entry with neither is a config
240
+ * error, reported here by name rather than as a mysterious missing alias later.
241
+ *
242
+ * Run on the ROOT config only — a sibling's config is that sibling's business
243
+ * and is validated when IT runs.
244
+ */
245
+ function assertAppSources(apps, file) {
246
+ for (const app of apps) {
247
+ const name = typeof app?.name === "string" && app.name ? app.name : JSON.stringify(app);
248
+ const url = typeof app?.url === "string" && app.url.trim();
249
+ const declaredPath = app?.path;
250
+ if (declaredPath != null && (typeof declaredPath !== "string" || !declaredPath.trim())) throw new Error(`[mono] mono.config.ts (${file}): app '${name}' has a \`path\` that is not a non-empty string`);
251
+ if (!url && !(typeof declaredPath === "string" && declaredPath.trim())) throw new Error(`[mono] mono.config.ts (${file}): app '${name}' declares neither url nor path — add \`url\` (synced by mono sync) or \`path\` (read in place).`);
252
+ }
253
+ }
254
+ /**
255
+ * The root config's apps, plus ONE level of the apps each of those declares by
256
+ * `path` — resolved against THAT app's directory, not ours.
257
+ *
258
+ * In a mono-lith every sibling carries its own `mono.config.ts`, and a
259
+ * remote's config can name a third sibling this root never listed. Its
260
+ * `extends` chain then imports `@<third>-root/mono.config`, which only
261
+ * resolves if that app has an alias here. So "present" and "aliased" are
262
+ * decided by this one walk, and `monoAlias` / `monoMissingApps` both take its
263
+ * answer.
264
+ *
265
+ * One level, never recursive: a host and its remote list each other, and the
266
+ * cycle must not loop. A sibling's own `.mono/apps` is never listed
267
+ * (`listClones: false`) — its clones are its standalone-dev business — and a
268
+ * sibling's missing `path` is skipped silently (`onMissingPath: 'ignore'`):
269
+ * that sibling reports it when it runs.
270
+ */
271
+ function resolveFederatedRoots(opts) {
272
+ const { dirname, appsDir = "./.mono/apps", onMissingPath = "report" } = opts;
273
+ const own = extractConfig(dirname);
274
+ const roots = resolveAppRoots({
275
+ dirname,
276
+ appsDir,
277
+ apps: own.apps,
278
+ onMissingPath
279
+ });
280
+ const seen = new Set(roots.map((r) => r.name));
281
+ if (own.name) seen.add(own.name);
282
+ for (const root of [...roots]) {
283
+ const declared = extractConfig(root.root).apps.filter((a) => a?.name && typeof a.path === "string" && a.path.trim() && !seen.has(a.name));
284
+ if (!declared.length) continue;
285
+ for (const found of resolveAppRoots({
286
+ dirname: root.root,
287
+ apps: declared,
288
+ listClones: false,
289
+ onMissingPath: "ignore"
290
+ })) {
291
+ if (seen.has(found.name)) continue;
292
+ seen.add(found.name);
293
+ roots.push({
294
+ ...found,
295
+ via: root.name
296
+ });
297
+ }
298
+ }
299
+ return roots;
300
+ }
301
+ /**
302
+ * Build the mono alias map for both Vite's `resolve.alias` and the jiti alias
303
+ * that `getMonoConfig` needs to parse `mono.config.ts`.
304
+ *
305
+ * The source subdir of each app is derived from its `type` (`vue` -> `src`,
306
+ * `nuxt` -> `app`): the own type from the config's top-level `type`, each
307
+ * remote's from its `apps[].type`. Unknown types fall back to `srcDir`.
308
+ *
309
+ * Convention (keyed off app names; `<src>` = `srcDirForType(type)`):
310
+ * - `@<own-name>` -> `<dirname>/<src>`
311
+ * - `@<own-name>-root` -> `<dirname>`
312
+ * - `@<remote>` -> `<dirname>/.mono/apps/<remote>/<src>`
313
+ * - `@<remote>-root` -> `<dirname>/.mono/apps/<remote>`
314
+ * - `@mono-apps` -> `<dirname>/.mono/apps`
315
+ *
316
+ * Name/type are read from `mono.config.ts` (or passed via `name`/`ownType`/
317
+ * `appTypes`). Remotes come from {@link resolveFederatedRoots}: the
318
+ * `.mono/apps/` listing, plus every app whose `apps[].path` names a directory
319
+ * — in which case `@<remote>` resolves THERE, in every command — plus the
320
+ * `path` apps those apps declare themselves. Returns absolute paths.
321
+ */
322
+ function monoAlias(opts) {
323
+ const { dirname, appsDir = "./.mono/apps", srcDir = "src", rootSuffix = "-root" } = opts;
324
+ const appsRoot = path.resolve(dirname, appsDir);
325
+ const parsed = extractConfig(dirname);
326
+ const own = opts.name ?? parsed.name;
327
+ if (!own) throw new Error("[@mono-lit/utility] monoAlias: could not read `name` from mono.config.ts. Pass { name } explicitly, or ensure name is a top-level string literal.");
328
+ const typeMap = {};
329
+ for (const app of parsed.apps) if (app?.name && app?.type) typeMap[app.name] = app.type;
330
+ Object.assign(typeMap, opts.appTypes ?? {});
331
+ const srcFor = (name) => {
332
+ const t = typeMap[name];
333
+ return t ? srcDirForType(t) : srcDir;
334
+ };
335
+ const ownType = opts.ownType ?? parsed.type;
336
+ const ownSrc = ownType ? srcDirForType(ownType) : srcDir;
337
+ const alias = {
338
+ "@mono-apps": appsRoot,
339
+ [`@${own}`]: path.resolve(dirname, ownSrc),
340
+ [`@${own}${rootSuffix}`]: path.resolve(dirname, ".")
341
+ };
342
+ for (const { name, root, type } of resolveFederatedRoots({
343
+ dirname,
344
+ appsDir
345
+ })) {
346
+ if (type && !typeMap[name]) typeMap[name] = type;
347
+ if (name === own) continue;
348
+ alias[`@${name}`] = path.resolve(root, srcFor(name));
349
+ alias[`@${name}${rootSuffix}`] = root;
350
+ }
351
+ return alias;
352
+ }
353
+ /** `from '@x/y'` / `import('@x')` — the alias specifiers a config file imports. */
354
+ const IMPORT_SPECIFIER_RE = /(?:\bfrom|\bimport)\s*\(?\s*['"]@([A-Za-z0-9_.-]+)(?:\/[^'"]*)?['"]/g;
355
+ /**
356
+ * Apps that are federated somewhere in the chain but aren't on disk.
357
+ *
358
+ * A cloned app never carries its own `.mono/` (gitignored, so it's absent from the
359
+ * archive `mono sync` downloads), so a host that federates apps of its own arrives
360
+ * with `import … from '@some-app-root/mono.config'` and nothing to resolve it
361
+ * against. `monoAlias` keys off the `.mono/apps/` DIRECTORY LISTING, so there is no
362
+ * key and jiti falls through to bare-package resolution — `Cannot find module`, and
363
+ * the config never loads. Finding those names first is what lets
364
+ * {@link monoStubAliases} neutralise them.
365
+ *
366
+ * Static only — {@link extractConfig} text-parses each config without executing it,
367
+ * which is the sole option: this runs BEFORE any config can be loaded.
368
+ *
369
+ * Two sources, union'd:
370
+ * - names in any reachable `apps[]` with no directory (carries `envToken`)
371
+ * - `@<name>-root/…` import specifiers with no alias key — covers a config that
372
+ * imports an app it never declared in `apps[]`
373
+ *
374
+ * Only the `-root` suffix form is scanned for the second source: `@scope/pkg` npm
375
+ * imports are syntactically identical to `@app/file`, and mistaking `@vueuse/core`
376
+ * for a mono app would stub a real dependency out of the build.
377
+ */
378
+ function monoMissingApps(opts) {
379
+ const { dirname, appsDir = "./.mono/apps", rootSuffix = "-root" } = opts;
380
+ const root = extractConfig(dirname);
381
+ const rootFor = /* @__PURE__ */ new Map();
382
+ for (const app of resolveFederatedRoots({
383
+ dirname,
384
+ appsDir
385
+ })) rootFor.set(app.name, app.root);
386
+ const present = new Set(rootFor.keys());
387
+ const own = root.name;
388
+ const missing = /* @__PURE__ */ new Map();
389
+ const consider = (name, via, envToken) => {
390
+ if (typeof name !== "string" || !name) return;
391
+ if (name === own || present.has(name) || missing.has(name)) return;
392
+ missing.set(name, {
393
+ name,
394
+ via,
395
+ ...typeof envToken === "string" && envToken ? { envToken } : {}
396
+ });
397
+ };
398
+ const sources = [{
399
+ dir: dirname,
400
+ via: own ?? "<root>",
401
+ config: root
402
+ }];
403
+ for (const [name, dir] of rootFor) sources.push({
404
+ dir,
405
+ via: name,
406
+ config: extractConfig(dir)
407
+ });
408
+ for (const { dir, via, config } of sources) {
409
+ for (const app of config.apps) consider(app?.name, via, app?.envToken);
410
+ for (const name of importedAppAliases(dir, rootSuffix)) consider(name, via);
411
+ }
412
+ return [...missing.values()];
413
+ }
414
+ /** `@<name>-root` specifiers imported by a config, as bare `<name>`s. */
415
+ function importedAppAliases(dir, rootSuffix) {
416
+ const file = findMonoConfigFile(dir);
417
+ if (!file) return [];
418
+ const clean = stripCommentsSafe(fs.readFileSync(file, "utf8"));
419
+ const names = [];
420
+ for (const match of clean.matchAll(IMPORT_SPECIFIER_RE)) {
421
+ const specifier = match[1];
422
+ if (!specifier.endsWith(rootSuffix) || specifier === rootSuffix) continue;
423
+ names.push(specifier.slice(0, -rootSuffix.length));
424
+ }
425
+ return names;
426
+ }
427
+ /** Config filenames an `extends` import can name — each needs its own exact key. */
428
+ const STUB_SPECIFIERS = [
429
+ "/mono.config",
430
+ "/mono.config.ts",
431
+ "/mono.config.js",
432
+ "/mono.config.mjs"
433
+ ];
434
+ /** Written once into `.mono/`; `.mono/` is generated and gitignored already. */
435
+ const STUB_FILENAME = "empty-mono-config.mjs";
436
+ const STUB_SOURCE = `// Generated by @mono-lit/utility — do not edit, do not commit (.mono/ is gitignored).
437
+ //
438
+ // Stands in for the \`mono.config\` of a federated app that isn't synced into
439
+ // .mono/apps/. Importing it makes the extends chain resolve; merging it
440
+ // contributes nothing. See \`monoStubAliases\` in @mono-lit/utility.
441
+ export default { apps: [], extends: [] }
442
+ `;
443
+ /**
444
+ * Alias entries that let a config chain load with apps missing from `.mono/apps/`.
445
+ *
446
+ * Each unsynced app gets EXACT keys for its config specifier only —
447
+ * `@<name>-root/mono.config` (+ `.ts`/`.js`/`.mjs`, and the `@<name>` form) — all
448
+ * pointing at one generated module that exports `{ apps: [], extends: [] }`. The
449
+ * import resolves, the layer merges to nothing, the build starts.
450
+ *
451
+ * Deliberately NOT the bare `@<name>` / `@<name>-root` prefixes: app code that
452
+ * imports a missing app (`@some-app/components/Foo.vue`) must still fail loudly. A
453
+ * page that can't exist is better than a page that silently renders blank.
454
+ *
455
+ * Exact keys work because alias matching (pathe's `resolveAlias`, used by jiti;
456
+ * the same rule in Vite) treats a key with no trailing segment as a full match, and
457
+ * sorts keys with more slashes first — so `@x-root/mono.config` is always tried
458
+ * before `@x-root`. For a missing app that prefix key doesn't exist anyway.
459
+ *
460
+ * Merge into BOTH alias maps: jiti's (so `getMonoConfig` can load) and Vite's (the
461
+ * browser graph resolves the same chain via `import monoConfig from '../mono.config'`
462
+ * in an app's `main.ts` — stub only jiti and the dev server starts, then dies on
463
+ * first page load).
464
+ */
465
+ function monoStubAliases(opts) {
466
+ const { dirname, appsDir = "./.mono/apps", rootSuffix = "-root" } = opts;
467
+ const missing = opts.missing ?? monoMissingApps(opts);
468
+ if (!missing.length) return {
469
+ alias: {},
470
+ missing,
471
+ stubFile: null
472
+ };
473
+ const monoDir = path.resolve(dirname, appsDir, "..");
474
+ const stubFile = path.join(monoDir, STUB_FILENAME);
475
+ if (!fs.existsSync(stubFile)) {
476
+ fs.mkdirSync(monoDir, { recursive: true });
477
+ fs.writeFileSync(stubFile, STUB_SOURCE);
478
+ }
479
+ const alias = {};
480
+ for (const { name } of missing) for (const base of [`@${name}`, `@${name}${rootSuffix}`]) for (const specifier of STUB_SPECIFIERS) alias[base + specifier] = stubFile;
481
+ return {
482
+ alias,
483
+ missing,
484
+ stubFile
485
+ };
486
+ }
487
+ /**
488
+ * The warning for stubbed apps — names them, says what was lost, and gives the
489
+ * command that fixes it. `envToken` is the actionable part: a private repo fails to
490
+ * sync silently until someone knows which variable to set.
491
+ */
492
+ function formatMissingApps(missing) {
493
+ const lines = missing.map(({ name, via, envToken }) => {
494
+ return ` • ${name} (required by ${via})${envToken ? ` envToken: ${envToken}` : ""}`;
495
+ });
496
+ return [
497
+ `[@mono-lit/utility] ${missing.length} federated app(s) are NOT synced into .mono/apps/:`,
498
+ ...lines,
499
+ "Their `mono.config` imports were stubbed with an empty config so the build could start.",
500
+ "Pages, components, composables and stores from them are NOT available.",
501
+ "Fix: run `mono sync && mono prepare`, declare them in this app’s own `apps[]`,",
502
+ "or point at a local checkout with `apps[].path`.",
503
+ "If a repo is private, set its envToken in .env."
504
+ ].join("\n");
505
+ }
506
+
507
+ //#endregion
508
+ export { extractTemplate as a, monoConfigFileFor as c, resolveFederatedRoots as d, stripCommentsSafe as f, extractSkill as i, monoMissingApps as l, extractConfig as n, formatMissingApps as o, extractConfigName as r, monoAlias as s, assertAppSources as t, monoStubAliases as u };