@vmz/vmz 0.0.1 → 0.0.3

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 (79) hide show
  1. package/README.md +52 -2
  2. package/bin/vmz.js +4 -0
  3. package/dist/application-cmd.d.ts +21 -0
  4. package/dist/application-cmd.js +347 -0
  5. package/dist/bundler-adapter.d.ts +63 -0
  6. package/dist/bundler-adapter.js +110 -0
  7. package/dist/cli.d.ts +23 -0
  8. package/dist/cli.js +474 -0
  9. package/dist/dev-session.d.ts +35 -0
  10. package/dist/dev-session.js +290 -0
  11. package/dist/document-build.d.ts +99 -0
  12. package/dist/document-build.js +273 -0
  13. package/dist/document-check.d.ts +44 -0
  14. package/dist/document-check.js +246 -0
  15. package/dist/document-cmd.d.ts +8 -0
  16. package/dist/document-cmd.js +146 -0
  17. package/dist/document-designs.d.ts +9 -0
  18. package/dist/document-designs.js +126 -0
  19. package/dist/document-enrich.d.ts +23 -0
  20. package/dist/document-enrich.js +233 -0
  21. package/dist/document-evidence.d.ts +49 -0
  22. package/dist/document-evidence.js +509 -0
  23. package/dist/document-integrate.d.ts +34 -0
  24. package/dist/document-integrate.js +88 -0
  25. package/dist/document-interactive.d.ts +69 -0
  26. package/dist/document-interactive.js +254 -0
  27. package/dist/document-locale.d.ts +31 -0
  28. package/dist/document-locale.js +59 -0
  29. package/dist/document-markdown.d.ts +12 -0
  30. package/dist/document-markdown.js +45 -0
  31. package/dist/document-scan.d.ts +21 -0
  32. package/dist/document-scan.js +151 -0
  33. package/dist/document-schema.d.ts +86 -0
  34. package/dist/document-schema.js +87 -0
  35. package/dist/explain-cmd.d.ts +5 -0
  36. package/dist/explain-cmd.js +123 -0
  37. package/dist/index.d.ts +359 -0
  38. package/dist/index.js +580 -0
  39. package/dist/invocation.d.ts +91 -0
  40. package/dist/invocation.js +190 -0
  41. package/dist/locale-check.d.ts +106 -0
  42. package/dist/locale-check.js +736 -0
  43. package/dist/locale-cmd.d.ts +5 -0
  44. package/dist/locale-cmd.js +442 -0
  45. package/dist/locale-delivery.d.ts +298 -0
  46. package/dist/locale-delivery.js +443 -0
  47. package/dist/locale-router.d.ts +206 -0
  48. package/dist/locale-router.js +507 -0
  49. package/dist/locale-runtime.d.ts +406 -0
  50. package/dist/locale-runtime.js +541 -0
  51. package/dist/locale-schema.d.ts +8 -0
  52. package/dist/locale-schema.js +9 -0
  53. package/dist/locale-tooling.d.ts +118 -0
  54. package/dist/locale-tooling.js +357 -0
  55. package/dist/log.d.ts +19 -0
  56. package/dist/log.js +42 -0
  57. package/dist/packages.d.ts +26 -0
  58. package/dist/packages.js +146 -0
  59. package/dist/plugin-host.d.ts +29 -0
  60. package/dist/plugin-host.js +369 -0
  61. package/dist/refactor-cmd.d.ts +8 -0
  62. package/dist/refactor-cmd.js +156 -0
  63. package/dist/resolve-native-cli.d.ts +14 -0
  64. package/dist/resolve-native-cli.js +84 -0
  65. package/dist/resolve.d.ts +24 -0
  66. package/dist/resolve.js +55 -0
  67. package/dist/test-cmd.d.ts +9 -0
  68. package/dist/test-cmd.js +363 -0
  69. package/dist/test-compile.d.ts +2 -0
  70. package/dist/test-compile.js +3 -0
  71. package/dist/test-discover.d.ts +2 -0
  72. package/dist/test-discover.js +3 -0
  73. package/dist/test-logic.d.ts +2 -0
  74. package/dist/test-logic.js +3 -0
  75. package/dist/test-protocol.d.ts +2 -0
  76. package/dist/test-protocol.js +3 -0
  77. package/dist/watch-diff.d.ts +17 -0
  78. package/dist/watch-diff.js +56 -0
  79. package/package.json +96 -3
