@vmz/vmz 0.2.3 → 0.2.5
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 +34 -4
- package/dist/workspace/diagnostic-context.d.ts +10 -0
- package/dist/workspace/diagnostic-context.js +53 -0
- package/dist/workspace/log-level.d.ts +25 -0
- package/dist/workspace/log-level.js +64 -0
- package/dist/workspace/log-style.d.ts +7 -0
- package/dist/workspace/log-style.js +20 -0
- package/dist/workspace/log.d.ts +10 -5
- package/dist/workspace/log.js +42 -14
- package/dist/workspace/pack-client-packages.js +39 -13
- package/locales/en-US/cli.json +5 -0
- package/package.json +14 -14
package/dist/cli/cli.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* Node CLI command implementations .
|
|
3
3
|
*/
|
|
4
4
|
import { spawn } from 'node:child_process';
|
|
5
|
-
import { existsSync } from 'node:fs';
|
|
6
5
|
import path from 'node:path';
|
|
7
6
|
import { createCli } from '@vmz/commander';
|
|
8
7
|
import { registerApplicationCommands } from './application-cmd.js';
|
|
@@ -20,6 +19,8 @@ import { emitLocaleRuntimeModules, localeHasErrors } from '../locale/locale-chec
|
|
|
20
19
|
import { registerLocaleCommands } from '../locale/locale-cmd.js';
|
|
21
20
|
import { emitLocaleRouteRealization } from '../locale/locale-route-emit.js';
|
|
22
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';
|
|
23
24
|
import { packFromDeploymentIr } from '../workspace/pack.js';
|
|
24
25
|
import { registerPlanCommands } from './plan-cmd.js';
|
|
25
26
|
import { loadVmzConfig } from '../workspace/plugin-host.js';
|
|
@@ -64,7 +65,11 @@ function buildProductCli(opts = {}) {
|
|
|
64
65
|
.option('--build', 'cli.opt.build')
|
|
65
66
|
.option('--check', 'cli.opt.check')
|
|
66
67
|
.option('--deny-warnings', 'cli.opt.deny-warnings');
|
|
67
|
-
withWorkspaceOpts(cli.command('check', 'cli.cmd.check'))
|
|
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));
|
|
68
73
|
withWorkspaceOpts(cli.command('build', 'cli.cmd.build')).action((options) => cmdBuild(options));
|
|
69
74
|
withWorkspaceOpts(cli.command('serve', 'cli.cmd.serve')).action((options) => cmdServe(options));
|
|
70
75
|
withWorkspaceOpts(cli.command('dev', 'cli.cmd.dev')).action((options) => cmdDev(options));
|
|
@@ -73,7 +78,11 @@ function buildProductCli(opts = {}) {
|
|
|
73
78
|
.option('--no-rust', 'cli.opt.format-no-rust')
|
|
74
79
|
.option('--no-vmz', 'cli.opt.format-no-vmz')
|
|
75
80
|
.action((options) => cmdFormat(options));
|
|
76
|
-
withWorkspaceOpts(cli.command('lint', 'cli.cmd.lint'))
|
|
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));
|
|
77
86
|
registerTestCommand(cli);
|
|
78
87
|
registerDocumentCommands(cli.command('document|docs', 'cli.cmd.document'));
|
|
79
88
|
registerLocaleCommands(cli.command('locale|locales', 'cli.cmd.locale'));
|
|
@@ -117,7 +126,25 @@ function cmdVersion() {
|
|
|
117
126
|
console.log(`native host=${native.hostProtocol} compiler=${native.compilerProtocol} program_ir=${native.programIrSchema} plugin=${native.pluginProtocol}`);
|
|
118
127
|
return 0;
|
|
119
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
|
+
}
|
|
120
144
|
async function cmdCheck(args) {
|
|
145
|
+
const optsErr = applyInspectLogOptions(args);
|
|
146
|
+
if (optsErr != null)
|
|
147
|
+
return optsErr;
|
|
121
148
|
const pathArg = args._[0] ?? '.';
|
|
122
149
|
const { project, outDir } = resolveWorkspaceDirs({
|
|
123
150
|
path: pathArg,
|
|
@@ -358,7 +385,7 @@ async function cmdServe(args) {
|
|
|
358
385
|
}
|
|
359
386
|
const outDir = resolveProfileArtifactDir(outDirRoot, selected.profile);
|
|
360
387
|
const hostJs = path.join(outDir, 'vmz-serve-host.mjs');
|
|
361
|
-
|
|
388
|
+
{
|
|
362
389
|
try {
|
|
363
390
|
materializeServeHostRuntime(outDir);
|
|
364
391
|
log.info(`materialized ${hostJs} from @vmz/core (release builds omit it)`);
|
|
@@ -498,6 +525,9 @@ async function cmdFormat(args) {
|
|
|
498
525
|
});
|
|
499
526
|
}
|
|
500
527
|
function cmdLint(args) {
|
|
528
|
+
const optsErr = applyInspectLogOptions(args);
|
|
529
|
+
if (optsErr != null)
|
|
530
|
+
return optsErr;
|
|
501
531
|
const pathArg = args._[0] ?? '.';
|
|
502
532
|
const { project, outDir } = resolveWorkspaceDirs({
|
|
503
533
|
path: pathArg,
|
|
@@ -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
|
+
}
|
package/dist/workspace/log.d.ts
CHANGED
|
@@ -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
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
};
|
package/dist/workspace/log.js
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
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
|
-
|
|
18
|
+
if (!progressVisible(getCliLogLevel()))
|
|
19
|
+
return;
|
|
20
|
+
console.error(...args);
|
|
12
21
|
},
|
|
13
22
|
warn(...args) {
|
|
14
|
-
|
|
23
|
+
if (!warnVisible(getCliLogLevel()))
|
|
24
|
+
return;
|
|
25
|
+
console.error(...args);
|
|
15
26
|
},
|
|
16
27
|
error(...args) {
|
|
17
|
-
console.error(
|
|
28
|
+
console.error(...args);
|
|
18
29
|
},
|
|
19
30
|
/** Localized framework error (`cli.err.*`). */
|
|
20
31
|
errorId(id, args) {
|
|
21
|
-
console.error(
|
|
32
|
+
console.error(vmzCliLocalize.t(id, args));
|
|
22
33
|
},
|
|
23
|
-
diagnostic(d) {
|
|
24
|
-
const
|
|
25
|
-
|
|
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
|
|
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(
|
|
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
|
-
|
|
47
|
-
|
|
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,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Not full oxc chunk-split/minify (`oxc-pending` remains for release minify).
|
|
10
10
|
*/
|
|
11
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs';
|
|
11
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, writeFileSync } from 'node:fs';
|
|
12
12
|
import path from 'node:path';
|
|
13
13
|
import { createRequire } from 'node:module';
|
|
14
14
|
import { resolvePackageRoot } from './packages.js';
|
|
@@ -29,15 +29,15 @@ export function packClientBareImports(outDir, opts = {}) {
|
|
|
29
29
|
const skippedVmz = [];
|
|
30
30
|
for (const file of listClientJs(outDir)) {
|
|
31
31
|
for (const spec of collectBareSpecs(readFileSync(file, 'utf8'))) {
|
|
32
|
-
|
|
33
|
-
bareQueue.push(spec);
|
|
32
|
+
bareQueue.push({ spec: String(spec), from: file });
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
while (bareQueue.length) {
|
|
37
|
-
const
|
|
36
|
+
const item = bareQueue.shift();
|
|
37
|
+
const { spec } = item;
|
|
38
38
|
if (bareToVendor.has(spec))
|
|
39
39
|
continue;
|
|
40
|
-
const resolved = resolveBareToSource(projectRoot, spec);
|
|
40
|
+
const resolved = resolveBareToSource(projectRoot, spec, item.from);
|
|
41
41
|
if (!resolved) {
|
|
42
42
|
if (!unresolved.includes(spec))
|
|
43
43
|
unresolved.push(spec);
|
|
@@ -59,7 +59,12 @@ export function packClientBareImports(outDir, opts = {}) {
|
|
|
59
59
|
for (const file of [...listClientJs(outDir), ...listVendorJs(outDir)]) {
|
|
60
60
|
const before = readFileSync(file, 'utf8');
|
|
61
61
|
let after = rewriteBareImports(before, file, bareToVendor);
|
|
62
|
-
|
|
62
|
+
try {
|
|
63
|
+
after = rewriteRelativeTsSpecs(after);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
throw new Error(`pack module ${file}: ${error instanceof Error ? error.message : String(error)}`);
|
|
67
|
+
}
|
|
63
68
|
if (after !== before) {
|
|
64
69
|
writeFileSync(file, after, 'utf8');
|
|
65
70
|
rewritten.push(path.relative(outDir, file).replace(/\\/g, '/'));
|
|
@@ -105,10 +110,8 @@ function materializeSourceTree(outDir, resolved, materializedSources, bareQueue)
|
|
|
105
110
|
writeFileSync(destAbs, js, 'utf8');
|
|
106
111
|
if (sourceFile === resolved.sourceFile)
|
|
107
112
|
entryDest = destAbs;
|
|
108
|
-
for (const bare of collectBareSpecs(js))
|
|
109
|
-
|
|
110
|
-
bareQueue.push(bare);
|
|
111
|
-
}
|
|
113
|
+
for (const bare of collectBareSpecs(js))
|
|
114
|
+
bareQueue.push({ spec: String(bare), from: sourceFile });
|
|
112
115
|
for (const rel of collectRelativeSpecs(js)) {
|
|
113
116
|
const target = resolveRelativeSource(path.dirname(sourceFile), rel);
|
|
114
117
|
if (target && !materializedSources.has(target))
|
|
@@ -208,9 +211,25 @@ function isRelativeOrAbsolute(spec) {
|
|
|
208
211
|
function shouldSkipBare(spec) {
|
|
209
212
|
return SKIP_PREFIXES.some((p) => spec.startsWith(p));
|
|
210
213
|
}
|
|
211
|
-
function resolveBareToSource(projectRoot, spec) {
|
|
214
|
+
function resolveBareToSource(projectRoot, spec, fromFile) {
|
|
212
215
|
const { pkgName, subpath } = splitPackageSpec(spec);
|
|
213
|
-
let pkgRoot =
|
|
216
|
+
let pkgRoot = null;
|
|
217
|
+
if (fromFile && existsSync(fromFile)) {
|
|
218
|
+
let cur = path.dirname(realpathSync(fromFile));
|
|
219
|
+
for (let i = 0; i < 12; i++) {
|
|
220
|
+
const nested = path.join(cur, 'node_modules', ...pkgName.split('/'));
|
|
221
|
+
if (existsSync(path.join(nested, 'package.json'))) {
|
|
222
|
+
pkgRoot = nested;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
const parent = path.dirname(cur);
|
|
226
|
+
if (parent === cur)
|
|
227
|
+
break;
|
|
228
|
+
cur = parent;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (!pkgRoot)
|
|
232
|
+
pkgRoot = resolvePackageRoot(projectRoot, pkgName);
|
|
214
233
|
if (!pkgRoot) {
|
|
215
234
|
let cur = projectRoot;
|
|
216
235
|
for (let i = 0; i < 8; i++) {
|
|
@@ -303,9 +322,16 @@ function packageDirName(pkgName) {
|
|
|
303
322
|
function materializeModule(sourceFile) {
|
|
304
323
|
const ext = path.extname(sourceFile).toLowerCase();
|
|
305
324
|
const raw = readFileSync(sourceFile, 'utf8');
|
|
325
|
+
if (ext === '.json')
|
|
326
|
+
return raw;
|
|
306
327
|
if (ext === '.ts' || ext === '.tsx')
|
|
307
328
|
return transpileTs(raw, sourceFile);
|
|
308
|
-
|
|
329
|
+
try {
|
|
330
|
+
return rewriteRelativeTsSpecs(raw);
|
|
331
|
+
}
|
|
332
|
+
catch (error) {
|
|
333
|
+
throw new Error(`pack source ${sourceFile}: ${error instanceof Error ? error.message : String(error)}`);
|
|
334
|
+
}
|
|
309
335
|
}
|
|
310
336
|
function transpileTs(source, filename) {
|
|
311
337
|
try {
|
package/locales/en-US/cli.json
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.2.5",
|
|
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.
|
|
52
|
-
"@vmz/core": "0.2.
|
|
53
|
-
"@vmz/diagnostic": "0.2.
|
|
54
|
-
"@vmz/plugin": "0.2.
|
|
55
|
-
"@vmz/protocol": "0.2.
|
|
51
|
+
"@vmz/commander": "0.2.5",
|
|
52
|
+
"@vmz/core": "0.2.5",
|
|
53
|
+
"@vmz/diagnostic": "0.2.5",
|
|
54
|
+
"@vmz/plugin": "0.2.5",
|
|
55
|
+
"@vmz/protocol": "0.2.5",
|
|
56
56
|
"jiti": "^2.6.1"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@vmz/plugin-markdown-it": "0.2.
|
|
60
|
-
"@vmz/test": "0.2.
|
|
59
|
+
"@vmz/plugin-markdown-it": "0.2.5",
|
|
60
|
+
"@vmz/test": "0.2.5",
|
|
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.
|
|
96
|
-
"@vmz/vmz-win32-arm64": "0.2.
|
|
97
|
-
"@vmz/vmz-darwin-x64": "0.2.
|
|
98
|
-
"@vmz/vmz-darwin-arm64": "0.2.
|
|
99
|
-
"@vmz/vmz-linux-x64": "0.2.
|
|
100
|
-
"@vmz/vmz-linux-arm64": "0.2.
|
|
95
|
+
"@vmz/vmz-win32-x64": "0.2.5",
|
|
96
|
+
"@vmz/vmz-win32-arm64": "0.2.5",
|
|
97
|
+
"@vmz/vmz-darwin-x64": "0.2.5",
|
|
98
|
+
"@vmz/vmz-darwin-arm64": "0.2.5",
|
|
99
|
+
"@vmz/vmz-linux-x64": "0.2.5",
|
|
100
|
+
"@vmz/vmz-linux-arm64": "0.2.5"
|
|
101
101
|
},
|
|
102
102
|
"publishConfig": {
|
|
103
103
|
"access": "public"
|