@genroc/eval-node 0.0.0-edge.defd0eb → 0.0.0-edge.e2853a29

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/import.js CHANGED
@@ -6,12 +6,10 @@
6
6
  // Two modes, one binary: "types" writes the declarations an editor needs and returns no
7
7
  // code; "build" typechecks and bundles. A separate types hook would mean a second `tsc`
8
8
  // over the same project.
9
- import { spawn } from "node:child_process";
10
9
  import { existsSync } from "node:fs";
11
- import { access, mkdir, writeFile } from "node:fs/promises";
10
+ import { access, writeFile } from "node:fs/promises";
12
11
  import { builtinModules } from "node:module";
13
- import { dirname, join, relative, resolve } from "node:path";
14
- import { fileURLToPath } from "node:url";
12
+ import { dirname, join, resolve } from "node:path";
15
13
  import commonjs from "@rollup/plugin-commonjs";
16
14
  import json from "@rollup/plugin-json";
17
15
  import { nodeResolve } from "@rollup/plugin-node-resolve";
@@ -30,11 +28,6 @@ async function exists(path) {
30
28
  return false;
31
29
  }
32
30
  }
33
- /** Creates the parent directory, which `.genroc-cache/` relies on: nothing else makes it. */
34
- async function write(path, content) {
35
- await mkdir(dirname(path), { recursive: true });
36
- await writeFile(path, content);
37
- }
38
31
  // ── JSON Schema → TypeScript ───────────────────────────────────────────────────
39
32
  /** Only genroc's keyword set is handled; anything else its strict decoder would have
40
33
  * refused before this ran (internal/schema, allowedKeywords). */
@@ -90,15 +83,17 @@ function objectType(s, used) {
90
83
  const doc = typeof sub.description === "string"
91
84
  ? ` /** ${sub.description} */\n`
92
85
  : "";
93
- lines.push(`${doc} ${propKey(key)}${required.has(key) ? "" : "?"}: ${tsType(sub, used)};`);
86
+ lines.push(`${doc} ${propKey(key)}${required.has(key) ? "" : "?"}: ${nest(tsType(sub, used))};`);
94
87
  }
95
88
  if (s.additionalProperties && typeof s.additionalProperties === "object") {
96
- lines.push(` [key: string]: ${tsType(s.additionalProperties, used)};`);
89
+ lines.push(` [key: string]: ${nest(tsType(s.additionalProperties, used))};`);
97
90
  }
98
91
  if (lines.length === 0)
99
92
  return "Record<string, unknown>";
100
93
  return `{\n${lines.join("\n")}\n}`;
101
94
  }
95
+ /** Every line but the first, which is already placed by the property that opens it. */
96
+ const nest = (t) => t.replace(/\n/g, "\n ");
102
97
  function union(parts) {
103
98
  const seen = [...new Set(parts)];
104
99
  return seen.length === 0 ? "unknown" : seen.join(" | ");
@@ -155,11 +150,7 @@ async function nearestTsconfig(from, root) {
155
150
  }
156
151
  }
