@vmz/vmz 0.2.1 → 0.2.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/dist/cli/cli.js CHANGED
@@ -68,7 +68,11 @@ function buildProductCli(opts = {}) {
68
68
  withWorkspaceOpts(cli.command('build', 'cli.cmd.build')).action((options) => cmdBuild(options));
69
69
  withWorkspaceOpts(cli.command('serve', 'cli.cmd.serve')).action((options) => cmdServe(options));
70
70
  withWorkspaceOpts(cli.command('dev', 'cli.cmd.dev')).action((options) => cmdDev(options));
71
- withWorkspaceOpts(cli.command('format', 'cli.cmd.format')).action((options) => cmdFormat(options));
71
+ withWorkspaceOpts(cli.command('format', 'cli.cmd.format'))
72
+ .option('--no-javascript', 'cli.opt.format-no-javascript')
73
+ .option('--no-rust', 'cli.opt.format-no-rust')
74
+ .option('--no-vmz', 'cli.opt.format-no-vmz')
75
+ .action((options) => cmdFormat(options));
72
76
  withWorkspaceOpts(cli.command('lint', 'cli.cmd.lint')).action((options) => cmdLint(options));
73
77
  registerTestCommand(cli);
74
78
  registerDocumentCommands(cli.command('document|docs', 'cli.cmd.document'));
@@ -472,7 +476,7 @@ async function cmdDev(args) {
472
476
  await session.stop();
473
477
  }
474
478
  }
