@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/nuxt.js
ADDED
|
@@ -0,0 +1,737 @@
|
|
|
1
|
+
import { o as pathAppRoots, t as appRootDirs } from "./app-roots-CvJnmXcs.js";
|
|
2
|
+
import { c as resolveMonoConfig, l as srcDirForType, o as resolveExtendsAppNames, s as resolveExtendsEcosystems } from "./create-config-DdL3Fh6T.js";
|
|
3
|
+
import { n as mergeEcosystem, r as monoEcosystem, t as ecosystemSubAllowed } from "./merge-file-CtyKTu5L.js";
|
|
4
|
+
import { t as getMonoConfig } from "./config-node-UzJrXg0Z.js";
|
|
5
|
+
import { d as resolveFederatedRoots, n as extractConfig, o as formatMissingApps, s as monoAlias, t as assertAppSources, u as monoStubAliases } from "./mono-alias-DNDm-jB_.js";
|
|
6
|
+
import { a as defaultMonoExpose, i as monoRouterLinkToNuxtLink, l as remoteGate, o as sanitizeForExpose, s as parsePageMeta } from "./mono-link-YlOQ2PVS.js";
|
|
7
|
+
import { r as registerMonoNuxtLayers, t as monoLayerCandidates } from "./nuxt-layers-DP1m7f1-.js";
|
|
8
|
+
import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
9
|
+
import { isAbsolute, join, normalize, relative, resolve, sep } from "node:path";
|
|
10
|
+
import { addComponentsDir, addImportsDir, addPlugin, addPluginTemplate, addRouteMiddleware, addTemplate, addVitePlugin, defineNuxtModule, extendPages, extendViteConfig } from "@nuxt/kit";
|
|
11
|
+
|
|
12
|
+
//#region src/nuxt/nuxt-ecosystem.ts
|
|
13
|
+
/**
|
|
14
|
+
* The built-in ecosystem map, given THIS app's `template`.
|
|
15
|
+
*
|
|
16
|
+
* `pages`/`imports`/`components` are role-independent — a host absorbs its
|
|
17
|
+
* remotes' features, a remote absorbs its host's, and both want the same four
|
|
18
|
+
* folders. The shell is where the roles disagree:
|
|
19
|
+
*
|
|
20
|
+
* - `layouts` follows `mono.vite()` exactly (`monoLayoutsOptions`): a `host`
|
|
21
|
+
* owns the shared shell and must not adopt a remote's `default.vue`, while a
|
|
22
|
+
* `remote` — and an ABSENT `template`, which has always read as `remote` —
|
|
23
|
+
* consumes the host's.
|
|
24
|
+
* - `middleware` / `plugins` have no `mono.vite()` analogue, so there is no
|
|
25
|
+
* prior behaviour to preserve. They are enabled for an EXPLICIT `remote`
|
|
26
|
+
* only: quietly running a remote's global middleware or its Sentry plugin
|
|
27
|
+
* inside an existing Nuxt host would be a regression, not a fix. A host that
|
|
28
|
+
* wants them opts in by restating the entry in `mono.utils.ecosystem`.
|
|
29
|
+
*/
|
|
30
|
+
function nuxtEcosystemDefaults(template) {
|
|
31
|
+
return {
|
|
32
|
+
pages: {
|
|
33
|
+
type: "pages",
|
|
34
|
+
relDir: "pages"
|
|
35
|
+
},
|
|
36
|
+
composables: {
|
|
37
|
+
type: "imports",
|
|
38
|
+
relDir: "composables"
|
|
39
|
+
},
|
|
40
|
+
stores: {
|
|
41
|
+
type: "imports",
|
|
42
|
+
relDir: "stores"
|
|
43
|
+
},
|
|
44
|
+
components: {
|
|
45
|
+
type: "components",
|
|
46
|
+
relDir: "components"
|
|
47
|
+
},
|
|
48
|
+
layouts: {
|
|
49
|
+
type: "layouts",
|
|
50
|
+
relDir: "layouts",
|
|
51
|
+
enabled: template !== "host"
|
|
52
|
+
},
|
|
53
|
+
middleware: {
|
|
54
|
+
type: "middleware",
|
|
55
|
+
relDir: "middleware",
|
|
56
|
+
enabled: template === "remote"
|
|
57
|
+
},
|
|
58
|
+
plugins: {
|
|
59
|
+
type: "plugins",
|
|
60
|
+
relDir: "plugins",
|
|
61
|
+
enabled: template === "remote"
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Default page-exclude globs for the federated `pages` dirs.
|
|
67
|
+
*
|
|
68
|
+
* Only the root `index.vue` is ever in question, and the answer is visible on
|
|
69
|
+
* disk: an app that ships its own `pages/index.vue` owns `/`, so a federated
|
|
70
|
+
* root index would clobber it. An app that does NOT — every remote, which takes
|
|
71
|
+
* the host's login page as `/` — must let it through. Same derivation as
|
|
72
|
+
* `monoPagesOptions` (`src/vite/mono-vite.ts`), which reads `ownsRoot` off the
|
|
73
|
+
* filesystem rather than asking the config.
|
|
74
|
+
*
|
|
75
|
+
* Deeper `<folder>/index.vue` pages are never excluded by this.
|
|
76
|
+
*/
|
|
77
|
+
function remotePageExcludes(ownPagesDir) {
|
|
78
|
+
return existsSync(join(ownPagesDir, "index.vue")) ? ["index.vue"] : [];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The identity two files fight over when one is federated and one is the app's
|
|
82
|
+
* own: the basename, minus its extension and minus a trailing Nuxt mode/scope
|
|
83
|
+
* suffix (`.client` / `.server` / `.global`).
|
|
84
|
+
*
|
|
85
|
+
* Dropping the suffix is deliberate — an app's own `plugins/mono.ts` should win
|
|
86
|
+
* over a host's `plugins/mono.client.ts`, since they are two versions of one
|
|
87
|
+
* plugin rather than two plugins.
|
|
88
|
+
*/
|
|
89
|
+
function ecosystemFileKey(file) {
|
|
90
|
+
return (file.replaceAll("\\", "/").split("/").pop() ?? file).replace(/\.(vue|[cm]?[jt]sx?)$/, "").replace(/\.(client|server|global)$/, "");
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The `ecosystemFileKey`s this app ships in its OWN `<srcDir>/<sub>` folder.
|
|
94
|
+
*
|
|
95
|
+
* Used to skip a federated layout/middleware/plugin the app has replaced. Nuxt
|
|
96
|
+
* already refuses to clobber for layouts (`app.layouts`) and middleware
|
|
97
|
+
* (`addRouteMiddleware` matches on name), but `addPlugin` dedupes on absolute
|
|
98
|
+
* `src` — which never matches across two checkouts — so the rule is applied
|
|
99
|
+
* here for all three rather than relying on three different behaviours.
|
|
100
|
+
*/
|
|
101
|
+
function ownEcosystemKeys(ownDir) {
|
|
102
|
+
const keys = /* @__PURE__ */ new Set();
|
|
103
|
+
if (!existsSync(ownDir)) return keys;
|
|
104
|
+
for (const entry of readdirSync(ownDir, { withFileTypes: true })) {
|
|
105
|
+
if (entry.isDirectory()) continue;
|
|
106
|
+
keys.add(ecosystemFileKey(entry.name));
|
|
107
|
+
}
|
|
108
|
+
return keys;
|
|
109
|
+
}
|
|
110
|
+
/** Recursively collect files under `dir` whose extension is in `exts`. */
|
|
111
|
+
function walkFiles(dir, exts) {
|
|
112
|
+
const out = [];
|
|
113
|
+
if (!existsSync(dir) || !statSync(dir).isDirectory()) return out;
|
|
114
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
115
|
+
const full = join(dir, entry.name);
|
|
116
|
+
if (entry.isDirectory()) out.push(...walkFiles(full, exts));
|
|
117
|
+
else if (exts.some((ext) => entry.name.endsWith(ext))) out.push(full);
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
/** Top-level files only (no recursion) whose extension is in `exts`. */
|
|
122
|
+
function topLevelFiles(dir, exts) {
|
|
123
|
+
if (!existsSync(dir) || !statSync(dir).isDirectory()) return [];
|
|
124
|
+
return readdirSync(dir, { withFileTypes: true }).filter((e) => !e.isDirectory() && exts.some((ext) => e.name.endsWith(ext))).map((e) => join(dir, e.name));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* `layouts/home.vue` -> `home`, `layouts/admin/users.vue` -> `admin-users` —
|
|
128
|
+
* the same path-to-name flattening Nuxt applies to its own `layouts/` dir.
|
|
129
|
+
*/
|
|
130
|
+
function layoutNameFor(layoutsDir, file) {
|
|
131
|
+
return relative(layoutsDir, file).replace(/\.vue$/, "").split(sep).join("-");
|
|
132
|
+
}
|
|
133
|
+
/** `route-guard.global.ts` -> `{ name: 'route-guard', global: true }`. */
|
|
134
|
+
function middlewareNameFor(file) {
|
|
135
|
+
const base = (file.replaceAll("\\", "/").split("/").pop() ?? file).replace(/\.[cm]?[jt]sx?$/, "");
|
|
136
|
+
const global = base.endsWith(".global");
|
|
137
|
+
return {
|
|
138
|
+
name: global ? base.slice(0, -7) : base,
|
|
139
|
+
global
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/** Source extensions Nuxt accepts for middleware / plugins. */
|
|
143
|
+
const SCRIPT_EXTENSIONS = [
|
|
144
|
+
".ts",
|
|
145
|
+
".mts",
|
|
146
|
+
".cts",
|
|
147
|
+
".js",
|
|
148
|
+
".mjs",
|
|
149
|
+
".cjs",
|
|
150
|
+
".tsx",
|
|
151
|
+
".jsx"
|
|
152
|
+
];
|
|
153
|
+
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/nuxt/host-nuxt.ts
|
|
156
|
+
/**
|
|
157
|
+
* Mono Nuxt module — the Nuxt equivalent of the Vite side's `mono.vite()`
|
|
158
|
+
* ecosystem block, and like it, ONE module serving both roles. A Nuxt HOST
|
|
159
|
+
* absorbs its remotes' features; a Nuxt REMOTE (`template: 'remote'`) absorbs
|
|
160
|
+
* its host's shell. `mono.config.ts`'s `template` is what says which, exactly as
|
|
161
|
+
* it does for `mono.vite()` — the file is still named `host-nuxt.ts` only
|
|
162
|
+
* because the export path `@mono-lit/utility/nuxt` is public.
|
|
163
|
+
*
|
|
164
|
+
* At BUILD time it:
|
|
165
|
+
*
|
|
166
|
+
* - builds the `monoAlias` map (`@<own>`, `@<remote>`, `@mono-apps`, …) and
|
|
167
|
+
* applies it to Nuxt + jiti, plus any `mono.alias` overrides
|
|
168
|
+
* - resolves `mono.config.ts` (incl. its `extends` chain) via c12/jiti and
|
|
169
|
+
* exposes a trimmed, serialisable subset to the client as the compile-time
|
|
170
|
+
* global `__MONO_CONFIG_EXPOSE__`
|
|
171
|
+
* - discovers folders across every federated app under `.mono/apps/<name>` (via
|
|
172
|
+
* `mergeEcosystem`) per the `ecosystem` map and wires each into Nuxt:
|
|
173
|
+
* - type 'pages' -> routes via `extendPages` (layout/title from `definePage`)
|
|
174
|
+
* - type 'imports' -> `addImportsDir` (composables/stores auto-import)
|
|
175
|
+
* - type 'components' -> `addComponentsDir`
|
|
176
|
+
* - type 'layouts' -> `app.layouts` via the `app:templates` hook
|
|
177
|
+
* - type 'middleware' -> `addRouteMiddleware` (`.global` honoured)
|
|
178
|
+
* - type 'plugins' -> `addPlugin` (`.client`/`.server` honoured)
|
|
179
|
+
* Defaults cover pages/composables/stores/components for every role, plus
|
|
180
|
+
* layouts/middleware/plugins for a remote — see `nuxtEcosystemDefaults`. A
|
|
181
|
+
* file this app ships itself always wins over the federated one of the same
|
|
182
|
+
* name.
|
|
183
|
+
* - rewrites the unplugin-vue-router macro `definePage({ meta: X })` to Nuxt's
|
|
184
|
+
* `definePageMeta(X)` for the out-of-tree remote `.vue` files
|
|
185
|
+
* - rewrites `<RouterLink>` -> `<NuxtLink>` in remote templates, so remote links
|
|
186
|
+
* prefetch and handle external URLs like the host's own
|
|
187
|
+
* - opens Vite's dev-server `fs.allow` to `.apps/` and excludes the
|
|
188
|
+
* web-components lib from dep pre-bundling (single `customElements.define`).
|
|
189
|
+
*
|
|
190
|
+
* Configure via the `mono` key in `nuxt.config.ts`; register with
|
|
191
|
+
* `modules: ['@mono-lit/utility/nuxt']`.
|
|
192
|
+
*/
|
|
193
|
+
/**
|
|
194
|
+
* Turn an `ecosystems` policy into a plain allow/deny for one custom
|
|
195
|
+
* `dir`/`sub` ecosystem entry.
|
|
196
|
+
*
|
|
197
|
+
* `mergeEcosystem` matches the policy against each resolved directory, but a
|
|
198
|
+
* custom entry's `dir` is arbitrary (`dir: 'shared/widgets'`) and carries no
|
|
199
|
+
* sub name to match on. So decide per app up front, using the entry's own
|
|
200
|
+
* identity as the sub, and hand `mergeEcosystem` a verdict instead: `[]` blocks
|
|
201
|
+
* that app, an absent key leaves it untouched.
|
|
202
|
+
*
|
|
203
|
+
* Returns `undefined` when no app is blocked, so the common path stays free of
|
|
204
|
+
* an empty filter object.
|
|
205
|
+
*/
|
|
206
|
+
function gateCustomEntry(ecosystems, sub) {
|
|
207
|
+
const blocked = {};
|
|
208
|
+
for (const [app, allow] of Object.entries(ecosystems)) if (!ecosystemSubAllowed(sub, allow)) blocked[app] = [];
|
|
209
|
+
return Object.keys(blocked).length ? blocked : void 0;
|
|
210
|
+
}
|
|
211
|
+
const monoNuxtModule = defineNuxtModule({
|
|
212
|
+
meta: {
|
|
213
|
+
name: "mono-nuxt",
|
|
214
|
+
configKey: "mono"
|
|
215
|
+
},
|
|
216
|
+
defaults: {},
|
|
217
|
+
async setup(options, nuxt) {
|
|
218
|
+
const rootDir = nuxt.options.rootDir;
|
|
219
|
+
const u = options.utils ?? options;
|
|
220
|
+
const optimizeExclude = u.optimizeExclude ?? ["@mono-lit/helper"];
|
|
221
|
+
assertAppSources(extractConfig(rootDir).apps, rootDir);
|
|
222
|
+
const appRoots = resolveFederatedRoots({ dirname: rootDir });
|
|
223
|
+
const alias = monoAlias({ dirname: rootDir });
|
|
224
|
+
for (const [key, value] of Object.entries(u.alias ?? {})) {
|
|
225
|
+
const dir = value?.dir;
|
|
226
|
+
if (!dir) continue;
|
|
227
|
+
alias[key] = isAbsolute(dir) ? dir : resolve(rootDir, dir);
|
|
228
|
+
}
|
|
229
|
+
nuxt.options.alias = {
|
|
230
|
+
...alias,
|
|
231
|
+
...nuxt.options.alias
|
|
232
|
+
};
|
|
233
|
+
const { alias: stubAlias, missing } = u.stubMissing === false ? {
|
|
234
|
+
alias: {},
|
|
235
|
+
missing: []
|
|
236
|
+
} : monoStubAliases({ dirname: rootDir });
|
|
237
|
+
if (missing.length && u.warnMissing !== false) console.warn(formatMissingApps(missing));
|
|
238
|
+
const rawConfig = await getMonoConfig({
|
|
239
|
+
cwd: rootDir,
|
|
240
|
+
jitiOptions: { alias: {
|
|
241
|
+
...alias,
|
|
242
|
+
...stubAlias
|
|
243
|
+
} }
|
|
244
|
+
});
|
|
245
|
+
const hasExtends = rawConfig.extends != null;
|
|
246
|
+
const activeNames = resolveExtendsAppNames(rawConfig);
|
|
247
|
+
const activeApps = hasExtends ? (rawConfig.apps ?? []).filter((a) => activeNames.includes(a.name)) : rawConfig.apps ?? [];
|
|
248
|
+
const activeRoots = appRoots.filter((r) => activeApps.some((a) => a.name === r.name));
|
|
249
|
+
const extendsEcosystems = resolveExtendsEcosystems(rawConfig);
|
|
250
|
+
const monoConfig = {
|
|
251
|
+
...resolveMonoConfig(rawConfig),
|
|
252
|
+
apps: rawConfig.apps,
|
|
253
|
+
...rawConfig.extends != null ? { extends: rawConfig.extends } : {}
|
|
254
|
+
};
|
|
255
|
+
const ownSrcDir = join(rootDir, srcDirForType(rawConfig.type ?? "nuxt"));
|
|
256
|
+
const ecosystem = {
|
|
257
|
+
...nuxtEcosystemDefaults(rawConfig.template),
|
|
258
|
+
...u.ecosystem ?? {}
|
|
259
|
+
};
|
|
260
|
+
const layerCandidates = monoLayerCandidates({
|
|
261
|
+
apps: activeApps,
|
|
262
|
+
appRoots,
|
|
263
|
+
template: rawConfig.template
|
|
264
|
+
});
|
|
265
|
+
const layered = registerMonoNuxtLayers({
|
|
266
|
+
nuxt,
|
|
267
|
+
candidates: layerCandidates
|
|
268
|
+
});
|
|
269
|
+
dedupeLayerPlugins(nuxt, layerCandidates, ownSrcDir);
|
|
270
|
+
const mergeApps = activeApps.filter((app) => !layered.has(app.name));
|
|
271
|
+
const mergeNames = activeNames.filter((name) => !layered.has(name));
|
|
272
|
+
if (layered.size) console.log(`[mono-nuxt] merged via native Nuxt layers: ${[...layered].join(", ")}`);
|
|
273
|
+
for (const [name, entry] of Object.entries(ecosystem)) {
|
|
274
|
+
if (!entry || entry.enabled === false) continue;
|
|
275
|
+
if (hasExtends && activeApps.length === 0) break;
|
|
276
|
+
const entryApps = entry.type === "imports" ? activeApps : mergeApps;
|
|
277
|
+
const entryNames = entry.type === "imports" ? activeNames : mergeNames;
|
|
278
|
+
if (!entryApps.length && hasExtends) continue;
|
|
279
|
+
const dirs = entry.relDir != null ? monoEcosystem({
|
|
280
|
+
dirname: rootDir,
|
|
281
|
+
apps: entryApps,
|
|
282
|
+
subs: entry.relDir,
|
|
283
|
+
appDir: entry.appDir,
|
|
284
|
+
includes: entry.includes,
|
|
285
|
+
excludes: entry.excludes,
|
|
286
|
+
ecosystems: extendsEcosystems,
|
|
287
|
+
dirIncludes: entry.dirIncludes,
|
|
288
|
+
dirExcludes: entry.dirExcludes
|
|
289
|
+
}) : mergeEcosystem({
|
|
290
|
+
dirname: rootDir,
|
|
291
|
+
dir: entry.dir,
|
|
292
|
+
sub: entry.sub,
|
|
293
|
+
appDir: entry.appDir,
|
|
294
|
+
appDirs: entry.appDirs,
|
|
295
|
+
includes: entry.includes ?? (hasExtends ? entryNames : void 0),
|
|
296
|
+
excludes: entry.excludes,
|
|
297
|
+
ecosystems: gateCustomEntry(extendsEcosystems, entry.sub ?? name),
|
|
298
|
+
dirIncludes: entry.dirIncludes,
|
|
299
|
+
dirExcludes: entry.dirExcludes
|
|
300
|
+
});
|
|
301
|
+
switch (entry.type) {
|
|
302
|
+
case "imports":
|
|
303
|
+
for (const dir of dirs) if (existsSync(dir)) addImportsDir([dir, join(dir, "**")]);
|
|
304
|
+
break;
|
|
305
|
+
case "components": {
|
|
306
|
+
const pathPrefix = entry.pathPrefix !== false;
|
|
307
|
+
for (const dir of dirs) if (existsSync(dir) && statSync(dir).isDirectory()) addComponentsDir({
|
|
308
|
+
path: dir,
|
|
309
|
+
pathPrefix
|
|
310
|
+
});
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
case "pages":
|
|
314
|
+
registerRemotePages(dirs, entry.exclude ?? remotePageExcludes(join(ownSrcDir, "pages")), name);
|
|
315
|
+
break;
|
|
316
|
+
case "layouts":
|
|
317
|
+
registerRemoteLayouts(nuxt, dirs, entry.exclude ?? [], ownSrcDir, name);
|
|
318
|
+
break;
|
|
319
|
+
case "middleware":
|
|
320
|
+
registerRemoteMiddleware(dirs, entry.exclude ?? [], ownSrcDir, name);
|
|
321
|
+
break;
|
|
322
|
+
case "plugins": registerRemotePlugins(dirs, entry.exclude ?? [], ownSrcDir, name);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
extendViteConfig((config) => {
|
|
326
|
+
config.define = {
|
|
327
|
+
...config.define,
|
|
328
|
+
__MONO_CONFIG_EXPOSE__: JSON.stringify(sanitizeForExpose((u.expose ?? defaultMonoExpose)(monoConfig)) ?? {})
|
|
329
|
+
};
|
|
330
|
+
if (Object.keys(stubAlias).length) {
|
|
331
|
+
config.resolve ??= {};
|
|
332
|
+
const existing = config.resolve.alias;
|
|
333
|
+
config.resolve.alias = Array.isArray(existing) ? [...Object.entries(stubAlias).map(([find, replacement]) => ({
|
|
334
|
+
find,
|
|
335
|
+
replacement
|
|
336
|
+
})), ...existing] : {
|
|
337
|
+
...stubAlias,
|
|
338
|
+
...existing
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
config.server ??= {};
|
|
342
|
+
config.server.fs ??= {};
|
|
343
|
+
config.server.fs.allow = [
|
|
344
|
+
...config.server.fs.allow ?? [],
|
|
345
|
+
rootDir,
|
|
346
|
+
join(rootDir, ".mono", "apps"),
|
|
347
|
+
...appRootDirs(pathAppRoots(appRoots))
|
|
348
|
+
];
|
|
349
|
+
config.optimizeDeps ??= {};
|
|
350
|
+
config.optimizeDeps.exclude = [...config.optimizeDeps.exclude ?? [], ...optimizeExclude];
|
|
351
|
+
config.ssr ??= {};
|
|
352
|
+
config.ssr.noExternal = [
|
|
353
|
+
...Array.isArray(config.ssr.noExternal) ? config.ssr.noExternal : [],
|
|
354
|
+
"@mono-lit/utility",
|
|
355
|
+
"notivue",
|
|
356
|
+
"devextreme",
|
|
357
|
+
"exceljs",
|
|
358
|
+
"file-saver-es",
|
|
359
|
+
"@odata2ts/http-client-fetch",
|
|
360
|
+
"uuid",
|
|
361
|
+
"tslib"
|
|
362
|
+
];
|
|
363
|
+
});
|
|
364
|
+
if (u.nuxtLink !== false) addVitePlugin(monoRouterLinkToNuxtLink({ appsRoots: appRootDirs(appRoots) }));
|
|
365
|
+
const isRemoteFile = remoteGate({ appsRoots: appRootDirs(appRoots) });
|
|
366
|
+
addVitePlugin({
|
|
367
|
+
name: "mono-define-page-to-pagemeta",
|
|
368
|
+
enforce: "pre",
|
|
369
|
+
transform(code, id) {
|
|
370
|
+
const file = id?.split("?")[0]?.replace(/\\/g, "/");
|
|
371
|
+
if (!file || !file.endsWith(".vue") || !isRemoteFile(file)) return;
|
|
372
|
+
if (!code.includes("definePage")) return;
|
|
373
|
+
const out = code.replace(/\bdefinePage\s*\(\s*\{\s*meta\s*:\s*(\{[\s\S]*?\})\s*,?\s*\}\s*\)/g, "definePageMeta($1)");
|
|
374
|
+
return out === code ? void 0 : {
|
|
375
|
+
code: out,
|
|
376
|
+
map: null
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
addPluginTemplate({
|
|
381
|
+
filename: "mono-state-init.mjs",
|
|
382
|
+
getContents: () => [
|
|
383
|
+
"import { initMono } from \"@mono-lit/utility/runtime\"",
|
|
384
|
+
"export default defineNuxtPlugin(() => {",
|
|
385
|
+
" initMono(__MONO_CONFIG_EXPOSE__)",
|
|
386
|
+
"})"
|
|
387
|
+
].join("\n")
|
|
388
|
+
});
|
|
389
|
+
if (usesPreFetchModule(nuxt)) {
|
|
390
|
+
defaultPreFetchLearning(nuxt);
|
|
391
|
+
registerPreFetchLearning(nuxt, monoConfig);
|
|
392
|
+
registerPreFetchDirs(nuxt, activeRoots);
|
|
393
|
+
registerPreFetchServer(nuxt, sanitizeForExpose((u.expose ?? defaultMonoExpose)(monoConfig)) ?? {});
|
|
394
|
+
addPluginTemplate({
|
|
395
|
+
filename: "mono-prefetch-bridge.client.mjs",
|
|
396
|
+
mode: "client",
|
|
397
|
+
getContents: () => [
|
|
398
|
+
"import { monoSetPrefetchBridge } from \"@mono-lit/utility/fetching\"",
|
|
399
|
+
"// Runs after @mono-lit/nuxt-pre-fetch's `pre` plugin, which provides $nuxtPreFetch.",
|
|
400
|
+
"export default defineNuxtPlugin({",
|
|
401
|
+
" name: \"mono:prefetch-bridge\",",
|
|
402
|
+
" setup(nuxtApp) {",
|
|
403
|
+
" const api = nuxtApp.$nuxtPreFetch",
|
|
404
|
+
" if (api && api.serving) monoSetPrefetchBridge(api)",
|
|
405
|
+
" },",
|
|
406
|
+
"})"
|
|
407
|
+
].join("\n")
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
function usesPreFetchModule(nuxt) {
|
|
413
|
+
return (nuxt.options.modules ?? []).map((entry) => Array.isArray(entry) ? entry[0] : entry).some((name) => typeof name === "string" && name.includes("nuxt-pre-fetch")) || nuxt.options.nuxtPreFetch !== void 0;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Learning follows the data layer the app installs, unless the app sets `nuxtPreFetch.learn.enabled`
|
|
417
|
+
* itself: `@mono-lit/data` describes a page's OData calls on the server (`definePrefetch`), so the
|
|
418
|
+
* first visit is prefetched and nothing needs learning; plain DevExtreme stores can't, so their calls
|
|
419
|
+
* marked `prefetch: true` are learned and prefetched from the next visit. (This module runs before
|
|
420
|
+
* nuxt-pre-fetch, which reads the option with the default in place.)
|
|
421
|
+
*/
|
|
422
|
+
function defaultPreFetchLearning(nuxt) {
|
|
423
|
+
const options = nuxt.options.nuxtPreFetch ??= {};
|
|
424
|
+
options.learn ??= {};
|
|
425
|
+
if (typeof options.learn.enabled === "boolean") return;
|
|
426
|
+
options.learn.enabled = !dataLayerDescribesRequests(nuxt);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Whether `@mono-lit/devextreme` — as this app resolves it: an alias, a pnpm override, or the package
|
|
430
|
+
* itself — is `@mono-lit/data`, the data layer that describes its requests on the server.
|
|
431
|
+
*/
|
|
432
|
+
function dataLayerDescribesRequests(nuxt) {
|
|
433
|
+
const DATA_LAYER = "@mono-lit/devextreme";
|
|
434
|
+
try {
|
|
435
|
+
const aliased = nuxt.options.alias[DATA_LAYER];
|
|
436
|
+
let dir = aliased && isAbsolute(aliased) ? aliased : realpathSync(resolve(nuxt.options.rootDir, "node_modules", DATA_LAYER));
|
|
437
|
+
for (let i = 0; i < 6; i++) {
|
|
438
|
+
const manifest = join(dir, "package.json");
|
|
439
|
+
if (existsSync(manifest)) return JSON.parse(readFileSync(manifest, "utf8")).name === "@mono-lit/data";
|
|
440
|
+
dir = resolve(dir, "..");
|
|
441
|
+
}
|
|
442
|
+
} catch {}
|
|
443
|
+
return false;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* The pages of every merged app are compiled into this one, so their `definePrefetch` files are
|
|
447
|
+
* too: each active app's `app/prefetch` (or `src/prefetch`) is appended to nuxt-pre-fetch's
|
|
448
|
+
* `prefetchDir` (this module runs before it, so the option is read with them).
|
|
449
|
+
*/
|
|
450
|
+
function registerPreFetchDirs(nuxt, roots) {
|
|
451
|
+
const dirs = roots.flatMap(({ root }) => ["app/prefetch", "src/prefetch"].map((dir) => resolve(root, dir))).filter((dir) => existsSync(dir));
|
|
452
|
+
if (!dirs.length) return;
|
|
453
|
+
const options = nuxt.options.nuxtPreFetch ??= {};
|
|
454
|
+
const own = options.prefetchDir ?? "prefetch";
|
|
455
|
+
options.prefetchDir = [.../* @__PURE__ */ new Set([...Array.isArray(own) ? own : [own], ...dirs])];
|
|
456
|
+
}
|
|
457
|
+
/** Hosts of every `fetching.api` entry and the auth cookie names, for learned requests. */
|
|
458
|
+
function registerPreFetchLearning(nuxt, monoConfig) {
|
|
459
|
+
const fetching = monoConfig.fetching;
|
|
460
|
+
const hosts = /* @__PURE__ */ new Set();
|
|
461
|
+
for (const entry of Object.values(fetching?.api ?? {})) {
|
|
462
|
+
if (typeof entry?.url !== "string") continue;
|
|
463
|
+
try {
|
|
464
|
+
hosts.add(new URL(entry.url).host.toLowerCase());
|
|
465
|
+
} catch {}
|
|
466
|
+
}
|
|
467
|
+
const auth = fetching?.auth ?? {};
|
|
468
|
+
const use = auth.use && typeof auth.use === "object" ? auth.use : {};
|
|
469
|
+
const cookies = [
|
|
470
|
+
auth.token,
|
|
471
|
+
auth.tokenRefresh,
|
|
472
|
+
use.apiRequest,
|
|
473
|
+
use.refreshTokenRequest
|
|
474
|
+
].filter((name) => typeof name === "string" && !!name);
|
|
475
|
+
const headers = Object.keys(fetching?.headers ?? {}).map((name) => name.toLowerCase());
|
|
476
|
+
const runtimeConfig = nuxt.options.runtimeConfig;
|
|
477
|
+
runtimeConfig.nuxtPreFetch ??= {};
|
|
478
|
+
const dynamic = runtimeConfig.nuxtPreFetch.dynamic ??= {};
|
|
479
|
+
const merge = (current, add) => [.../* @__PURE__ */ new Set([...Array.isArray(current) ? current : [], ...add])];
|
|
480
|
+
dynamic.allowedHosts = merge(dynamic.allowedHosts, [...hosts]);
|
|
481
|
+
dynamic.authCookies = merge(dynamic.authCookies, cookies);
|
|
482
|
+
if (headers.length) dynamic.forwardHeaders = merge(dynamic.forwardHeaders ?? ["accept"], headers);
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* `definePrefetch` files call `monoFetch.prefetch` / `monoFetchOdata.prefetch` on the SERVER:
|
|
486
|
+
* Nitro needs the same (exposed) mono config the browser gets, and has to bundle the packages
|
|
487
|
+
* whose folder-style deep imports (`devextreme/core/utils/deferred`) plain Node can't load.
|
|
488
|
+
*/
|
|
489
|
+
function registerPreFetchServer(nuxt, exposed) {
|
|
490
|
+
const plugin = addTemplate({
|
|
491
|
+
filename: "mono/prefetch-init.mjs",
|
|
492
|
+
write: true,
|
|
493
|
+
getContents: () => [
|
|
494
|
+
"import { initMono } from \"@mono-lit/utility/runtime\"",
|
|
495
|
+
"import config from \"#mono/config\"",
|
|
496
|
+
"export default function monoPrefetchInit() { initMono(config) }"
|
|
497
|
+
].join("\n")
|
|
498
|
+
});
|
|
499
|
+
nuxt.hook("nitro:config", (nitroConfig) => {
|
|
500
|
+
nitroConfig.virtual ??= {};
|
|
501
|
+
nitroConfig.virtual["#mono/config"] = () => `export default ${JSON.stringify(exposed)}`;
|
|
502
|
+
nitroConfig.plugins ??= [];
|
|
503
|
+
nitroConfig.plugins.push(plugin.dst);
|
|
504
|
+
nitroConfig.alias = {
|
|
505
|
+
...appPackageAliases(nuxt.options.rootDir, "@mono-lit/utility"),
|
|
506
|
+
...nitroConfig.alias
|
|
507
|
+
};
|
|
508
|
+
nitroConfig.externals ??= {};
|
|
509
|
+
nitroConfig.externals.inline = [
|
|
510
|
+
...nitroConfig.externals.inline ?? [],
|
|
511
|
+
"@mono-lit/utility",
|
|
512
|
+
"@mono-lit/devextreme",
|
|
513
|
+
"@mono-lit/data",
|
|
514
|
+
"devextreme",
|
|
515
|
+
plugin.dst
|
|
516
|
+
];
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* `<pkg>` and each of its `exports` subpaths, resolved to the copy THIS app links (its
|
|
521
|
+
* `node_modules/<pkg>`, symlinks followed): exact-path aliases that pin one instance. Empty when
|
|
522
|
+
* the app doesn't link it.
|
|
523
|
+
*/
|
|
524
|
+
function appPackageAliases(rootDir, pkg) {
|
|
525
|
+
try {
|
|
526
|
+
const dir = realpathSync(resolve(rootDir, "node_modules", pkg));
|
|
527
|
+
const manifest = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
|
|
528
|
+
const aliases = {};
|
|
529
|
+
for (const [subpath, target] of Object.entries(manifest.exports ?? {})) {
|
|
530
|
+
const entry = typeof target === "string" ? target : target?.import ?? target?.default;
|
|
531
|
+
if (typeof entry !== "string" || subpath.includes("*")) continue;
|
|
532
|
+
aliases[subpath === "." ? pkg : `${pkg}${subpath.slice(1)}`] = resolve(dir, entry);
|
|
533
|
+
}
|
|
534
|
+
return aliases;
|
|
535
|
+
} catch {
|
|
536
|
+
return {};
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Register every `.vue` under the given remote `dirs` as a Nuxt route, skipping
|
|
541
|
+
* files matching any `exclude` glob and never clobbering an existing host route.
|
|
542
|
+
*/
|
|
543
|
+
function registerRemotePages(dirs, exclude, label) {
|
|
544
|
+
extendPages((pages) => {
|
|
545
|
+
const existing = new Set(pages.map((p) => p.path));
|
|
546
|
+
const added = [];
|
|
547
|
+
for (const dir of dirs) {
|
|
548
|
+
if (!existsSync(dir)) continue;
|
|
549
|
+
for (const file of walkVue(dir)) {
|
|
550
|
+
const rel = relative(dir, file).split(sep).join("/");
|
|
551
|
+
if (exclude.some((pattern) => globMatch(pattern, rel))) continue;
|
|
552
|
+
const routePath = toRoutePath(rel);
|
|
553
|
+
if (existing.has(routePath)) continue;
|
|
554
|
+
existing.add(routePath);
|
|
555
|
+
pages.push({
|
|
556
|
+
name: "remote-" + rel.replace(/\.vue$/, "").replace(/[^a-zA-Z0-9]+/g, "-"),
|
|
557
|
+
path: routePath,
|
|
558
|
+
file,
|
|
559
|
+
meta: { ...parsePageMeta(safeRead(file)) }
|
|
560
|
+
});
|
|
561
|
+
added.push(routePath);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (added.length) console.log(`[mono-nuxt] merged remote route(s) [${label}]:`, added.join(", "));
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Give this app's own plugins priority over a Nuxt LAYER's, by name.
|
|
569
|
+
*
|
|
570
|
+
* Nuxt gives layouts and middleware that rule for free but not plugins, which it
|
|
571
|
+
* dedupes on absolute `src` — so a remote's `plugins/mono.ts` and its host's
|
|
572
|
+
* both survive, and both call `createMono()` with a different config. Dropping
|
|
573
|
+
* the layer's copy is the whole fix.
|
|
574
|
+
*
|
|
575
|
+
* Runs on `app:resolve`, the one point where `app.plugins` exists and is still
|
|
576
|
+
* mutable. A no-op when this app ships no plugins of its own.
|
|
577
|
+
*/
|
|
578
|
+
function dedupeLayerPlugins(nuxt, candidates, ownSrcDir) {
|
|
579
|
+
if (!candidates.length) return;
|
|
580
|
+
const ownKeys = ownEcosystemKeys(join(ownSrcDir, "plugins"));
|
|
581
|
+
if (!ownKeys.size) return;
|
|
582
|
+
const roots = candidates.map((c) => normalize(c.root).toLowerCase());
|
|
583
|
+
const inLayer = (src) => {
|
|
584
|
+
const file = normalize(src).toLowerCase();
|
|
585
|
+
return roots.some((root) => file.startsWith(root + sep));
|
|
586
|
+
};
|
|
587
|
+
nuxt.hook("app:resolve", (app) => {
|
|
588
|
+
const dropped = [];
|
|
589
|
+
app.plugins = app.plugins.filter((plugin) => {
|
|
590
|
+
const src = plugin?.src;
|
|
591
|
+
if (!src || !inLayer(src)) return true;
|
|
592
|
+
if (!ownKeys.has(ecosystemFileKey(src))) return true;
|
|
593
|
+
dropped.push(relative(rootOf(candidates, src), src).split(sep).join("/"));
|
|
594
|
+
return false;
|
|
595
|
+
});
|
|
596
|
+
if (dropped.length) console.log(`[mono-nuxt] shadowed federated plugin(s) with this app's own:`, dropped.join(", "));
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
/** The layer root a file sits in, for a readable log line. */
|
|
600
|
+
function rootOf(candidates, file) {
|
|
601
|
+
const lower = normalize(file).toLowerCase();
|
|
602
|
+
return candidates.find((c) => lower.startsWith(normalize(c.root).toLowerCase() + sep))?.root ?? "";
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Register every `.vue` under the given federated `layouts` dirs as a Nuxt
|
|
606
|
+
* layout, so a remote renders inside its host's shell.
|
|
607
|
+
*
|
|
608
|
+
* Done through the `app:templates` hook rather than kit's `addLayout` on
|
|
609
|
+
* purpose: `addLayout` routes the file through `addTemplate`, which COPIES it
|
|
610
|
+
* into `.nuxt/` — a snapshot that breaks HMR on the host's shell and any
|
|
611
|
+
* path-relative import inside it. Writing `app.layouts` directly is what Nuxt
|
|
612
|
+
* itself does for `<srcDir>/layouts`, and it points at the real file.
|
|
613
|
+
*
|
|
614
|
+
* The hook runs after Nuxt has resolved this app's own layouts, so the
|
|
615
|
+
* `layoutName in app.layouts` guard already gives own-file-wins; the
|
|
616
|
+
* `ownEcosystemKeys` check in front of it makes the same rule explicit and
|
|
617
|
+
* consistent with middleware/plugins.
|
|
618
|
+
*/
|
|
619
|
+
function registerRemoteLayouts(nuxt, dirs, exclude, ownSrcDir, label) {
|
|
620
|
+
const own = ownEcosystemKeys(join(ownSrcDir, "layouts"));
|
|
621
|
+
const found = [];
|
|
622
|
+
for (const dir of dirs) for (const file of walkFiles(dir, [".vue"])) {
|
|
623
|
+
const rel = relative(dir, file).split(sep).join("/");
|
|
624
|
+
if (exclude.some((pattern) => globMatch(pattern, rel))) continue;
|
|
625
|
+
if (own.has(ecosystemFileKey(file))) continue;
|
|
626
|
+
found.push({
|
|
627
|
+
name: layoutNameFor(dir, file),
|
|
628
|
+
file
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
if (!found.length) return;
|
|
632
|
+
nuxt.hook("app:templates", (app) => {
|
|
633
|
+
const added = [];
|
|
634
|
+
for (const { name, file } of found) {
|
|
635
|
+
if (name in app.layouts) continue;
|
|
636
|
+
app.layouts[name] = {
|
|
637
|
+
name,
|
|
638
|
+
file
|
|
639
|
+
};
|
|
640
|
+
added.push(name);
|
|
641
|
+
}
|
|
642
|
+
if (added.length) console.log(`[mono-nuxt] merged federated layout(s) [${label}]:`, added.join(", "));
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Register the top-level files of the given federated `middleware` dirs as Nuxt
|
|
647
|
+
* route middleware, honouring the `.global` suffix.
|
|
648
|
+
*
|
|
649
|
+
* TOP LEVEL ONLY, deliberately: Nuxt treats every file in `middleware/` as a
|
|
650
|
+
* middleware, but a federated app nests plain helper modules underneath —
|
|
651
|
+
* mono-nuxt-host keeps its guard dispatcher in `middleware/run-guards.ts` and
|
|
652
|
+
* the guards themselves in `middleware/guards/`, imported BY the global
|
|
653
|
+
* middleware rather than registered alongside it. Recursing would register four
|
|
654
|
+
* guards as four independent middlewares.
|
|
655
|
+
*
|
|
656
|
+
* `addRouteMiddleware` matches on `name`, so a name this app already defines is
|
|
657
|
+
* left alone (it warns rather than overwrites); the `ownEcosystemKeys` check
|
|
658
|
+
* skips it before that happens.
|
|
659
|
+
*/
|
|
660
|
+
function registerRemoteMiddleware(dirs, exclude, ownSrcDir, label) {
|
|
661
|
+
const own = ownEcosystemKeys(join(ownSrcDir, "middleware"));
|
|
662
|
+
const added = [];
|
|
663
|
+
for (const dir of dirs) for (const file of topLevelFiles(dir, SCRIPT_EXTENSIONS)) {
|
|
664
|
+
const rel = relative(dir, file).split(sep).join("/");
|
|
665
|
+
if (exclude.some((pattern) => globMatch(pattern, rel))) continue;
|
|
666
|
+
if (own.has(ecosystemFileKey(file))) continue;
|
|
667
|
+
const { name, global } = middlewareNameFor(file);
|
|
668
|
+
addRouteMiddleware({
|
|
669
|
+
name,
|
|
670
|
+
path: file,
|
|
671
|
+
global
|
|
672
|
+
});
|
|
673
|
+
added.push(global ? `${name} (global)` : name);
|
|
674
|
+
}
|
|
675
|
+
if (added.length) console.log(`[mono-nuxt] merged federated middleware [${label}]:`, added.join(", "));
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Register the top-level files of the given federated `plugins` dirs as Nuxt
|
|
679
|
+
* plugins. `normalizePlugin` reads the `.client` / `.server` suffix off the
|
|
680
|
+
* path itself, so no `mode` is passed.
|
|
681
|
+
*
|
|
682
|
+
* `append: true` keeps discovery order — `addPlugin` unshifts by default, which
|
|
683
|
+
* would reverse a whole directory.
|
|
684
|
+
*
|
|
685
|
+
* This is the one destination where own-file-wins is load-bearing rather than
|
|
686
|
+
* belt-and-braces: `addPlugin` dedupes on the absolute `src`, which never
|
|
687
|
+
* matches across two checkouts. A remote shipping its own `plugins/mono.ts`
|
|
688
|
+
* (pointing `createMono` at ITS config instead of the host's) relies on this.
|
|
689
|
+
*/
|
|
690
|
+
function registerRemotePlugins(dirs, exclude, ownSrcDir, label) {
|
|
691
|
+
const own = ownEcosystemKeys(join(ownSrcDir, "plugins"));
|
|
692
|
+
const added = [];
|
|
693
|
+
for (const dir of dirs) for (const file of topLevelFiles(dir, SCRIPT_EXTENSIONS)) {
|
|
694
|
+
const rel = relative(dir, file).split(sep).join("/");
|
|
695
|
+
if (exclude.some((pattern) => globMatch(pattern, rel))) continue;
|
|
696
|
+
if (own.has(ecosystemFileKey(file))) continue;
|
|
697
|
+
addPlugin({ src: file }, { append: true });
|
|
698
|
+
added.push(rel);
|
|
699
|
+
}
|
|
700
|
+
if (added.length) console.log(`[mono-nuxt] merged federated plugin(s) [${label}]:`, added.join(", "));
|
|
701
|
+
}
|
|
702
|
+
/** Recursively collect `.vue` files under a directory. */
|
|
703
|
+
function walkVue(dir) {
|
|
704
|
+
const out = [];
|
|
705
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
706
|
+
const full = join(dir, entry.name);
|
|
707
|
+
if (entry.isDirectory()) out.push(...walkVue(full));
|
|
708
|
+
else if (entry.name.endsWith(".vue")) out.push(full);
|
|
709
|
+
}
|
|
710
|
+
return out;
|
|
711
|
+
}
|
|
712
|
+
/** `budget/alokasi/index.vue` -> `/budget/alokasi`, `budget/[id].vue` -> `/budget/:id`. */
|
|
713
|
+
function toRoutePath(rel) {
|
|
714
|
+
let p = rel.replace(/\.vue$/, "").replace(/\/index$/, "").replace(/\[([^\]]+)\]/g, ":$1");
|
|
715
|
+
p = "/" + p;
|
|
716
|
+
if (p.length > 1 && p.endsWith("/")) p = p.slice(0, -1);
|
|
717
|
+
return p;
|
|
718
|
+
}
|
|
719
|
+
function safeRead(file) {
|
|
720
|
+
try {
|
|
721
|
+
return readFileSync(file, "utf-8");
|
|
722
|
+
} catch {
|
|
723
|
+
return "";
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Minimal glob matcher for a `/`-joined relative path. Supports `**` (any path
|
|
728
|
+
* segments), `*` (any chars within a segment) and `?` (single char). No
|
|
729
|
+
* dependency — enough for page-exclude patterns like `index.vue` (root only).
|
|
730
|
+
*/
|
|
731
|
+
function globMatch(pattern, input) {
|
|
732
|
+
const re = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "\0").replace(/\*/g, "[^/]*").replace(//g, ".*").replace(/\?/g, "[^/]");
|
|
733
|
+
return new RegExp(`^${re}$`).test(input);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
//#endregion
|
|
737
|
+
export { monoNuxtModule as default };
|