@mono-lit/utility 0.0.0-stage → 0.0.1

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 +156 -2
  3. package/dist/app-roots-BJsIxzjk.d.ts +91 -0
  4. package/dist/app-roots-CvJnmXcs.js +128 -0
  5. package/dist/config-node-UzJrXg0Z.js +76 -0
  6. package/dist/config-node.d.ts +977 -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-D3m6xTaQ.d.ts +733 -0
  11. package/dist/create-config-DdL3Fh6T.js +357 -0
  12. package/dist/fetching.d.ts +239 -0
  13. package/dist/fetching.js +867 -0
  14. package/dist/generate-CJ7MtcDd.js +291 -0
  15. package/dist/index-C2hZeNkq.d.ts +365 -0
  16. package/dist/index-ClrZbU7n.d.ts +518 -0
  17. package/dist/index.d.ts +29 -0
  18. package/dist/index.js +939 -0
  19. package/dist/merge-file-C5nzi_MY.d.ts +122 -0
  20. package/dist/merge-file-CtyKTu5L.js +133 -0
  21. package/dist/mock-db-5mJTObSC.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 +151 -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 +27 -0
  33. package/dist/mono-skills.d.ts +1 -0
  34. package/dist/mono-skills.js +830 -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 +34 -0
  39. package/dist/nuxt-layers.js +3 -0
  40. package/dist/nuxt-runtime.d.ts +18 -0
  41. package/dist/nuxt-runtime.js +102 -0
  42. package/dist/nuxt.d.ts +386 -0
  43. package/dist/nuxt.js +590 -0
  44. package/dist/runtime-C_IWNrAG.js +5817 -0
  45. package/dist/runtime.d.ts +2583 -0
  46. package/dist/runtime.js +4 -0
  47. package/dist/session-Bk985AIM.js +1721 -0
  48. package/dist/types-B6FdB7LJ.d.ts +57 -0
  49. package/dist/universal-B2eD9xho.d.ts +97 -0
  50. package/dist/universal-BNTo_83u.js +599 -0
  51. package/dist/virtual-mono-apps.d.ts +16 -0
  52. package/dist/vite.d.ts +940 -0
  53. package/dist/vite.js +1132 -0
  54. package/package.json +141 -3
