@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.
- package/LICENSE.md +54 -0
- package/README.md +157 -3
- package/dist/app-roots-CvJnmXcs.js +128 -0
- package/dist/app-roots-DK41xMWj.d.ts +90 -0
- package/dist/config-node-UzJrXg0Z.js +76 -0
- package/dist/config-node.d.ts +923 -0
- package/dist/config-node.js +7 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +3 -0
- package/dist/create-config-B8IhX4ht.d.ts +735 -0
- package/dist/create-config-DdL3Fh6T.js +357 -0
- package/dist/fetching.d.ts +244 -0
- package/dist/fetching.js +1015 -0
- package/dist/generate-CJ7MtcDd.js +291 -0
- package/dist/index-BAy6tbOG.d.ts +371 -0
- package/dist/index-DYlzhHq7.d.ts +514 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +941 -0
- package/dist/merge-file-CLc3wxY4.d.ts +99 -0
- package/dist/merge-file-CtyKTu5L.js +133 -0
- package/dist/mock-db-4tTWrF-P.js +1282 -0
- package/dist/mock-db.d.ts +2 -0
- package/dist/mock-db.js +4 -0
- package/dist/mono-alias-DNDm-jB_.js +508 -0
- package/dist/mono-clone.mjs +958 -0
- package/dist/mono-db.d.ts +1 -0
- package/dist/mono-db.js +158 -0
- package/dist/mono-env.mjs +231 -0
- package/dist/mono-git.mjs +798 -0
- package/dist/mono-link-YlOQ2PVS.js +488 -0
- package/dist/mono-prepare.d.ts +1 -0
- package/dist/mono-prepare.js +28 -0
- package/dist/mono-skills.d.ts +1 -0
- package/dist/mono-skills.js +837 -0
- package/dist/mono-tsconfig-D2qRL9_R.js +204 -0
- package/dist/mono.mjs +34 -0
- package/dist/nuxt-layers-DP1m7f1-.js +176 -0
- package/dist/nuxt-layers.d.ts +36 -0
- package/dist/nuxt-layers.js +3 -0
- package/dist/nuxt-runtime.d.ts +17 -0
- package/dist/nuxt-runtime.js +102 -0
- package/dist/nuxt.d.ts +390 -0
- package/dist/nuxt.js +737 -0
- package/dist/runtime-vs7U9Ed4.js +6054 -0
- package/dist/runtime.d.ts +2518 -0
- package/dist/runtime.js +4 -0
- package/dist/session-Bcig-rPi.js +1721 -0
- package/dist/types-B6FdB7LJ.d.ts +57 -0
- package/dist/universal-BR0O7Qwk.d.ts +59 -0
- package/dist/universal-DIVEzCvN.js +600 -0
- package/dist/virtual-mono-apps.d.ts +16 -0
- package/dist/vite.d.ts +943 -0
- package/dist/vite.js +1132 -0
- package/package.json +141 -3
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,943 @@
|
|
|
1
|
+
import { c as MonoConfig, o as MonoAppType, w as MonoTemplate } from "./create-config-B8IhX4ht.js";
|
|
2
|
+
import { r as MonoAppRootSource, t as MonoAppRoot } from "./app-roots-DK41xMWj.js";
|
|
3
|
+
import { Plugin, PluginOption, ViteDevServer } from "vite";
|
|
4
|
+
//#region src/vite/remote-matcher.d.ts
|
|
5
|
+
/** The options every compat transform accepts, so they stay interchangeable. */
|
|
6
|
+
interface MonoRemoteGateOptions {
|
|
7
|
+
/** Only transform files whose id contains this marker. Default '/.mono/apps/'. */
|
|
8
|
+
appsMarker?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Absolute roots that also count as remote source — a locally-linked app's
|
|
11
|
+
* checkout. `monoRepo()` supplies these; there is nothing to pass by hand.
|
|
12
|
+
*/
|
|
13
|
+
appsRoots?: string[];
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/vite/mono-pagemeta.d.ts
|
|
17
|
+
interface MonoPageMetaPluginOptions extends MonoRemoteGateOptions {}
|
|
18
|
+
/**
|
|
19
|
+
* Vite plugin: strip the Nuxt page macro `definePageMeta({ … })` from synced
|
|
20
|
+
* remote `.vue` files (those under `.mono/apps/`) so it never reaches the Vue/Vite
|
|
21
|
+
* host's runtime.
|
|
22
|
+
*
|
|
23
|
+
* The Vue host doesn't need the macro: route META (layout/title) is injected
|
|
24
|
+
* separately by the host's `extendRoute` via `parsePageMetaFromFile`, which reads
|
|
25
|
+
* the page from disk (and so is unaffected by this in-memory strip). Removing the
|
|
26
|
+
* call outright — rather than rewriting it to unplugin-vue-router's `definePage`
|
|
27
|
+
* — means we don't depend on vue-router's own macro-stripping transform (and its
|
|
28
|
+
* `transform.filter`/ordering) ever running on the same module. Our single
|
|
29
|
+
* `enforce: 'pre'` transform, before `@vitejs/plugin-vue` compiles the SFC, is
|
|
30
|
+
* all that's required.
|
|
31
|
+
*
|
|
32
|
+
* `enforce: 'pre'` so it runs before the SFC is compiled — place `monoVue()`
|
|
33
|
+
* before `VueRouter()` in the plugins array.
|
|
34
|
+
*/
|
|
35
|
+
export declare function monoPageMetaToDefinePage(options?: MonoPageMetaPluginOptions): Plugin;
|
|
36
|
+
/** Clearer alias for {@link monoPageMetaToDefinePage}. */
|
|
37
|
+
export declare const monoStripPageMeta: typeof monoPageMetaToDefinePage;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/vite/mono-layout-slot.d.ts
|
|
40
|
+
/**
|
|
41
|
+
* Vite plugin: rewrite a synced remote **layout**'s default `<slot/>` (the
|
|
42
|
+
* Nuxt page outlet) into `<router-view />` for the Vue/Vite host.
|
|
43
|
+
*
|
|
44
|
+
* `vite-plugin-vue-layouts-next`'s `setupLayouts` wraps each page as a CHILD
|
|
45
|
+
* route of its layout, so the layout component must render `<router-view/>` for
|
|
46
|
+
* the page to appear. Nuxt layouts instead use `<slot/>` (NuxtLayout injects the
|
|
47
|
+
* page into the default slot). Without this rewrite the page renders nowhere — the
|
|
48
|
+
* layout chrome shows but the page content is blank.
|
|
49
|
+
*
|
|
50
|
+
* Scope: `.vue` files under a remote `.mono/apps/.../layouts/` dir. Only the DEFAULT
|
|
51
|
+
* slot is rewritten — named slots (`<slot name="…">`) are left untouched, since
|
|
52
|
+
* those are real content slots, not the page outlet. `<router-view>` is globally
|
|
53
|
+
* registered by `app.use(router)`, so no import is needed.
|
|
54
|
+
*
|
|
55
|
+
* Mirror of `mono-pagemeta`'s transform; the Nuxt host never runs this (it uses
|
|
56
|
+
* the same layout files via `<slot/>`).
|
|
57
|
+
*/
|
|
58
|
+
export declare function monoLayoutSlotToRouterView(options?: MonoPageMetaPluginOptions): Plugin;
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/vite/mono-nuxt-state.d.ts
|
|
61
|
+
interface MonoNuxtStatePluginOptions extends MonoPageMetaPluginOptions {
|
|
62
|
+
/**
|
|
63
|
+
* Module the shims are imported from. Default `'@mono-lit/utility/runtime'` — change
|
|
64
|
+
* it if the host aliases the package or wants its own implementation.
|
|
65
|
+
*/
|
|
66
|
+
importFrom?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Nuxt auto-imports to shim. Default `['useState', 'clearNuxtState']`. Every
|
|
69
|
+
* name listed must be exported by `importFrom`.
|
|
70
|
+
*/
|
|
71
|
+
composables?: string[];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Vite plugin: make Nuxt's `useState()` work in a Vue/Vite host.
|
|
75
|
+
*
|
|
76
|
+
* A synced Nuxt remote writes `const msg = useState('msg', () => 'hello')` and
|
|
77
|
+
* relies on Nuxt auto-importing it. Nothing provides that name in a plain Vue app,
|
|
78
|
+
* so the page dies with `useState is not defined`. This plugin rewrites the
|
|
79
|
+
* remote's modules to pull the name from `@mono-lit/utility/runtime`, whose
|
|
80
|
+
* {@link ../composables/nuxt-state.useState | shim} is the same thing minus the
|
|
81
|
+
* SSR payload: a keyed ref registry, so `useState('msg', () => 'hello')` resolves
|
|
82
|
+
* to a shared `ref('hello')` and a keyless call to a plain one.
|
|
83
|
+
*
|
|
84
|
+
* Injecting an import (rather than textually rewriting the call to `ref(...)`)
|
|
85
|
+
* keeps the KEY meaningful — two components on the same key must see one ref,
|
|
86
|
+
* which a per-call `ref()` can't do — and doesn't depend on the host auto-importing
|
|
87
|
+
* `ref`.
|
|
88
|
+
*
|
|
89
|
+
* Scope: files under `.mono/apps/` (the `appsMarker` option; pass `''` to cover the
|
|
90
|
+
* host's own sources too). A file is left alone when it already binds the name
|
|
91
|
+
* itself — an explicit import, a local `const`/`function`, or an aliased
|
|
92
|
+
* (`useState as x`) Nuxt import. A PLAIN import from a Nuxt virtual module
|
|
93
|
+
* (`#imports` / `#app`) is stripped first, since those specifiers resolve to
|
|
94
|
+
* nothing outside Nuxt.
|
|
95
|
+
*
|
|
96
|
+
* `enforce: 'pre'` so `.vue` files are still raw SFC source — register before
|
|
97
|
+
* `@vitejs/plugin-vue`, alongside the other `monoVue()` plugins.
|
|
98
|
+
*/
|
|
99
|
+
export declare function monoNuxtStateToRef(options?: MonoNuxtStatePluginOptions): Plugin;
|
|
100
|
+
/** Clearer alias for {@link monoNuxtStateToRef}. */
|
|
101
|
+
export declare const monoNuxtState: typeof monoNuxtStateToRef;
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/vite/mono-link.d.ts
|
|
104
|
+
interface MonoLinkPluginOptions extends MonoPageMetaPluginOptions {
|
|
105
|
+
/**
|
|
106
|
+
* Give an external link `rel="noopener noreferrer"` when it has no `rel` of its
|
|
107
|
+
* own (what `<NuxtLink external>` does). Default true; `no-rel` on the source
|
|
108
|
+
* tag opts out per-link.
|
|
109
|
+
*/
|
|
110
|
+
externalRel?: boolean;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Vite plugin: `<NuxtLink>` -> `<RouterLink>` (or `<a>`) for a Vue/Vite host.
|
|
114
|
+
*
|
|
115
|
+
* A synced Nuxt remote links with `<NuxtLink to="/x">`, which Nuxt auto-imports.
|
|
116
|
+
* The Vue host has no such component, so Vue logs `Failed to resolve component:
|
|
117
|
+
* NuxtLink` and renders nothing. This rewrites the tag in remote templates:
|
|
118
|
+
*
|
|
119
|
+
* - `<NuxtLink to="/x">` -> `<RouterLink to="/x">`
|
|
120
|
+
* - `<NuxtLink external to="/x">` -> `<RouterLink to="/x" target="_blank" rel="noopener noreferrer">`
|
|
121
|
+
* - `<NuxtLink to="https://…">` -> `<a href="https://…" rel="noopener noreferrer">`
|
|
122
|
+
*
|
|
123
|
+
* `external` stays a RouterLink because vue-router's `guardEvent` won't intercept
|
|
124
|
+
* a click on a targeted anchor — the browser navigates for real, which is what
|
|
125
|
+
* `external` means, and `to` still resolves as a route. An ABSOLUTE `to` is the
|
|
126
|
+
* one case that can't: `router.resolve('https://x.dev')` treats it as a path and
|
|
127
|
+
* renders `href="/https://x.dev"`, so those become a real `<a>` (with
|
|
128
|
+
* `target="_blank"` too when the tag also said `external`).
|
|
129
|
+
*
|
|
130
|
+
* Nuxt-only props (`prefetch`, `no-rel`, `trailing-slash`, …) are dropped rather
|
|
131
|
+
* than passed through, or they'd land on the DOM as literal attributes. `href` is
|
|
132
|
+
* renamed to `to` (NuxtLink accepts both), and for the `<a>` form `to` becomes
|
|
133
|
+
* `href`. Everything else — `class`, `target`, `@click`, `v-if`, slots — is left
|
|
134
|
+
* exactly as written, and `</NuxtLink>` follows whatever its opening tag became.
|
|
135
|
+
*
|
|
136
|
+
* Case is preserved: `<nuxt-link>` -> `<router-link>`. `RouterLink` is registered
|
|
137
|
+
* globally by `app.use(router)`, so nothing needs importing.
|
|
138
|
+
*
|
|
139
|
+
* LIMITS (both warn at build time rather than mis-compiling): a computed
|
|
140
|
+
* `:external="cond"` can't be resolved here, so the link stays in-app (no
|
|
141
|
+
* `target`); and a `custom` NuxtLink gets neither treatment, since it renders no
|
|
142
|
+
* element of its own — only the `v-slot="{ href, navigate }"` content.
|
|
143
|
+
*
|
|
144
|
+
* `enforce: 'pre'` — the SFC must still be raw source, so register before
|
|
145
|
+
* `@vitejs/plugin-vue` (`monoVue()` / `monoRepo().nuxt().hostResolver()` do).
|
|
146
|
+
*/
|
|
147
|
+
export declare function monoNuxtLinkToRouterLink(options?: MonoLinkPluginOptions): Plugin;
|
|
148
|
+
/**
|
|
149
|
+
* Vite plugin (Nuxt host): `<RouterLink>` -> `<NuxtLink>` for synced **Vue**
|
|
150
|
+
* remotes — the mirror of {@link monoNuxtLinkToRouterLink}, registered by
|
|
151
|
+
* `@mono-lit/utility/nuxt`.
|
|
152
|
+
*
|
|
153
|
+
* `<RouterLink>` does resolve under Nuxt (vue-router registers it), so this isn't
|
|
154
|
+
* a fix for a broken render — it's so remote links behave like the host's own:
|
|
155
|
+
* route prefetching, external/absolute-URL handling, and `trailingSlash`
|
|
156
|
+
* normalisation, none of which RouterLink does. Every RouterLink prop (`to`,
|
|
157
|
+
* `replace`, `active-class`, `exact-active-class`, `custom`, `aria-current-value`)
|
|
158
|
+
* is a NuxtLink prop too, so this is a pure tag rename — attributes, slots and
|
|
159
|
+
* `v-slot` bindings pass through untouched. Case is preserved:
|
|
160
|
+
* `<router-link>` -> `<nuxt-link>`.
|
|
161
|
+
*/
|
|
162
|
+
export declare function monoRouterLinkToNuxtLink(options?: MonoLinkPluginOptions): Plugin;
|
|
163
|
+
/** Clearer aliases. */
|
|
164
|
+
export declare const monoNuxtLink: typeof monoNuxtLinkToRouterLink;
|
|
165
|
+
export declare const monoRouterLink: typeof monoRouterLinkToNuxtLink;
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/vite/extend-route.d.ts
|
|
168
|
+
interface MonoExtendRouteOptions extends MonoRemoteGateOptions {
|
|
169
|
+
/**
|
|
170
|
+
* Give every route an explicit `meta.layout` so `setupLayouts` wraps each page
|
|
171
|
+
* exactly once. Without it, a page inside a folder that has no `index.vue`
|
|
172
|
+
* renders its layout TWICE — see {@link monoExtendRoute}. Default true.
|
|
173
|
+
*/
|
|
174
|
+
normalizeLayouts?: boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Layout for pages that declare none. MUST match the app's
|
|
177
|
+
* `Layouts({ defaultLayout })`, or those pages get an unknown layout name.
|
|
178
|
+
* Default 'default'.
|
|
179
|
+
*/
|
|
180
|
+
defaultLayout?: string;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* The narrow surface of vue-router's `EditableTreeNode` we touch in `extendRoute`.
|
|
184
|
+
* `components` is a **Map** (view name -> resolved filepath) in vue-router 5;
|
|
185
|
+
* `component` is the convenience getter for the `default` view's filepath.
|
|
186
|
+
*/
|
|
187
|
+
interface ExtendRouteNode {
|
|
188
|
+
component?: string;
|
|
189
|
+
components?: Map<string, string> | Record<string, string>;
|
|
190
|
+
/** Readonly, and NEVER contains `definePage()` meta — parse the source for that. */
|
|
191
|
+
meta?: Readonly<Record<string, unknown>>;
|
|
192
|
+
addToMeta(meta: Record<string, unknown>): void;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Build a `VueRouter({ extendRoute })` callback that does two things.
|
|
196
|
+
*
|
|
197
|
+
* **1. Seeds meta for synced remote pages** (component path under `appsMarker`,
|
|
198
|
+
* default `/.mono/apps/`). Remote Nuxt pages declare meta with `definePageMeta`,
|
|
199
|
+
* which vue-router does not read from disk (and which `monoVue()` strips from the
|
|
200
|
+
* runtime build), so it's parsed from the source and added to the route where
|
|
201
|
+
* `setupLayouts` can see `meta.layout`.
|
|
202
|
+
*
|
|
203
|
+
* **2. Gives every route an explicit layout, so no page is wrapped twice.**
|
|
204
|
+
* `setupLayouts` wraps in two independent places: every TOP-LEVEL record, and any
|
|
205
|
+
* record that declares `meta.layout`. A page folder becomes a component-less GROUP
|
|
206
|
+
* record (`{ path: '/module-one', children: [{ path: 'example', … }] }`), and the
|
|
207
|
+
* plugin's guard against wrapping such a group only fires when the group's `''`
|
|
208
|
+
* child is already a layout — i.e. only when the folder has an `index.vue` that
|
|
209
|
+
* itself declares a layout. Any other shape gets the default layout around the
|
|
210
|
+
* group AND the page's own layout inside it:
|
|
211
|
+
*
|
|
212
|
+
* "/module-one" L(default) <-- group, wrapped because it is top-level
|
|
213
|
+
* "" (group)
|
|
214
|
+
* "example" L(home) <-- page, wrapped because it declares a layout
|
|
215
|
+
* "" PAGE
|
|
216
|
+
*
|
|
217
|
+
* So `pages/module-one/example.vue` renders two nested layouts while
|
|
218
|
+
* `pages/flow/{index,create}.vue` renders one. Fixed per node, no child lookahead:
|
|
219
|
+
* - a group (no component) gets `layout: false`, which `setupLayouts` honours by
|
|
220
|
+
* leaving the record alone — killing the outer wrapper
|
|
221
|
+
* - a page that declares no layout gets `defaultLayout`, so removing that wrapper
|
|
222
|
+
* can't leave a page unwrapped
|
|
223
|
+
*
|
|
224
|
+
* Layout normalisation applies to EVERY route, not just remote ones: a host-owned
|
|
225
|
+
* nested folder doubles exactly the same way. `meta.layout` is read from the page
|
|
226
|
+
* SOURCE because `EditableTreeNode.meta` deliberately excludes `definePage()` meta.
|
|
227
|
+
* A page declaring `layout: false` keeps it — never overwrite an explicit value.
|
|
228
|
+
*
|
|
229
|
+
* Reads the default component filepath via `route.component` — NOT
|
|
230
|
+
* `Object.values(route.components)`, which yields `[]` because `components` is a `Map`.
|
|
231
|
+
*
|
|
232
|
+
* import { monoExtendRoute } from '@mono-lit/utility/vite'
|
|
233
|
+
* VueRouter({ routesFolder: [...], extendRoute: monoExtendRoute() })
|
|
234
|
+
*/
|
|
235
|
+
export declare function monoExtendRoute(options?: MonoExtendRouteOptions): (route: ExtendRouteNode) => void;
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region src/vite/mono-vite.d.ts
|
|
238
|
+
/**
|
|
239
|
+
* Options shared by every ecosystem key. The federated dirs are mono's job; this
|
|
240
|
+
* is how you say where *this* app's own copies live.
|
|
241
|
+
*/
|
|
242
|
+
interface MonoViteOwnDirs {
|
|
243
|
+
/**
|
|
244
|
+
* This app's own dir(s) for that ecosystem, placed BEFORE the federated ones.
|
|
245
|
+
*
|
|
246
|
+
* Defaults to the type-aware convention (`src/pages` in a `vue` app,
|
|
247
|
+
* `app/components` in a `nuxt` one) and is **skipped when it does not exist**,
|
|
248
|
+
* so an app that simply has no `layouts/` needs no configuration. Pass `false`
|
|
249
|
+
* for federated dirs only.
|
|
250
|
+
*/
|
|
251
|
+
own?: string | string[] | false;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Options for the underlying plugin, merged OVER mono's defaults. Left loose on
|
|
255
|
+
* purpose: @mono-lit/utility does not depend on these packages (see
|
|
256
|
+
* `./resolve-from-root`), so importing their option types would drag them into
|
|
257
|
+
* the install graph for the sake of autocomplete.
|
|
258
|
+
*/
|
|
259
|
+
type PluginOpts = Record<string, any>;
|
|
260
|
+
/** One option object per ecosystem plugin. */
|
|
261
|
+
type MonoEcoOptions = PluginOpts & MonoViteOwnDirs;
|
|
262
|
+
/** The ecosystem plugins mono can build. */
|
|
263
|
+
type MonoEcoKey = 'pages' | 'layouts' | 'composables' | 'components';
|
|
264
|
+
/** Upstream plugin name for each key — used for the duplicate warning. */
|
|
265
|
+
export declare const MONO_ECO_PLUGIN_NAMES: Record<MonoEcoKey, string>;
|
|
266
|
+
interface MonoViteOptions {
|
|
267
|
+
/** `vue-router/vite`. `false` to register it yourself. */
|
|
268
|
+
pages?: false | MonoEcoOptions;
|
|
269
|
+
/** `unplugin-vue-components/vite`. */
|
|
270
|
+
components?: false | MonoEcoOptions;
|
|
271
|
+
/** `vite-plugin-vue-layouts-next`. */
|
|
272
|
+
layouts?: false | MonoEcoOptions;
|
|
273
|
+
/** `unplugin-auto-import/vite` — this key carries the plugin's options. */
|
|
274
|
+
composables?: false | MonoEcoOptions;
|
|
275
|
+
/** The stores half of the same auto-import plugin: dirs only. */
|
|
276
|
+
stores?: false | MonoViteOwnDirs;
|
|
277
|
+
/**
|
|
278
|
+
* Force the Nuxt-compat transforms on or off, or pass their options.
|
|
279
|
+
* Default: **auto** — on iff some extends-active app has `type: 'nuxt'`.
|
|
280
|
+
*
|
|
281
|
+
* These are NOT flattened onto the top level, because
|
|
282
|
+
* `MonoRepoNuxtHostOptions` already carries a `composables` key (which Nuxt
|
|
283
|
+
* composables `useState` should be shimmed from) that would collide with the
|
|
284
|
+
* ecosystem key of the same name.
|
|
285
|
+
*/
|
|
286
|
+
nuxtCompat?: boolean | MonoRepoNuxtHostOptions;
|
|
287
|
+
/** `false` to skip `extendRoute`. You almost certainly do not want to. */
|
|
288
|
+
extendRoute?: false | MonoExtendRouteOptions;
|
|
289
|
+
}
|
|
290
|
+
/** Everything the builders need from the `monoRepo()` closure. */
|
|
291
|
+
interface MonoViteContext {
|
|
292
|
+
rootDir: string;
|
|
293
|
+
/** This app's own kind, from `mono.config.ts` `type`. */
|
|
294
|
+
ownType: MonoAppType;
|
|
295
|
+
/**
|
|
296
|
+
* This app's own role, from `mono.config.ts` `template`. Leaf-only — never
|
|
297
|
+
* inherited through `extends`. `undefined` behaves as `'remote'`, which is
|
|
298
|
+
* what this file did before the field existed.
|
|
299
|
+
*/
|
|
300
|
+
template?: MonoTemplate;
|
|
301
|
+
apps: {
|
|
302
|
+
name: string;
|
|
303
|
+
type: MonoAppType;
|
|
304
|
+
path?: string;
|
|
305
|
+
}[];
|
|
306
|
+
ecosystem: (subs: string | string[]) => string[];
|
|
307
|
+
extendRoute: (options?: MonoExtendRouteOptions) => unknown;
|
|
308
|
+
hostResolver: (options?: MonoRepoNuxtHostOptions) => Plugin[];
|
|
309
|
+
plugin: Plugin;
|
|
310
|
+
/**
|
|
311
|
+
* What the consumer has already wired themselves this config-load, so
|
|
312
|
+
* `vite()` does not register a second copy. Marked SYNCHRONOUSLY, because a
|
|
313
|
+
* `vite.config.ts` array literal evaluates left to right and `vite()` runs in
|
|
314
|
+
* that same pass. Three things mark it:
|
|
315
|
+
*
|
|
316
|
+
* - the plugin factories (`mono.pages()`) and their `.options()` siblings
|
|
317
|
+
* - `mono.ecosystem('pages' | 'components' | 'layouts' | 'composables' |
|
|
318
|
+
* 'stores')` — asking mono for an ecosystem's dirs means you are feeding
|
|
319
|
+
* them to your own plugin, which is exactly the long-hand config
|
|
320
|
+
* - `mono.nuxt().hostResolver()`, which marks `'compat'`
|
|
321
|
+
*
|
|
322
|
+
* An explicit option (`vite({ components: {…} })`) overrides the skip.
|
|
323
|
+
*/
|
|
324
|
+
built: Set<MonoEcoKey | 'compat' | 'plugin'>;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Which ecosystem a `mono.ecosystem(sub)` call belongs to, by first path
|
|
328
|
+
* segment — `composables/shared` and `stores/shared` both feed auto-import.
|
|
329
|
+
*/
|
|
330
|
+
export declare const MONO_ECO_SUB_KEYS: Record<string, MonoEcoKey>;
|
|
331
|
+
/** Map one ecosystem subpath to the plugin that consumes it, if any. */
|
|
332
|
+
export declare function ecoKeyForSub(sub: string): MonoEcoKey | undefined;
|
|
333
|
+
/** `VueRouter()` options: own + federated page folders, plus `extendRoute`. */
|
|
334
|
+
export declare function monoPagesOptions(ctx: MonoViteContext, opts?: MonoEcoOptions, extendRouteOpts?: false | MonoExtendRouteOptions): PluginOpts;
|
|
335
|
+
/**
|
|
336
|
+
* `Layouts()` options: own layout dirs, plus the federated ones unless this app
|
|
337
|
+
* is the host.
|
|
338
|
+
*
|
|
339
|
+
* Layouts are the one ecosystem where the two roles genuinely disagree. A HOST
|
|
340
|
+
* ships the shared shell, so it renders its own `layouts/` and must not adopt a
|
|
341
|
+
* remote's — a remote's `default.vue` would otherwise compete with the shell's.
|
|
342
|
+
* A REMOTE is the opposite: it has no shell of its own and consumes the host's.
|
|
343
|
+
* `template` in `mono.config.ts` is what says which, and it is the only thing
|
|
344
|
+
* that can — the distinction is not visible on disk (an app with no `layouts/`
|
|
345
|
+
* looks the same either way, and `ownDirs` already drops it).
|
|
346
|
+
*
|
|
347
|
+
* `template` sets a DEFAULT, not a lock: `layoutsDirs` replaces the whole list,
|
|
348
|
+
* so one call can always opt out without a mono-specific knob.
|
|
349
|
+
*/
|
|
350
|
+
export declare function monoLayoutsOptions(ctx: MonoViteContext, opts?: MonoEcoOptions): PluginOpts;
|
|
351
|
+
/**
|
|
352
|
+
* Per-ecosystem controls for the auto-import plugin.
|
|
353
|
+
*
|
|
354
|
+
* `unplugin-auto-import` is the one plugin that serves TWO ecosystems, because
|
|
355
|
+
* it has a single `dirs` array. So it is named after the plugin rather than an
|
|
356
|
+
* ecosystem, and each ecosystem is a named sub-key — rather than the positional
|
|
357
|
+
* second argument this used to take, or two plugin instances, which would both
|
|
358
|
+
* transform every module and race on the same `auto-imports.d.ts`.
|
|
359
|
+
*/
|
|
360
|
+
interface MonoAutoImportOptions extends PluginOpts {
|
|
361
|
+
/** This app's own `composables/` dir, or `false` to take only federated ones. */
|
|
362
|
+
composables?: false | MonoViteOwnDirs;
|
|
363
|
+
/** This app's own `stores/` dir, or `false` to leave stores out entirely. */
|
|
364
|
+
stores?: false | MonoViteOwnDirs;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* `AutoImport()` options: own + federated composables AND stores dirs.
|
|
368
|
+
*
|
|
369
|
+
* `imports` covers only the preset NAMES that resolve from this app. The object
|
|
370
|
+
* presets (`unheadVueComposablesImports`, `VueRouterAutoImports`) need a module
|
|
371
|
+
* load, which cannot happen synchronously — import them in your config and pass
|
|
372
|
+
* your own `imports`, or use `mono.autoImport()`, which resolves them for you.
|
|
373
|
+
*/
|
|
374
|
+
export declare function monoAutoImportOptions(ctx: MonoViteContext, opts?: MonoAutoImportOptions): PluginOpts;
|
|
375
|
+
/** `Components()` options: own + federated component dirs. */
|
|
376
|
+
export declare function monoComponentsOptions(ctx: MonoViteContext, opts?: MonoEcoOptions): PluginOpts;
|
|
377
|
+
/** `vue-router/vite` + `ecosystem('pages')` + `extendRoute`. `enforce: 'pre'`. */
|
|
378
|
+
export declare function monoPages(ctx: MonoViteContext, opts?: MonoEcoOptions, extendRouteOpts?: false | MonoExtendRouteOptions): Promise<PluginOption>;
|
|
379
|
+
/** `vite-plugin-vue-layouts-next` + `ecosystem('layouts')`. `enforce: 'pre'`. */
|
|
380
|
+
export declare function monoLayouts(ctx: MonoViteContext, opts?: MonoEcoOptions): Promise<PluginOption>;
|
|
381
|
+
/**
|
|
382
|
+
* `unplugin-auto-import/vite` + the federated composables AND stores dirs.
|
|
383
|
+
* `enforce: 'post'`. One plugin covers both ecosystems, so `stores` is a
|
|
384
|
+
* dirs-only companion option rather than its own factory.
|
|
385
|
+
*/
|
|
386
|
+
export declare function monoAutoImport(ctx: MonoViteContext, opts?: MonoAutoImportOptions): Promise<PluginOption>;
|
|
387
|
+
/** `unplugin-vue-components/vite` + `ecosystem('components')`. `enforce: 'post'`. */
|
|
388
|
+
export declare function monoComponents(ctx: MonoViteContext, opts?: MonoEcoOptions): Promise<PluginOption>;
|
|
389
|
+
/**
|
|
390
|
+
* Build the federated plugin stack.
|
|
391
|
+
*
|
|
392
|
+
* Returned order matters only WITHIN each `enforce` bucket, and that is exactly
|
|
393
|
+
* what this controls: compat transforms before `VueRouter` (both `pre`), and
|
|
394
|
+
* `mono.plugin` after auto-import/components (both `post`).
|
|
395
|
+
*
|
|
396
|
+
* Any ecosystem plugin already built via its own factory earlier in the same
|
|
397
|
+
* `plugins` array is skipped, so mixing the two styles never double-registers.
|
|
398
|
+
*/
|
|
399
|
+
export declare function monoVite(ctx: MonoViteContext, opts?: MonoViteOptions): Promise<PluginOption[]>;
|
|
400
|
+
/**
|
|
401
|
+
* Make `mono.vite()` win when an ecosystem is registered twice.
|
|
402
|
+
*
|
|
403
|
+
* The long-hand config registers `VueRouter`/`AutoImport`/`Components`/`Layouts`
|
|
404
|
+
* by hand. Passing that ecosystem to `vite({ components: {…} })` says "mono owns
|
|
405
|
+
* this one now" — so mono's instance stays live and the hand-written one is
|
|
406
|
+
* stood down, leaving exactly one active plugin per ecosystem.
|
|
407
|
+
*
|
|
408
|
+
* When neither instance is mono's, nothing is touched: that is the consumer's
|
|
409
|
+
* own duplicate, and silently disabling one would be worse than saying so.
|
|
410
|
+
*/
|
|
411
|
+
export declare function reconcileEcoPlugins(plugins: unknown): {
|
|
412
|
+
won: string[];
|
|
413
|
+
conflicting: string[];
|
|
414
|
+
};
|
|
415
|
+
//#endregion
|
|
416
|
+
//#region src/composables/expose.d.ts
|
|
417
|
+
/**
|
|
418
|
+
* Deep-clone `value` keeping ONLY JSON-safe leaves: strings, numbers, booleans,
|
|
419
|
+
* null, plain objects and arrays. Everything else is thrown away automatically —
|
|
420
|
+
* functions & class constructors (e.g. `oDataService: DefaultService`, DevExtreme
|
|
421
|
+
* `DataSource`/`ODataStore`/`CustomStore`), class instances, symbols, `undefined`,
|
|
422
|
+
* `bigint`, `Date`, `Map`, `Set`. Cycles and runaway depth are guarded, so it
|
|
423
|
+
* never throws and never leaks non-serialisable values into a client bundle.
|
|
424
|
+
*
|
|
425
|
+
* The single source of truth for the `__MONO_CONFIG_EXPOSE__` global shared by
|
|
426
|
+
* the Vite host (`monoRepo`) and the Nuxt host (`@mono-lit/utility/nuxt`).
|
|
427
|
+
*
|
|
428
|
+
* Exported so a custom `expose` can opt into the same sanitisation:
|
|
429
|
+
* expose: (c) => sanitizeForExpose({ ...c, extra: customInstance })
|
|
430
|
+
*/
|
|
431
|
+
export declare function sanitizeForExpose(value: unknown, depth?: number, seen?: WeakSet<object>): unknown;
|
|
432
|
+
//#endregion
|
|
433
|
+
//#region src/vite/mono-repo.d.ts
|
|
434
|
+
interface MonoRepoOptions {
|
|
435
|
+
/**
|
|
436
|
+
* Override/extend the auto-computed `monoAlias` map. Each entry's `dir` is
|
|
437
|
+
* resolved against the project root (absolute paths kept as-is). Example:
|
|
438
|
+
* alias: { '@mono-host': { dir: 'src' } }
|
|
439
|
+
*/
|
|
440
|
+
alias?: Record<string, {
|
|
441
|
+
dir: string;
|
|
442
|
+
}>;
|
|
443
|
+
/**
|
|
444
|
+
* Customize the client-exposed config global `__MONO_CONFIG_EXPOSE__`.
|
|
445
|
+
* Receives the resolved mono config; return the (serialisable) object to
|
|
446
|
+
* expose. Defaults to the same trimmed, browser-safe subset the Nuxt module
|
|
447
|
+
* ships (`name`/`apps`/`cookie`/`env`/`jwt`/`menu` + `fetching.auth`).
|
|
448
|
+
*/
|
|
449
|
+
expose?: (config: MonoConfig) => Record<string, unknown>;
|
|
450
|
+
/** Packages excluded from Vite dep pre-bundling (web-components dedup). Default ['@mono-lit/helper']. */
|
|
451
|
+
optimizeExclude?: string[];
|
|
452
|
+
/** Project root. Defaults to `process.cwd()` (Vite's default root). */
|
|
453
|
+
dirname?: string;
|
|
454
|
+
/** Folder scanned for remotes. Default './.mono/apps'. */
|
|
455
|
+
appsDir?: string;
|
|
456
|
+
/**
|
|
457
|
+
* Let the config chain load when a federated app isn't synced into
|
|
458
|
+
* `.mono/apps/`: its `mono.config` import resolves to an empty config instead of
|
|
459
|
+
* throwing `Cannot find module '@<app>-root/mono.config'`. Only that specifier is
|
|
460
|
+
* stubbed — app code importing a missing app still fails. Default true.
|
|
461
|
+
*/
|
|
462
|
+
stubMissing?: boolean;
|
|
463
|
+
/** Warn (once) naming the apps that were stubbed. Default true. */
|
|
464
|
+
warnMissing?: boolean;
|
|
465
|
+
/**
|
|
466
|
+
* @deprecated `apps[].path` is honoured in every command; nothing depends on
|
|
467
|
+
* which one is running. Accepted so existing `monoRepo({ command })` calls
|
|
468
|
+
* keep type-checking.
|
|
469
|
+
*/
|
|
470
|
+
command?: 'serve' | 'build';
|
|
471
|
+
/** @deprecated `apps[].path` is authoritative in every command; ignored. */
|
|
472
|
+
link?: boolean;
|
|
473
|
+
/**
|
|
474
|
+
* Restart the dev server when this app's or any active app's
|
|
475
|
+
* `mono.config.ts` changes (see `monoLith`). Default true.
|
|
476
|
+
*/
|
|
477
|
+
restartOnConfigChange?: boolean;
|
|
478
|
+
/**
|
|
479
|
+
* Add every `path` sibling's source dir to the dev watcher, so a page or
|
|
480
|
+
* component ADDED in a sibling reaches the ecosystem plugins. Default true.
|
|
481
|
+
*/
|
|
482
|
+
watchSiblings?: boolean;
|
|
483
|
+
}
|
|
484
|
+
/** Options for {@link MonoRepoNuxt.hostResolver} (mirrors `monoNuxtHost`'s options). */
|
|
485
|
+
interface MonoRepoNuxtHostOptions extends MonoNuxtStatePluginOptions, MonoLinkPluginOptions {
|
|
486
|
+
/**
|
|
487
|
+
* Define the Nuxt compile-time constants `import.meta.server` / `import.meta.client`
|
|
488
|
+
* for synced remote code that branches on them (a Vite SPA client is
|
|
489
|
+
* `client: true`, `server: false`). Default true.
|
|
490
|
+
*/
|
|
491
|
+
defineImportMeta?: boolean;
|
|
492
|
+
/**
|
|
493
|
+
* Resolve Nuxt's `useState()` (and `clearNuxtState()`) to the `@mono-lit/utility/runtime`
|
|
494
|
+
* shim in synced remote code. Default true.
|
|
495
|
+
*/
|
|
496
|
+
nuxtState?: boolean;
|
|
497
|
+
/**
|
|
498
|
+
* Rewrite `<NuxtLink>` in synced remote templates to `<RouterLink>` — plus
|
|
499
|
+
* `target="_blank"` when the link is `external`, or a plain `<a>` when `to` is
|
|
500
|
+
* an absolute URL vue-router can't resolve. Default true.
|
|
501
|
+
*/
|
|
502
|
+
nuxtLink?: boolean;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Nuxt-host compatibility helpers — used when a federated **remote is a Nuxt
|
|
506
|
+
* app** rendered inside this Vue/Vite host. Returned by {@link MonoRepoResult.nuxt}.
|
|
507
|
+
*/
|
|
508
|
+
interface MonoRepoNuxt {
|
|
509
|
+
/**
|
|
510
|
+
* The Vite plugins that resolve unsupported Nuxt code in a Vue/Vite host
|
|
511
|
+
* (= `monoNuxtHost()`): strips the `definePageMeta({…})` macro from
|
|
512
|
+
* `.mono/apps/*.vue`, rewrites a remote layout's default `<slot/>` ->
|
|
513
|
+
* `<router-view/>`, points Nuxt's auto-imported `useState()` at the
|
|
514
|
+
* `@mono-lit/utility/runtime` shim, rewrites `<NuxtLink>` -> `<RouterLink>` (plus
|
|
515
|
+
* `target="_blank"` when `external`), and defines `import.meta.server`/`import.meta.client`.
|
|
516
|
+
* Spread BEFORE `VueRouter()`:
|
|
517
|
+
* plugins: [...mono.nuxt().hostResolver(), VueRouter({...})]
|
|
518
|
+
*/
|
|
519
|
+
hostResolver: (options?: MonoRepoNuxtHostOptions) => Plugin[];
|
|
520
|
+
/**
|
|
521
|
+
* A `VueRouter({ extendRoute })` callback (= `monoExtendRoute()`) that injects
|
|
522
|
+
* `{ layout, title }` parsed from a synced remote page's source so
|
|
523
|
+
* `setupLayouts` can wrap it. Host pages (which use `definePage`) are skipped.
|
|
524
|
+
* VueRouter({ extendRoute: mono.nuxt().extendRoute() })
|
|
525
|
+
*/
|
|
526
|
+
extendRoute: (options?: MonoExtendRouteOptions) => ReturnType<typeof monoExtendRoute>;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Result of {@link monoRepo} — a Vite plugin plus the resolved mono values.
|
|
530
|
+
*
|
|
531
|
+
* `plugin` wires `resolve.alias`, `__MONO_CONFIG_EXPOSE__`, `server.fs.allow` and
|
|
532
|
+
* dep dedup; `ecosystem(subs)` discovers remote dirs (type-aware) to feed the
|
|
533
|
+
* ecosystem plugins AT REGISTRATION TIME; `nuxt()` exposes the nuxt-host compat
|
|
534
|
+
* helpers (`hostResolver`, `extendRoute`) for when a remote is a Nuxt app.
|
|
535
|
+
*/
|
|
536
|
+
interface MonoRepoResult {
|
|
537
|
+
/**
|
|
538
|
+
* Everything mono-specific, in one entry. Register it LAST.
|
|
539
|
+
*
|
|
540
|
+
* ```ts
|
|
541
|
+
* plugins: [vue({…}), UnoCSS(), mono.vite()]
|
|
542
|
+
* ```
|
|
543
|
+
*
|
|
544
|
+
* **The same call in a host and in a remote.** It is named after Vite, not
|
|
545
|
+
* after a role, because that is what it is: the mono half of *this app's*
|
|
546
|
+
* `vite.config.ts`, whichever side of the federation the app is on.
|
|
547
|
+
* Everything that used to differ between the two templates is derived —
|
|
548
|
+
* the Nuxt-compat transforms from `apps[].type`, `src/` vs `app/` from
|
|
549
|
+
* `type`, the root-`index.vue` exclusion from whether this app ships its own
|
|
550
|
+
* `pages/index.vue`. The one thing that cannot be derived is layouts, and
|
|
551
|
+
* `template: 'host' | 'remote'` in `mono.config.ts` declares it.
|
|
552
|
+
*
|
|
553
|
+
* Always contributes:
|
|
554
|
+
* - **The Nuxt-remote compat transforms** — strips `definePageMeta`, rewrites
|
|
555
|
+
* a remote layout's `<slot/>` to `<router-view/>`, shims `useState`, turns
|
|
556
|
+
* `<NuxtLink>` into `<RouterLink>`. Added **only when a federated remote is
|
|
557
|
+
* `type: 'nuxt'`**, read from `mono.config.ts` — so one config file serves a
|
|
558
|
+
* Nuxt remote and a Vue remote unchanged, with nothing to switch by hand.
|
|
559
|
+
* - **`plugin`** — `resolve.alias`, `__MONO_CONFIG_EXPOSE__`,
|
|
560
|
+
* `server.fs.allow`, dep dedup. Skipped if you list `mono.plugin` yourself.
|
|
561
|
+
*
|
|
562
|
+
* Plus any ecosystem you hand it. Each gets one flat key — `pages`,
|
|
563
|
+
* `components`, `layouts`, `composables`, `stores` — carrying that plugin's
|
|
564
|
+
* options over mono's defaults (see {@link MonoViteOptions}):
|
|
565
|
+
*
|
|
566
|
+
* | you write | result |
|
|
567
|
+
* | --- | --- |
|
|
568
|
+
* | nothing for that key | whatever YOU registered runs; `vite()` stays out |
|
|
569
|
+
* | `{ components: {…} }` | mono builds it and **wins** — your instance is stood down |
|
|
570
|
+
* | `{ components: false }` | yours runs, explicitly |
|
|
571
|
+
*
|
|
572
|
+
* "Stays out" is not guesswork: taking an ecosystem's options or dirs from
|
|
573
|
+
* mono — `mono.components.options()`, `mono.ecosystem('components')` — marks
|
|
574
|
+
* it as yours. And winning means neutralising the loser's hooks rather than
|
|
575
|
+
* removing it, because Vite fixes the plugin list before any `config()` hook
|
|
576
|
+
* runs; mono logs which ones it took over.
|
|
577
|
+
*
|
|
578
|
+
* Position-independent in both directions: Vite buckets plugins by `enforce`
|
|
579
|
+
* before running any hook, and the compat transforms declare a hook-level
|
|
580
|
+
* `order: 'pre'`, so they run ahead of `VueRouter` and `vue()` no matter
|
|
581
|
+
* where this sits.
|
|
582
|
+
*/
|
|
583
|
+
vite: (options?: MonoViteOptions) => Promise<PluginOption[]>;
|
|
584
|
+
/**
|
|
585
|
+
* `vue-router/vite`, federated.
|
|
586
|
+
*
|
|
587
|
+
* `mono.pages()` is the ready-made plugin; **`mono.pages.options()`** is just
|
|
588
|
+
* its options, synchronously, for the `VueRouter` you construct:
|
|
589
|
+
*
|
|
590
|
+
* ```ts
|
|
591
|
+
* VueRouter(mono.pages.options())
|
|
592
|
+
* ```
|
|
593
|
+
*
|
|
594
|
+
* What the options carry:
|
|
595
|
+
* - `routesFolder` — this app's own `src/pages` (`app/pages` in a Nuxt app),
|
|
596
|
+
* plus every federated remote's pages, type-driven. Dirs that do not exist
|
|
597
|
+
* are dropped.
|
|
598
|
+
* - `extendRoute` — seeds `{ layout, title }` onto every route, so
|
|
599
|
+
* `setupLayouts` cannot wrap a page twice. Overriding it replaces that;
|
|
600
|
+
* leave it alone unless you mean to.
|
|
601
|
+
* - When this app has its own `pages/index.vue` it owns `/`, so each remote's
|
|
602
|
+
* root `index.vue` is excluded automatically.
|
|
603
|
+
*
|
|
604
|
+
* Anything you pass wins: `mono.pages.options({ importMode: 'sync' })`.
|
|
605
|
+
* `own` sets this app's dir (`false` = federated only); `routesFolder`
|
|
606
|
+
* REPLACES the whole list, federated entries included.
|
|
607
|
+
*
|
|
608
|
+
* Taking either form marks pages as yours, so `vite()` will not register a
|
|
609
|
+
* second `VueRouter`.
|
|
610
|
+
*/
|
|
611
|
+
pages: ((options?: MonoEcoOptions) => Promise<PluginOption>) & {
|
|
612
|
+
/** The `VueRouter()` options — see {@link MonoRepoResult.pages}. */
|
|
613
|
+
options: (options?: MonoEcoOptions) => Record<string, any>;
|
|
614
|
+
};
|
|
615
|
+
/**
|
|
616
|
+
* `vite-plugin-vue-layouts-next`, federated.
|
|
617
|
+
*
|
|
618
|
+
* ```ts
|
|
619
|
+
* Layouts(mono.layouts.options())
|
|
620
|
+
* ```
|
|
621
|
+
*
|
|
622
|
+
* `layoutsDirs` is this app's own `src/layouts` when it exists, plus every
|
|
623
|
+
* federated app's layouts — so an app that ships none resolves to the other
|
|
624
|
+
* app's alone, with nothing hardcoded. `defaultLayout` defaults to
|
|
625
|
+
* `'default'`.
|
|
626
|
+
*
|
|
627
|
+
* **The one ecosystem `template` changes.** A `template: 'host'` app owns the
|
|
628
|
+
* shared shell, so it takes its own layouts and NO federated ones; anything
|
|
629
|
+
* else (including no `template` at all) takes both. Nothing on disk can tell
|
|
630
|
+
* the two apart, which is why this is declared rather than derived.
|
|
631
|
+
*
|
|
632
|
+
* Anything you pass wins: `mono.layouts.options({ defaultLayout: 'blank' })`.
|
|
633
|
+
* `own` sets this app's dir (`false` = federated only); `layoutsDirs`
|
|
634
|
+
* REPLACES the whole list.
|
|
635
|
+
*
|
|
636
|
+
* Taking either form marks layouts as yours, so `vite()` skips its own copy.
|
|
637
|
+
*/
|
|
638
|
+
layouts: ((options?: MonoEcoOptions) => Promise<PluginOption>) & {
|
|
639
|
+
/** The `Layouts()` options — see {@link MonoRepoResult.layouts}. */
|
|
640
|
+
options: (options?: MonoEcoOptions) => Record<string, any>;
|
|
641
|
+
};
|
|
642
|
+
/**
|
|
643
|
+
* `unplugin-auto-import/vite`, federated.
|
|
644
|
+
*
|
|
645
|
+
* ```ts
|
|
646
|
+
* AutoImport(mono.autoImport.options())
|
|
647
|
+
* ```
|
|
648
|
+
*
|
|
649
|
+
* **This one is named after the plugin, not an ecosystem** — it is the only
|
|
650
|
+
* 2:1 case, serving composables AND stores from a single `dirs` array. So
|
|
651
|
+
* both are named sub-keys of one call, rather than two plugin instances
|
|
652
|
+
* (which would each transform every module and race on the same
|
|
653
|
+
* `auto-imports.d.ts`):
|
|
654
|
+
*
|
|
655
|
+
* ```ts
|
|
656
|
+
* AutoImport(mono.autoImport.options({
|
|
657
|
+
* composables: { own: 'src/use' },
|
|
658
|
+
* stores: false, // leave stores out entirely
|
|
659
|
+
* imports: [ … ],
|
|
660
|
+
* }))
|
|
661
|
+
* ```
|
|
662
|
+
*
|
|
663
|
+
* `dirs` is this app's own `composables/` and `stores/` plus every federated
|
|
664
|
+
* remote's `composables`, `composables/shared`, `stores` and `stores/shared`.
|
|
665
|
+
* Dirs that do not exist are dropped.
|
|
666
|
+
*
|
|
667
|
+
* The one asymmetry in this API: **`options()` fills `imports` with the
|
|
668
|
+
* preset NAMES only** (`vue`, `vue-router`, `@vueuse/core`, `pinia` — each
|
|
669
|
+
* only if resolvable from this app). The object presets
|
|
670
|
+
* (`unheadVueComposablesImports`, `VueRouterAutoImports`) need a module load,
|
|
671
|
+
* which cannot happen synchronously — import them in your config and pass
|
|
672
|
+
* your own `imports`, or use the async `mono.autoImport()`, which resolves
|
|
673
|
+
* them for you.
|
|
674
|
+
*
|
|
675
|
+
* Taking either form marks this ecosystem as yours, so `vite()` skips its own.
|
|
676
|
+
*/
|
|
677
|
+
autoImport: ((options?: MonoAutoImportOptions) => Promise<PluginOption>) & {
|
|
678
|
+
/** The `AutoImport()` options — see {@link MonoRepoResult.autoImport}. */
|
|
679
|
+
options: (options?: MonoAutoImportOptions) => Record<string, any>;
|
|
680
|
+
};
|
|
681
|
+
/**
|
|
682
|
+
* Alias of {@link MonoRepoResult.autoImport}, kept because this ecosystem is
|
|
683
|
+
* named `composables` everywhere else (`vite({ composables })`,
|
|
684
|
+
* `ecosystem('composables')`). Prefer `autoImport` — the name says which
|
|
685
|
+
* plugin you get, and that stores come with it.
|
|
686
|
+
*/
|
|
687
|
+
composables: ((options?: MonoAutoImportOptions) => Promise<PluginOption>) & {
|
|
688
|
+
options: (options?: MonoAutoImportOptions) => Record<string, any>;
|
|
689
|
+
};
|
|
690
|
+
/**
|
|
691
|
+
* `unplugin-vue-components/vite`, federated.
|
|
692
|
+
*
|
|
693
|
+
* ```ts
|
|
694
|
+
* Components(mono.components.options())
|
|
695
|
+
* ```
|
|
696
|
+
*
|
|
697
|
+
* `dirs` is this app's own `src/components` (`app/components` in a Nuxt app)
|
|
698
|
+
* plus every federated remote's, type-driven; dirs that do not exist are
|
|
699
|
+
* dropped. Defaults also cover `dts`, `directoryAsNamespace`,
|
|
700
|
+
* `collapseSamePrefixes`, `extensions` and `include`.
|
|
701
|
+
*
|
|
702
|
+
* Anything you pass wins:
|
|
703
|
+
* `mono.components.options({ directoryAsNamespace: false })`. `own` sets this
|
|
704
|
+
* app's dir (`false` = federated only); `dirs` REPLACES the whole list, so to
|
|
705
|
+
* ADD one, spread first:
|
|
706
|
+
*
|
|
707
|
+
* ```ts
|
|
708
|
+
* Components(mono.components.options({
|
|
709
|
+
* dirs: [...mono.components.options().dirs, 'src/widgets'],
|
|
710
|
+
* }))
|
|
711
|
+
* ```
|
|
712
|
+
*
|
|
713
|
+
* Taking either form marks components as yours, so `vite()` skips its own.
|
|
714
|
+
*/
|
|
715
|
+
components: ((options?: MonoEcoOptions) => Promise<PluginOption>) & {
|
|
716
|
+
/** The `Components()` options — see {@link MonoRepoResult.components}. */
|
|
717
|
+
options: (options?: MonoEcoOptions) => Record<string, any>;
|
|
718
|
+
};
|
|
719
|
+
/** Vite plugin — register LAST. Wires alias, define, server.fs, optimizeDeps. */
|
|
720
|
+
plugin: Plugin;
|
|
721
|
+
/**
|
|
722
|
+
* Discover remote folders across every extends-active app for the given
|
|
723
|
+
* subpath(s). Type-aware: a `nuxt` remote resolves to `app/<sub>`, a `vue`
|
|
724
|
+
* remote to `src/<sub>`. Equivalent to
|
|
725
|
+
* `monoEcosystem({ dirname, apps, subs })` — centralised here so the config
|
|
726
|
+
* is loaded only once.
|
|
727
|
+
*
|
|
728
|
+
* Pass the result into the ecosystem plugins when you register them:
|
|
729
|
+
* AutoImport({ dirs: ['src/composables', ...mono.ecosystem(['composables/shared', 'composables'])] })
|
|
730
|
+
* Components({ dirs: ['./src/components', ...mono.ecosystem('components')] })
|
|
731
|
+
* Layouts({ layoutsDirs: mono.ecosystem('layouts') })
|
|
732
|
+
* VueRouter({ routesFolder: [{ src: 'src/pages' }, ...mono.ecosystem('pages')] })
|
|
733
|
+
*/
|
|
734
|
+
ecosystem: (subs: string | string[]) => string[];
|
|
735
|
+
/**
|
|
736
|
+
* A `VueRouter({ extendRoute })` callback (= `monoExtendRoute()`). Wire it in
|
|
737
|
+
* EVERY federated app, Nuxt remote or not: besides seeding meta for synced Nuxt
|
|
738
|
+
* pages, it gives every route an explicit `meta.layout` so `setupLayouts` can't
|
|
739
|
+
* wrap a page twice (a page in a folder with no `index.vue` otherwise renders
|
|
740
|
+
* its layout nested inside the default one).
|
|
741
|
+
* VueRouter({ routesFolder: [...], extendRoute: mono.extendRoute() })
|
|
742
|
+
*/
|
|
743
|
+
extendRoute: (options?: MonoExtendRouteOptions) => ReturnType<typeof monoExtendRoute>;
|
|
744
|
+
/**
|
|
745
|
+
* Nuxt-host compatibility helpers (`hostResolver`, `extendRoute`) for when a
|
|
746
|
+
* federated remote is a Nuxt app rendered in this Vue/Vite host. See
|
|
747
|
+
* {@link MonoRepoNuxt}.
|
|
748
|
+
*/
|
|
749
|
+
nuxt: () => MonoRepoNuxt;
|
|
750
|
+
/** The resolved mono config (post `extends`-chain merge). */
|
|
751
|
+
config: MonoConfig;
|
|
752
|
+
/** The computed `monoAlias` map (also applied by `plugin`). */
|
|
753
|
+
alias: Record<string, string>;
|
|
754
|
+
/** The extends-active apps `{ name, type }` that `ecosystem()` discovers over. */
|
|
755
|
+
apps: {
|
|
756
|
+
name: string;
|
|
757
|
+
type: MonoAppType;
|
|
758
|
+
path?: string;
|
|
759
|
+
}[];
|
|
760
|
+
/**
|
|
761
|
+
* Every federated app resolved to the directory it is read from — a
|
|
762
|
+
* `.mono/apps` clone or an `apps[].path` sibling (`source`). For anything
|
|
763
|
+
* that needs the directories themselves, e.g. UnoCSS `content.filesystem`
|
|
764
|
+
* globs over sibling sources.
|
|
765
|
+
*/
|
|
766
|
+
appRoots: MonoAppRoot[];
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Mono Vite host helper — the single-call Vite equivalent of the Nuxt host's
|
|
770
|
+
* `@mono-lit/utility/nuxt` module.
|
|
771
|
+
*
|
|
772
|
+
* Loads `mono.config.ts` ONCE (c12/jiti, taught the `monoAlias` map), resolves
|
|
773
|
+
* the `extends`-active apps, and returns:
|
|
774
|
+
* - `plugin`: a Vite plugin (register LAST) wiring `resolve.alias`,
|
|
775
|
+
* `__MONO_CONFIG_EXPOSE__`, `server.fs.allow` and dep dedup
|
|
776
|
+
* - `ecosystem(subs)`: type-aware remote dir discovery (`nuxt` -> `app/<sub>`,
|
|
777
|
+
* `vue` -> `src/<sub>`) to feed AutoImport / Components / Layouts / VueRouter
|
|
778
|
+
* `routesFolder` at registration time
|
|
779
|
+
* - `config` / `alias` / `apps`: the resolved values, for advanced use
|
|
780
|
+
*
|
|
781
|
+
* Why async + explicit dirs (not post-registration injection): current
|
|
782
|
+
* `unplugin-auto-import` exposes no `api`, `unplugin-vue-components`' `api` has
|
|
783
|
+
* no `options`, and `vue-router` / `vite-plugin-vue-layouts-next` capture their
|
|
784
|
+
* dirs option in a closure — so none of them can be mutated after registration.
|
|
785
|
+
* Passing dirs at registration is the only reliable path; this helper just
|
|
786
|
+
* centralises the config load so you discover them with one-liner
|
|
787
|
+
* `mono.ecosystem(...)` instead of repeating `monoAlias` / `getMonoConfig` /
|
|
788
|
+
* `activeApps` / `define` / `server.fs` in every host.
|
|
789
|
+
*
|
|
790
|
+
* import { monoRepo } from '@mono-lit/utility/vite'
|
|
791
|
+
*
|
|
792
|
+
* export default defineConfig(async ({ mode }) => {
|
|
793
|
+
* const mono = await monoRepo()
|
|
794
|
+
* return {
|
|
795
|
+
* plugins: [
|
|
796
|
+
* vue({ template: { compilerOptions: { isCustomElement } } }),
|
|
797
|
+
* UnoCSS(),
|
|
798
|
+
* mono.vite(), // ← VueRouter + layouts + auto-import + components + plugin
|
|
799
|
+
* ],
|
|
800
|
+
* }
|
|
801
|
+
* })
|
|
802
|
+
*
|
|
803
|
+
* The same file works whether the federated remote is a Nuxt app or a Vue one —
|
|
804
|
+
* `vite()` reads `apps[].type` and adds the Nuxt-compat transforms only when one
|
|
805
|
+
* is a Nuxt remote. `ecosystem()` stays public for anything `vite()` does not
|
|
806
|
+
* own, and any ecosystem key can be turned off to register it by hand:
|
|
807
|
+
*
|
|
808
|
+
* mono.vite({ layouts: false }),
|
|
809
|
+
* Layouts({ layoutsDirs: mono.ecosystem('layouts') }),
|
|
810
|
+
*/
|
|
811
|
+
export declare function monoRepo(options?: MonoRepoOptions): Promise<MonoRepoResult>;
|
|
812
|
+
//#endregion
|
|
813
|
+
//#region src/composables/parse-page-meta.d.ts
|
|
814
|
+
/**
|
|
815
|
+
* Page meta mono cares about: `layout` (which layout wraps the page)
|
|
816
|
+
* and `title` (route title). Both optional.
|
|
817
|
+
*/
|
|
818
|
+
interface MonoPageMeta {
|
|
819
|
+
/** Layout name, or `false` for a page that opts out of layouts entirely. */
|
|
820
|
+
layout?: string | false;
|
|
821
|
+
title?: string;
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Extract `{ layout, title }` from a page's `<script setup>` source, supporting
|
|
825
|
+
* BOTH macro forms:
|
|
826
|
+
* - Nuxt: `definePageMeta({ layout: 'home', title: 'Home' })`
|
|
827
|
+
* - vue-router (unplugin-vue-router): `definePage({ meta: { layout, title } })`
|
|
828
|
+
*
|
|
829
|
+
* String-literal values only (layout/title are always literals in these apps).
|
|
830
|
+
* Used by the Nuxt host module (to seed remote route meta) and by the Vite
|
|
831
|
+
* host's `extendRoute` (since unplugin-vue-router reads page files from disk and
|
|
832
|
+
* never sees the `definePageMeta -> definePage` Vite transform).
|
|
833
|
+
*/
|
|
834
|
+
export declare function parsePageMeta(code: string): MonoPageMeta;
|
|
835
|
+
/** {@link parsePageMeta} for a file path (build-time, Node). Returns `{}` on read error. */
|
|
836
|
+
export declare function parsePageMetaFromFile(file: string): MonoPageMeta;
|
|
837
|
+
//#endregion
|
|
838
|
+
//#region src/vite/resolve-from-root.d.ts
|
|
839
|
+
/** A loader that imports bare specifiers as the app at `rootDir` would. */
|
|
840
|
+
type RootLoader = <T = any>(id: string) => Promise<T>;
|
|
841
|
+
/**
|
|
842
|
+
* Build a {@link RootLoader} anchored at `rootDir`.
|
|
843
|
+
*
|
|
844
|
+
* `createRequire` needs a *file* to resolve from — `noop.js` never has to exist,
|
|
845
|
+
* it only fixes the directory the walk starts in.
|
|
846
|
+
*/
|
|
847
|
+
export declare function createRootLoader(rootDir: string): RootLoader;
|
|
848
|
+
/** `true` when `id` can be resolved from the app root. Never throws. */
|
|
849
|
+
export declare function canResolveFromRoot(rootDir: string, id: string): boolean;
|
|
850
|
+
//#endregion
|
|
851
|
+
//#region src/vite/mono-lith.d.ts
|
|
852
|
+
export declare const MONO_APPS_VIRTUAL_ID = "virtual:mono-apps";
|
|
853
|
+
interface MonoLithOptions {
|
|
854
|
+
/** Project root. Defaults to `process.cwd()`. */
|
|
855
|
+
dirname?: string;
|
|
856
|
+
/** Folder scanned for clones. @default './.mono/apps' */
|
|
857
|
+
appsDir?: string;
|
|
858
|
+
/**
|
|
859
|
+
* Pre-resolved roots (what `monoRepo` already computed). Resolved from
|
|
860
|
+
* `mono.config.ts` when omitted.
|
|
861
|
+
*/
|
|
862
|
+
appRoots?: MonoAppRoot[];
|
|
863
|
+
/**
|
|
864
|
+
* Names of the apps that contribute — the `extends`-gated set. Every
|
|
865
|
+
* resolved root when omitted. Drives `virtual:mono-apps` and the config
|
|
866
|
+
* watch list; siblings are served and watched regardless.
|
|
867
|
+
*/
|
|
868
|
+
activeNames?: string[];
|
|
869
|
+
/**
|
|
870
|
+
* Restart the dev server when any active app's `mono.config.ts` changes.
|
|
871
|
+
* @default true
|
|
872
|
+
*/
|
|
873
|
+
restartOnConfigChange?: boolean;
|
|
874
|
+
/**
|
|
875
|
+
* Add every `path` sibling's source dir to the dev watcher so new files are
|
|
876
|
+
* picked up by the ecosystem plugins.
|
|
877
|
+
* @default true
|
|
878
|
+
*/
|
|
879
|
+
watchSiblings?: boolean;
|
|
880
|
+
}
|
|
881
|
+
/** The hooks, shared by {@link monoLith} and `monoRepo`'s own plugin. */
|
|
882
|
+
interface MonoLithHooks {
|
|
883
|
+
/** Extra `server.fs.allow` entries: every `path` root. */
|
|
884
|
+
fsAllow: string[];
|
|
885
|
+
/** The resolved roots this instance works from. */
|
|
886
|
+
appRoots: MonoAppRoot[];
|
|
887
|
+
configureServer: (server: ViteDevServer) => void;
|
|
888
|
+
resolveId: (id: string) => string | undefined;
|
|
889
|
+
load: (id: string) => string | undefined;
|
|
890
|
+
}
|
|
891
|
+
export declare function createMonoLithHooks(options?: MonoLithOptions): MonoLithHooks;
|
|
892
|
+
/**
|
|
893
|
+
* Standalone plugin for a long-hand `vite.config.ts`. `monoRepo().vite()` /
|
|
894
|
+
* `mono.plugin` already include these hooks — do not register both.
|
|
895
|
+
*
|
|
896
|
+
* ```ts
|
|
897
|
+
* import { monoLith } from '@mono-lit/utility/vite'
|
|
898
|
+
* plugins: [VueRouter({ … }), vue(), monoLith({ dirname: __dirname })]
|
|
899
|
+
* ```
|
|
900
|
+
*/
|
|
901
|
+
export declare function monoLith(options?: MonoLithOptions): Plugin;
|
|
902
|
+
//#endregion
|
|
903
|
+
//#region src/vite/index.d.ts
|
|
904
|
+
export interface MonoVueOptions extends MonoNuxtStatePluginOptions, MonoLinkPluginOptions {
|
|
905
|
+
/**
|
|
906
|
+
* Define the Nuxt compile-time constants `import.meta.server` /
|
|
907
|
+
* `import.meta.client` for synced remote code that branches on them
|
|
908
|
+
* (a Vite SPA client is `client: true`, `server: false`). Default true.
|
|
909
|
+
*/
|
|
910
|
+
defineImportMeta?: boolean;
|
|
911
|
+
/**
|
|
912
|
+
* Resolve Nuxt's `useState()` (and `clearNuxtState()`) to the `@mono-lit/utility/runtime`
|
|
913
|
+
* shim in synced remote code. Default true.
|
|
914
|
+
*/
|
|
915
|
+
nuxtState?: boolean;
|
|
916
|
+
/**
|
|
917
|
+
* Rewrite `<NuxtLink>` in synced remote templates to `<RouterLink>` — plus
|
|
918
|
+
* `target="_blank"` when the link is `external`, or a plain `<a>` when `to` is
|
|
919
|
+
* an absolute URL vue-router can't resolve. Default true.
|
|
920
|
+
*/
|
|
921
|
+
nuxtLink?: boolean;
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* Vite-host compatibility layer for running a **Nuxt remote** inside a plain
|
|
925
|
+
* Vue 3 + Vite host. Returns the plugins needed for the narrow Nuxt surface the
|
|
926
|
+
* synced remote code uses:
|
|
927
|
+
* - strips the Nuxt `definePageMeta({…})` macro from `.mono/apps/*.vue` (route meta is
|
|
928
|
+
* injected separately by the host's `extendRoute` via `parsePageMetaFromFile`)
|
|
929
|
+
* - rewrites a remote layout's default `<slot/>` -> `<router-view/>` (so Nuxt
|
|
930
|
+
* `<slot>` layouts render the page under `setupLayouts`' nested routes)
|
|
931
|
+
* - points Nuxt's auto-imported `useState()` at the `@mono-lit/utility/runtime` shim
|
|
932
|
+
* (a keyed ref registry — `useState('k', () => 'hello')` -> a shared `ref('hello')`)
|
|
933
|
+
* - rewrites `<NuxtLink>` -> `<RouterLink>` (`external` adds `target="_blank"`,
|
|
934
|
+
* so the browser navigates for real; an absolute-URL `to` becomes an `<a>`)
|
|
935
|
+
* - defines `import.meta.server`/`import.meta.client` (SPA client constants)
|
|
936
|
+
*
|
|
937
|
+
* Mirrors `@mono-lit/helper/vite`'s `monoSsr()` shape. Register before `VueRouter()`:
|
|
938
|
+
* import { monoVue } from '@mono-lit/utility/vite'
|
|
939
|
+
* plugins: [ ...monoVue(), VueRouter({...}), vue(), ... ]
|
|
940
|
+
*/
|
|
941
|
+
declare function monoVue(options?: MonoVueOptions): Plugin[];
|
|
942
|
+
//#endregion
|
|
943
|
+
export { type MonoAppRoot, type MonoAppRootSource, type MonoAutoImportOptions, type MonoEcoKey, type MonoEcoOptions, type MonoExtendRouteOptions, type MonoLinkPluginOptions, type MonoLithHooks, type MonoLithOptions, type MonoNuxtStatePluginOptions, type MonoPageMeta, type MonoPageMetaPluginOptions, type MonoRepoNuxt, type MonoRepoNuxtHostOptions, type MonoRepoOptions, type MonoRepoResult, type MonoViteContext, type MonoViteOptions, type MonoViteOwnDirs, type RootLoader, monoVue as monoNuxtHost, monoVue };
|