@mono-lit/utility 0.0.0-stage → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/LICENSE.md +54 -0
  2. package/README.md +157 -3
  3. package/dist/app-roots-CvJnmXcs.js +128 -0
  4. package/dist/app-roots-DK41xMWj.d.ts +90 -0
  5. package/dist/config-node-UzJrXg0Z.js +76 -0
  6. package/dist/config-node.d.ts +923 -0
  7. package/dist/config-node.js +7 -0
  8. package/dist/config.d.ts +2 -0
  9. package/dist/config.js +3 -0
  10. package/dist/create-config-B8IhX4ht.d.ts +735 -0
  11. package/dist/create-config-DdL3Fh6T.js +357 -0
  12. package/dist/fetching.d.ts +244 -0
  13. package/dist/fetching.js +1015 -0
  14. package/dist/generate-CJ7MtcDd.js +291 -0
  15. package/dist/index-BAy6tbOG.d.ts +371 -0
  16. package/dist/index-DYlzhHq7.d.ts +514 -0
  17. package/dist/index.d.ts +25 -0
  18. package/dist/index.js +941 -0
  19. package/dist/merge-file-CLc3wxY4.d.ts +99 -0
  20. package/dist/merge-file-CtyKTu5L.js +133 -0
  21. package/dist/mock-db-4tTWrF-P.js +1282 -0
  22. package/dist/mock-db.d.ts +2 -0
  23. package/dist/mock-db.js +4 -0
  24. package/dist/mono-alias-DNDm-jB_.js +508 -0
  25. package/dist/mono-clone.mjs +958 -0
  26. package/dist/mono-db.d.ts +1 -0
  27. package/dist/mono-db.js +158 -0
  28. package/dist/mono-env.mjs +231 -0
  29. package/dist/mono-git.mjs +798 -0
  30. package/dist/mono-link-YlOQ2PVS.js +488 -0
  31. package/dist/mono-prepare.d.ts +1 -0
  32. package/dist/mono-prepare.js +28 -0
  33. package/dist/mono-skills.d.ts +1 -0
  34. package/dist/mono-skills.js +837 -0
  35. package/dist/mono-tsconfig-D2qRL9_R.js +204 -0
  36. package/dist/mono.mjs +34 -0
  37. package/dist/nuxt-layers-DP1m7f1-.js +176 -0
  38. package/dist/nuxt-layers.d.ts +36 -0
  39. package/dist/nuxt-layers.js +3 -0
  40. package/dist/nuxt-runtime.d.ts +17 -0
  41. package/dist/nuxt-runtime.js +102 -0
  42. package/dist/nuxt.d.ts +390 -0
  43. package/dist/nuxt.js +737 -0
  44. package/dist/runtime-vs7U9Ed4.js +6054 -0
  45. package/dist/runtime.d.ts +2518 -0
  46. package/dist/runtime.js +4 -0
  47. package/dist/session-Bcig-rPi.js +1721 -0
  48. package/dist/types-B6FdB7LJ.d.ts +57 -0
  49. package/dist/universal-BR0O7Qwk.d.ts +59 -0
  50. package/dist/universal-DIVEzCvN.js +600 -0
  51. package/dist/virtual-mono-apps.d.ts +16 -0
  52. package/dist/vite.d.ts +943 -0
  53. package/dist/vite.js +1132 -0
  54. package/package.json +141 -3
