@heroiclands/package-build 23.2.1 → 23.3.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.
@@ -66,6 +66,34 @@ export function evalArgs(typPath, fontArgs) {
66
66
  return ["eval", "--in", typPath, ...fontArgs, PAGES_EXPRESSION];
67
67
  }
68
68
 
69
+ /**
70
+ * Say why a finished Typst process failed.
71
+ *
72
+ * A process killed by a signal has no exit status and prints nothing, so the
73
+ * signal is named; `SIGKILL` is the kernel's out-of-memory kill. Otherwise the
74
+ * first line the compiler printed is the reason, and the exit code stands in
75
+ * when it printed none.
76
+ *
77
+ * @param {{status: number | null, signal: string | null, stderr?: string | null, stdout?: string | null}} result -
78
+ * The finished process.
79
+ * @param {string} binary - The Typst binary.
80
+ * @param {string} subcommand - The Typst subcommand that ran.
81
+ * @returns {string} The reason, ready to follow the failing command's name.
82
+ */
83
+ export function typstFailure(result, binary, subcommand) {
84
+ const command = `\`${binary} ${subcommand}\``;
85
+ if (result.signal) {
86
+ const hint = result.signal === "SIGKILL" ? " (most often the memory limit)" : "";
87
+ return `${command} was killed by ${result.signal}${hint}`;
88
+ }
89
+ const detail = String(result.stderr || result.stdout || "")
90
+ .trim()
91
+ .split("\n")[0];
92
+ return detail ?
93
+ `${command} failed: ${detail}`
94
+ : `${command} exited with code ${result.status} and printed nothing`;
95
+ }
96
+
69
97
  /**
70
98
  * Measure the page each labelled entry of a book starts on.
71
99
  *
@@ -87,12 +115,7 @@ export function readEntryPages(typPath, fontArgs, binary = "typst") {
87
115
  return fail(`could not run \`${binary}\`: ${err.message}`);
88
116
  }
89
117
  if (result.error) return fail(`could not run \`${binary}\`: ${result.error.message}`);
90
- if (result.status !== 0) {
91
- const detail = String(result.stderr || result.stdout || "")
92
- .trim()
93
- .split("\n")[0];
94
- return fail(`\`${binary} eval\` failed: ${detail}`);
95
- }
118
+ if (result.status !== 0) return fail(typstFailure(result, binary, "eval"));
96
119
  let rows;
97
120
  try {
98
121
  rows = JSON.parse(result.stdout);