@boringparts/verule 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/dist/additional-inputs.d.ts +13 -0
- package/dist/additional-inputs.js +68 -0
- package/dist/cli-command-identity.d.ts +13 -0
- package/dist/cli-command-identity.js +15 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +42 -0
- package/dist/config-loader.d.ts +14 -0
- package/dist/config-loader.js +203 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/inline-ignore.d.ts +44 -0
- package/dist/inline-ignore.js +297 -0
- package/dist/main.d.ts +12381 -0
- package/dist/main.js +531 -0
- package/dist/observation.d.ts +93 -0
- package/dist/observation.js +703 -0
- package/dist/projects.d.ts +21 -0
- package/dist/projects.js +171 -0
- package/dist/report-wire.d.ts +1260 -0
- package/dist/report-wire.js +629 -0
- package/dist/session-command.d.ts +48 -0
- package/dist/session-command.js +71 -0
- package/dist/session.d.ts +15 -0
- package/dist/session.js +677 -0
- package/dist/shared-session.d.ts +13 -0
- package/dist/shared-session.js +333 -0
- package/dist/types.d.ts +307 -0
- package/dist/types.js +43 -0
- package/dist/watch-command.d.ts +664 -0
- package/dist/watch-command.js +99 -0
- package/dist/watch.d.ts +57 -0
- package/dist/watch.js +792 -0
- package/package.json +57 -3
- package/README.md +0 -3
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { text } from "@boringparts/cli-contract";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { loadProjectConfigWithDependencies } from "./config-loader.js";
|
|
5
|
+
import { REPORT_SCHEMA_VERSION, watchProject } from "./index.js";
|
|
6
|
+
import { appendGapLines, checkReportSchema, formatDiagnosticsLines, toWireReport, } from "./report-wire.js";
|
|
7
|
+
export const recomputationScopeSchema = z.object({
|
|
8
|
+
recomputedProjects: z.array(z.string()),
|
|
9
|
+
reusedProjects: z.array(z.string()),
|
|
10
|
+
recomputedFiles: z.array(z.string()),
|
|
11
|
+
reusedFiles: z.array(z.string()),
|
|
12
|
+
removedFiles: z.array(z.string()),
|
|
13
|
+
invalidatedBy: z.array(z.string()),
|
|
14
|
+
});
|
|
15
|
+
export const memoryStatsSchema = z.object({
|
|
16
|
+
hostRssBytes: z.number().int().nonnegative(),
|
|
17
|
+
engineRssBytes: z.number().int().nonnegative().optional(),
|
|
18
|
+
});
|
|
19
|
+
export const watchReportRecordSchema = checkReportSchema.extend({
|
|
20
|
+
sequence: z.number().int().positive(),
|
|
21
|
+
trigger: z.enum(["initial", "change"]),
|
|
22
|
+
snapshotId: z.number().int().positive(),
|
|
23
|
+
recomputation: recomputationScopeSchema,
|
|
24
|
+
memory: memoryStatsSchema,
|
|
25
|
+
});
|
|
26
|
+
export const watchFailureRecordSchema = z.object({
|
|
27
|
+
reportVersion: z.literal(REPORT_SCHEMA_VERSION),
|
|
28
|
+
sequence: z.number().int().positive(),
|
|
29
|
+
trigger: z.enum(["initial", "change"]),
|
|
30
|
+
code: z.string(),
|
|
31
|
+
message: z.string(),
|
|
32
|
+
});
|
|
33
|
+
export function formatWatchReportText(record) {
|
|
34
|
+
const lines = formatDiagnosticsLines(record);
|
|
35
|
+
appendGapLines(lines, record.gaps);
|
|
36
|
+
const gapSuffix = record.gaps.length > 0 ? ` (${record.gaps.length} gap(s))` : "";
|
|
37
|
+
const summary = record.diagnostics.length === 0
|
|
38
|
+
? `[watch #${record.sequence}] No violations found across ${record.projects.length} project(s)${gapSuffix}.`
|
|
39
|
+
: `[watch #${record.sequence}] Found ${record.diagnostics.length} violation(s)${gapSuffix}.`;
|
|
40
|
+
if (lines.length === 0) {
|
|
41
|
+
return text.line(summary);
|
|
42
|
+
}
|
|
43
|
+
return text.fragment(`${[...lines, summary].join("\n")}\n`);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Streams complete analysis reports and single-round failures for `verule watch`,
|
|
47
|
+
* preserving the long-lived analysis session across edits until aborted.
|
|
48
|
+
*/
|
|
49
|
+
export async function* streamWatchEvents(workingDirectory, configOption, signal, outcome) {
|
|
50
|
+
const events = watchProject({
|
|
51
|
+
cwd: workingDirectory,
|
|
52
|
+
...(signal !== undefined ? { signal } : {}),
|
|
53
|
+
...(configOption !== undefined
|
|
54
|
+
? { watchFiles: [resolve(workingDirectory, configOption)] }
|
|
55
|
+
: {}),
|
|
56
|
+
loadConfig: async () => {
|
|
57
|
+
const loaded = await loadProjectConfigWithDependencies(workingDirectory, configOption);
|
|
58
|
+
return {
|
|
59
|
+
config: loaded.config,
|
|
60
|
+
watchFiles: loaded.watchFiles,
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
for await (const event of events) {
|
|
65
|
+
if (event.kind === "report") {
|
|
66
|
+
const wire = toWireReport(event.report);
|
|
67
|
+
yield outcome.record.report({
|
|
68
|
+
...wire,
|
|
69
|
+
sequence: event.sequence,
|
|
70
|
+
trigger: event.trigger,
|
|
71
|
+
snapshotId: event.snapshotId,
|
|
72
|
+
recomputation: {
|
|
73
|
+
recomputedProjects: [...event.recomputation.recomputedProjects],
|
|
74
|
+
reusedProjects: [...event.recomputation.reusedProjects],
|
|
75
|
+
recomputedFiles: [...event.recomputation.recomputedFiles],
|
|
76
|
+
reusedFiles: [...event.recomputation.reusedFiles],
|
|
77
|
+
removedFiles: [...event.recomputation.removedFiles],
|
|
78
|
+
invalidatedBy: [...event.recomputation.invalidatedBy],
|
|
79
|
+
},
|
|
80
|
+
memory: {
|
|
81
|
+
hostRssBytes: event.memory.hostRssBytes,
|
|
82
|
+
...(event.memory.engineRssBytes !== undefined
|
|
83
|
+
? { engineRssBytes: event.memory.engineRssBytes }
|
|
84
|
+
: {}),
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
yield outcome.record.failed({
|
|
90
|
+
reportVersion: REPORT_SCHEMA_VERSION,
|
|
91
|
+
sequence: event.sequence,
|
|
92
|
+
trigger: event.trigger,
|
|
93
|
+
code: event.code,
|
|
94
|
+
message: event.message,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return outcome.streamSuccess();
|
|
99
|
+
}
|
package/dist/watch.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type AnalysisSession, type CheckReport, type MemoryStats, type ObserveLimitInput, type ObserveMode, type ObserveOptions, type RecomputationScope, type SourceTarget, type VeruleConfig, type VeruleErrorCode, type WatchConfigLoadResult, type WatchEvent, type WatchProjectOptions } from "./types.ts";
|
|
2
|
+
export type WorkspaceFailureInfo = {
|
|
3
|
+
readonly code: VeruleErrorCode;
|
|
4
|
+
readonly message: string;
|
|
5
|
+
};
|
|
6
|
+
export type WorkspaceControllerOptions = {
|
|
7
|
+
readonly cwd: string;
|
|
8
|
+
readonly config?: VeruleConfig;
|
|
9
|
+
readonly loadConfig?: () => Promise<WatchConfigLoadResult>;
|
|
10
|
+
readonly watchFiles?: readonly string[];
|
|
11
|
+
readonly observe?: ObserveMode;
|
|
12
|
+
readonly observeLimit?: ObserveLimitInput;
|
|
13
|
+
readonly debounceMs?: number;
|
|
14
|
+
readonly onBatchReady?: () => void;
|
|
15
|
+
};
|
|
16
|
+
export type WorkspaceCheckParams = {
|
|
17
|
+
readonly ruleIds?: readonly string[];
|
|
18
|
+
readonly at?: string | SourceTarget;
|
|
19
|
+
readonly observe?: ObserveMode | ObserveOptions;
|
|
20
|
+
readonly observeLimit?: ObserveLimitInput;
|
|
21
|
+
};
|
|
22
|
+
export declare function toExecutionErrorInfo(err: unknown): WorkspaceFailureInfo;
|
|
23
|
+
export declare function initialRecomputationScope(session: AnalysisSession): RecomputationScope;
|
|
24
|
+
export type WorkspaceApplyResult = {
|
|
25
|
+
readonly applied: false;
|
|
26
|
+
} | {
|
|
27
|
+
readonly applied: true;
|
|
28
|
+
readonly trigger: "initial" | "change";
|
|
29
|
+
readonly session: AnalysisSession;
|
|
30
|
+
readonly recomputation: RecomputationScope;
|
|
31
|
+
readonly memory: MemoryStats;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Shared incremental workspace controller used by both `watchProject` and `startSharedSession`.
|
|
35
|
+
* Serializes filesystem watcher updates, synchronous disk checks, config reloads, and checks
|
|
36
|
+
* on a single underlying `AnalysisSession`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createWorkspaceController(options: WorkspaceControllerOptions): {
|
|
39
|
+
absCwd: string;
|
|
40
|
+
readonly session: AnalysisSession | undefined;
|
|
41
|
+
syncWatchers: () => void;
|
|
42
|
+
syncAdditionalInputs: () => void;
|
|
43
|
+
openInitial: () => Promise<{
|
|
44
|
+
session: AnalysisSession;
|
|
45
|
+
recomputation: RecomputationScope;
|
|
46
|
+
memory: MemoryStats;
|
|
47
|
+
}>;
|
|
48
|
+
applyPendingBatch: () => Promise<WorkspaceApplyResult>;
|
|
49
|
+
checkLatest: (params?: WorkspaceCheckParams) => Promise<CheckReport>;
|
|
50
|
+
close: () => Promise<void>;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Watches a project directory (and any external config dependency files), updating an
|
|
54
|
+
* {@link AnalysisSession} incrementally and yielding a complete report or failure record
|
|
55
|
+
* after each initial check and subsequent save.
|
|
56
|
+
*/
|
|
57
|
+
export declare function watchProject(options: WatchProjectOptions): AsyncGenerator<WatchEvent, void, void>;
|