@@ -0,0 +1,99 @@
1
+ import { o as MonoAppType } from "./create-config-B8IhX4ht.js";
2
+ //#region src/composables/merge-file.d.ts
3
+ type EcoSub = "composables" | "stores" | "components";
4
+ type DirValue = string | string[];
5
+ type MatchValue = string | RegExp | ((value: string) => boolean);
6
+ type MergeEcosystemOptions<T = string> = {
7
+ dirname: string;
8
+ appDir?: string;
9
+ /**
10
+ * Pre-resolved app roots, replacing the `.mono/apps/` listing.
11
+ *
12
+ * `monoEcosystem` passes these so an app pointed at a local checkout by
13
+ * `apps[].path` contributes its dirs — a directory listing cannot see one.
14
+ * Omit for the plain scan.
15
+ */
16
+ appRoots?: {
17
+ name: string;
18
+ root: string;
19
+ }[];
20
+ /**
21
+ * App name filters.
22
+ */
23
+ includes?: string[];
24
+ excludes?: string[];
25
+ /**
26
+ * Directory path.
27
+ */
28
+ dir?: DirValue;
29
+ sub?: EcoSub;
30
+ /**
31
+ * Per-app directory override.
32
+ */
33
+ appDirs?: Record<string, DirValue>;
34
+ /**
35
+ * Per-app ecosystem allowlist, from an `extends` entry's `ecosystems`.
36
+ * App absent = unrestricted; `[]` = contributes nothing. See
37
+ * {@link ecosystemSubAllowed}.
38
+ *
39
+ * Honoured here as well as in {@link monoEcosystem} so calling the
40
+ * low-level primitive directly cannot escape a config's policy.
41
+ */
42
+ ecosystems?: Record<string, string[]>;
43
+ /**
44
+ * Resolved directory filters.
45
+ */
46
+ dirIncludes?: MatchValue[];
47
+ dirExcludes?: MatchValue[];
48
+ /**
49
+ * Output mapper.
50
+ */
51
+ map?: (dir: string, ctx: {
52
+ appName: string;
53
+ appRoot: string;
54
+ }) => T;
55
+ };
56
+ declare function mergeEcosystem<T = string>({ dirname, appDir, appRoots, includes, excludes, dir, sub, appDirs, ecosystems, dirIncludes, dirExcludes, map }: MergeEcosystemOptions<T>): T[];
57
+ type MonoEcosystemOptions = {
58
+ dirname: string;
59
+ /**
60
+ * Resolved apps (name + kind). Each app's srcDir is derived from `type`.
61
+ * `path` is read too — carry it through, or a locally-linked app silently
62
+ * contributes nothing.
63
+ */
64
+ apps: {
65
+ name: string;
66
+ type: MonoAppType;
67
+ path?: string;
68
+ }[];
69
+ /**
70
+ * Subpath(s) relative to each app's srcDir — e.g. `'pages'`,
71
+ * `['composables/shared', 'stores/shared', 'composables']`. Resolved per app
72
+ * to `<srcDirForType(type)>/<sub>` (`src/pages` for a vue app, `app/pages`
73
+ * for a nuxt app).
74
+ */
75
+ subs: string | string[];
76
+ appDir?: string;
77
+ includes?: string[];
78
+ excludes?: string[];
79
+ /**
80
+ * Per-app ecosystem allowlist from `resolveExtendsEcosystems(rawConfig)`.
81
+ * App absent = unrestricted; `[]` = contributes nothing.
82
+ */
83
+ ecosystems?: Record<string, string[]>;
84
+ dirIncludes?: MatchValue[];
85
+ dirExcludes?: MatchValue[];
86
+ /** @deprecated `apps[].path` is authoritative in every command; ignored. */
87
+ link?: boolean;
88
+ };
89
+ /**
90
+ * Type-aware wrapper over {@link mergeEcosystem}: builds per-app `appDirs` from
91
+ * each app's `type` (`vue` -> `src/<sub>`, `nuxt` -> `app/<sub>`) so a host can
92
+ * pull in a remote without hardcoding its source folder. Only apps present in
93
+ * both `apps` and {@link resolveAppRoots} produce dirs — which means the
94
+ * `.mono/apps/` clone, or the local checkout an app's `path` names. Returns
95
+ * absolute, existing dirs.
96
+ */
97
+ declare function monoEcosystem({ dirname, apps, subs, appDir, includes, excludes, ecosystems, dirIncludes, dirExcludes }: MonoEcosystemOptions): string[];
98
+ //#endregion
99
+ export { monoEcosystem as i, MonoEcosystemOptions as n, mergeEcosystem as r, MergeEcosystemOptions as t };
@@ -0,0 +1,133 @@
1
+ import { c as resolveAppRoots } from "./app-roots-CvJnmXcs.js";
2
+ import { l as srcDirForType } from "./create-config-DdL3Fh6T.js";
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+
6
+ //#region src/composables/merge-file.ts
7
+ function toArray(value) {
8
+ if (!value) return [];
9
+ return Array.isArray(value) ? value : [value];
10
+ }
11
+ function uniq(value) {
12
+ return [...new Set(value)];
13
+ }
14
+ function resolveDirValue({ dir, sub }) {
15
+ const dirs = toArray(dir);
16
+ if (!dirs.length && sub) return [path.join("src", sub)];
17
+ if (!sub) return dirs;
18
+ return dirs.map((d) => path.join(d, sub));
19
+ }
20
+ /** `.\Foo\bar/` -> `Foo/bar`, so policy and candidate compare on equal terms. */
21
+ function normalizeSub(value) {
22
+ return value.replaceAll("\\", "/").replace(/^\.\//, "").replace(/\/+$/, "");
23
+ }
24
+ /**
25
+ * Does `sub` fall inside an `ecosystems` allowlist?
26
+ *
27
+ * Matching is **segment-wise**, not `startsWith`: `'composables'` admits
28
+ * `'composables/shared'` (the shape hosts actually pass), while `'compos'`
29
+ * admits nothing and `'composables/shared'` admits only itself.
30
+ *
31
+ * `undefined` means no policy was declared, so everything is allowed; an empty
32
+ * list is an explicit "nothing".
33
+ */
34
+ function ecosystemSubAllowed(sub, allow) {
35
+ if (!allow) return true;
36
+ if (!allow.length) return false;
37
+ const target = normalizeSub(sub);
38
+ return allow.some((entry) => {
39
+ const allowed = normalizeSub(entry);
40
+ return target === allowed || target.startsWith(`${allowed}/`);
41
+ });
42
+ }
43
+ /**
44
+ * Reduce a candidate relative dir to the sub an `ecosystems` list is written
45
+ * in: `app/pages` and `src/pages` both mean `pages`. Lets the policy apply in
46
+ * {@link mergeEcosystem}, which — unlike {@link monoEcosystem} — only ever sees
47
+ * resolved directories, never the sub names they came from.
48
+ */
49
+ function candidateSub(rel) {
50
+ const normalized = normalizeSub(rel);
51
+ const [head, ...rest] = normalized.split("/");
52
+ return rest.length && (head === "src" || head === "app") ? rest.join("/") : normalized;
53
+ }
54
+ function matches(value, matcher) {
55
+ if (typeof matcher === "string") return value.includes(matcher);
56
+ if (matcher instanceof RegExp) return matcher.test(value);
57
+ return matcher(value);
58
+ }
59
+ function passDirFilter({ dir, dirIncludes, dirExcludes }) {
60
+ const normalized = dir.replaceAll("\\", "/");
61
+ if (dirIncludes?.length) {
62
+ if (!dirIncludes.some((m) => matches(normalized, m))) return false;
63
+ }
64
+ if (dirExcludes?.length) {
65
+ if (dirExcludes.some((m) => matches(normalized, m))) return false;
66
+ }
67
+ return true;
68
+ }
69
+ function mergeEcosystem({ dirname, appDir = "./.mono/apps", appRoots, includes, excludes, dir, sub, appDirs = {}, ecosystems, dirIncludes, dirExcludes, map }) {
70
+ const appsDir = path.resolve(dirname, appDir);
71
+ const roots = appRoots ?? (fs.existsSync(appsDir) ? fs.readdirSync(appsDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => ({
72
+ name: d.name,
73
+ root: path.join(appsDir, d.name)
74
+ })) : []);
75
+ if (!roots.length) return [];
76
+ return roots.filter(({ name }) => {
77
+ if (includes?.length && !includes.includes(name)) return false;
78
+ if (excludes?.length && excludes.includes(name)) return false;
79
+ return true;
80
+ }).flatMap(({ name: appName, root: appRoot }) => {
81
+ return uniq((appDirs[appName] ? toArray(appDirs[appName]) : resolveDirValue({
82
+ dir,
83
+ sub
84
+ })).filter((rel) => ecosystemSubAllowed(candidateSub(rel), ecosystems?.[appName]))).map((rel) => path.resolve(appRoot, rel)).filter((resolvedDir) => fs.existsSync(resolvedDir)).filter((resolvedDir) => passDirFilter({
85
+ dir: resolvedDir,
86
+ dirIncludes,
87
+ dirExcludes
88
+ })).map((resolvedDir) => {
89
+ if (map) return map(resolvedDir, {
90
+ appName,
91
+ appRoot
92
+ });
93
+ return resolvedDir;
94
+ });
95
+ });
96
+ }
97
+ /**
98
+ * Type-aware wrapper over {@link mergeEcosystem}: builds per-app `appDirs` from
99
+ * each app's `type` (`vue` -> `src/<sub>`, `nuxt` -> `app/<sub>`) so a host can
100
+ * pull in a remote without hardcoding its source folder. Only apps present in
101
+ * both `apps` and {@link resolveAppRoots} produce dirs — which means the
102
+ * `.mono/apps/` clone, or the local checkout an app's `path` names. Returns
103
+ * absolute, existing dirs.
104
+ */
105
+ function monoEcosystem({ dirname, apps, subs, appDir, includes, excludes, ecosystems, dirIncludes, dirExcludes }) {
106
+ const subList = toArray(subs);
107
+ const appDirs = {};
108
+ for (const app of apps) {
109
+ if (!app?.name || !app?.type) continue;
110
+ const keep = subList.filter((s) => ecosystemSubAllowed(s, ecosystems?.[app.name]));
111
+ if (!keep.length) continue;
112
+ const src = srcDirForType(app.type);
113
+ appDirs[app.name] = keep.map((s) => path.join(src, s));
114
+ }
115
+ return mergeEcosystem({
116
+ dirname,
117
+ appDir,
118
+ appRoots: resolveAppRoots({
119
+ dirname,
120
+ ...appDir ? { appsDir: appDir } : {},
121
+ apps,
122
+ onMissingPath: "ignore"
123
+ }),
124
+ appDirs,
125
+ includes,
126
+ excludes,
127
+ dirIncludes,
128
+ dirExcludes
129
+ });
130
+ }
131
+
132
+ //#endregion
133
+ export { mergeEcosystem as n, monoEcosystem as r, ecosystemSubAllowed as t };