@mono-lit/utility 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,153 @@
1
+ import { r as dedupeConfigArrays } from "./create-config-DdL3Fh6T.js";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import os from "node:os";
5
+ import { loadConfig } from "c12";
6
+
7
+ //#region src/composables/config-node.ts
8
+ /**
9
+ * Runtime-only imports a `mono.config.ts` makes that the Node-side readers never use.
10
+ *
11
+ * App configs import `{ DataSource, ODataStore, CustomStore }` from
12
+ * `@mono-lit/devextreme` and only STORE them (`dataSource: DataSource`), for the
13
+ * browser to use. Nothing that reads the config in Node needs them: the Nuxt/Vite
14
+ * integrations read `name` / `apps` / `menu` / `template`, `sanitizeForExpose` drops
15
+ * functions, and `mono db` reads the mock schemas.
16
+ *
17
+ * Loading the real package is very slow. It pulls in hundreds of DevExtreme
18
+ * `devextreme/data/*` CommonJS files written with directory imports, and jiti
19
+ * resolves every one with synchronous `stat` calls. c12 also creates jiti with
20
+ * `moduleCache: false`, so EVERY `getMonoConfig` call pays the cost again. On
21
+ * Windows that measured ~0.7–1.2 s per config, against ~0.15 s stubbed. A
22
+ * mono-lith host loads one config per app at startup, which made Nuxt report
23
+ * `mono-nuxt` and app modules as slow to set up (7–12 s).
24
+ */
25
+ const RUNTIME_STUBS = { "@mono-lit/devextreme": {
26
+ file: "devextreme-v1.mjs",
27
+ source: `// Generated by @mono-lit/utility; do not edit.
28
+ //
29
+ // Stands in for @mono-lit/devextreme while a mono.config is loaded in Node
30
+ // (getMonoConfig). The config only stores these classes for the browser; Node-side
31
+ // readers never construct them. See RUNTIME_STUBS in @mono-lit/utility.
32
+ export class DataSource {}
33
+ export class CustomStore {}
34
+ export class ODataStore {}
35
+ export class ArrayStore {}
36
+ export function config() { return {} }
37
+ `
38
+ } };
39
+ let runtimeStubAliasCache;
40
+ /**
41
+ * Write the stub modules once per process into the OS temp dir and return the
42
+ * alias map (specifier → stub file). The temp dir instead of the app's `.mono/`,
43
+ * because sibling apps in a mono-lith are read in place and may have no `.mono/`.
44
+ */
45
+ function runtimeStubAliases() {
46
+ if (runtimeStubAliasCache) return runtimeStubAliasCache;
47
+ const dir = path.join(os.tmpdir(), "mono-lit-utility", "config-stubs");
48
+ const alias = {};
49
+ for (const [specifier, { file, source }] of Object.entries(RUNTIME_STUBS)) {
50
+ const target = path.join(dir, file);
51
+ let current;
52
+ try {
53
+ current = fs.readFileSync(target, "utf8");
54
+ } catch {
55
+ current = void 0;
56
+ }
57
+ if (current !== source) {
58
+ fs.mkdirSync(dir, { recursive: true });
59
+ const tmp = `${target}.${process.pid}.tmp`;
60
+ fs.writeFileSync(tmp, source);
61
+ try {
62
+ fs.renameSync(tmp, target);
63
+ } catch (error) {
64
+ fs.rmSync(tmp, { force: true });
65
+ if (!fs.existsSync(target)) throw error;
66
+ }
67
+ }
68
+ alias[specifier] = target;
69
+ }
70
+ runtimeStubAliasCache = alias;
71
+ return alias;
72
+ }
73
+ function getCwd() {
74
+ return typeof process !== "undefined" ? process.cwd() : void 0;
75
+ }
76
+ /**
77
+ * Collapse name-keyed arrays that may carry one duplicate per layer, so the
78
+ * loaded config behaves like a single config.
79
+ *
80
+ * Delegates to `dedupeConfigArrays` from `create-config` rather than owning a
81
+ * rule: this used to keep the FIRST occurrence while the runtime resolver keeps
82
+ * the LAST, which are opposite precedence rules for the same data. It is a no-op
83
+ * while `extend: false` (below) leaves c12 with only the root config's own
84
+ * arrays, but the two must never be able to disagree.
85
+ */
86
+ function normalizeMergedConfig(config) {
87
+ return dedupeConfigArrays(config);
88
+ }
89
+ async function loadMonoConfig(options = {}) {
90
+ const { stubRuntimeDeps = true, ...loadOptions } = options;
91
+ const jitiOptions = stubRuntimeDeps ? {
92
+ ...loadOptions.jitiOptions,
93
+ alias: {
94
+ ...runtimeStubAliases(),
95
+ ...loadOptions.jitiOptions?.alias
96
+ }
97
+ } : loadOptions.jitiOptions;
98
+ const result = await loadConfig({
99
+ name: "mono",
100
+ cwd: options.cwd ?? getCwd(),
101
+ extend: false,
102
+ defaults: {
103
+ apps: [],
104
+ name: "mono-app",
105
+ type: "vue",
106
+ menu: [],
107
+ cookie: [],
108
+ jwt: {}
109
+ },
110
+ ...loadOptions,
111
+ ...jitiOptions ? { jitiOptions } : {}
112
+ });
113
+ return {
114
+ ...result,
115
+ config: normalizeMergedConfig(result.config)
116
+ };
117
+ }
118
+ async function getMonoConfig(options = {}) {
119
+ try {
120
+ return (await loadMonoConfig(options)).config;
121
+ } catch (error) {
122
+ throw describeConfigLoadError(error);
123
+ }
124
+ }
125
+ /** `Cannot find module '@some-app-root/mono.config'` — the shape jiti throws. */
126
+ const MISSING_ALIAS_RE = /Cannot find module ['"](@[^'"]+)['"]/;
127
+ /**
128
+ * Turn an unresolved mono alias into an error that says what to do.
129
+ *
130
+ * `mono.config.ts` reaches other apps through ordinary `import`s resolved by jiti
131
+ * against the alias map, and those aliases come from the `.mono/apps/` directory
132
+ * listing. An app that isn't synced therefore surfaces as a bare `Cannot find
133
+ * module '@x-root/mono.config'` — a specifier nobody typed by hand, thrown from
134
+ * inside c12, naming no file and no fix.
135
+ *
136
+ * Pattern-based on purpose: this module knows nothing about the alias map, and
137
+ * shouldn't. Covers the paths that never call `monoStubAliases` (the `mono db` CLI)
138
+ * and the specifiers a config-only stub can't satisfy (a host config importing a
139
+ * missing app's OData service).
140
+ */
141
+ function describeConfigLoadError(error) {
142
+ const message = error instanceof Error ? error.message : String(error);
143
+ const specifier = MISSING_ALIAS_RE.exec(message)?.[1];
144
+ if (!specifier) return error;
145
+ return new Error([
146
+ `[@mono-lit/utility] Failed to load mono.config: cannot resolve '${specifier}'.`,
147
+ "That looks like a federated mono app that isn't present in .mono/apps/.",
148
+ "Run `mono sync && mono prepare`. If the repo is private, set its envToken in .env."
149
+ ].join("\n"), { cause: error });
150
+ }
151
+
152
+ //#endregion
153
+ export { loadMonoConfig as n, getMonoConfig as t };
@@ -5,6 +5,13 @@ import { TSConfig } from "pkg-types";
5
5
  //#region src/composables/config-node.d.ts
