@genroc/eval-node 0.13.0 → 0.15.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.
- package/dist/import.js +26 -43
- package/dist/worker.js +3 -3
- package/import.ts +33 -47
- package/package.json +1 -1
- package/worker.ts +5 -5
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,
|
|
10
|
+
import { access, writeFile } from "node:fs/promises";
|
|
12
11
|
import { builtinModules } from "node:module";
|
|
13
|
-
import { dirname, join,
|
|
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). */
|
|
@@ -157,11 +150,7 @@ async function nearestTsconfig(from, root) {
|
|
|
157
150
|
}
|
|
158
151
|
}
|
|
159
152
|
async function typecheck(sites) {
|
|
160
|
-
//
|
|
161
|
-
// coexist with it. The suffix is what keeps the scratch area out of its way.
|
|
162
|
-
const dir = join(root, ".genroc-cache");
|
|
163
|
-
await write(join(dir, ".gitignore"), "*\n");
|
|
164
|
-
// 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
|
|
165
154
|
// check each script under the other author's options.
|
|
166
155
|
const groups = new Map();
|
|
167
156
|
for (const at of sites) {
|
|
@@ -172,10 +161,10 @@ async function typecheck(sites) {
|
|
|
172
161
|
else
|
|
173
162
|
groups.set(base, [at]);
|
|
174
163
|
}
|
|
175
|
-
|
|
164
|
+
const diagnostics = [];
|
|
176
165
|
for (const [base, group] of groups) {
|
|
177
166
|
const config = {
|
|
178
|
-
...(base ? { extends:
|
|
167
|
+
...(base ? { extends: base } : {}),
|
|
179
168
|
compilerOptions: {
|
|
180
169
|
noEmit: true,
|
|
181
170
|
strict: true,
|
|
@@ -191,37 +180,31 @@ async function typecheck(sites) {
|
|
|
191
180
|
// base config there is nothing to opt in with, so the default stays none.
|
|
192
181
|
...(base ? {} : { types: [] }),
|
|
193
182
|
},
|
|
194
|
-
files: group.flatMap((s) => [
|
|
195
|
-
relative(dir, s.file),
|
|
196
|
-
relative(dir, typesPathFor(s.file)),
|
|
197
|
-
]),
|
|
183
|
+
files: group.flatMap((s) => [s.file, typesPathFor(s.file)]),
|
|
198
184
|
// `files` overrides the base's, but a base `include` survives beside it and would
|
|
199
185
|
// drag the author's whole tree in, to be checked under the worker lib.
|
|
200
186
|
include: [],
|
|
201
187
|
};
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
188
|
+
// Never written: the name only anchors `@types` lookup at the root, where a real one would sit.
|
|
189
|
+
const parsed = ts.parseJsonConfigFileContent(config, ts.sys, root, undefined, join(root, "tsconfig.json"));
|
|
190
|
+
const program = ts.createProgram({
|
|
191
|
+
rootNames: parsed.fileNames,
|
|
192
|
+
options: parsed.options,
|
|
193
|
+
projectReferences: parsed.projectReferences,
|
|
194
|
+
configFileParsingDiagnostics: parsed.errors,
|
|
195
|
+
});
|
|
196
|
+
diagnostics.push(...parsed.errors, ...ts.getPreEmitDiagnostics(program));
|
|
205
197
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
proc.stderr.on("data", (c) => (err += c));
|
|
217
|
-
const code = await new Promise((resolve, reject) => {
|
|
218
|
-
proc.on("error", reject);
|
|
219
|
-
proc.on("close", (c) => resolve(c ?? 1));
|
|
220
|
-
});
|
|
221
|
-
if (code !== 0) {
|
|
222
|
-
// tsc reports on stdout; the exit code IS the type check, so this is the diagnostic
|
|
223
|
-
// genctl surfaces and the reason a failed import never produces a string.
|
|
224
|
-
die([out, err].filter(Boolean).join("\n").trimEnd());
|
|
198
|
+
if (diagnostics.length > 0) {
|
|
199
|
+
// The diagnostics are the whole type check: this is what genctl surfaces, and the reason a
|
|
200
|
+
// failed import never produces a string.
|
|
201
|
+
die(ts
|
|
202
|
+
.formatDiagnostics(diagnostics, {
|
|
203
|
+
getCanonicalFileName: (f) => f,
|
|
204
|
+
getCurrentDirectory: () => root,
|
|
205
|
+
getNewLine: () => "\n",
|
|
206
|
+
})
|
|
207
|
+
.trimEnd());
|
|
225
208
|
}
|
|
226
209
|
}
|
|
227
210
|
// ── bundle ─────────────────────────────────────────────────────────────────────
|
|
@@ -378,7 +361,7 @@ for (const at of located) {
|
|
|
378
361
|
byPath.set(at.file, at);
|
|
379
362
|
}
|
|
380
363
|
for (const at of byPath.values()) {
|
|
381
|
-
await
|
|
364
|
+
await writeFile(typesPathFor(at.file), declarations(at));
|
|
382
365
|
}
|
|
383
366
|
if (manifest.mode === "types") {
|
|
384
367
|
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.
|
|
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 "
|
|
73
|
-
const rest = e.path[0] === "
|
|
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,
|
|
11
|
+
import { access, writeFile } from "node:fs/promises";
|
|
13
12
|
import { builtinModules } from "node:module";
|
|
14
|
-
import { dirname, join,
|
|
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
|
|
@@ -217,12 +209,7 @@ async function nearestTsconfig(
|
|
|
217
209
|
}
|
|
218
210
|
|
|
219
211
|
async function typecheck(sites: Located[]): Promise<void> {
|
|
220
|
-
//
|
|
221
|
-
// coexist with it. The suffix is what keeps the scratch area out of its way.
|
|
222
|
-
const dir = join(root, ".genroc-cache");
|
|
223
|
-
await write(join(dir, ".gitignore"), "*\n");
|
|
224
|
-
|
|
225
|
-
// 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
|
|
226
213
|
// check each script under the other author's options.
|
|
227
214
|
const groups = new Map<string, Located[]>();
|
|
228
215
|
for (const at of sites) {
|
|
@@ -232,10 +219,10 @@ async function typecheck(sites: Located[]): Promise<void> {
|
|
|
232
219
|
else groups.set(base, [at]);
|
|
233
220
|
}
|
|
234
221
|
|
|
235
|
-
|
|
222
|
+
const diagnostics: ts.Diagnostic[] = [];
|
|
236
223
|
for (const [base, group] of groups) {
|
|
237
224
|
const config: Record<string, unknown> = {
|
|
238
|
-
...(base ? { extends:
|
|
225
|
+
...(base ? { extends: base } : {}),
|
|
239
226
|
compilerOptions: {
|
|
240
227
|
noEmit: true,
|
|
241
228
|
strict: true,
|
|
@@ -251,41 +238,40 @@ async function typecheck(sites: Located[]): Promise<void> {
|
|
|
251
238
|
// base config there is nothing to opt in with, so the default stays none.
|
|
252
239
|
...(base ? {} : { types: [] }),
|
|
253
240
|
},
|
|
254
|
-
files: group.flatMap((s) => [
|
|
255
|
-
relative(dir, s.file),
|
|
256
|
-
relative(dir, typesPathFor(s.file)),
|
|
257
|
-
]),
|
|
241
|
+
files: group.flatMap((s) => [s.file, typesPathFor(s.file)]),
|
|
258
242
|
// `files` overrides the base's, but a base `include` survives beside it and would
|
|
259
243
|
// drag the author's whole tree in, to be checked under the worker lib.
|
|
260
244
|
include: [],
|
|
261
245
|
};
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
246
|
+
// Never written: the name only anchors `@types` lookup at the root, where a real one would sit.
|
|
247
|
+
const parsed = ts.parseJsonConfigFileContent(
|
|
248
|
+
config,
|
|
249
|
+
ts.sys,
|
|
250
|
+
root,
|
|
251
|
+
undefined,
|
|
252
|
+
join(root, "tsconfig.json"),
|
|
265
253
|
);
|
|
266
|
-
|
|
267
|
-
|
|
254
|
+
const program = ts.createProgram({
|
|
255
|
+
rootNames: parsed.fileNames,
|
|
256
|
+
options: parsed.options,
|
|
257
|
+
projectReferences: parsed.projectReferences,
|
|
258
|
+
configFileParsingDiagnostics: parsed.errors,
|
|
259
|
+
});
|
|
260
|
+
diagnostics.push(...parsed.errors, ...ts.getPreEmitDiagnostics(program));
|
|
268
261
|
}
|
|
269
|
-
}
|
|
270
262
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
proc.on("close", (c) => resolve(c ?? 1));
|
|
284
|
-
});
|
|
285
|
-
if (code !== 0) {
|
|
286
|
-
// tsc reports on stdout; the exit code IS the type check, so this is the diagnostic
|
|
287
|
-
// genctl surfaces and the reason a failed import never produces a string.
|
|
288
|
-
die([out, err].filter(Boolean).join("\n").trimEnd());
|
|
263
|
+
if (diagnostics.length > 0) {
|
|
264
|
+
// The diagnostics are the whole type check: this is what genctl surfaces, and the reason a
|
|
265
|
+
// failed import never produces a string.
|
|
266
|
+
die(
|
|
267
|
+
ts
|
|
268
|
+
.formatDiagnostics(diagnostics, {
|
|
269
|
+
getCanonicalFileName: (f) => f,
|
|
270
|
+
getCurrentDirectory: () => root,
|
|
271
|
+
getNewLine: () => "\n",
|
|
272
|
+
})
|
|
273
|
+
.trimEnd(),
|
|
274
|
+
);
|
|
289
275
|
}
|
|
290
276
|
}
|
|
291
277
|
|
|
@@ -484,7 +470,7 @@ for (const at of located) {
|
|
|
484
470
|
}
|
|
485
471
|
|
|
486
472
|
for (const at of byPath.values()) {
|
|
487
|
-
await
|
|
473
|
+
await writeFile(typesPathFor(at.file), declarations(at));
|
|
488
474
|
}
|
|
489
475
|
|
|
490
476
|
if (manifest.mode === "types") {
|
package/package.json
CHANGED
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
|
-
|
|
47
|
-
|
|
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.
|
|
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 "
|
|
87
|
-
const rest = e.path[0] === "
|
|
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;
|