@ttsc/lint 0.23.0 → 0.25.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.
@@ -1,33 +1,37 @@
1
- export declare const CONFIG_EVALUATOR_MAX_BUFFER: number;
2
- export declare const CONFIG_EVALUATOR_TIMEOUT_MS = 60000;
3
- export declare const CONFIG_EVALUATOR_TEARDOWN_GRACE_MS = 5000;
4
- export declare const CONFIG_EVALUATOR_STATUS_FD = 3;
5
- export declare const CONFIG_EVALUATOR_PROCESS_OPTIONS: Readonly<{
6
- killSignal: "SIGKILL";
7
- maxBuffer: number;
8
- timeout: number;
9
- }>;
10
1
  interface ConfigEvaluatorProcessResult {
11
2
  error?: Error;
12
- output?: readonly (string | null)[] | null;
13
3
  signal: NodeJS.Signals | null;
14
4
  status: number | null;
15
- stderr: string | null | undefined;
16
5
  }
17
6
  /**
18
7
  * Classify the ways the isolated lint-config evaluator can stop.
19
8
  *
20
- * Node reports both timeout and max-buffer termination with the configured
21
- * signal, so the process error code must take precedence over the signal. The
22
- * evaluator uses `SIGKILL`: Node's synchronous process API otherwise keeps
23
- * waiting when a POSIX child handles the default `SIGTERM` without exiting. A
24
- * bare signal is an external termination and a non-zero status is an evaluator
25
- * failure whose stderr tail contains the useful user-config diagnostic.
9
+ * The evaluator writes the child's own output straight to this process's
10
+ * stderr, so a diagnostic has already reached the user by the time anything
11
+ * here runs. What is left to say is only how the process ended: it never
12
+ * launched, something outside killed it, or it exited non-zero after printing
13
+ * its own reason.
14
+ *
15
+ * Nothing is bounded here — not time, not output. Both were the compiler
16
+ * deciding, on numbers nobody chose for this machine, that a user's own config
17
+ * had run too long or said too much. A slow config is a slow build the user can
18
+ * watch and interrupt; a loud one is output they asked for. Neither is this
19
+ * process's memory to spend either, because the child's streams are no longer
20
+ * collected into it.
26
21
  */
27
22
  export declare function configEvaluatorProcessFailure(result: ConfigEvaluatorProcessResult, configPath: string): Error | undefined;
28
23
  /**
29
- * Pass the semantic deadline and private status pipe through the `ttsx` wrapper
30
- * to the runtime child that actually executes the config.
24
+ * Read the failure envelope the evaluator writes to its result file when it
25
+ * stops on an error it can name.
26
+ *
27
+ * This is the other half of classifying how the evaluation ended, which is why
28
+ * it lives beside {@link configEvaluatorProcessFailure} rather than at the call
29
+ * site: the status says that it failed, and this says why.
30
+ *
31
+ * Only a well-formed envelope is honoured. A real evaluation payload never
32
+ * carries this key, and every other shape — an absent file, a build that failed
33
+ * before the loader ran, a half-written result, a payload written before a
34
+ * later non-zero exit — leaves the process status to speak for itself.
31
35
  */
32
- export declare function configEvaluatorBoundaryEnvironment(now?: number): NodeJS.ProcessEnv;
36
+ export declare function configEvaluatorFailureReason(outputPath: string): string;
33
37
  export {};
@@ -1,40 +1,28 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CONFIG_EVALUATOR_PROCESS_OPTIONS = exports.CONFIG_EVALUATOR_STATUS_FD = exports.CONFIG_EVALUATOR_TEARDOWN_GRACE_MS = exports.CONFIG_EVALUATOR_TIMEOUT_MS = exports.CONFIG_EVALUATOR_MAX_BUFFER = void 0;
4
6
  exports.configEvaluatorProcessFailure = configEvaluatorProcessFailure;
