sverka 0.0.0 → 0.2.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.
package/dist/bin.d.mts ADDED
@@ -0,0 +1 @@
1
+ export {}
package/dist/bin.mjs ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+ import { t as missingBuildHint } from "./errors-DHioC6LB.mjs";
3
+ import process from "node:process";
4
+ //#region src/bin.ts
5
+ async function start() {
6
+ try {
7
+ const { main } = await import("./index.mjs");
8
+ process.exitCode = await main(process.argv.slice(2));
9
+ } catch (e) {
10
+ const hint = missingBuildHint(e);
11
+ if (hint !== null) process.stderr.write(`error: ${hint}\n`);
12
+ else {
13
+ const msg = e instanceof Error ? e.stack ?? e.message : String(e);
14
+ process.stderr.write(`fatal: ${msg}\n`);
15
+ }
16
+ process.exitCode = 3;
17
+ }
18
+ }
19
+ start();
20
+ //#endregion
21
+ export {};
22
+
23
+ //# sourceMappingURL=bin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.mjs","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\nimport process from \"node:process\";\nimport { missingBuildHint } from \"./internal/errors.js\";\n\n// Set process.exitCode and let the event loop drain instead of calling\n// process.exit() immediately — a forced exit can truncate buffered stdout/stderr\n// writes when output is piped or large.\nasync function start(): Promise<void> {\n try {\n // Dynamic import so a missing @sverka/* dist (partial build) lands here\n // as a readable hint instead of Node's raw ERR_MODULE_NOT_FOUND.\n const { main } = await import(\"./index.js\");\n process.exitCode = await main(process.argv.slice(2));\n } catch (e: unknown) {\n const hint = missingBuildHint(e);\n if (hint !== null) {\n process.stderr.write(`error: ${hint}\\n`);\n } else {\n const msg = e instanceof Error ? (e.stack ?? e.message) : String(e);\n process.stderr.write(`fatal: ${msg}\\n`);\n }\n process.exitCode = 3;\n }\n}\n\nvoid start();\n"],"mappings":";;;;AAOA,eAAe,QAAuB;CACpC,IAAI;EAGF,MAAM,EAAE,SAAS,MAAM,OAAO;EAC9B,QAAQ,WAAW,MAAM,KAAK,QAAQ,KAAK,MAAM,CAAC,CAAC;CACrD,SAAS,GAAY;EACnB,MAAM,OAAO,iBAAiB,CAAC;EAC/B,IAAI,SAAS,MACX,QAAQ,OAAO,MAAM,UAAU,KAAK,GAAG;OAClC;GACL,MAAM,MAAM,aAAa,QAAS,EAAE,SAAS,EAAE,UAAW,OAAO,CAAC;GAClE,QAAQ,OAAO,MAAM,UAAU,IAAI,GAAG;EACxC;EACA,QAAQ,WAAW;CACrB;AACF;AAEK,MAAM"}
@@ -0,0 +1,16 @@
1
+ //#region src/internal/errors.ts
2
+ /**
3
+ * When a workspace @sverka/* dependency resolves but its dist output is
4
+ * missing (partial build, stale checkout), Node throws a raw
5
+ * ERR_MODULE_NOT_FOUND that does not tell the user what to do. Detect that
6
+ * case and return an actionable hint, or null for unrelated errors.
7
+ */
8
+ function missingBuildHint(e) {
9
+ const msg = e instanceof Error ? e.message : String(e);
10
+ if ((e.code === "ERR_MODULE_NOT_FOUND" || /Cannot find (?:module|package)/.test(msg)) && msg.includes("@sverka/") && /[/\\]dist[/\\]/.test(msg)) return "a @sverka/* dependency has no build output — run `bun run build` in the sverka checkout and retry";
11
+ return null;
12
+ }
13
+ //#endregion
14
+ export { missingBuildHint as t };
15
+
16
+ //# sourceMappingURL=errors-DHioC6LB.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-DHioC6LB.mjs","names":[],"sources":["../src/internal/errors.ts"],"sourcesContent":["// Error-message helpers shared by the bin entry and the command dispatcher.\n\n/**\n * When a workspace @sverka/* dependency resolves but its dist output is\n * missing (partial build, stale checkout), Node throws a raw\n * ERR_MODULE_NOT_FOUND that does not tell the user what to do. Detect that\n * case and return an actionable hint, or null for unrelated errors.\n */\nexport function missingBuildHint(e: unknown): string | null {\n const msg = e instanceof Error ? e.message : String(e);\n const code = (e as { code?: unknown }).code;\n const isModuleNotFound =\n code === \"ERR_MODULE_NOT_FOUND\" ||\n /Cannot find (?:module|package)/.test(msg);\n if (\n isModuleNotFound &&\n msg.includes(\"@sverka/\") &&\n /[/\\\\]dist[/\\\\]/.test(msg)\n ) {\n return (\n \"a @sverka/* dependency has no build output — \" +\n \"run `bun run build` in the sverka checkout and retry\"\n );\n }\n return null;\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,iBAAiB,GAA2B;CAC1D,MAAM,MAAM,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC;CAKrD,KAJc,EAAyB,SAE5B,0BACT,iCAAiC,KAAK,GAAG,MAGzC,IAAI,SAAS,UAAU,KACvB,iBAAiB,KAAK,GAAG,GAEzB,OACE;CAIJ,OAAO;AACT"}
@@ -0,0 +1,84 @@
1
+ //#region src/types.d.ts
2
+ /** Global flags parsed from the command line. */
3
+ export interface GlobalFlags {
4
+ /** Output format. Defaults to "text". */
5
+ format: "text" | "json" | "html" | "sarif" | "web";
6
+ /** Path to sverka.config.ts. */
7
+ config: string | null;
8
+ /** Root directory. Defaults to process.cwd(). */
9
+ root: string;
10
+ /** Suppress non-error output. */
11
+ quiet: boolean;
12
+ /** Enable verbose output with debug information. */
13
+ verbose: boolean;
14
+ }
15
+ /** Output writer abstraction for testability. */
16
+ export interface OutputWriter {
17
+ write(text: string): void;
18
+ writeLine(text: string): void;
19
+ error(text: string): void;
20
+ errorLine(text: string): void;
21
+ /** Write a debug line, only visible when --verbose is set. */
22
+ debug(text: string): void;
23
+ }
24
+ /** Exit codes used by the CLI. */
25
+ export declare const ExitCode: {
26
+ readonly Success: 0;
27
+ readonly PolicyFail: 1;
28
+ readonly UsageError: 2;
29
+ readonly RuntimeError: 3;
30
+ };
31
+ export type ExitCode = (typeof ExitCode)[keyof typeof ExitCode];
32
+ /** CLI error codes. */
33
+ export type CliErrorCode = "UNKNOWN_COMMAND" | "MISSING_ARG" | "INVALID_FLAG" | "CONFIG_EXISTS" | "RUNTIME_NOT_AVAILABLE" | "SDK_ERROR" | "PACKAGE_ERROR";
34
+ /** Error thrown when CLI argument parsing or command execution fails. */
35
+ export declare class CliError extends Error {
36
+ readonly code: CliErrorCode;
37
+ readonly exitCode: ExitCode;
38
+ readonly cause: unknown;
39
+ constructor(message: string, code: CliErrorCode, exitCode: ExitCode, cause?: unknown);
40
+ }
41
+ //#endregion
42
+ //#region src/main.d.ts
43
+ /** Optional dependencies for main (testability seam). */
44
+ interface MainDeps {
45
+ output?: OutputWriter;
46
+ }
47
+ /**
48
+ * The main CLI entry point.
49
+ * @param argv Command-line arguments (excluding node and script path).
50
+ * @returns Exit code (0 = success, 1 = policy fail, 2 = usage error, 3 = runtime error).
51
+ */
52
+ export declare function main(argv: string[], deps?: MainDeps): Promise<number>;
53
+ //#endregion
54
+ //#region src/output.d.ts
55
+ /** A sink that receives a string. */
56
+ type WriteSink = (text: string) => void;
57
+ /**
58
+ * OutputWriter that writes to caller-provided sinks (stdout/stderr).
59
+ * In production, the sinks write to process.stdout/process.stderr.
60
+ * In tests, the sinks capture into arrays.
61
+ */
62
+ export declare class ConsoleOutputWriter implements OutputWriter {
63
+ #private;
64
+ constructor(out: WriteSink, err: WriteSink, quiet?: boolean, verbose?: boolean);
65
+ write(text: string): void;
66
+ writeLine(text: string): void;
67
+ error(text: string): void;
68
+ errorLine(text: string): void;
69
+ /** Write a debug line to stderr, only when --verbose is set. */
70
+ debug(text: string): void;
71
+ }
72
+ /**
73
+ * Create an OutputWriter from global flags. In JSON format, stdout is NOT
74
+ * suppressed by --quiet (the JSON result is the data and must be emitted).
75
+ */
76
+ export declare function createOutputWriter(global: GlobalFlags, out: WriteSink, err: WriteSink): ConsoleOutputWriter;
77
+ /**
78
+ * Wrap any OutputWriter with --quiet / --verbose semantics from global flags.
79
+ * Use for injected test writers so they respect the same suppression rules.
80
+ */
81
+ export declare function wrapOutputWriter(global: GlobalFlags, base: OutputWriter): OutputWriter;
82
+ //#endregion
83
+ export type { MainDeps, WriteSink };
84
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/main.ts","../src/output.ts"],"mappings":";;iBAGiB;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;;iBAIe;EACf,MAAM;EACN,UAAU;EACV,MAAM;EACN,UAAU;;EAEV,MAAM;;;qBAIK;;;;;;YAOD,mBAAmB,uBAAuB;;YAG1C;;qBAUC,iBAAiB;WACnB,MAAM;WACN,UAAU;WACD;EAEhB,YAAA,iBACA,MAAM,cACN,UAAU,UACV;;;;;UC/Ba;EACf,SAAS;;;;;;;wBA2XW,KAAK,gBAAgB,OAAO,WAAW;;;;KCjZjD,aAAa;;;;;;qBAOZ,+BAA+B;;EAM9B,YAAA,KAAK,WAAW,KAAK,WAAW,iBAAe;EAO3D,MAAM;EAKN,UAAU;EAKV,MAAM;EAIN,UAAU;;EAKV,MAAM;;;;;;wBAwDQ,mBACd,QAAQ,aACR,KAAK,WACL,KAAK,YACJ;;;;;wBAYa,iBACd,QAAQ,aACR,MAAM,eACL"}