475
- function cmdFormat(args) {
479
+ async function cmdFormat(args) {
476
480
  const pathArg = args._[0] ?? '.';
477
481
  const { project, outDir } = resolveWorkspaceDirs({
478
482
  path: pathArg,
@@ -480,20 +484,18 @@ function cmdFormat(args) {
480
484
  });
481
485
  const checkOnly = Boolean(args.check);
482
486
  log.info(`format ${project}${checkOnly ? ' --check' : ''}`);
483
- const ws = createWorkspace({ root: project, outDir });
484
- try {
485
- const report = ws.format(checkOnly);
486
- const errors = log.diagnostics(report.diagnostics ?? []);
487
- if (checkOnly) {
488
- log.info(`checked ${report.filesChecked} file(s); ${report.filesNeedWrite} need write`);
489
- return errors || report.filesNeedWrite > 0 ? 1 : 0;
490
- }
491
- log.info(`formatted ${report.filesWritten}/${report.filesChecked} file(s)`);
492
- return errors ? 1 : 0;
493
- }
494
- finally {
495
- ws.dispose();
496
- }
487
+ const { runFormatCommand } = await import('./format-cmd.js');
488
+ return runFormatCommand({
489
+ project,
490
+ outDir,
491
+ check: checkOnly,
492
+ overrides: {
493
+ javascript: args['no-javascript'] ? false : undefined,
494
+ rust: args['no-rust'] ? false : undefined,
495
+ vmz: args['no-vmz'] ? false : undefined,
496
+ },
497
+ createWorkspace,
498
+ });
497
499
  }
498
500
  function cmdLint(args) {
499
501
  const pathArg = args._[0] ?? '.';
@@ -0,0 +1,28 @@
1
+ /**
2
+ * `vmz format` — workspace surfaces (JS/TS + Rust) + `.vmz` authoring formatter.
3
+ */
4
+ export type FormatCommandOptions = {
5
+ project: string;
6
+ outDir: string;
7
+ check: boolean;
8
+ overrides?: {
9
+ javascript?: boolean;
10
+ rust?: boolean;
11
+ vmz?: boolean;
12
+ };
13
+ createWorkspace: (opts: {
14
+ root: string;
15
+ outDir: string;
16
+ }) => {
17
+ format: (checkOnly?: boolean) => {
18
+ filesChecked: number;
19
+ filesWritten: number;
20
+ filesNeedWrite: number;
21
+ diagnostics?: Array<{
22
+ severity?: string;
23
+ }>;
24
+ };
25
+ dispose: () => void;
26
+ };
27
+ };
28
+ export declare function runFormatCommand(opts: FormatCommandOptions): Promise<number>;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * `vmz format` — workspace surfaces (JS/TS + Rust) + `.vmz` authoring formatter.
3
+ */
4
+ import { loadNative } from '../workspace/public-api.js';
5
+ import { loadVmzConfig } from '../workspace/plugin-host.js';
6
+ import { log } from '../workspace/log.js';
7
+ import { resolveFormatConfig } from './format-config.js';
8
+ export async function runFormatCommand(opts) {
9
+ const { project, outDir, check, createWorkspace } = opts;
10
+ const { format: formatConfig } = await loadVmzConfig(project);
11
+ const resolved = resolveFormatConfig(project, formatConfig);
12
+ if (opts.overrides?.javascript !== undefined)
13
+ resolved.javascript = opts.overrides.javascript;
14
+ if (opts.overrides?.rust !== undefined)
15
+ resolved.rust = opts.overrides.rust;
16
+ if (opts.overrides?.vmz !== undefined)
17
+ resolved.vmz = opts.overrides.vmz;
18
+ const native = loadNative();
19
+ let exit = 0;
20
+ if (resolved.javascript || resolved.rust) {
21
+ const report = native.formatWorkspaceRun({
22
+ cwd: project,
23
+ check,
24
+ includes: resolved.includes,
25
+ excludes: resolved.excludes,
26
+ rust: resolved.rust,
27
+ javascript: resolved.javascript,
28
+ styleConfig: resolved.style,
29
+ });
30
+ if (report.errors.length > 0) {
31
+ for (const message of report.errors) {
32
+ log.error(message);
33
+ }
34
+ exit = 1;
35
+ }
36
+ else if (check && report.formatted === 0 && report.unchanged > 0) {
37
+ log.info(`workspace format: no changes needed (${report.unchanged} file(s) checked)`);
38
+ }
39
+ else if (!check) {
40
+ log.info(`workspace format: ${report.formatted} file(s) updated, ${report.unchanged} unchanged`);
41
+ }
42
+ }
43
+ if (resolved.vmz) {
44
+ log.info(`format .vmz ${project}${check ? ' --check' : ''}`);
45
+ const ws = createWorkspace({ root: project, outDir });
46
+ try {
47
+ const report = ws.format(check);
48
+ const errors = log.diagnostics(report.diagnostics ?? []);
49
+ if (check) {
50
+ log.info(`checked ${report.filesChecked} .vmz file(s); ${report.filesNeedWrite} need write`);
51
+ if (report.filesNeedWrite > 0)
52
+ exit = 1;
53
+ }
54
+ else {
55
+ log.info(`formatted ${report.filesWritten}/${report.filesChecked} .vmz file(s)`);
56
+ }
57
+ if (errors)
58
+ exit = 1;
59
+ }
60
+ finally {
61
+ ws.dispose();
62
+ }
63
+ }
64
+ return exit;
65
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `vmz.config` `format` resolution for `vmz format`.
3
+ */
4
+ import type { VmzFormatConfig } from '@vmz/plugin';
5
+ export type ResolvedFormatOptions = {
6
+ includes?: string[];
7
+ excludes: string[];
8
+ rust: boolean;
9
+ javascript: boolean;
10
+ vmz: boolean;
11
+ style: string;
12
+ };
13
+ /** VMZ hybrid monorepo — JS/TS surfaces only, never whole-repo walk. */
14
+ export declare const VMZ_FRAMEWORK_INCLUDES: readonly ["scripts/**", "packages/runtimes/**", "packages/examples/**", "packages/editors/**", "packages/ui/**", "packages/plugins/**", "packages/content/**", "packages/homepage/**", "package.json", "biome.json", "vmz.config.ts", "nifty.config.ts"];
15
+ /** Merge `vmz.config` `format` with framework monorepo defaults. */
16
+ export declare function resolveFormatConfig(projectRoot: string, format?: VmzFormatConfig): ResolvedFormatOptions;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * `vmz.config` `format` resolution for `vmz format`.
3
+ */
4
+ import { existsSync } from 'node:fs';
5
+ import path from 'node:path';
6
+ /** VMZ hybrid monorepo — JS/TS surfaces only, never whole-repo walk. */
7
+ export const VMZ_FRAMEWORK_INCLUDES = [
8
+ 'scripts/**',
9
+ 'packages/runtimes/**',
10
+ 'packages/examples/**',
11
+ 'packages/editors/**',
12
+ 'packages/ui/**',
13
+ 'packages/plugins/**',
14
+ 'packages/content/**',
15
+ 'packages/homepage/**',
16
+ 'package.json',
17
+ 'biome.json',
18
+ 'vmz.config.ts',
19
+ 'nifty.config.ts',
20
+ ];
21
+ const DEFAULT_EXCLUDES = ['**/fixtures/**'];
22
+ function isFrameworkMonorepoRoot(projectRoot) {
23
+ return existsSync(path.join(projectRoot, 'packages', 'runtimes'));
24
+ }
25
+ /** Merge `vmz.config` `format` with framework monorepo defaults. */
26
+ export function resolveFormatConfig(projectRoot, format) {
27
+ const frameworkRoot = isFrameworkMonorepoRoot(projectRoot);
28
+ const hasCargo = existsSync(path.join(projectRoot, 'Cargo.toml'));
29
+ const hasFormatSection = format !== undefined;
30
+ return {
31
+ includes: format?.includes ?? (frameworkRoot ? [...VMZ_FRAMEWORK_INCLUDES] : undefined),
32
+ excludes: [...DEFAULT_EXCLUDES, ...(format?.excludes ?? [])],
33
+ rust: format?.rust ?? (hasCargo && (frameworkRoot || hasFormatSection)),
34
+ javascript: format?.javascript ?? (frameworkRoot || hasFormatSection),
35
+ vmz: format?.vmz ?? true,
36
+ style: format?.style ?? 'biome.json',
37
+ };
38
+ }
@@ -17,6 +17,7 @@ export declare function importMaybeTs(full: any): Promise<any>;
17
17
  * engines: import('@vmz/plugin').VmzEngines,
18
18
  * delivery: import('@vmz/plugin').DeliveryAuthoring | null,
19
19
  * application: { id?: string } | null,
20
+ * format: import('@vmz/plugin').VmzFormatConfig | null,
20
21
  * path: string | null,
21
22
  * pluginPath: string | null,
22
23
  * }>}
@@ -26,6 +27,7 @@ export declare function loadVmzConfig(project: any): Promise<{
26
27
  engines: {};
27
28
  delivery: any;
28
29
  application: any;
30
+ format: any;
29
31
  path: any;
30
32
  pluginPath: any;
31
33
  }>;
@@ -36,6 +36,7 @@ export async function importMaybeTs(full) {
36
36
  * engines: import('@vmz/plugin').VmzEngines,
37
37
  * delivery: import('@vmz/plugin').DeliveryAuthoring | null,
38
38
  * application: { id?: string } | null,
39
+ * format: import('@vmz/plugin').VmzFormatConfig | null,
39
40
  * path: string | null,
40
41
  * pluginPath: string | null,
41
42
  * }>}
@@ -49,6 +50,8 @@ export async function loadVmzConfig(project) {
49
50
  let delivery = null;
50
51
  /** @type {{ id?: string } | null} */
51
52
  let application = null;
53
+ /** @type {import('@vmz/plugin').VmzFormatConfig | null} */
54
+ let format = null;
52
55
  /** @type {string | null} */
53
56
  let configPath = null;
54
57
  /** @type {string | null} */
@@ -67,6 +70,9 @@ export async function loadVmzConfig(project) {
67
70
  if (cfg?.application && typeof cfg.application === 'object') {
68
71
  application = cfg.application;
69
72
  }
73
+ if (cfg?.format && typeof cfg.format === 'object') {
74
+ format = cfg.format;
75
+ }
70
76
  for (const entry of raw) {
71
77
  plugins.push(await resolvePluginEntry(project, entry));
72
78
  }
@@ -80,7 +86,7 @@ export async function loadVmzConfig(project) {
80
86
  plugins.push(await resolvePluginEntry(project, full));
81
87
  break;
82
88
  }
83
- return { plugins, engines, delivery, application, path: configPath, pluginPath };
89
+ return { plugins, engines, delivery, application, format, path: configPath, pluginPath };
84
90
  }
85
91
  /**
86
92
  * @param {string} project
@@ -5,7 +5,10 @@
5
5
  "cli.cmd.build": "Build project via Workspace",
6
6
  "cli.cmd.serve": "Serve dist (optional --build)",
7
7
  "cli.cmd.dev": "Rebuild session",
8
- "cli.cmd.format": "Format .vmz via N-API",
8
+ "cli.cmd.format": "Format workspace surfaces and .vmz via vmz.config format",
9
+ "cli.opt.format-no-javascript": "Skip JS/TS workspace format",
10
+ "cli.opt.format-no-rust": "Skip cargo fmt",
11
+ "cli.opt.format-no-vmz": "Skip .vmz author format",
9
12
  "cli.cmd.lint": "Lint (= check) via N-API",
10
13
  "cli.cmd.test": "Native test discover / report",
11
14
  "cli.cmd.document": "Project /documents domain",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vmz/vmz",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
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.1",
52
- "@vmz/core": "0.2.1",
53
- "@vmz/diagnostic": "0.2.1",
54
- "@vmz/plugin": "0.2.1",
55
- "@vmz/protocol": "0.2.1",
51
+ "@vmz/commander": "0.2.2",
52
+ "@vmz/core": "0.2.2",
53
+ "@vmz/diagnostic": "0.2.2",
54
+ "@vmz/plugin": "0.2.2",
55
+ "@vmz/protocol": "0.2.2",
56
56
  "jiti": "^2.6.1"
57
57
  },
58
58
  "peerDependencies": {
59
- "@vmz/plugin-markdown-it": "0.2.1",
60
- "@vmz/test": "0.2.1",
59
+ "@vmz/plugin-markdown-it": "0.2.2",
60
+ "@vmz/test": "0.2.2",
61
61
  "typescript": "^5.8.3"
62
62
  },
63
63
  "peerDependenciesMeta": {
@@ -92,12 +92,12 @@
92
92
  "cli"
93
93
  ],
94
94
  "optionalDependencies": {
95
- "@vmz/vmz-win32-x64": "0.2.1",
96
- "@vmz/vmz-win32-arm64": "0.2.1",
97
- "@vmz/vmz-darwin-x64": "0.2.1",
98
- "@vmz/vmz-darwin-arm64": "0.2.1",
99
- "@vmz/vmz-linux-x64": "0.2.1",
100
- "@vmz/vmz-linux-arm64": "0.2.1"
95
+ "@vmz/vmz-win32-x64": "0.2.2",
96
+ "@vmz/vmz-win32-arm64": "0.2.2",
97
+ "@vmz/vmz-darwin-x64": "0.2.2",
98
+ "@vmz/vmz-darwin-arm64": "0.2.2",
99
+ "@vmz/vmz-linux-x64": "0.2.2",
100
+ "@vmz/vmz-linux-arm64": "0.2.2"
101
101
  },
102
102
  "publishConfig": {
103
103
  "access": "public"