@isentinel/eslint-config 6.0.0-beta.9 → 6.0.1

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.
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,98 @@
1
+ import { Buffer } from "node:buffer";
2
+ import process from "node:process";
3
+ import { pathToFileURL } from "node:url";
4
+ //#region src/lint-cli/bootstrap.ts
5
+ /**
6
+ * Engine bootstrap for the lint runner. Spawned as
7
+ * `node <this file> <engine bin>` with the engine's complete argument list as a
8
+ * JSON string array on stdin; it decodes that list, installs it as
9
+ * `process.argv` and then loads the engine's own bin in this same process.
10
+ *
11
+ * It exists to keep file lists off OS command lines: a hook selecting thousands
12
+ * of files would otherwise overflow `CreateProcessW` (32,767 chars) or cmd.exe
13
+ * (8,191) and have to be split into batches, each one starting another lint
14
+ * stack. The command line that launches this process has the same two
15
+ * arguments however many files the run lints.
16
+ *
17
+ * Kept free of imports beyond Node's own so it loads in milliseconds and
18
+ * nothing it pulls in can observe the placeholder `process.argv`.
19
+ */
20
+ /** The exit code for a launch this bootstrap could not complete. */
21
+ const BOOTSTRAP_FAILURE = 2;
22
+ /**
23
+ * Read stdin to its end. Asynchronous rather than `readFileSync(0)`, which can
24
+ * fail with `EAGAIN` on a non-blocking pipe before the writer has finished.
25
+ *
26
+ * @returns The bytes stdin carried.
27
+ */
28
+ async function readStdin() {
29
+ const chunks = [];
30
+ for await (const chunk of process.stdin) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk), "utf8"));
31
+ return Buffer.concat(chunks);
32
+ }
33
+ /**
34
+ * Whether a decoded payload is an array of strings. Restated rather than
35
+ * imported from the package's guards, so this entry stays dependency-free.
36
+ *
37
+ * @param value - The decoded payload.
38
+ * @returns Whether every element is a string.
39
+ */
40
+ function isStringArray(value) {
41
+ return Array.isArray(value) && value.every((element) => typeof element === "string");
42
+ }
43
+ /**
44
+ * Decode the engine argument list the runner streamed in.
45
+ *
46
+ * @param bytes - The raw stdin payload.
47
+ * @returns The arguments, verbatim.
48
+ */
49
+ function decodeArguments(bytes) {
50
+ const decoder = new TextDecoder("utf-8", { fatal: true });
51
+ const parsed = JSON.parse(decoder.decode(bytes));
52
+ if (!isStringArray(parsed)) throw new TypeError("expected a JSON array of argument strings on stdin");
53
+ return parsed;
54
+ }
55
+ /**
56
+ * Read and validate everything the launch needs. Only this phase is the
57
+ * bootstrap's own: its failures are reported as such and exit 2.
58
+ *
59
+ * @returns The launch.
60
+ * @rejects {Error} When the usage, stdin or argument payload is invalid.
61
+ */
62
+ async function prepare() {
63
+ const [bin, ...extra] = process.argv.slice(2);
64
+ if (bin === void 0 || bin.length === 0 || extra.length > 0) throw new Error("usage: node bootstrap <engine bin> (arguments as JSON on stdin)");
65
+ return {
66
+ args: decodeArguments(await readStdin()),
67
+ bin
68
+ };
69
+ }
70
+ /**
71
+ * Prepare the launch, then become the engine.
72
+ *
73
+ * The engine import stays outside the catch around {@link prepare}: its
74
+ * failures are left to Node's default handling, so they surface (stack and
75
+ * exit code included) exactly as they would from a direct `node <bin>` launch.
76
+ *
77
+ * @rejects {Error} Whatever the engine's own module evaluation throws.
78
+ */
79
+ async function main() {
80
+ let launch;
81
+ try {
82
+ launch = await prepare();
83
+ } catch (err) {
84
+ const message = err instanceof Error ? err.message : String(err);
85
+ process.stderr.write(`isentinel-lint: could not start the engine: ${message}\n`);
86
+ process.exitCode = BOOTSTRAP_FAILURE;
87
+ return;
88
+ }
89
+ process.argv = [
90
+ process.execPath,
91
+ launch.bin,
92
+ ...launch.args
93
+ ];
94
+ await import(pathToFileURL(launch.bin).href);
95
+ }
96
+ main();
97
+ //#endregion
98
+ export {};
@@ -0,0 +1 @@
1
+ export {}