@vmz/vmz 0.2.4 → 0.2.6

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/dist/cli/cli.js CHANGED
@@ -19,6 +19,8 @@ import { emitLocaleRuntimeModules, localeHasErrors } from '../locale/locale-chec
19
19
  import { registerLocaleCommands } from '../locale/locale-cmd.js';
20
20
  import { emitLocaleRouteRealization } from '../locale/locale-route-emit.js';
21
21
  import { log } from '../workspace/log.js';
22
+ import { resolveCliLogLevel, setCliLogLevel } from '../workspace/log-level.js';
23
+ import { parseCliLogStyle, setCliLogStyle } from '../workspace/log-style.js';
22
24
  import { packFromDeploymentIr } from '../workspace/pack.js';
23
25
  import { registerPlanCommands } from './plan-cmd.js';
24
26
  import { loadVmzConfig } from '../workspace/plugin-host.js';
@@ -63,7 +65,11 @@ function buildProductCli(opts = {}) {
63
65
  .option('--build', 'cli.opt.build')
64
66
  .option('--check', 'cli.opt.check')
65
67
  .option('--deny-warnings', 'cli.opt.deny-warnings');
66
- withWorkspaceOpts(cli.command('check', 'cli.cmd.check')).action((options) => cmdCheck(options));
68
+ withWorkspaceOpts(cli.command('check', 'cli.cmd.check'))
69
+ .option('--level <level>', 'cli.opt.level')
70
+ .option('--info', 'cli.opt.info-level')
71
+ .option('--style <style>', 'cli.opt.diag-style')
72
+ .action((options) => cmdCheck(options));
67
73
  withWorkspaceOpts(cli.command('build', 'cli.cmd.build')).action((options) => cmdBuild(options));
68
74
  withWorkspaceOpts(cli.command('serve', 'cli.cmd.serve')).action((options) => cmdServe(options));
69
75
  withWorkspaceOpts(cli.command('dev', 'cli.cmd.dev')).action((options) => cmdDev(options));
@@ -72,7 +78,11 @@ function buildProductCli(opts = {}) {
72
78
  .option('--no-rust', 'cli.opt.format-no-rust')
73
79
  .option('--no-vmz', 'cli.opt.format-no-vmz')
74
80
  .action((options) => cmdFormat(options));
75
- withWorkspaceOpts(cli.command('lint', 'cli.cmd.lint')).action((options) => cmdLint(options));
81
+ withWorkspaceOpts(cli.command('lint', 'cli.cmd.lint'))
82
+ .option('--level <level>', 'cli.opt.level')
83
+ .option('--info', 'cli.opt.info-level')
84
+ .option('--style <style>', 'cli.opt.diag-style')
85
+ .action((options) => cmdLint(options));
76
86
  registerTestCommand(cli);
77
87
  registerDocumentCommands(cli.command('document|docs', 'cli.cmd.document'));
78
88
  registerLocaleCommands(cli.command('locale|locales', 'cli.cmd.locale'));
@@ -116,7 +126,25 @@ function cmdVersion() {
116
126
  console.log(`native host=${native.hostProtocol} compiler=${native.compilerProtocol} program_ir=${native.programIrSchema} plugin=${native.pluginProtocol}`);
117
127
  return 0;
118
128
  }
129
+ function applyInspectLogOptions(args) {
130
+ const level = resolveCliLogLevel({ level: args.level, info: Boolean(args.info) });
131
+ if (level == null) {
132
+ log.errorId('cli.err.invalid_level', { level: String(args.level ?? '') });
133
+ return 1;
134
+ }
135
+ setCliLogLevel(level);
136
+ const style = parseCliLogStyle(args.style);
137
+ if (style == null) {
138
+ log.errorId('cli.err.invalid_style', { style: String(args.style ?? '') });
139
+ return 1;
140
+ }
141
+ setCliLogStyle(style);
142
+ return null;
143
+ }
119
144
  async function cmdCheck(args) {
145
+ const optsErr = applyInspectLogOptions(args);
146
+ if (optsErr != null)
147
+ return optsErr;
120
148
  const pathArg = args._[0] ?? '.';
121
149
  const { project, outDir } = resolveWorkspaceDirs({
122
150
  path: pathArg,
@@ -497,6 +525,9 @@ async function cmdFormat(args) {
497
525
  });
498
526
  }
499
527
  function cmdLint(args) {
528
+ const optsErr = applyInspectLogOptions(args);
529
+ if (optsErr != null)
530
+ return optsErr;
500
531
  const pathArg = args._[0] ?? '.';
501
532
  const { project, outDir } = resolveWorkspaceDirs({
502
533
  path: pathArg,
@@ -24,6 +24,8 @@ export function materializeServeHostRuntime(outDir, coreDist = resolveCoreRuntim
24
24
  if (entry.rewriteVmzRuntimeImport) {
25
25
  const text = readFileSync(src, 'utf8')
26
26
  .replace(/from\s+(['"])\.\/vmz-runtime\.js\1/g, 'from $1../../vmz-runtime.js$1')
27
+ .replace(/from\s+(['"])\.\.\/\.\.\/faces\/vmz-runtime\.js\1/g, 'from $1../../../vmz-runtime.js$1')
28
+ .replace(/from\s+(['"])\.\.\/\.\.\/faces\/server\.js\1/g, 'from $1../../../vmz-runtime.js$1')
27
29
  .replace(/from\s+(['"])\.\.\/faces\/vmz-runtime\.js\1/g, 'from $1../../vmz-runtime.js$1')
28
30
  .replace(/from\s+(['"])\.\.\/faces\/server\.js\1/g, 'from $1../../vmz-runtime.js$1');
29
31
  writeFileSync(dst, text, 'utf8');
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Load packages/runtimes/vmz/delivery-runtime-files.json — sole browser/SSR delivery copy list.
3
+ */
4
+ export type DeliveryRuntimeFileEntry = {
5
+ src: string;
6
+ out: string;
7
+ };
8
+ export type DeliveryRuntimeFilesManifest = {
9
+ schema: string;
10
+ flatBarrels: DeliveryRuntimeFileEntry[];
11
+ nested: DeliveryRuntimeFileEntry[];
12
+ };
13
+ export declare function loadDeliveryRuntimeFilesManifest(pathOverride?: string): DeliveryRuntimeFilesManifest;
14
+ /** All [src, out] pairs for materialize / pack. */
15
+ export declare function deliveryRuntimeFilePairs(manifest?: DeliveryRuntimeFilesManifest): ReadonlyArray<readonly [string, string]>;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Load packages/runtimes/vmz/delivery-runtime-files.json — sole browser/SSR delivery copy list.
3
+ */
4
+ import { readFileSync } from 'node:fs';
5
+ import { dirname, join } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+ const MANIFEST_BASENAME = 'delivery-runtime-files.json';
8
+ function manifestPathFromHere() {
9
+ const here = dirname(fileURLToPath(import.meta.url));
10
+ return join(here, '..', '..', MANIFEST_BASENAME);
11
+ }
12
+ let cached = null;
13
+ export function loadDeliveryRuntimeFilesManifest(pathOverride) {
14
+ if (!pathOverride && cached)
15
+ return cached;
16
+ const p = pathOverride || manifestPathFromHere();
17
+ const raw = JSON.parse(readFileSync(p, 'utf8'));
18
+ if (raw.schema !== 'vmz.delivery-runtime-files.v0') {
19
+ throw new Error(`delivery-runtime-files: unexpected schema ${raw.schema}`);
20
+ }
21
+ if (!Array.isArray(raw.flatBarrels) || !raw.flatBarrels.length) {
22
+ throw new Error('delivery-runtime-files: flatBarrels empty');
23
+ }
24
+ if (!Array.isArray(raw.nested) || !raw.nested.length) {
25
+ throw new Error('delivery-runtime-files: nested empty');
26
+ }
27
+ if (!pathOverride)
28
+ cached = raw;
29
+ return raw;
30
+ }
31
+ /** All [src, out] pairs for materialize / pack. */
32
+ export function deliveryRuntimeFilePairs(manifest = loadDeliveryRuntimeFilesManifest()) {
33
+ return [...manifest.flatBarrels, ...manifest.nested].map((f) => [f.src, f.out]);
34
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Rewrite `@vmz/core` dist imports for flat app delivery layout.
3
+ * Keep in sync with `rewrite_delivery_imports` in vmz-compiler compile.rs.
4
+ */
5
+ /** @param {string} text @param {string} outName delivery-relative output path */
6
+ export declare function rewriteDeliveryImports(text: string, outName: string): string;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Rewrite `@vmz/core` dist imports for flat app delivery layout.
3
+ * Keep in sync with `rewrite_delivery_imports` in vmz-compiler compile.rs.
4
+ */
5
+ function replaceImportPath(text, from, to) {
6
+ let out = text;
7
+ out = out.replaceAll(`'${from}'`, `'${to}'`);
8
+ out = out.replaceAll(`"${from}"`, `"${to}"`);
9
+ return out;
10
+ }
11
+ function replaceQuotedPrefix(text, from, to) {
12
+ let out = text;
13
+ out = out.replaceAll(`'${from}`, `'${to}`);
14
+ out = out.replaceAll(`"${from}`, `"${to}`);
15
+ return out;
16
+ }
17
+ function rewriteFlatDeliveryImports(text) {
18
+ let out = text;
19
+ const pairs = [
20
+ ['../browser/dom-core.js', './dom-core.js'],
21
+ ['../browser/direct-host-box.js', './direct-host-box.js'],
22
+ ['../browser/unknown-component.js', './unknown-component.js'],
23
+ ['../shared/dom-attr-normalize.js', './dom-attr-normalize.js'],
24
+ ['../browser/client-nav.js', './vmz-client-nav.js'],
25
+ ['../ssr/dom-ssr.js', './dom-ssr.js'],
26
+ ['../faces/server.js', './vmz-runtime.js'],
27
+ ['../faces/vmz-runtime.js', './vmz-runtime.js'],
28
+ ['../faces/http.js', './vmz-http.js'],
29
+ ];
30
+ for (const [from, to] of pairs) {
31
+ out = replaceImportPath(out, from, to);
32
+ }
33
+ return out;
34
+ }
35
+ function rewriteNestedSsrDelivery(text) {
36
+ let out = text;
37
+ for (const [from, to] of [
38
+ ['../browser/dom-core.js', '../dom-core.js'],
39
+ ['../browser/direct-host-box.js', '../direct-host-box.js'],
40
+ ['../browser/unknown-component.js', '../unknown-component.js'],
41
+ ]) {
42
+ out = replaceImportPath(out, from, to);
43
+ }
44
+ return out;
45
+ }
46
+ function rewriteNestedBrowserDelivery(text) {
47
+ let out = replaceImportPath(text, '../../shared/dom-attr-normalize.js', '../../dom-attr-normalize.js');
48
+ for (const [from, to] of [
49
+ ['../direct-host-box.js', '../../direct-host-box.js'],
50
+ ['../unknown-component.js', '../../unknown-component.js'],
51
+ ['../dom-core.js', '../../dom-core.js'],
52
+ ]) {
53
+ out = replaceImportPath(out, from, to);
54
+ }
55
+ return out;
56
+ }
57
+ function rewriteFlatDeliveryRoot(text, outName) {
58
+ let out = rewriteFlatDeliveryImports(text);
59
+ if (outName === 'dom-core.js') {
60
+ for (const [from, to] of [
61
+ ['./diagnostics/', './browser/diagnostics/'],
62
+ ['./dom/', './browser/dom/'],
63
+ ['./reactivity/', './browser/reactivity/'],
64
+ ]) {
65
+ out = replaceQuotedPrefix(out, from, to);
66
+ }
67
+ }
68
+ else if (outName === 'dom-ssr.js') {
69
+ out = replaceImportPath(out, './render.js', './ssr/render.js');
70
+ out = replaceQuotedPrefix(out, '../browser/resume/', './browser/resume/');
71
+ }
72
+ else if (outName === 'vmz-client-nav.js') {
73
+ out = replaceQuotedPrefix(out, './navigation/', './browser/navigation/');
74
+ }
75
+ else if (outName === 'dom.browser.js') {
76
+ out = replaceQuotedPrefix(out, '../browser/resume/', './browser/resume/');
77
+ }
78
+ return out;
79
+ }
80
+ /** @param {string} text @param {string} outName delivery-relative output path */
81
+ export function rewriteDeliveryImports(text, outName) {
82
+ if (outName.startsWith('ssr/'))
83
+ return rewriteNestedSsrDelivery(text);
84
+ if (outName.startsWith('browser/'))
85
+ return rewriteNestedBrowserDelivery(text);
86
+ return rewriteFlatDeliveryRoot(text, outName);
87
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Source cache + OffsetIndex-backed PositionContext for CLI pretty diagnostics.
3
+ */
4
+ import type { PositionContext } from '@vmz/diagnostic';
5
+ /** Read and memoize a source file for snippet rendering. */
6
+ export declare function readDiagnosticSource(path: string): string | undefined;
7
+ /** OffsetIndex PositionContext for one source buffer (memoized per path). */
8
+ export declare function positionContextForSource(path: string, sourceText: string): PositionContext;
9
+ /** Clear caches between CLI invocations in long-lived hosts. */
10
+ export declare function resetDiagnosticContext(): void;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Source cache + OffsetIndex-backed PositionContext for CLI pretty diagnostics.
3
+ */
4
+ import { existsSync, readFileSync } from 'node:fs';
5
+ import { loadNative } from './public-api.js';
6
+ const sourceCache = new Map();
7
+ const positionCache = new Map();
8
+ function normalizePath(path) {
9
+ return path.replace(/\\/g, '/');
10
+ }
11
+ /** Read and memoize a source file for snippet rendering. */
12
+ export function readDiagnosticSource(path) {
13
+ const key = normalizePath(path);
14
+ if (sourceCache.has(key))
15
+ return sourceCache.get(key);
16
+ if (!path || !existsSync(path))
17
+ return undefined;
18
+ try {
19
+ const text = readFileSync(path, 'utf8');
20
+ sourceCache.set(key, text);
21
+ return text;
22
+ }
23
+ catch {
24
+ return undefined;
25
+ }
26
+ }
27
+ /** OffsetIndex PositionContext for one source buffer (memoized per path). */
28
+ export function positionContextForSource(path, sourceText) {
29
+ const key = normalizePath(path);
30
+ const cached = positionCache.get(key);
31
+ if (cached)
32
+ return cached;
33
+ const native = loadNative();
34
+ if (typeof native.offsetIndexLineCol !== 'function') {
35
+ const fallback = { lineCol: () => ({ line: 1, column: 1 }) };
36
+ positionCache.set(key, fallback);
37
+ return fallback;
38
+ }
39
+ const source = String(sourceText ?? '');
40
+ const ctx = {
41
+ lineCol(offset) {
42
+ const row = native.offsetIndexLineCol(source, Math.max(0, Number(offset) || 0) >>> 0);
43
+ return { line: row.line, column: row.column };
44
+ },
45
+ };
46
+ positionCache.set(key, ctx);
47
+ return ctx;
48
+ }
49
+ /** Clear caches between CLI invocations in long-lived hosts. */
50
+ export function resetDiagnosticContext() {
51
+ sourceCache.clear();
52
+ positionCache.clear();
53
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * CLI output verbosity for diagnostics and progress lines.
3
+ *
4
+ * `error` — errors only
5
+ * `warn` — errors + warnings (default)
6
+ * `info` — errors + warnings + advice, plus progress lines
7
+ */
8
+ export type CliLogLevel = 'error' | 'warn' | 'info';
9
+ /** Active CLI log level (default `warn`). */
10
+ export declare function getCliLogLevel(): CliLogLevel;
11
+ /** Set active CLI log level for the current command invocation. */
12
+ export declare function setCliLogLevel(level: CliLogLevel): void;
13
+ /** Parse `--level` values; `null` when unrecognized. */
14
+ export declare function parseCliLogLevel(raw: unknown): CliLogLevel | null;
15
+ /** Resolve level from `check` / `lint` flags (`--info` overrides `--level`). */
16
+ export declare function resolveCliLogLevel(args: {
17
+ level?: unknown;
18
+ info?: boolean;
19
+ }): CliLogLevel | null;
20
+ /** Whether a diagnostic severity should be printed at `level`. */
21
+ export declare function diagnosticVisible(severity: string | undefined, level: CliLogLevel): boolean;
22
+ /** Progress / summary lines (`log.info`) only at `info`. */
23
+ export declare function progressVisible(level: CliLogLevel): boolean;
24
+ /** Non-diagnostic warn lines at `warn` and above. */
25
+ export declare function warnVisible(level: CliLogLevel): boolean;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * CLI output verbosity for diagnostics and progress lines.
3
+ *
4
+ * `error` — errors only
5
+ * `warn` — errors + warnings (default)
6
+ * `info` — errors + warnings + advice, plus progress lines
7
+ */
8
+ const LEVEL_RANK = {
9
+ error: 0,
10
+ warn: 1,
11
+ info: 2,
12
+ };
13
+ let currentLevel = 'warn';
14
+ /** Active CLI log level (default `warn`). */
15
+ export function getCliLogLevel() {
16
+ return currentLevel;
17
+ }
18
+ /** Set active CLI log level for the current command invocation. */
19
+ export function setCliLogLevel(level) {
20
+ currentLevel = level;
21
+ }
22
+ /** Parse `--level` values; `null` when unrecognized. */
23
+ export function parseCliLogLevel(raw) {
24
+ if (raw == null || raw === '')
25
+ return 'warn';
26
+ const s = String(raw).trim().toLowerCase();
27
+ if (s === 'error')
28
+ return 'error';
29
+ if (s === 'warn' || s === 'warning')
30
+ return 'warn';
31
+ if (s === 'info' || s === 'advice')
32
+ return 'info';
33
+ return null;
34
+ }
35
+ /** Resolve level from `check` / `lint` flags (`--info` overrides `--level`). */
36
+ export function resolveCliLogLevel(args) {
37
+ if (args.info)
38
+ return 'info';
39
+ return parseCliLogLevel(args.level);
40
+ }
41
+ function normalizeDiagnosticSeverity(severity) {
42
+ if (severity === 'warning')
43
+ return 'warning';
44
+ if (severity === 'advice')
45
+ return 'advice';
46
+ return 'error';
47
+ }
48
+ /** Whether a diagnostic severity should be printed at `level`. */
49
+ export function diagnosticVisible(severity, level) {
50
+ const sev = normalizeDiagnosticSeverity(severity);
51
+ if (sev === 'error')
52
+ return true;
53
+ if (sev === 'warning')
54
+ return LEVEL_RANK[level] >= LEVEL_RANK.warn;
55
+ return LEVEL_RANK[level] >= LEVEL_RANK.info;
56
+ }
57
+ /** Progress / summary lines (`log.info`) only at `info`. */
58
+ export function progressVisible(level) {
59
+ return level === 'info';
60
+ }
61
+ /** Non-diagnostic warn lines at `warn` and above. */
62
+ export function warnVisible(level) {
63
+ return LEVEL_RANK[level] >= LEVEL_RANK.warn;
64
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * CLI diagnostic layout: `pretty` (snippets) vs `compact` (single-line, CI-friendly).
3
+ */
4
+ export type CliLogStyle = 'pretty' | 'compact';
5
+ export declare function getCliLogStyle(): CliLogStyle;
6
+ export declare function setCliLogStyle(style: CliLogStyle): void;
7
+ export declare function parseCliLogStyle(raw: unknown): CliLogStyle | null;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * CLI diagnostic layout: `pretty` (snippets) vs `compact` (single-line, CI-friendly).
3
+ */
4
+ let currentStyle = 'pretty';
5
+ export function getCliLogStyle() {
6
+ return currentStyle;
7
+ }
8
+ export function setCliLogStyle(style) {
9
+ currentStyle = style;
10
+ }
11
+ export function parseCliLogStyle(raw) {
12
+ if (raw == null || raw === '')
13
+ return 'pretty';
14
+ const s = String(raw).trim().toLowerCase();
15
+ if (s === 'pretty')
16
+ return 'pretty';
17
+ if (s === 'compact')
18
+ return 'compact';
19
+ return null;
20
+ }
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Unified CLI logging / diagnostics via `@vmz/diagnostic` + product catalog.
3
3
  */
4
+ import { type CliLogLevel } from './log-level.js';
4
5
  export type DiagnosticLike = {
5
6
  severity?: string;
6
7
  path?: string;
@@ -12,15 +13,19 @@ export type DiagnosticLike = {
12
13
  end: number;
13
14
  };
14
15
  };
16
+ export type DiagnosticLogOptions = {
17
+ denyWarnings?: boolean;
18
+ level?: CliLogLevel;
19
+ };
15
20
  export declare const log: {
16
21
  info(...args: unknown[]): void;
17
22
  warn(...args: unknown[]): void;
18
23
  error(...args: unknown[]): void;
19
24
  /** Localized framework error (`cli.err.*`). */
20
25
  errorId(id: string, args?: Record<string, string>): void;
21
- diagnostic(d: DiagnosticLike): void;
22
- /** Failing count: errors, and warnings when `denyWarnings`. */
23
- diagnostics(diagnostics: DiagnosticLike[] | null | undefined, opts?: {
24
- denyWarnings?: boolean;
25
- }): number;
26
+ diagnostic(d: DiagnosticLike, opts?: {
27
+ level?: CliLogLevel;
28
+ }): boolean;
29
+ /** Failing count: errors, and warnings when `denyWarnings` (independent of print level). */
30
+ diagnostics(diagnostics: DiagnosticLike[] | null | undefined, opts?: DiagnosticLogOptions): number;
26
31
  };
@@ -3,32 +3,48 @@
3
3
  */
4
4
  import { formatDiagnostic } from '@vmz/diagnostic';
5
5
  import { loadCliCatalog, resolveVmzLocale, vmzCliLocalize } from '../cli/cli-localize.js';
6
- function stamp(level) {
7
- return `vmz ${level}`;
6
+ import { positionContextForSource, readDiagnosticSource } from './diagnostic-context.js';
7
+ import { diagnosticVisible, getCliLogLevel, progressVisible, warnVisible } from './log-level.js';
8
+ import { getCliLogStyle } from './log-style.js';
9
+ function normalizeSeverity(severity) {
10
+ if (severity === 'warning')
11
+ return 'warning';
12
+ if (severity === 'advice')
13
+ return 'advice';
14
+ return 'error';
8
15
  }
9
16
  export const log = {
10
17
  info(...args) {
11
- console.error(stamp('info'), ...args);
18
+ if (!progressVisible(getCliLogLevel()))
19
+ return;
20
+ console.error(...args);
12
21
  },
13
22
  warn(...args) {
14
- console.error(stamp('warn'), ...args);
23
+ if (!warnVisible(getCliLogLevel()))
24
+ return;
25
+ console.error(...args);
15
26
  },
16
27
  error(...args) {
17
- console.error(stamp('error'), ...args);
28
+ console.error(...args);
18
29
  },
19
30
  /** Localized framework error (`cli.err.*`). */
20
31
  errorId(id, args) {
21
- console.error(stamp('error'), vmzCliLocalize.t(id, args));
32
+ console.error(vmzCliLocalize.t(id, args));
22
33
  },
23
- diagnostic(d) {
24
- const severity = d.severity === 'warning' || d.severity === 'advice' || d.severity === 'error' ? d.severity : 'error';
25
- // Only invent transitional `diag.message` when wire has no code; never remap a real code.
34
+ diagnostic(d, opts = {}) {
35
+ const level = opts.level ?? getCliLogLevel();
36
+ const severity = normalizeSeverity(d.severity);
37
+ if (!diagnosticVisible(severity, level))
38
+ return false;
26
39
  const hasCode = Boolean(d.code && String(d.code).length);
27
40
  const code = hasCode ? String(d.code) : 'diag.message';
28
41
  const locale = resolveVmzLocale();
29
42
  const catalog = loadCliCatalog(locale);
43
+ const path = d.path || '';
44
+ const style = getCliLogStyle();
45
+ const sourceText = style === 'pretty' && path ? readDiagnosticSource(path) : undefined;
30
46
  const line = formatDiagnostic({
31
- path: d.path || '',
47
+ path,
32
48
  severity,
33
49
  code,
34
50
  args: d.args ?? (!hasCode && d.message ? { message: String(d.message) } : undefined),
@@ -37,14 +53,26 @@ export const log = {
37
53
  }, {
38
54
  locale,
39
55
  catalog,
56
+ sourceText,
57
+ position: sourceText ? positionContextForSource(path, sourceText) : undefined,
58
+ style,
40
59
  });
41
- console.error(stamp(severity === 'warning' ? 'warn' : severity === 'error' ? 'error' : 'diag'), line);
60
+ console.error(line);
61
+ return true;
42
62
  },
43
- /** Failing count: errors, and warnings when `denyWarnings`. */
63
+ /** Failing count: errors, and warnings when `denyWarnings` (independent of print level). */
44
64
  diagnostics(diagnostics, opts = {}) {
65
+ const level = opts.level ?? getCliLogLevel();
66
+ const style = getCliLogStyle();
45
67
  let failing = 0;
46
- for (const d of diagnostics ?? []) {
47
- this.diagnostic(d);
68
+ const items = diagnostics ?? [];
69
+ const visible = items.filter((d) => diagnosticVisible(normalizeSeverity(d.severity), level));
70
+ for (let i = 0; i < visible.length; i += 1) {
71
+ this.diagnostic(visible[i], { level });
72
+ if (style === 'pretty' && i + 1 < visible.length)
73
+ console.error('');
74
+ }
75
+ for (const d of items) {
48
76
  if (d.severity === 'error')
49
77
  failing += 1;
50
78
  else if (opts.denyWarnings && d.severity === 'warning')
@@ -8,28 +8,10 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
8
8
  import path from 'node:path';
9
9
  import { loadDeploymentIr, planBundleInputs } from './bundler-adapter.js';
10
10
  import { packClientBareImports } from './pack-client-packages.js';
11
+ import { deliveryRuntimeFilePairs } from './delivery-runtime-files.js';
12
+ import { rewriteDeliveryImports } from './delivery-runtime-imports.js';
11
13
  import { writePrettyJsonFile } from './pretty-json.js';
12
14
  export const PACK_MANIFEST_SCHEMA = 'vmz.pack.manifest.v0';
13
- /** Keep in sync with `rewrite_flat_delivery_imports` in vmz-compiler compile.rs. */
14
- function rewriteFlatDeliveryImports(text) {
15
- let out = text;
16
- const pairs = [
17
- ['../browser/dom-core.js', './dom-core.js'],
18
- ['../browser/direct-host-box.js', './direct-host-box.js'],
19
- ['../browser/unknown-component.js', './unknown-component.js'],
20
- ['../shared/dom-attr-normalize.js', './dom-attr-normalize.js'],
21
- ['../browser/client-nav.js', './vmz-client-nav.js'],
22
- ['../ssr/dom-ssr.js', './dom-ssr.js'],
23
- ['../faces/server.js', './vmz-runtime.js'],
24
- ['../faces/vmz-runtime.js', './vmz-runtime.js'],
25
- ['../faces/http.js', './vmz-http.js'],
26
- ];
27
- for (const [from, to] of pairs) {
28
- out = out.replaceAll(`'${from}'`, `'${to}'`);
29
- out = out.replaceAll(`"${from}"`, `"${to}"`);
30
- }
31
- return out;
32
- }
33
15
  /**
34
16
  * Ensure dom split companions sit next to vmz-dom.js (barrel imports ./dom-core.js).
35
17
  * Always refresh from `@vmz/core` when present so SSR/runtime fixes are not sticky in outDir.
@@ -40,22 +22,13 @@ function rewriteFlatDeliveryImports(text) {
40
22
  export function ensureRuntimeCompanions(outDir, coreDist) {
41
23
  if (!coreDist)
42
24
  return [];
43
- const companions = [
44
- ['browser/dom-core.js', 'dom-core.js'],
45
- ['ssr/dom-ssr.js', 'dom-ssr.js'],
46
- ['faces/dom.client.js', 'dom.client.js'],
47
- ['faces/dom.browser.js', 'dom.browser.js'],
48
- ['browser/direct-host-box.js', 'direct-host-box.js'],
49
- ['browser/unknown-component.js', 'unknown-component.js'],
50
- ['shared/dom-attr-normalize.js', 'dom-attr-normalize.js'],
51
- ];
52
25
  const copied = [];
53
- for (const [srcRel, outName] of companions) {
26
+ for (const [srcRel, outName] of deliveryRuntimeFilePairs()) {
54
27
  const src = path.join(coreDist, srcRel);
55
28
  if (!existsSync(src))
56
29
  continue;
57
30
  const dest = path.join(outDir, outName);
58
- const text = rewriteFlatDeliveryImports(readFileSync(src, 'utf8'));
31
+ const text = rewriteDeliveryImports(readFileSync(src, 'utf8'), outName);
59
32
  mkdirSync(path.dirname(dest), { recursive: true });
60
33
  writeFileSync(dest, text);
61
34
  copied.push(outName);
@@ -62,6 +62,9 @@
62
62
  "cli.opt.build": "Build before serve",
63
63
  "cli.opt.check": "Format check-only / extract fail on CJK",
64
64
  "cli.opt.deny-warnings": "Treat warnings as errors",
65
+ "cli.opt.level": "Diagnostic verbosity: error | warn | info (default warn)",
66
+ "cli.opt.info-level": "Show advice diagnostics and progress (same as --level info)",
67
+ "cli.opt.diag-style": "Diagnostic layout: pretty | compact (default pretty)",
65
68
  "cli.opt.json": "Write JSON to stdout or file",
66
69
  "cli.opt.root": "Project root",
67
70
  "cli.opt.out": "Output directory",
@@ -101,6 +104,8 @@
101
104
  "cli.err.unknown_plan_kind": "unknown plan kind `{kind}` (locale | document-route)",
102
105
  "cli.err.gha.mode": "unknown --mode {mode} (status | wait)",
103
106
  "cli.err.gha.repo": "set --owner/--repo or GITHUB_REPOSITORY (owner/repo)",
107
+ "cli.err.invalid_level": "unknown --level `{level}` (error | warn | info)",
108
+ "cli.err.invalid_style": "unknown --style `{style}` (pretty | compact)",
104
109
  "cli.err.unknown_target": "unknown --target {target} (browser | mini-program-wechat)",
105
110
  "cli.err.document_build_aborted": "document build aborted due to diagnostics",
106
111
  "cli.err.locale_rename_usage": "usage: vmz locale rename <from-message-id> <to-message-id>",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vmz/vmz",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "type": "module",
5
5
  "description": "VMZ Node toolchain — N-API workspace session + CLI (publish name @vmz/vmz)",
6
6
  "license": "MIT",
@@ -48,16 +48,16 @@
48
48
  }
49
49
  },
50
50
  "dependencies": {
51
- "@vmz/commander": "0.2.4",
52
- "@vmz/core": "0.2.4",
53
- "@vmz/diagnostic": "0.2.4",
54
- "@vmz/plugin": "0.2.4",
55
- "@vmz/protocol": "0.2.4",
51
+ "@vmz/commander": "0.2.6",
52
+ "@vmz/core": "0.2.6",
53
+ "@vmz/diagnostic": "0.2.6",
54
+ "@vmz/plugin": "0.2.6",
55
+ "@vmz/protocol": "0.2.6",
56
56
  "jiti": "^2.6.1"
57
57
  },
58
58
  "peerDependencies": {
59
- "@vmz/plugin-markdown-it": "0.2.4",
60
- "@vmz/test": "0.2.4",
59
+ "@vmz/plugin-markdown-it": "0.2.6",
60
+ "@vmz/test": "0.2.6",
61
61
  "typescript": "^5.8.3"
62
62
  },
63
63
  "peerDependenciesMeta": {
@@ -85,6 +85,10 @@
85
85
  "verify:list": "node --import ../../../scripts/test/resolve-ts-from-js.mjs --experimental-strip-types ./tests/conformance/run.ts --list",
86
86
  "build:js": "node ../../../scripts/build/clean-package-dist.mjs packages/runtimes/vmz/dist && tsc -p tsconfig.json"
87
87
  },
88
+ "publishConfig": {
89
+ "access": "public",
90
+ "name": "@vmz/vmz"
91
+ },
88
92
  "keywords": [
89
93
  "vmz",
90
94
  "napi",
@@ -92,15 +96,12 @@
92
96
  "cli"
93
97
  ],
94
98
  "optionalDependencies": {
95
- "@vmz/vmz-win32-x64": "0.2.4",
96
- "@vmz/vmz-win32-arm64": "0.2.4",
97
- "@vmz/vmz-darwin-x64": "0.2.4",
98
- "@vmz/vmz-darwin-arm64": "0.2.4",
99
- "@vmz/vmz-linux-x64": "0.2.4",
100
- "@vmz/vmz-linux-arm64": "0.2.4"
101
- },
102
- "publishConfig": {
103
- "access": "public"
99
+ "@vmz/vmz-win32-x64": "0.2.6",
100
+ "@vmz/vmz-win32-arm64": "0.2.6",
101
+ "@vmz/vmz-darwin-x64": "0.2.6",
102
+ "@vmz/vmz-darwin-arm64": "0.2.6",
103
+ "@vmz/vmz-linux-x64": "0.2.6",
104
+ "@vmz/vmz-linux-arm64": "0.2.6"
104
105
  },
105
106
  "repository": {
106
107
  "type": "git",