5
- exports.configEvaluatorBoundaryEnvironment = configEvaluatorBoundaryEnvironment;
6
- exports.CONFIG_EVALUATOR_MAX_BUFFER = 16 * 1024 * 1024;
7
- exports.CONFIG_EVALUATOR_TIMEOUT_MS = 60_000;
8
- exports.CONFIG_EVALUATOR_TEARDOWN_GRACE_MS = 5_000;
9
- exports.CONFIG_EVALUATOR_STATUS_FD = 3;
10
- exports.CONFIG_EVALUATOR_PROCESS_OPTIONS = Object.freeze({
11
- killSignal: "SIGKILL",
12
- maxBuffer: exports.CONFIG_EVALUATOR_MAX_BUFFER,
13
- timeout: exports.CONFIG_EVALUATOR_TIMEOUT_MS + exports.CONFIG_EVALUATOR_TEARDOWN_GRACE_MS,
14
- });
7
+ exports.configEvaluatorFailureReason = configEvaluatorFailureReason;
8
+ const node_fs_1 = __importDefault(require("node:fs"));
15
9
  /**
16
10
  * Classify the ways the isolated lint-config evaluator can stop.
17
11
  *
18
- * Node reports both timeout and max-buffer termination with the configured
19
- * signal, so the process error code must take precedence over the signal. The
20
- * evaluator uses `SIGKILL`: Node's synchronous process API otherwise keeps
21
- * waiting when a POSIX child handles the default `SIGTERM` without exiting. A
22
- * bare signal is an external termination and a non-zero status is an evaluator
23
- * failure whose stderr tail contains the useful user-config diagnostic.
12
+ * The evaluator writes the child's own output straight to this process's
13
+ * stderr, so a diagnostic has already reached the user by the time anything
14
+ * here runs. What is left to say is only how the process ended: it never
15
+ * launched, something outside killed it, or it exited non-zero after printing
16
+ * its own reason.
17
+ *
18
+ * Nothing is bounded here — not time, not output. Both were the compiler
19
+ * deciding, on numbers nobody chose for this machine, that a user's own config
20
+ * had run too long or said too much. A slow config is a slow build the user can
21
+ * watch and interrupt; a loud one is output they asked for. Neither is this
22
+ * process's memory to spend either, because the child's streams are no longer
23
+ * collected into it.
24
24
  */
25
25
  function configEvaluatorProcessFailure(result, configPath) {
26
- const code = result.error?.code;
27
- const nestedCode = result.output?.[exports.CONFIG_EVALUATOR_STATUS_FD]?.trim() ?? "";
28
- if (code === "ETIMEDOUT" || nestedCode === "ETIMEDOUT") {
29
- return new Error(`@ttsc/lint: ttsx evaluation of ${configPath} timed out after ` +
30
- `${exports.CONFIG_EVALUATOR_TIMEOUT_MS / 1_000} seconds. ` +
31
- "Simplify the config or move heavy work out of top-level.");
32
- }
33
- if (code === "ENOBUFS" || nestedCode === "ENOBUFS") {
34
- return new Error(`@ttsc/lint: ttsx evaluation of ${configPath} exceeded the ` +
35
- `${exports.CONFIG_EVALUATOR_MAX_BUFFER / (1024 * 1024)} MiB output limit. ` +
36
- "Reduce console output from the config and its dependencies.");
37
- }
38
26
  if (result.error) {
39
27
  return new Error(`@ttsc/lint: failed to spawn ttsx for ${configPath}: ${result.error.message}`);
40
28
  }
@@ -42,35 +30,34 @@ function configEvaluatorProcessFailure(result, configPath) {
42
30
  return new Error(`@ttsc/lint: ttsx evaluation of ${configPath} was killed by signal ${result.signal}.`);
43
31
  }
44
32
  if (result.status !== 0) {
45
- const reason = configEvaluatorFailureReason(result.stderr);
46
- return new Error(`@ttsc/lint: lint config ${configPath} evaluation failed with exit code ${String(result.status)}` +
47
- (reason === "" ? "" : "\n" + reason));
33
+ return new Error(`@ttsc/lint: lint config ${configPath} evaluation failed with exit code ${String(result.status)}`);
48
34
  }
49
35
  return undefined;
50
36
  }