@@ -0,0 +1,190 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * `vmz` CLI invocation modes (JS gate only; Rust binary stays full).
4
+ *
5
+ * Three modes — do not collapse them:
6
+ * - **developer**: monorepo source checkout (`packages/runtimes/vmz`, not under node_modules)
7
+ * - **project**: app's `node_modules/vmz` or `node_modules/@vmz/vmz` (pnpm/npm/yarn)
8
+ * - **global**: npm/pnpm global (or any install under node_modules that is not the nearest project one)
9
+ *
10
+ */
11
+ import { spawn } from 'node:child_process';
12
+ import { existsSync, realpathSync } from 'node:fs';
13
+ import path from 'node:path';
14
+ import { fileURLToPath } from 'node:url';
15
+ /** @typedef {'developer' | 'project' | 'global'} InvocationMode */
16
+ /**
17
+ * Package root of the running `vmz` / `@vmz/vmz` install (`…/vmz`, not `…/vmz/dist`).
18
+ * @param {string} [fromUrl]
19
+ */
20
+ export function resolveThisPackageRoot(fromUrl = import.meta.url) {
21
+ return path.resolve(path.dirname(fileURLToPath(fromUrl)), '..');
22
+ }
23
+ /**
24
+ * @param {string} p
25
+ */
26
+ function tryRealpath(p) {
27
+ try {
28
+ return realpathSync(p);
29
+ }
30
+ catch {
31
+ return path.resolve(p);
32
+ }
33
+ }
34
+ /**
35
+ * Walk from `startDir` for nearest project `vmz` / `@vmz/vmz` package root.
36
+ * @param {string} startDir
37
+ * @returns {string | null} realpath of package root
38
+ */
39
+ export function findNearestProjectVmz(startDir) {
40
+ let dir = path.resolve(startDir);
41
+ for (;;) {
42
+ const candidates = [path.join(dir, 'node_modules', 'vmz'), path.join(dir, 'node_modules', '@vmz', 'vmz')];
43
+ for (const candidate of candidates) {
44
+ const pkgJson = path.join(candidate, 'package.json');
45
+ if (existsSync(pkgJson)) {
46
+ return tryRealpath(candidate);
47
+ }
48
+ }
49
+ const parent = path.dirname(dir);
50
+ if (parent === dir)
51
+ return null;
52
+ dir = parent;
53
+ }
54
+ }
55
+ /**
56
+ * Resolve CLI entry for a `vmz` package root (`bin/vmz.js`).
57
+ * @param {string} packageRoot
58
+ * @returns {string | null}
59
+ */
60
+ export function resolveVmzBin(packageRoot) {
61
+ const bin = path.join(packageRoot, 'bin', 'vmz.js');
62
+ if (existsSync(bin))
63
+ return tryRealpath(bin);
64
+ return null;
65
+ }
66
+ /**
67
+ * Install lives under a `node_modules` tree (npm -g, pnpm store link, etc.).
68
+ * Workspace source checkout (`packages/runtimes/vmz`) does not → developer mode.
69
+ * @param {string} packageRoot
70
+ */
71
+ export function isUnderNodeModules(packageRoot) {
72
+ const norm = path.normalize(packageRoot);
73
+ const parts = norm.split(path.sep);
74
+ return parts.includes('node_modules');
75
+ }
76
+ /**
77
+ * Classify how this process was launched.
78
+ *
79
+ * | mode | thisPackageRoot | rule |
80
+ * |-------------|-----------------------------------------|-------------------------------------------|
81
+ * | developer | monorepo `packages/runtimes/vmz` | not under `node_modules` |
82
+ * | project | app `node_modules/(@vmz/)vmz` | under node_modules ∧ equals nearest |
83
+ * | global | global / unrelated node_modules install | under node_modules ∧ not nearest project |
84
+ *
85
+ * @param {{
86
+ * cwd?: string,
87
+ * thisPackageRoot?: string,
88
+ * }} [opts]
89
+ * @returns {{
90
+ * mode: InvocationMode,
91
+ * cwd: string,
92
+ * thisPackageRoot: string,
93
+ * nearestProjectVmz: string | null,
94
+ * isDeveloper: boolean,
95
+ * isProjectLocal: boolean,
96
+ * isGlobalLike: boolean,
97
+ * }}
98
+ */
99
+ export function getInvocationContext(opts = {}) {
100
+ const cwd = path.resolve(opts.cwd ?? process.cwd());
101
+ const thisPackageRoot = tryRealpath(opts.thisPackageRoot ?? resolveThisPackageRoot());
102
+ const nearestProjectVmz = findNearestProjectVmz(cwd);
103
+ const underNm = isUnderNodeModules(thisPackageRoot);
104
+ /** @type {InvocationMode} */
105
+ let mode;
106
+ if (!underNm) {
107
+ mode = 'developer';
108
+ }
109
+ else if (nearestProjectVmz != null && nearestProjectVmz === thisPackageRoot) {
110
+ mode = 'project';
111
+ }
112
+ else {
113
+ mode = 'global';
114
+ }
115
+ return {
116
+ mode,
117
+ cwd,
118
+ thisPackageRoot,
119
+ nearestProjectVmz,
120
+ isDeveloper: mode === 'developer',
121
+ isProjectLocal: mode === 'project',
122
+ /** @deprecated prefer `mode === 'global'`; kept for call sites */
123
+ isGlobalLike: mode === 'global',
124
+ };
125
+ }
126
+ /**
127
+ * Commands allowed in **global** mode without re-exec / refusal.
128
+ * Developer + project modes allow the full CLI.
129
+ * @param {string | undefined} cmd
130
+ */
131
+ export function isGlobalAllowedCommand(cmd) {
132
+ if (!cmd)
133
+ return true;
134
+ return (cmd === 'help' ||
135
+ cmd === '-h' ||
136
+ cmd === '--help' ||
137
+ cmd === 'version' ||
138
+ cmd === '-V' ||
139
+ cmd === '--version' ||
140
+ cmd === 'new' ||
141
+ cmd === 'init');
142
+ }
143
+ /**
144
+ * @param {string} bin
145
+ * @param {string[]} argv full argv including command (e.g. `['check', '.']`)
146
+ * @returns {Promise<number>}
147
+ */
148
+ export function reexecProjectVmz(bin, argv) {
149
+ return new Promise((resolve) => {
150
+ const child = spawn(process.execPath, [bin, ...argv], {
151
+ stdio: 'inherit',
152
+ env: process.env,
153
+ });
154
+ child.on('error', () => resolve(1));
155
+ child.on('exit', (code, signal) => {
156
+ if (signal)
157
+ resolve(1);
158
+ else
159
+ resolve(code ?? 1);
160
+ });
161
+ });
162
+ }
163
+ /**
164
+ * Guard for project-only commands when the current install is **global** mode.
165
+ * Developer / project → proceed. Global + local present → re-exec. Global alone → refuse.
166
+ *
167
+ * @returns {Promise<{ action: 'proceed' } | { action: 'exit', code: number }>}
168
+ */
169
+ export async function gateGlobalProjectCommand(opts) {
170
+ const { argv, cwd = process.cwd(), thisPackageRoot, reexec = reexecProjectVmz, logError = (msg) => console.error(msg) } = opts;
171
+ const ctx = getInvocationContext({ cwd, thisPackageRoot });
172
+ if (ctx.mode !== 'global') {
173
+ return { action: 'proceed' };
174
+ }
175
+ if (ctx.nearestProjectVmz && ctx.nearestProjectVmz !== ctx.thisPackageRoot) {
176
+ const bin = resolveVmzBin(ctx.nearestProjectVmz);
177
+ if (!bin) {
178
+ logError('found project `@vmz/vmz` / `vmz` but bin/vmz.js is missing.');
179
+ return { action: 'exit', code: 1 };
180
+ }
181
+ const code = await reexec(bin, argv);
182
+ return { action: 'exit', code };
183
+ }
184
+ logError('this `vmz` is a global install (mode=global); project commands need a project install.');
185
+ logError('Install in the app: pnpm add -D @vmz/vmz');
186
+ logError('Or scaffold: vmz new <dir>');
187
+ logError('Then run: pnpm exec vmz <command>');
188
+ logError('(developer mode: run from vmz-framework packages/runtimes/vmz source — full CLI)');
189
+ return { action: 'exit', code: 1 };
190
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * @param {string} literal
3
+ */
4
+ export declare function validateLocaleId(literal: any): {
5
+ ok: boolean;
6
+ message: string;
7
+ } | {
8
+ ok: boolean;
9
+ message?: undefined;
10
+ };
11
+ /**
12
+ * Flatten catalog object into MessageId → string template.
13
+ * Arrays are forbidden.
14
+ * @param {any} node
15
+ * @param {string} prefix
16
+ * @param {Array<{code:string,severity:string,message:string,path?:string}>} diagnostics
17
+ * @param {string} sourcePath
18
+ * @returns {Map<string, string>}
19
+ */
20
+ export declare function flattenCatalog(node: any, prefix: any, diagnostics: any, sourcePath: any): Map<any, any>;
21
+ /**
22
+ * ICU MessageFormat compatible subset: extract argument names + kinds.
23
+ * @param {string} template
24
+ * @returns {{ ok: boolean, params: Array<{ name: string, kind: string }>, error?: string }}
25
+ */
26
+ export declare function extractMessageParams(template: any): {
27
+ ok: boolean;
28
+ params: any[];
29
+ error: string;
30
+ } | {
31
+ ok: boolean;
32
+ params: {
33
+ name: any;
34
+ kind: any;
35
+ }[];
36
+ error?: undefined;
37
+ };
38
+ /**
39
+ * Detect fallback cycles (explicit DAG).
40
+ * @param {Record<string, string[]>} fallback
41
+ * @param {Set<string>} known
42
+ */
43
+ export declare function findFallbackCycles(fallback: any, known: any): {
44
+ cycles: any[];
45
+ unknown: any[];
46
+ };
47
+ /**
48
+ * @param {{ projectRoot: string, strict?: boolean, checkUnused?: boolean }} opts
49
+ */
50
+ export declare function checkLocales(opts: any): {
51
+ schema: string;
52
+ status: string;
53
+ root: any;
54
+ localesRoot: string;
55
+ manifest: any;
56
+ catalogIds: any[];
57
+ messageCatalog: {
58
+ schema: string;
59
+ messages: any[];
60
+ };
61
+ typedModules: any[];
62
+ usages: {
63
+ catalogs: any[];
64
+ messageIds: any[];
65
+ };
66
+ diagnostics: any;
67
+ };
68
+ /**
69
+ * Scan src for `#locales/<catalog>` imports and `messageId` string literals after import.
70
+ * First-slice heuristic — full VPG edges land with compiler deepen.
71
+ */
72
+ export declare function scanLocaleUsages(projectRoot: any): {
73
+ catalogs: Set<unknown>;
74
+ messageIds: Set<unknown>;
75
+ importedNames: Map<any, any>;
76
+ };
77
+ /**
78
+ * Emit typed module stubs for `#locales/*` ( surface).
79
+ * @param {ReturnType<typeof checkLocales>} report
80
+ * @param {string} outDir
81
+ */
82
+ export declare function emitLocaleTypedModules(report: any, outDir: any): any[];
83
+ /**
84
+ * MessageId rename plan — WorkspaceEdit-shaped, no parallel rename IR.
85
+ * @param {ReturnType<typeof checkLocales>} report
86
+ * @param {string} fromId
87
+ * @param {string} toId
88
+ */
89
+ export declare function planLocaleRename(report: any, fromId: any, toId: any): {
90
+ schema: string;
91
+ status: string;
92
+ fromId: any;
93
+ toId: any;
94
+ edits: any[];
95
+ error: string;
96
+ virtualModule?: undefined;
97
+ } | {
98
+ schema: string;
99
+ status: string;
100
+ fromId: any;
101
+ toId: any;
102
+ edits: any[];
103
+ virtualModule: string;
104
+ error?: undefined;
105
+ };
106
+ export declare function localeHasErrors(report: any): any;