6
6
  export interface LoadMonoConfigOptions extends Partial<LoadConfigOptions<MonoConfig>> {
7
7
  cwd?: string;
8
+ /**
9
+ * Swap runtime-only imports of `mono.config.ts` for inert stubs while loading it
10
+ * in Node (default `true`). See `RUNTIME_STUBS`. Set `false` only if a Node-side
11
+ * caller really needs the real classes out of the config. A caller's own
12
+ * `jitiOptions.alias` entry for the same specifier still wins.
13
+ */
14
+ stubRuntimeDeps?: boolean;
8
15
  }
9
16
  export declare function loadMonoConfig(options?: LoadMonoConfigOptions): Promise<{
10
17
  config: MonoConfig;
@@ -1,5 +1,5 @@
1
1
  import { a as isMissingPathError, c as pathAppRoots, i as isHostedApp, l as resetAppPathWarnings, n as hasUrl, o as linkedAppRoots, r as hostedAppRoots, s as missingPathMessage, t as appRootDirs, u as resolveAppRoots } from "./app-roots-LpDrHF_J.js";
2
- import { n as loadMonoConfig, t as getMonoConfig } from "./config-node-UzJrXg0Z.js";
2
+ import { n as loadMonoConfig, t as getMonoConfig } from "./config-node-Dn0K54kd.js";
3
3
  import { a as extractTemplate, c as monoConfigFileFor, d as resolveFederatedRoots, f as stripCommentsSafe, i as extractSkill, l as monoMissingApps, n as extractConfig, o as formatMissingApps, r as extractConfigName, s as monoAlias, t as assertAppSources, u as monoStubAliases } from "./mono-alias-BU2B0tYL.js";
4
4
  import { a as buildMonoTsconfig, i as adoptHostedApps, n as MONO_DIR, o as monoTsconfigPaths, r as MONO_TSCONFIG_REF, s as runMonoPrepare, t as MONO_APPS_DIR } from "./mono-tsconfig-CYOKwy6E.js";
5
5
  import { A as BASE_ARGS, B as refPatterns, C as commitAndPush, D as repoDir, E as readRepoFile, F as parseHeadSha, G as SKILLS_DEFAULTS, H as tokenRemote, I as parseLsRemote, J as loadSkillsEnv, K as isGenericAppName, L as parseSymref, M as firstFatal, N as gitEnv, O as resolveRemote, P as isNonFastForward, R as redactUrl, S as SkillsAccessError, T as listRepoFiles, U as ALLOWED_FLAGS, V as runGit, W as GENERIC_APP_NAMES, Y as resolveSkillTarget, _ as stagingRoot, a as applyPlan, b as resolveAppId, c as chunkConversation, d as REQUIRED_FILES, f as cacheDir, g as removeSession, h as moveToFailed, i as runSearch, j as classifyGitFailure, k as skillsRoot, l as redact, m as loadStagedSession, n as runCheck, o as buildSavePlan, p as listSessions, q as loadSkillConfig, r as runRead, s as runSave, t as runSessionShow, u as redactBuffer, v as validateStagedSession, w as ensureRepo, x as detectActor, y as normalizeAppId, z as refDirCandidates } from "./session-CbSl2BMJ.js";
package/dist/mono-db.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { c as resolveMonoConfig } from "./create-config-DdL3Fh6T.js";
2
- import { t as getMonoConfig } from "./config-node-UzJrXg0Z.js";
2
+ import { t as getMonoConfig } from "./config-node-Dn0K54kd.js";
3
3
  import { s as monoAlias } from "./mono-alias-BU2B0tYL.js";
4
4
  import { n as generateSeed, s as parseMockSchema } from "./generate-CJ7MtcDd.js";
5
5
  import { writeFileSync } from "node:fs";
package/dist/nuxt.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { c as pathAppRoots, t as appRootDirs } from "./app-roots-LpDrHF_J.js";
2
2
  import { c as resolveMonoConfig, l as srcDirForType, o as resolveExtendsAppNames, s as resolveExtendsEcosystems } from "./create-config-DdL3Fh6T.js";
3
3
  import { n as mergeEcosystem, r as monoEcosystem, t as ecosystemSubAllowed } from "./merge-file-DahuGcvr.js";
4
- import { t as getMonoConfig } from "./config-node-UzJrXg0Z.js";
4
+ import { t as getMonoConfig } from "./config-node-Dn0K54kd.js";
5
5
  import { d as resolveFederatedRoots, n as extractConfig, o as formatMissingApps, s as monoAlias, t as assertAppSources, u as monoStubAliases } from "./mono-alias-BU2B0tYL.js";
6
6
  import { a as defaultMonoExpose, c as createMonoLithHooks, f as remoteGate, i as monoRouterLinkToNuxtLink, o as sanitizeForExpose, u as parsePageMeta } from "./mono-link-URGX8xsT.js";
7
7
  import { r as registerMonoNuxtLayers, t as monoLayerCandidates } from "./nuxt-layers-BO0AGwA5.js";
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { c as pathAppRoots, t as appRootDirs } from "./app-roots-LpDrHF_J.js";
2
2
  import { c as resolveMonoConfig, l as srcDirForType, o as resolveExtendsAppNames, s as resolveExtendsEcosystems } from "./create-config-DdL3Fh6T.js";
3
3
  import { r as monoEcosystem } from "./merge-file-DahuGcvr.js";
4
- import { t as getMonoConfig } from "./config-node-UzJrXg0Z.js";
4
+ import { t as getMonoConfig } from "./config-node-Dn0K54kd.js";
5
5
  import { d as resolveFederatedRoots, n as extractConfig, o as formatMissingApps, s as monoAlias, t as assertAppSources, u as monoStubAliases } from "./mono-alias-BU2B0tYL.js";
6
6
  import { a as defaultMonoExpose, c as createMonoLithHooks, d as parsePageMetaFromFile, f as remoteGate, i as monoRouterLinkToNuxtLink, l as monoLith, n as monoNuxtLinkToRouterLink, o as sanitizeForExpose, r as monoRouterLink, s as MONO_APPS_VIRTUAL_ID, t as monoNuxtLink, u as parsePageMeta } from "./mono-link-URGX8xsT.js";
7
7
  import { existsSync } from "node:fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mono-lit/utility",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Mono config, fetching, auth/token, Nuxt/Vite integration and shared helpers for the @mono-lit ecosystem.",
5
5
  "keywords": [
6
6
  "vue",
@@ -110,7 +110,7 @@
110
110
  "vite": "8.3.4",
111
111
  "vue-tsc": "~3.2.0",
112
112
  "yup": "1.7.1",
113
- "@mono-lit/helper": "0.1.0"
113
+ "@mono-lit/helper": "0.1.6"
114
114
  },
115
115
  "dependencies": {
116
116
  "@nuxt/kit": "^4.6.2",
@@ -1,76 +0,0 @@
1
- import { r as dedupeConfigArrays } from "./create-config-DdL3Fh6T.js";
2
- import { loadConfig } from "c12";
3
-
4
- //#region src/composables/config-node.ts
5
- function getCwd() {
6
- return typeof process !== "undefined" ? process.cwd() : void 0;
7
- }
8
- /**
9
- * Collapse name-keyed arrays that may carry one duplicate per layer, so the
10
- * loaded config behaves like a single config.
11
- *
12
- * Delegates to `dedupeConfigArrays` from `create-config` rather than owning a
13
- * rule: this used to keep the FIRST occurrence while the runtime resolver keeps
14
- * the LAST, which are opposite precedence rules for the same data. It is a no-op
15
- * while `extend: false` (below) leaves c12 with only the root config's own
16
- * arrays, but the two must never be able to disagree.
17
- */
18
- function normalizeMergedConfig(config) {
19
- return dedupeConfigArrays(config);
20
- }
21
- async function loadMonoConfig(options = {}) {
22
- const result = await loadConfig({
23
- name: "mono",
24
- cwd: options.cwd ?? getCwd(),
25
- extend: false,
26
- defaults: {
27
- apps: [],
28
- name: "mono-app",
29
- type: "vue",
30
- menu: [],
31
- cookie: [],
32
- jwt: {}
33
- },
34
- ...options
35
- });
36
- return {
37
- ...result,
38
- config: normalizeMergedConfig(result.config)
39
- };
40
- }
41
- async function getMonoConfig(options = {}) {
42
- try {
43
- return (await loadMonoConfig(options)).config;
44
- } catch (error) {
45
- throw describeConfigLoadError(error);
46
- }
47
- }
48
- /** `Cannot find module '@some-app-root/mono.config'` — the shape jiti throws. */
49
- const MISSING_ALIAS_RE = /Cannot find module ['"](@[^'"]+)['"]/;
50
- /**
51
- * Turn an unresolved mono alias into an error that says what to do.
52
- *
53
- * `mono.config.ts` reaches other apps through ordinary `import`s resolved by jiti
54
- * against the alias map, and those aliases come from the `.mono/apps/` directory
55
- * listing. An app that isn't synced therefore surfaces as a bare `Cannot find
56
- * module '@x-root/mono.config'` — a specifier nobody typed by hand, thrown from
57
- * inside c12, naming no file and no fix.
58
- *
59
- * Pattern-based on purpose: this module knows nothing about the alias map, and
60
- * shouldn't. Covers the paths that never call `monoStubAliases` (the `mono db` CLI)
61
- * and the specifiers a config-only stub can't satisfy (a host config importing a
62
- * missing app's OData service).
63
- */
64
- function describeConfigLoadError(error) {
65
- const message = error instanceof Error ? error.message : String(error);
66
- const specifier = MISSING_ALIAS_RE.exec(message)?.[1];
67
- if (!specifier) return error;
68
- return new Error([
69
- `[@mono-lit/utility] Failed to load mono.config: cannot resolve '${specifier}'.`,
70
- "That looks like a federated mono app that isn't present in .mono/apps/.",
71
- "Run `mono sync && mono prepare`. If the repo is private, set its envToken in .env."
72
- ].join("\n"), { cause: error });
73
- }
74
-
75
- //#endregion
76
- export { loadMonoConfig as n, getMonoConfig as t };