51
37
  /**
52
- * Pass the semantic deadline and private status pipe through the `ttsx` wrapper
53
- * to the runtime child that actually executes the config.
54
- */
55
- function configEvaluatorBoundaryEnvironment(now = Date.now()) {
56
- return {
57
- TTSC_TTSX_EVALUATOR_DEADLINE_MS: String(now + exports.CONFIG_EVALUATOR_TIMEOUT_MS),
58
- TTSC_TTSX_EVALUATOR_MAX_BUFFER_BYTES: String(exports.CONFIG_EVALUATOR_MAX_BUFFER),
59
- TTSC_TTSX_EVALUATOR_STATUS_FD: String(exports.CONFIG_EVALUATOR_STATUS_FD),
60
- };
61
- }
62
- /**
63
- * Return the useful tail of evaluator stderr without turning an exception into
64
- * an unbounded duplicate of the already-forwarded child stream.
38
+ * Read the failure envelope the evaluator writes to its result file when it
39
+ * stops on an error it can name.
40
+ *
41
+ * This is the other half of classifying how the evaluation ended, which is why
42
+ * it lives beside {@link configEvaluatorProcessFailure} rather than at the call
43
+ * site: the status says that it failed, and this says why.
44
+ *
45
+ * Only a well-formed envelope is honoured. A real evaluation payload never
46
+ * carries this key, and every other shape — an absent file, a build that failed
47
+ * before the loader ran, a half-written result, a payload written before a
48
+ * later non-zero exit — leaves the process status to speak for itself.
65
49
  */
66
- function configEvaluatorFailureReason(stderr) {
67
- const bounded = (stderr ?? "").slice(-CONFIG_EVALUATOR_REASON_MAX_CHARS);
68
- const lines = bounded
69
- .split(/\r?\n/)
70
- .map((line) => line.trimEnd())
71
- .filter((line) => line.trim() !== "");
72
- return lines.slice(-CONFIG_EVALUATOR_REASON_LINES).join("\n");
50
+ function configEvaluatorFailureReason(outputPath) {
51
+ try {
52
+ const parsed = JSON.parse(node_fs_1.default.readFileSync(outputPath, "utf8"));
53
+ if (typeof parsed !== "object" || parsed === null)
54
+ return "";
55
+ const message = parsed
56
+ .__ttscLoaderError;
57
+ return typeof message === "string" ? message.trim() : "";
58
+ }
59
+ catch {
60
+ return "";
61
+ }
73
62
  }
74
- const CONFIG_EVALUATOR_REASON_LINES = 5;
75
- const CONFIG_EVALUATOR_REASON_MAX_CHARS = 8 * 1024;
76
63
  //# sourceMappingURL=configEvaluatorFailure.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"configEvaluatorFailure.js","sourceRoot":"","sources":["../../src/internal/configEvaluatorFailure.ts"],"names":[],"mappings":";;;;;AAAa,QAAA,2BAA2B,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAC/C,QAAA,2BAA2B,GAAG,MAAM,CAAC;AACrC,QAAA,kCAAkC,GAAG,KAAK,CAAC;AAC3C,QAAA,0BAA0B,GAAG,CAAC,CAAC;AAC/B,QAAA,gCAAgC,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5D,UAAU,EAAE,SAAkB;IAC9B,SAAS,EAAE,QAAA,2BAA2B;IACtC,OAAO,EAAE,QAAA,2BAA2B,GAAG,QAAA,kCAAkC;CAC1E,CAAC,CAAC;AAUH;;;;;;;;;GASG;AACH,uCACE,MAAoC,EACpC,UAAkB;IAElB,MAAM,IAAI,GAAI,MAAM,CAAC,KAA2C,EAAE,IAAI,CAAC;IACvE,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,QAAA,0BAA0B,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC7E,IAAI,IAAI,KAAK,WAAW,IAAI,UAAU,KAAK,WAAW,EAAE,CAAC;QACvD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