157
152
  async function typecheck(sites) {
158
- // NOT `.genroc`: that is the project config FILE, and a directory of the same name cannot
159
- // coexist with it. The suffix is what keeps the scratch area out of its way.
160
- const dir = join(root, ".genroc-cache");
161
- await write(join(dir, ".gitignore"), "*\n");
162
- // One tsc per distinct base config: `extends` takes a single base, so merging two would
153
+ // One program per distinct base config: `extends` takes a single base, so merging two would
163
154
  // check each script under the other author's options.
164
155
  const groups = new Map();
165
156
  for (const at of sites) {
@@ -170,10 +161,10 @@ async function typecheck(sites) {
170
161
  else
171
162
  groups.set(base, [at]);
172
163
  }
173
- let n = 0;
164
+ const diagnostics = [];
174
165
  for (const [base, group] of groups) {
175
166
  const config = {
176
- ...(base ? { extends: relative(dir, base) } : {}),
167
+ ...(base ? { extends: base } : {}),
177
168
  compilerOptions: {
178
169
  noEmit: true,
179
170
  strict: true,
@@ -189,37 +180,33 @@ async function typecheck(sites) {
189
180
  // base config there is nothing to opt in with, so the default stays none.
190
181
  ...(base ? {} : { types: [] }),
191
182
  },
192
- files: group.flatMap((s) => [
193
- relative(dir, s.file),
194
- relative(dir, typesPathFor(s.file)),
195
- ]),
183
+ files: group.flatMap((s) => [s.file, typesPathFor(s.file)]),
196
184
  // `files` overrides the base's, but a base `include` survives beside it and would
197
185
  // drag the author's whole tree in, to be checked under the worker lib.
198
186
  include: [],
199
187
  };
200
- const configPath = join(dir, groups.size === 1 ? "tsconfig.json" : `tsconfig.${n++}.json`);
201
- await write(configPath, JSON.stringify(config, null, 2));
202
- await runTsc(root, configPath);
188
+ // Never written: the name only anchors `@types` lookup at the root. It must not be
189
+ // `tsconfig.json`: that is the base the config `extends` whenever the author keeps one at
190
+ // the root, and tsc refuses a config that extends its own path as circular.
191
+ const parsed = ts.parseJsonConfigFileContent(config, ts.sys, root, undefined, join(root, "tsconfig.genroc.json"));
192
+ const program = ts.createProgram({
193
+ rootNames: parsed.fileNames,
194
+ options: parsed.options,
195
+ projectReferences: parsed.projectReferences,
196
+ configFileParsingDiagnostics: parsed.errors,
197
+ });
198
+ diagnostics.push(...parsed.errors, ...ts.getPreEmitDiagnostics(program));
203
199
  }
204
- }
205
- async function runTsc(root, configPath) {
206
- const tsc = fileURLToPath(import.meta.resolve("typescript/bin/tsc"));
207
- const proc = spawn(process.execPath, [tsc, "--noEmit", "-p", configPath], {
208
- cwd: root,
209
- stdio: ["ignore", "pipe", "pipe"],
210
- });
211
- let out = "";
212
- let err = "";
213
- proc.stdout.on("data", (c) => (out += c));
214
- proc.stderr.on("data", (c) => (err += c));
215
- const code = await new Promise((resolve, reject) => {
216
- proc.on("error", reject);
217
- proc.on("close", (c) => resolve(c ?? 1));
218
- });
219
- if (code !== 0) {
220
- // tsc reports on stdout; the exit code IS the type check, so this is the diagnostic
221
- // genctl surfaces and the reason a failed import never produces a string.
222
- die([out, err].filter(Boolean).join("\n").trimEnd());
200
+ if (diagnostics.length > 0) {
201
+ // The diagnostics are the whole type check: this is what genctl surfaces, and the reason a
202
+ // failed import never produces a string.
203
+ die(ts
204
+ .formatDiagnostics(diagnostics, {
205
+ getCanonicalFileName: (f) => f,
206
+ getCurrentDirectory: () => root,
207
+ getNewLine: () => "\n",
208
+ })
209
+ .trimEnd());
223
210
  }
224
211
  }
225
212
  // ── bundle ─────────────────────────────────────────────────────────────────────
@@ -376,7 +363,7 @@ for (const at of located) {
376
363
  byPath.set(at.file, at);
377
364
  }
378
365
  for (const at of byPath.values()) {
379
- await write(typesPathFor(at.file), declarations(at));
366
+ await writeFile(typesPathFor(at.file), declarations(at));
380
367
  }
381
368
  if (manifest.mode === "types") {
382
369
  console.log(JSON.stringify(manifest, null, 2));
package/dist/worker.js CHANGED
@@ -62,15 +62,15 @@ async function fetchObject(ref) {
62
62
  /** Put each listed value back where its path says it belongs. Paths are arrays of keys, so this
63
63
  * needs no parser: the whole reason they are not JSON Pointer strings. */
64
64
  async function resolveObjects(job) {
65
- let input = job.input;
65
+ let input = job.external_input;
66
66
  for (const e of job.objects ?? []) {
67
67
  const value = await fetchObject(e.ref);
68
68
  if (e.path.length === 0) {
69
69
  input = value;
70
70
  continue;
71
71
  }
72
- // The path is rooted at the entry and starts with "input", which is the value being rebuilt.
73
- const rest = e.path[0] === "input" ? e.path.slice(1) : e.path;
72
+ // The path is rooted at the entry and starts with "external_input", the value being rebuilt.
73
+ const rest = e.path[0] === "external_input" ? e.path.slice(1) : e.path;
74
74
  if (rest.length === 0) {
75
75
  input = value;
76
76
  continue;
package/import.ts CHANGED
@@ -7,12 +7,10 @@
7
7
  // code; "build" typechecks and bundles. A separate types hook would mean a second `tsc`
8
8
  // over the same project.
9
9
 
10
- import { spawn } from "node:child_process";
11
10
  import { existsSync } from "node:fs";
12
- import { access, mkdir, writeFile } from "node:fs/promises";
11
+ import { access, writeFile } from "node:fs/promises";
13
12
  import { builtinModules } from "node:module";
14
- import { dirname, join, relative, resolve } from "node:path";
15
- import { fileURLToPath } from "node:url";
13
+ import { dirname, join, resolve } from "node:path";
16
14
 
17
15
  import commonjs from "@rollup/plugin-commonjs";
18
16
  import json from "@rollup/plugin-json";
@@ -70,12 +68,6 @@ async function exists(path: string): Promise<boolean> {
70
68
  }
71
69
  }
72
70
 
73
- /** Creates the parent directory, which `.genroc-cache/` relies on: nothing else makes it. */
74
- async function write(path: string, content: string): Promise<void> {
75
- await mkdir(dirname(path), { recursive: true });
76
- await writeFile(path, content);
77
- }
78
-
79
71
  // ── JSON Schema → TypeScript ───────────────────────────────────────────────────
80
72
 
81
73
  /** Only genroc's keyword set is handled; anything else its strict decoder would have
@@ -137,16 +129,21 @@ function objectType(s: Schema, used: Set<string>): string {
137
129
  ? ` /** ${sub.description} */\n`
138
130
  : "";
139
131
  lines.push(
140
- `${doc} ${propKey(key)}${required.has(key) ? "" : "?"}: ${tsType(sub, used)};`,
132
+ `${doc} ${propKey(key)}${required.has(key) ? "" : "?"}: ${nest(tsType(sub, used))};`,
141
133
  );
142
134
  }
143
135
  if (s.additionalProperties && typeof s.additionalProperties === "object") {
144
- lines.push(` [key: string]: ${tsType(s.additionalProperties, used)};`);
136
+ lines.push(
137
+ ` [key: string]: ${nest(tsType(s.additionalProperties, used))};`,
138
+ );
145
139
  }
146
140
  if (lines.length === 0) return "Record<string, unknown>";
147
141
  return `{\n${lines.join("\n")}\n}`;
148
142
  }
149
143
 
144
+ /** Every line but the first, which is already placed by the property that opens it. */
145
+ const nest = (t: string) => t.replace(/\n/g, "\n ");
146
+
150
147
  function union(parts: string[]): string {
151
148
  const seen = [...new Set(parts)];
152
149
  return seen.length === 0 ? "unknown" : seen.join(" | ");
@@ -212,12 +209,7 @@ async function nearestTsconfig(
212
209
  }
213
210
 
214
211
  async function typecheck(sites: Located[]): Promise<void> {
215
- // NOT `.genroc`: that is the project config FILE, and a directory of the same name cannot
216
- // coexist with it. The suffix is what keeps the scratch area out of its way.
217
- const dir = join(root, ".genroc-cache");
218
- await write(join(dir, ".gitignore"), "*\n");
219
-
220
- // One tsc per distinct base config: `extends` takes a single base, so merging two would
212
+ // One program per distinct base config: `extends` takes a single base, so merging two would
221
213
  // check each script under the other author's options.
222
214
  const groups = new Map<string, Located[]>();
223
215
  for (const at of sites) {
@@ -227,10 +219,10 @@ async function typecheck(sites: Located[]): Promise<void> {
227
219
  else groups.set(base, [at]);
228
220
  }
229
221
 
230
- let n = 0;
222
+ const diagnostics: ts.Diagnostic[] = [];
231
223
  for (const [base, group] of groups) {
232
224
  const config: Record<string, unknown> = {
233
- ...(base ? { extends: relative(dir, base) } : {}),
225
+ ...(base ? { extends: base } : {}),
234
226
  compilerOptions: {
235
227
  noEmit: true,
236
228
  strict: true,
@@ -246,41 +238,42 @@ async function typecheck(sites: Located[]): Promise<void> {
246
238
  // base config there is nothing to opt in with, so the default stays none.
247
239
  ...(base ? {} : { types: [] }),
248
240
  },
249
- files: group.flatMap((s) => [
250
- relative(dir, s.file),
251
- relative(dir, typesPathFor(s.file)),
252
- ]),
241
+ files: group.flatMap((s) => [s.file, typesPathFor(s.file)]),
253
242
  // `files` overrides the base's, but a base `include` survives beside it and would
254
243
  // drag the author's whole tree in, to be checked under the worker lib.
255
244
  include: [],
256
245
  };
257
- const configPath = join(
258
- dir,
259
- groups.size === 1 ? "tsconfig.json" : `tsconfig.${n++}.json`,
246
+ // Never written: the name only anchors `@types` lookup at the root. It must not be
247
+ // `tsconfig.json`: that is the base the config `extends` whenever the author keeps one at
248
+ // the root, and tsc refuses a config that extends its own path as circular.
249
+ const parsed = ts.parseJsonConfigFileContent(
250
+ config,
251
+ ts.sys,
252
+ root,
253
+ undefined,
254
+ join(root, "tsconfig.genroc.json"),
260
255
  );
261
- await write(configPath, JSON.stringify(config, null, 2));
262
- await runTsc(root, configPath);
256
+ const program = ts.createProgram({
257
+ rootNames: parsed.fileNames,
258
+ options: parsed.options,
259
+ projectReferences: parsed.projectReferences,
260
+ configFileParsingDiagnostics: parsed.errors,
261
+ });
262
+ diagnostics.push(...parsed.errors, ...ts.getPreEmitDiagnostics(program));
263
263
  }
264
- }
265
264
 
266
- async function runTsc(root: string, configPath: string): Promise<void> {
267
- const tsc = fileURLToPath(import.meta.resolve("typescript/bin/tsc"));
268
- const proc = spawn(process.execPath, [tsc, "--noEmit", "-p", configPath], {
269
- cwd: root,
270
- stdio: ["ignore", "pipe", "pipe"],
271
- });
272
- let out = "";
273
- let err = "";
274
- proc.stdout.on("data", (c: Buffer) => (out += c));
275
- proc.stderr.on("data", (c: Buffer) => (err += c));
276
- const code = await new Promise<number>((resolve, reject) => {
277
- proc.on("error", reject);
278
- proc.on("close", (c) => resolve(c ?? 1));
279
- });
280
- if (code !== 0) {
281
- // tsc reports on stdout; the exit code IS the type check, so this is the diagnostic
282
- // genctl surfaces and the reason a failed import never produces a string.
283
- die([out, err].filter(Boolean).join("\n").trimEnd());
265
+ if (diagnostics.length > 0) {
266
+ // The diagnostics are the whole type check: this is what genctl surfaces, and the reason a
267
+ // failed import never produces a string.
268
+ die(
269
+ ts
270
+ .formatDiagnostics(diagnostics, {
271
+ getCanonicalFileName: (f) => f,
272
+ getCurrentDirectory: () => root,
273
+ getNewLine: () => "\n",
274
+ })
275
+ .trimEnd(),
276
+ );
284
277
  }
285
278
  }
286
279
 
@@ -479,7 +472,7 @@ for (const at of located) {
479
472
  }
480
473
 
481
474
  for (const at of byPath.values()) {
482
- await write(typesPathFor(at.file), declarations(at));
475
+ await writeFile(typesPathFor(at.file), declarations(at));
483
476
  }
484
477
 
485
478
  if (manifest.mode === "types") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genroc/eval-node",
3
- "version": "0.0.0-edge.defd0eb",
3
+ "version": "0.0.0-edge.e2853a29",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24"
package/worker.ts CHANGED
@@ -43,8 +43,8 @@ type ObjectEntry = { path: (string | number)[]; ref: string; size: number };
43
43
  type QueueTask = {
44
44
  token: string;
45
45
  process: string;
46
- task_id: string;
47
- input: unknown;
46
+ task: string;
47
+ external_input: unknown;
48
48
  objects?: ObjectEntry[];
49
49
  raises?: Record<string, unknown>;
50
50
  };
@@ -76,15 +76,15 @@ async function fetchObject(ref: string): Promise<unknown> {
76
76
  /** Put each listed value back where its path says it belongs. Paths are arrays of keys, so this
77
77
  * needs no parser: the whole reason they are not JSON Pointer strings. */
78
78
  async function resolveObjects(job: QueueTask): Promise<unknown> {
79
- let input: any = job.input;
79
+ let input: any = job.external_input;
80
80
  for (const e of job.objects ?? []) {
81
81
  const value = await fetchObject(e.ref);
82
82
  if (e.path.length === 0) {
83
83
  input = value;
84
84
  continue;
85
85
  }
86
- // The path is rooted at the entry and starts with "input", which is the value being rebuilt.
87
- const rest = e.path[0] === "input" ? e.path.slice(1) : e.path;
86
+ // The path is rooted at the entry and starts with "external_input", the value being rebuilt.
87
+ const rest = e.path[0] === "external_input" ? e.path.slice(1) : e.path;
88
88
  if (rest.length === 0) {
89
89
  input = value;
90
90
  continue;