@@ -0,0 +1,204 @@
1
+ import { c as resolveAppRoots } from "./app-roots-CvJnmXcs.js";
2
+ import { f as stripCommentsSafe, n as extractConfig, s as monoAlias } from "./mono-alias-DNDm-jB_.js";
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { readTSConfig, writeTSConfig } from "pkg-types";
6
+
7
+ //#region src/composables/mono-tsconfig.ts
8
+ /** Folder (relative to an app root) that holds the generated tsconfig. */
9
+ const MONO_DIR = ".mono";
10
+ /** Reference to the generated tsconfig, as written into the root `extends`. */
11
+ const MONO_TSCONFIG_REF = `./${MONO_DIR}/tsconfig.json`;
12
+ /** Folder (relative to an app root) that holds the cloned remotes. */
13
+ const MONO_APPS_DIR = `${MONO_DIR}/apps`;
14
+ /**
15
+ * Turn an absolute path into a POSIX, tsconfig-friendly relative path from
16
+ * `fromDir`, always prefixed with `./` or `../` so TypeScript treats it as a
17
+ * path mapping rather than a bare module name.
18
+ */
19
+ function toRelativePosix(fromDir, absTarget) {
20
+ let rel = path.relative(fromDir, absTarget).split(path.sep).join("/");
21
+ if (rel === "") rel = ".";
22
+ if (!rel.startsWith(".")) rel = `./${rel}`;
23
+ return rel;
24
+ }
25
+ /**
26
+ * Build the `compilerOptions.paths` map for `.mono/tsconfig.json` from the mono
27
+ * alias map.
28
+ *
29
+ * `monoAlias` returns absolute directory paths keyed WITHOUT a `/*` glob (e.g.
30
+ * `@mono-host` -> `<abs>/src`). tsconfig `paths` need the `/*` glob on both the
31
+ * key and the value, and the value must be relative to the `.mono/` folder that
32
+ * the file lives in. So `@mono-host` -> `{ "@mono-host/*": ["../src/*"] }`.
33
+ *
34
+ * All alias/type/srcDir rules are inherited from `monoAlias` — nothing is
35
+ * re-implemented here.
36
+ */
37
+ function monoTsconfigPaths(opts) {
38
+ const monoDir = path.resolve(opts.dirname, MONO_DIR);
39
+ const alias = monoAlias(opts);
40
+ const paths = {};
41
+ for (const [key, absDir] of Object.entries(alias)) {
42
+ const rel = toRelativePosix(monoDir, absDir);
43
+ paths[`${key}/*`] = [`${rel}/*`];
44
+ }
45
+ return paths;
46
+ }
47
+ /** The object written to `<dirname>/.mono/tsconfig.json`. */
48
+ function buildMonoTsconfig(opts) {
49
+ return { compilerOptions: { paths: monoTsconfigPaths(opts) } };
50
+ }
51
+ /** Normalise a tsconfig `extends` field (string | string[] | undefined) to an array. */
52
+ function extendsToArray(value) {
53
+ if (!value) return [];
54
+ return Array.isArray(value) ? [...value] : [value];
55
+ }
56
+ /**
57
+ * Point every cloned remote's `tsconfig.json` at the host's generated
58
+ * `.mono/tsconfig.json` (as `../../tsconfig.json`), and strip the inline alias
59
+ * keys that file now owns.
60
+ *
61
+ * WHY: a clone arrives with no usable `paths`. Its own `.mono/tsconfig.json` is
62
+ * gitignored, so it is absent from the archive `mono sync` downloads, and
63
+ * `sanitizeClonedTsconfig` then strips the dangling `.mono` `extends` from it.
64
+ * That matters beyond editor comfort: `@vue/compiler-sfc` resolves the type-only
65
+ * imports in `defineProps<ImportedType>()` through the NEAREST tsconfig's `paths`
66
+ * (`ts.findConfigFile` walks up from the SFC and stops at the clone's own
67
+ * tsconfig — it never reaches the host's). Vite's `resolve.alias` is invisible to
68
+ * it. So a remote whose SFCs do `defineProps<NodeWrapperProps>()` with
69
+ * `import type { NodeWrapperProps } from '@some-app/types'` breaks the host build
70
+ * with `Failed to resolve import source "@some-app/types"` unless the clone's
71
+ * tsconfig maps the alias.
72
+ *
73
+ * The host already has every mapping it needs — `.mono/tsconfig.json` covers each
74
+ * remote (`@flow-app/*` -> `./apps/flow-app/src/*`) and its `paths` are relative
75
+ * to `.mono/`, so they stay correct when inherited from a clone two levels down.
76
+ * Wiring it here means remotes need no committed workaround of their own.
77
+ *
78
+ * The ref goes LAST for the same reason as the root tsconfig: tsconfig replaces
79
+ * the whole `paths` object with the last config that defines it, so the generated
80
+ * map wins over anything else the clone extends. Idempotent.
81
+ */
82
+ async function wireClonedApps(dirname, monoTsconfigPath, writtenKeys) {
83
+ const wired = [];
84
+ const roots = resolveAppRoots({
85
+ dirname,
86
+ appsDir: MONO_APPS_DIR,
87
+ apps: extractConfig(dirname).apps,
88
+ onMissingPath: "ignore"
89
+ });
90
+ for (const { name: appName, root: appDir } of roots.filter((r) => r.source === "clone")) {
91
+ const appTsconfigPath = path.join(appDir, "tsconfig.json");
92
+ if (!fs.existsSync(appTsconfigPath)) continue;
93
+ const ref = toRelativePosix(appDir, monoTsconfigPath);
94
+ try {
95
+ const raw = fs.readFileSync(appTsconfigPath, "utf8");
96
+ const app = await readTSConfig(appTsconfigPath);
97
+ if (Object.keys(app).length === 0 && stripCommentsSafe(raw).replace(/\s+/g, "") !== "{}") continue;
98
+ const before = extendsToArray(app.extends);
99
+ const next = [...before.filter((r) => r !== ref), ref];
100
+ let strippedPaths = false;
101
+ const appPaths = app.compilerOptions?.paths;
102
+ if (appPaths) {
103
+ for (const key of writtenKeys) if (key in appPaths) {
104
+ delete appPaths[key];
105
+ strippedPaths = true;
106
+ }
107
+ if (Object.keys(appPaths).length === 0) delete app.compilerOptions.paths;
108
+ }
109
+ if (before.length === next.length && before.every((r, i) => r === next[i]) && !strippedPaths) continue;
110
+ app.extends = next;
111
+ await writeTSConfig(appTsconfigPath, app);
112
+ wired.push(appName);
113
+ } catch {}
114
+ }
115
+ return wired;
116
+ }
117
+ /**
118
+ * Generate `<dirname>/.mono/tsconfig.json` from the mono alias map and wire it
119
+ * into the root `tsconfig.json` via `extends`, stripping the now-redundant
120
+ * inline `@mono-*` paths. Idempotent: safe to run repeatedly.
121
+ */
122
+ async function runMonoPrepare(opts) {
123
+ const { dirname } = opts;
124
+ const tsconfig = buildMonoTsconfig({ dirname });
125
+ const writtenKeys = Object.keys(tsconfig.compilerOptions?.paths ?? {});
126
+ const writtenPaths = tsconfig.compilerOptions?.paths ?? {};
127
+ const monoDir = path.resolve(dirname, MONO_DIR);
128
+ if (!fs.existsSync(monoDir)) fs.mkdirSync(monoDir, { recursive: true });
129
+ const monoTsconfigPath = path.join(monoDir, "tsconfig.json");
130
+ await writeTSConfig(monoTsconfigPath, tsconfig);
131
+ const rootTsconfigPath = path.resolve(dirname, "tsconfig.json");
132
+ if (!fs.existsSync(rootTsconfigPath)) throw new Error(`[@mono-lit/utility] mono prepare: no tsconfig.json found at ${rootTsconfigPath}`);
133
+ const root = await readTSConfig(rootTsconfigPath);
134
+ const outsideProject = pathsOutsideProject(dirname, writtenPaths);
135
+ const rootDir = root.compilerOptions?.rootDir;
136
+ if (rootDir && outsideProject.length) console.warn(`[mono] tsconfig.json sets rootDir "${rootDir}" but ${outsideProject.join(", ")} map outside the project (apps[].path siblings). Remove rootDir, or set it to the folder that contains every sibling (e.g. "../").`);
137
+ const previousExtends = extendsToArray(root.extends);
138
+ const addedExtends = !previousExtends.includes(MONO_TSCONFIG_REF);
139
+ root.extends = [...previousExtends.filter((ref) => ref !== MONO_TSCONFIG_REF), MONO_TSCONFIG_REF];
140
+ const removedKeys = [];
141
+ const rootPaths = root.compilerOptions?.paths;
142
+ if (rootPaths) {
143
+ for (const key of writtenKeys) if (key in rootPaths) {
144
+ delete rootPaths[key];
145
+ removedKeys.push(key);
146
+ }
147
+ if (Object.keys(rootPaths).length === 0) delete root.compilerOptions.paths;
148
+ }
149
+ await writeTSConfig(rootTsconfigPath, root);
150
+ const wiredApps = await wireClonedApps(dirname, monoTsconfigPath, writtenKeys);
151
+ const unpreparedApps = unpreparedPathApps(dirname);
152
+ if (unpreparedApps.length) console.warn(`[mono] ${unpreparedApps.join(", ")}: tsconfig.json extends ./.mono/tsconfig.json but the file is missing — run \`mono prepare\` in that app.`);
153
+ return {
154
+ monoTsconfigPath,
155
+ rootTsconfigPath,
156
+ writtenKeys,
157
+ removedKeys,
158
+ addedExtends,
159
+ wiredApps,
160
+ outsideProject,
161
+ unpreparedApps
162
+ };
163
+ }
164
+ /** Written alias keys whose target directory is not under `dirname`. */
165
+ function pathsOutsideProject(dirname, paths) {
166
+ const monoDir = path.resolve(dirname, MONO_DIR);
167
+ const outside = [];
168
+ for (const [key, targets] of Object.entries(paths)) for (const target of targets) {
169
+ const abs = path.resolve(monoDir, target.replace(/\/\*$/, ""));
170
+ const rel = path.relative(dirname, abs);
171
+ if (rel.startsWith("..") || path.isAbsolute(rel)) {
172
+ outside.push(key);
173
+ break;
174
+ }
175
+ }
176
+ return outside;
177
+ }
178
+ /** `path` apps whose tsconfig extends a `.mono/tsconfig.json` that does not exist. */
179
+ function unpreparedPathApps(dirname) {
180
+ const names = [];
181
+ const roots = resolveAppRoots({
182
+ dirname,
183
+ appsDir: MONO_APPS_DIR,
184
+ apps: extractConfig(dirname).apps,
185
+ onMissingPath: "ignore",
186
+ listClones: false
187
+ });
188
+ for (const { name, root } of roots) {
189
+ const tsconfigPath = path.join(root, "tsconfig.json");
190
+ if (!fs.existsSync(tsconfigPath)) continue;
191
+ let refs = [];
192
+ try {
193
+ refs = extendsToArray(JSON.parse(stripCommentsSafe(fs.readFileSync(tsconfigPath, "utf8")))?.extends);
194
+ } catch {
195
+ continue;
196
+ }
197
+ const ref = refs.find((r) => r.replace(/\\/g, "/").endsWith(`${MONO_DIR}/tsconfig.json`));
198
+ if (ref && !fs.existsSync(path.resolve(root, ref))) names.push(name);
199
+ }
200
+ return names;
201
+ }
202
+
203
+ //#endregion
204
+ export { monoTsconfigPaths as a, buildMonoTsconfig as i, MONO_DIR as n, runMonoPrepare as o, MONO_TSCONFIG_REF as r, MONO_APPS_DIR as t };
package/dist/mono.mjs ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from 'node:child_process'
3
+ import { fileURLToPath } from 'node:url'
4
+ import { dirname, resolve } from 'node:path'
5
+
6
+ const here = dirname(fileURLToPath(import.meta.url))
7
+ const [sub, ...rest] = process.argv.slice(2)
8
+
9
+ const targets = {
10
+ env: 'mono-env.mjs',
11
+ sync: 'mono-clone.mjs',
12
+ prepare: 'mono-prepare.js',
13
+ skills: 'mono-skills.js',
14
+ db: 'mono-db.js',
15
+ }
16
+
17
+ const target = targets[sub]
18
+
19
+ if (!target) {
20
+ console.error('Usage: mono <command> [...args]')
21
+ console.error('Commands:')
22
+ console.error(' env -e <file> [-a <app>] [-r <dir>] -- <cmd> Load env, then run <cmd>')
23
+ console.error(' sync [--no-prune] Sync apps from mono.config into .mono/apps (an app removed from `apps[]` is deleted; --no-prune keeps it)')
24
+ console.error(' prepare [--cwd <dir>] Generate .mono/tsconfig.json and wire it into root tsconfig')
25
+ console.error(' skills <check|init|save|retry|read|search|sync|session|template|...> MONO Skills: app knowledge + AI session history in the repo set as `skill` in mono.config.ts')
26
+ console.error(' db <validate|preview|export> Mock IndexedDB backend: validate schemas, preview seed data')
27
+ process.exit(sub ? 1 : 0)
28
+ }
29
+
30
+ const result = spawnSync(process.execPath, [resolve(here, target), ...rest], {
31
+ stdio: 'inherit',
32
+ })
33
+
34
+ process.exit(result.status ?? 1)
@@ -0,0 +1,176 @@
1
+ import { c as resolveAppRoots } from "./app-roots-CvJnmXcs.js";
2
+ import { a as extractTemplate, n as extractConfig } from "./mono-alias-DNDm-jB_.js";
3
+ import { existsSync } from "node:fs";
4
+ import { join, normalize, resolve } from "node:path";
5
+
6
+ //#region src/nuxt/nuxt-layers.ts
7
+ /** Config filenames Nuxt accepts at a layer root. */
8
+ const NUXT_CONFIG_FILES = [
9
+ "nuxt.config.ts",
10
+ "nuxt.config.mts",
11
+ "nuxt.config.cts",
12
+ "nuxt.config.js",
13
+ "nuxt.config.mjs",
14
+ "nuxt.config.cjs"
15
+ ];
16
+ /** The `nuxt.config.*` at `dir`, or `null` — what makes a directory layer-able. */
17
+ function nuxtConfigFile(dir) {
18
+ for (const name of NUXT_CONFIG_FILES) {
19
+ const file = join(dir, name);
20
+ if (existsSync(file)) return file;
21
+ }
22
+ return null;
23
+ }
24
+ /**
25
+ * Which federated apps should be merged by **Nuxt's own layer machinery**
26
+ * instead of by mono's ecosystem merge.
27
+ *
28
+ * When both sides are Nuxt, Nuxt already does everything that merge does, and
29
+ * does it better: pages, layouts, middleware, plugins, components, `app.vue`,
30
+ * `error.vue` and `app/router.options.ts` are all resolved across layers, with
31
+ * the CONSUMING app winning on any file at the same path relative to its srcDir.
32
+ * That last rule is the own-file-wins behaviour mono has to implement by hand —
33
+ * here it is free, and exactly right.
34
+ *
35
+ * Three conditions, each load-bearing:
36
+ *
37
+ * - **`type: 'nuxt'`.** A Vue remote has no Nuxt srcDir convention and no
38
+ * `nuxt.config`; it can only go through mono's merge.
39
+ * - **a `nuxt.config.*` on disk.** An app that has not been synced yet has an
40
+ * empty (or absent) directory, and mono's merge already degrades gracefully
41
+ * there — `monoStubAliases` stubs its config so the chain still loads.
42
+ * - **not `template: 'host'`.** Layers are all-or-nothing, so opting a host in
43
+ * would hand it its remotes' `layouts/` with no way to refuse — the one thing
44
+ * `template` exists to prevent. Mono's merge CAN gate layouts, so a host keeps
45
+ * using it.
46
+ */
47
+ function monoLayerCandidates({ apps, appRoots, template }) {
48
+ if (template === "host") return [];
49
+ const out = [];
50
+ for (const app of apps) {
51
+ if (app?.type !== "nuxt" || !app.name) continue;
52
+ const root = appRoots.find((r) => r.name === app.name)?.root;
53
+ if (!root) continue;
54
+ const configFile = nuxtConfigFile(root);
55
+ if (!configFile) continue;
56
+ out.push({
57
+ name: app.name,
58
+ root,
59
+ configFile
60
+ });
61
+ }
62
+ return out;
63
+ }
64
+ /**
65
+ * A `NuxtConfigLayer` for a federated app, minimal but complete.
66
+ *
67
+ * Only what the LAZY layer consumers read is filled in — `getLayerDirectories`
68
+ * (`@nuxt/kit`) wants `config.rootDir` / `config.srcDir` / `config.dir.*` /
69
+ * `config.serverDir` / `cwd`, and that feeds `resolveApp`, the pages scan and
70
+ * the components scan.
71
+ *
72
+ * Everything else in the layer's real `nuxt.config` is deliberately NOT read.
73
+ * Nuxt merges layer config (modules, css, vite, devServer, hooks, sentry…)
74
+ * while LOADING the config, long before any module runs, so a layer registered
75
+ * from a module contributes files only. That is the behaviour we want: a remote
76
+ * wants the host's shell, not its dev-server port, its Sentry DSN or a second
77
+ * registration of every module it already lists itself.
78
+ */
79
+ function buildMonoNuxtLayer(candidate) {
80
+ const { root, configFile } = candidate;
81
+ return {
82
+ cwd: root,
83
+ configFile,
84
+ config: {
85
+ rootDir: root,
86
+ srcDir: join(root, "app"),
87
+ serverDir: join(root, "server"),
88
+ dir: {
89
+ pages: "pages",
90
+ layouts: "layouts",
91
+ middleware: "middleware",
92
+ plugins: "plugins",
93
+ modules: "modules",
94
+ public: "public",
95
+ shared: "shared",
96
+ app: "app"
97
+ }
98
+ }
99
+ };
100
+ }
101
+ /**
102
+ * Append federated Nuxt apps to `nuxt.options._layers`, returning the names now
103
+ * handled by Nuxt.
104
+ *
105
+ * **Appended, never prepended.** `getLayerDirectories` preserves `_layers`
106
+ * order, and every consumer treats earlier layers as higher priority —
107
+ * `layouts[name] ||= …` keeps the first, `app.mainComponent ||= findPath(…)`
108
+ * takes the first hit, pages dedupe on the first route. Layer 0 is the
109
+ * consuming app, so appending is what makes ITS files win.
110
+ *
111
+ * **Why this works from inside a module at all.** Nuxt reads `_layers` lazily
112
+ * for everything that matters here: `resolveApp` (layouts, middleware, plugins,
113
+ * app.vue, error.vue), the pages scan and the components scan all run on
114
+ * `app:resolve`, well after modules are installed. The one early reader is the
115
+ * `nuxt:imports` module, which snapshots composables dirs in its own `setup()` —
116
+ * so composables and stores are NOT covered here and keep going through
117
+ * `addImportsDir`, which is hook-based and therefore still open.
118
+ */
119
+ function registerMonoNuxtLayers({ nuxt, candidates }) {
120
+ if (!candidates.length) return /* @__PURE__ */ new Set();
121
+ const layers = nuxt.options._layers ?? [];
122
+ if (!nuxt.options._layers) nuxt.options._layers = layers;
123
+ const known = new Set(layers.map((layer) => normalize(String(layer.cwd ?? "")).toLowerCase()));
124
+ const added = /* @__PURE__ */ new Set();
125
+ for (const candidate of candidates) {
126
+ if (known.has(normalize(candidate.root).toLowerCase())) {
127
+ added.add(candidate.name);
128
+ continue;
129
+ }
130
+ layers.push(buildMonoNuxtLayer(candidate));
131
+ added.add(candidate.name);
132
+ }
133
+ return added;
134
+ }
135
+ /**
136
+ * The same federated Nuxt apps as absolute directories, for a `nuxt.config`
137
+ * that wants to declare them by hand:
138
+ *
139
+ * ```ts
140
+ * export default defineNuxtConfig({ extends: monoNuxtLayers() })
141
+ * ```
142
+ *
143
+ * **You do not need this.** `@mono-lit/utility/nuxt` registers the layers itself, from
144
+ * `mono.config.ts`, so a remote's `nuxt.config.ts` is identical to a host's.
145
+ * This exists for the case where a layer's own `nuxt.config` must be merged too
146
+ * (its `modules`, `css`, `vite` options) — declaring `extends` at config-load
147
+ * time is the only way to get that, and the module then detects the layer and
148
+ * stands down rather than adding it twice.
149
+ *
150
+ * It is deliberately synchronous and argument-free: `extends` is resolved while
151
+ * the config is still loading, so `mono.config.ts` cannot be imported yet (its
152
+ * own `extends` chain reaches for `@mono-host-root/mono.config`, an alias mono
153
+ * has not installed at that point). Hence the static parse.
154
+ */
155
+ function monoNuxtLayers(opts = {}) {
156
+ const { dirname = process.cwd(), includes, excludes } = opts;
157
+ const root = resolve(dirname);
158
+ const apps = extractConfig(root).apps.filter((app) => {
159
+ if (!app?.name) return false;
160
+ if (includes?.length && !includes.includes(app.name)) return false;
161
+ if (excludes?.length && excludes.includes(app.name)) return false;
162
+ return true;
163
+ });
164
+ if (!apps.length) return [];
165
+ return monoLayerCandidates({
166
+ apps,
167
+ appRoots: resolveAppRoots({
168
+ dirname: root,
169
+ apps
170
+ }),
171
+ template: extractTemplate(root)
172
+ }).map((candidate) => candidate.root);
173
+ }
174
+
175
+ //#endregion
176
+ export { monoNuxtLayers as n, registerMonoNuxtLayers as r, monoLayerCandidates as t };
@@ -0,0 +1,34 @@
1
+ //#region src/nuxt/nuxt-layers.d.ts
2
+ interface MonoNuxtLayersOptions {
3
+ /** Project root. `apps[].path` resolves against it. @default process.cwd() */
4
+ dirname?: string;
5
+ /** @deprecated `apps[].path` is authoritative in every command; ignored. */
6
+ link?: boolean;
7
+ /** Only these app names become layers. */
8
+ includes?: string[];
9
+ /** These app names never become layers. */
10
+ excludes?: string[];
11
+ }
12
+ /**
13
+ * The same federated Nuxt apps as absolute directories, for a `nuxt.config`
14
+ * that wants to declare them by hand:
15
+ *
16
+ * ```ts
17
+ * export default defineNuxtConfig({ extends: monoNuxtLayers() })
18
+ * ```
19
+ *
20
+ * **You do not need this.** `@mono-lit/utility/nuxt` registers the layers itself, from
21
+ * `mono.config.ts`, so a remote's `nuxt.config.ts` is identical to a host's.
22
+ * This exists for the case where a layer's own `nuxt.config` must be merged too
23
+ * (its `modules`, `css`, `vite` options) — declaring `extends` at config-load
24
+ * time is the only way to get that, and the module then detects the layer and
25
+ * stands down rather than adding it twice.
26
+ *
27
+ * It is deliberately synchronous and argument-free: `extends` is resolved while
28
+ * the config is still loading, so `mono.config.ts` cannot be imported yet (its
29
+ * own `extends` chain reaches for `@mono-host-root/mono.config`, an alias mono
30
+ * has not installed at that point). Hence the static parse.
31
+ */
32
+ declare function monoNuxtLayers(opts?: MonoNuxtLayersOptions): string[];
33
+ //#endregion
34
+ export { type MonoNuxtLayersOptions, monoNuxtLayers };
@@ -0,0 +1,3 @@
1
+ import { n as monoNuxtLayers } from "./nuxt-layers-DP1m7f1-.js";
2
+
3
+ export { monoNuxtLayers };
@@ -0,0 +1,18 @@
1
+ import { o as setMonoEventResolver, t as MonoRequestEvent } from "./universal-B2eD9xho.js";
2
+ import { Driver, Storage } from "unstorage";
3
+ import { H3Event } from "h3";
4
+
5
+ //#region src/nuxt/ssr-cookie.d.ts
6
+ interface MonoCookieDriverOptions {
7
+ /** h3 request event (server). When absent, the driver uses document.cookie (client). */
8
+ event?: H3Event;
9
+ }
10
+ /**
11
+ * unstorage cookie driver. Values are plain strings; expiry is passed through the
12
+ * transaction options as `{ expires: Date }` on `setItem`.
13
+ */
14
+ declare const monoCookieDriver: (opts: MonoCookieDriverOptions | undefined) => Driver<MonoCookieDriverOptions | undefined, any>;
15
+ /** A unstorage Storage bound to the cookie driver (server event or client). */
16
+ declare function monoCookieStorage(event?: H3Event): Storage;
17
+ //#endregion
18
+ export { type MonoCookieDriverOptions, type MonoRequestEvent, monoCookieDriver, monoCookieStorage, setMonoEventResolver };
@@ -0,0 +1,102 @@
1
+ import { a as setMonoEventResolver } from "./universal-BNTo_83u.js";
2
+ import { createStorage, defineDriver } from "unstorage";
3
+ import { deleteCookie, getCookie, parseCookies, setCookie } from "h3";
4
+
5
+ //#region src/nuxt/ssr-cookie.ts
6
+ const isClient = () => typeof document !== "undefined";
7
+ function clientReadCookie(name) {
8
+ const nameEQ = encodeURIComponent(name) + "=";
9
+ for (const c of document.cookie.split(";").map((s) => s.trim())) if (c.startsWith(nameEQ)) return decodeURIComponent(c.substring(nameEQ.length));
10
+ return null;
11
+ }
12
+ function clientWriteCookie(name, value, expires) {
13
+ const parts = [
14
+ `${encodeURIComponent(name)}=${encodeURIComponent(value)}`,
15
+ expires ? `expires=${expires.toUTCString()}` : "",
16
+ "path=/"
17
+ ].filter(Boolean);
18
+ document.cookie = parts.join("; ");
19
+ }
20
+ function clientDeleteCookie(name) {
21
+ document.cookie = `${encodeURIComponent(name)}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
22
+ }
23
+ function clientCookieKeys() {
24
+ return document.cookie.split(";").map((s) => s.trim()).filter(Boolean).map((c) => decodeURIComponent(c.split("=")[0]));
25
+ }
26
+ /**
27
+ * Per-request write overlay. On the server, h3 `setCookie` writes to the RESPONSE,
28
+ * so `getCookie` (request) can't see a just-written value within the same render.
29
+ * We mirror writes into an overlay keyed by the request event; `null` = tombstone.
30
+ */
31
+ const serverOverlay = /* @__PURE__ */ new WeakMap();
32
+ function overlayFor(event) {
33
+ let m = serverOverlay.get(event);
34
+ if (!m) {
35
+ m = /* @__PURE__ */ new Map();
36
+ serverOverlay.set(event, m);
37
+ }
38
+ return m;
39
+ }
40
+ /**
41
+ * unstorage cookie driver. Values are plain strings; expiry is passed through the
42
+ * transaction options as `{ expires: Date }` on `setItem`.
43
+ */
44
+ const monoCookieDriver = defineDriver((opts = {}) => {
45
+ const event = opts.event;
46
+ const onServer = () => Boolean(event) && !isClient();
47
+ const serverGet = (key) => {
48
+ const ov = overlayFor(event);
49
+ if (ov.has(key)) return ov.get(key) ?? null;
50
+ return getCookie(event, key) ?? null;
51
+ };
52
+ return {
53
+ name: "mono-cookie",
54
+ options: opts,
55
+ hasItem(key) {
56
+ if (onServer()) return serverGet(key) != null;
57
+ return isClient() ? clientReadCookie(key) != null : false;
58
+ },
59
+ getItem(key) {
60
+ if (onServer()) return serverGet(key);
61
+ return isClient() ? clientReadCookie(key) : null;
62
+ },
63
+ setItem(key, value, tOptions) {
64
+ const expires = tOptions?.expires;
65
+ if (onServer()) {
66
+ setCookie(event, key, String(value), {
67
+ path: "/",
68
+ expires
69
+ });
70
+ overlayFor(event).set(key, String(value));
71
+ return;
72
+ }
73
+ if (isClient()) clientWriteCookie(key, String(value), expires);
74
+ },
75
+ removeItem(key) {
76
+ if (onServer()) {
77
+ deleteCookie(event, key, { path: "/" });
78
+ overlayFor(event).set(key, null);
79
+ return;
80
+ }
81
+ if (isClient()) clientDeleteCookie(key);
82
+ },
83
+ getKeys() {
84
+ if (onServer()) {
85
+ const ov = overlayFor(event);
86
+ const keys = new Set(Object.keys(parseCookies(event)));
87
+ for (const [k, v] of ov) if (v == null) keys.delete(k);
88
+ else keys.add(k);
89
+ return [...keys];
90
+ }
91
+ return isClient() ? clientCookieKeys() : [];
92
+ },
93
+ clear() {}
94
+ };
95
+ });
96
+ /** A unstorage Storage bound to the cookie driver (server event or client). */
97
+ function monoCookieStorage(event) {
98
+ return createStorage({ driver: monoCookieDriver({ event }) });
99
+ }
100
+
101
+ //#endregion
102
+ export { monoCookieDriver, monoCookieStorage, setMonoEventResolver };