@genroc/eval-node 0.0.0-edge.eadd43a → 0.0.0-edge.ed194e03
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/LICENSE +202 -0
- package/README.md +1 -1
- package/dist/eval.js +9 -17
- package/dist/import.js +50 -88
- package/dist/realm.js +8 -16
- package/dist/worker.js +33 -65
- package/eval.ts +13 -23
- package/import.ts +63 -101
- package/package.json +1 -1
- package/realm.ts +8 -16
- package/worker.ts +37 -70
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ resolver's exit code, so a stored definition cannot hold code that failed to typ
|
|
|
26
26
|
|
|
27
27
|
## Building
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
pnpm run build # tsc -p tsconfig.build.json -> dist/
|
|
30
30
|
|
|
31
31
|
The published package is JavaScript, not TypeScript. **Node refuses to strip types for files
|
|
32
32
|
under `node_modules`**, so shipping `.ts` works from a checkout and fails for every consumer —
|
package/dist/eval.js
CHANGED
|
@@ -1,28 +1,21 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// the containment stays swappable.
|
|
5
|
-
//
|
|
6
|
-
// The containment is a Worker per execution (realm.ts). It is what makes the budget real:
|
|
7
|
-
// a synchronous busy loop never yields, so no in-process timer can interrupt it, and only a
|
|
8
|
-
// thread the host can kill bounds it.
|
|
1
|
+
// Imports a script module in its own realm (a Worker per execution, realm.ts), calls its default
|
|
2
|
+
// export, and classifies every outcome (README.md). Only a killable thread bounds a synchronous
|
|
3
|
+
// busy loop, which is what makes the budget real. Knows nothing of genroc; worker.ts does.
|
|
9
4
|
import { Worker } from "node:worker_threads";
|
|
10
5
|
const DEFAULT_TIMEOUT_MS = 5_000;
|
|
11
6
|
// Resolved from THIS file's own extension: run from a checkout it is `.ts`, and from the
|
|
12
7
|
// published package `.js`, because Node will not strip types under node_modules.
|
|
13
8
|
const REALM_URL = new URL(import.meta.url.endsWith(".ts") ? "./realm.ts" : "./realm.js", import.meta.url);
|
|
14
|
-
/** Thrown, not returned: a realm that fails to start is the
|
|
15
|
-
* answers by releasing the claim
|
|
16
|
-
* return value. */
|
|
9
|
+
/** Thrown, not returned: a realm that fails to start is the runner faulting, which worker.ts
|
|
10
|
+
* answers by releasing the claim. */
|
|
17
11
|
class RealmFault extends Error {
|
|
18
12
|
constructor(message) {
|
|
19
13
|
super(message);
|
|
20
14
|
this.name = "RealmFault";
|
|
21
15
|
}
|
|
22
16
|
}
|
|
23
|
-
/** Thrown when `signal` aborts: the
|
|
24
|
-
*
|
|
25
|
-
* runner did not fault -- nothing is wrong, the answer is simply no longer wanted. */
|
|
17
|
+
/** Thrown when `signal` aborts: the answer is no longer wanted, so worker.ts releases rather
|
|
18
|
+
* than answers. Not a RealmFault: nothing is wrong. */
|
|
26
19
|
export class Cancelled extends Error {
|
|
27
20
|
constructor() {
|
|
28
21
|
super("cancelled");
|
|
@@ -46,9 +39,8 @@ export async function evaluate(req, signal) {
|
|
|
46
39
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
47
40
|
}
|
|
48
41
|
worker.once("message", (reply) => resolve(reply));
|
|
49
|
-
// A script may
|
|
50
|
-
//
|
|
51
|
-
// this too, by which time the promise has settled and the first result stands.
|
|
42
|
+
// A script may `process.exit()`, which would otherwise look like a hang until the budget.
|
|
43
|
+
// Our own terminate() fires this too, after the promise has settled.
|
|
52
44
|
worker.once("exit", (code) => resolve(exited(code)));
|
|
53
45
|
worker.once("error", (err) => reject(new RealmFault(errorText(err))));
|
|
54
46
|
worker.postMessage({ code: req.code, input: req.input });
|
package/dist/import.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// The code-phase resolver: manifest on stdin, `{"code": [...]}` on stdout,
|
|
3
|
-
// with
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// Two modes, one binary: "types" writes the declarations an editor needs and returns no
|
|
7
|
-
// code; "build" typechecks and bundles. A separate types hook would mean a second `tsc`
|
|
8
|
-
// over the same project.
|
|
9
|
-
import { spawn } from "node:child_process";
|
|
2
|
+
// The code-phase resolver: manifest on stdin, `{"code": [...]}` on stdout, diagnostic on stderr
|
|
3
|
+
// with a non-zero exit (specs/source-resolution.md). Two modes share one `tsc` pass: "types"
|
|
4
|
+
// writes declarations only, "build" typechecks and bundles.
|
|
10
5
|
import { existsSync } from "node:fs";
|
|
11
|
-
import { access,
|
|
6
|
+
import { access, writeFile } from "node:fs/promises";
|
|
12
7
|
import { builtinModules } from "node:module";
|
|
13
|
-
import { dirname, join,
|
|
14
|
-
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { dirname, join, resolve } from "node:path";
|
|
15
9
|
import commonjs from "@rollup/plugin-commonjs";
|
|
16
10
|
import json from "@rollup/plugin-json";
|
|
17
11
|
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
@@ -30,11 +24,6 @@ async function exists(path) {
|
|
|
30
24
|
return false;
|
|
31
25
|
}
|
|
32
26
|
}
|
|
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
27
|
// ── JSON Schema → TypeScript ───────────────────────────────────────────────────
|
|
39
28
|
/** Only genroc's keyword set is handled; anything else its strict decoder would have
|
|
40
29
|
* refused before this ran (internal/schema, allowedKeywords). */
|
|
@@ -90,15 +79,17 @@ function objectType(s, used) {
|
|
|
90
79
|
const doc = typeof sub.description === "string"
|
|
91
80
|
? ` /** ${sub.description} */\n`
|
|
92
81
|
: "";
|
|
93
|
-
lines.push(`${doc} ${propKey(key)}${required.has(key) ? "" : "?"}: ${tsType(sub, used)};`);
|
|
82
|
+
lines.push(`${doc} ${propKey(key)}${required.has(key) ? "" : "?"}: ${nest(tsType(sub, used))};`);
|
|
94
83
|
}
|
|
95
84
|
if (s.additionalProperties && typeof s.additionalProperties === "object") {
|
|
96
|
-
lines.push(` [key: string]: ${tsType(s.additionalProperties, used)};`);
|
|
85
|
+
lines.push(` [key: string]: ${nest(tsType(s.additionalProperties, used))};`);
|
|
97
86
|
}
|
|
98
87
|
if (lines.length === 0)
|
|
99
88
|
return "Record<string, unknown>";
|
|
100
89
|
return `{\n${lines.join("\n")}\n}`;
|
|
101
90
|
}
|
|
91
|
+
/** Every line but the first, which is already placed by the property that opens it. */
|
|
92
|
+
const nest = (t) => t.replace(/\n/g, "\n ");
|
|
102
93
|
function union(parts) {
|
|
103
94
|
const seen = [...new Set(parts)];
|
|
104
95
|
return seen.length === 0 ? "unknown" : seen.join(" | ");
|
|
@@ -106,13 +97,6 @@ function union(parts) {
|
|
|
106
97
|
const IDENT = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
107
98
|
const propKey = (k) => (IDENT.test(k) ? k : JSON.stringify(k));
|
|
108
99
|
const identifier = (n) => IDENT.test(n) ? n : `Def_${n.replace(/[^A-Za-z0-9_$]/g, "_")}`;
|
|
109
|
-
function deref(s, defs) {
|
|
110
|
-
let cur = s;
|
|
111
|
-
for (let i = 0; cur && typeof cur.$ref === "string" && i < 16; i++) {
|
|
112
|
-
cur = defs[cur.$ref.replace(/^#\/\$defs\//, "")];
|
|
113
|
-
}
|
|
114
|
-
return cur;
|
|
115
|
-
}
|
|
116
100
|
/** Emits one named type per reachable $def rather than inlining: a task output may
|
|
117
101
|
* reference itself (specs/recursive-type-inference.md) and inlining would not terminate. */
|
|
118
102
|
function declarations(at) {
|
|
@@ -149,9 +133,8 @@ function typesPathFor(scriptPath) {
|
|
|
149
133
|
return scriptPath.replace(/\.[^.\/]+$/, "") + ".genroc.d.ts";
|
|
150
134
|
}
|
|
151
135
|
// ── typecheck ──────────────────────────────────────────────────────────────────
|
|
152
|
-
/** The
|
|
153
|
-
*
|
|
154
|
-
* the project root: above it is not this project. */
|
|
136
|
+
/** The tsconfig the author's editor reads, so editor and apply agree. Stops at the project
|
|
137
|
+
* root. */
|
|
155
138
|
async function nearestTsconfig(from, root) {
|
|
156
139
|
for (let dir = from;; dir = dirname(dir)) {
|
|
157
140
|
const candidate = join(dir, "tsconfig.json");
|
|
@@ -162,11 +145,7 @@ async function nearestTsconfig(from, root) {
|
|
|
162
145
|
}
|
|
163
146
|
}
|
|
164
147
|
async function typecheck(sites) {
|
|
165
|
-
//
|
|
166
|
-
// coexist with it. The suffix is what keeps the scratch area out of its way.
|
|
167
|
-
const dir = join(root, ".genroc-cache");
|
|
168
|
-
await write(join(dir, ".gitignore"), "*\n");
|
|
169
|
-
// One tsc per distinct base config: `extends` takes a single base, so merging two would
|
|
148
|
+
// One program per distinct base config: `extends` takes a single base, so merging two would
|
|
170
149
|
// check each script under the other author's options.
|
|
171
150
|
const groups = new Map();
|
|
172
151
|
for (const at of sites) {
|
|
@@ -177,10 +156,10 @@ async function typecheck(sites) {
|
|
|
177
156
|
else
|
|
178
157
|
groups.set(base, [at]);
|
|
179
158
|
}
|
|
180
|
-
|
|
159
|
+
const diagnostics = [];
|
|
181
160
|
for (const [base, group] of groups) {
|
|
182
161
|
const config = {
|
|
183
|
-
...(base ? { extends:
|
|
162
|
+
...(base ? { extends: base } : {}),
|
|
184
163
|
compilerOptions: {
|
|
185
164
|
noEmit: true,
|
|
186
165
|
strict: true,
|
|
@@ -191,42 +170,36 @@ async function typecheck(sites) {
|
|
|
191
170
|
// `lib` DESCRIBES the realm and is written after `extends` so a base cannot widen it:
|
|
192
171
|
// a worker thread has no document, whatever an author's config claims.
|
|
193
172
|
lib: ["esnext", "webworker"],
|
|
194
|
-
// `types` is the author's
|
|
195
|
-
//
|
|
196
|
-
// base config there is nothing to opt in with, so the default stays none.
|
|
173
|
+
// `types` is the author's opt-in to node globals, which the realm has. With no base
|
|
174
|
+
// config there is nothing to opt in with, so it stays none.
|
|
197
175
|
...(base ? {} : { types: [] }),
|
|
198
176
|
},
|
|
199
|
-
files: group.flatMap((s) => [
|
|
200
|
-
relative(dir, s.file),
|
|
201
|
-
relative(dir, typesPathFor(s.file)),
|
|
202
|
-
]),
|
|
177
|
+
files: group.flatMap((s) => [s.file, typesPathFor(s.file)]),
|
|
203
178
|
// `files` overrides the base's, but a base `include` survives beside it and would
|
|
204
179
|
// drag the author's whole tree in, to be checked under the worker lib.
|
|
205
180
|
include: [],
|
|
206
181
|
};
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
182
|
+
// Never written; anchors `@types` lookup at the root. Not `tsconfig.json`: that is often the
|
|
183
|
+
// base it extends, and tsc refuses a circular extends.
|
|
184
|
+
const parsed = ts.parseJsonConfigFileContent(config, ts.sys, root, undefined, join(root, "tsconfig.genroc.json"));
|
|
185
|
+
const program = ts.createProgram({
|
|
186
|
+
rootNames: parsed.fileNames,
|
|
187
|
+
options: parsed.options,
|
|
188
|
+
projectReferences: parsed.projectReferences,
|
|
189
|
+
configFileParsingDiagnostics: parsed.errors,
|
|
190
|
+
});
|
|
191
|
+
diagnostics.push(...parsed.errors, ...ts.getPreEmitDiagnostics(program));
|
|
210
192
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
proc.stderr.on("data", (c) => (err += c));
|
|
222
|
-
const code = await new Promise((resolve, reject) => {
|
|
223
|
-
proc.on("error", reject);
|
|
224
|
-
proc.on("close", (c) => resolve(c ?? 1));
|
|
225
|
-
});
|
|
226
|
-
if (code !== 0) {
|
|
227
|
-
// tsc reports on stdout; the exit code IS the type check, so this is the diagnostic
|
|
228
|
-
// genctl surfaces and the reason a failed import never produces a string.
|
|
229
|
-
die([out, err].filter(Boolean).join("\n").trimEnd());
|
|
193
|
+
if (diagnostics.length > 0) {
|
|
194
|
+
// The diagnostics are the whole type check: this is what genctl surfaces, and the reason a
|
|
195
|
+
// failed import never produces a string.
|
|
196
|
+
die(ts
|
|
197
|
+
.formatDiagnostics(diagnostics, {
|
|
198
|
+
getCanonicalFileName: (f) => f,
|
|
199
|
+
getCurrentDirectory: () => root,
|
|
200
|
+
getNewLine: () => "\n",
|
|
201
|
+
})
|
|
202
|
+
.trimEnd());
|
|
230
203
|
}
|
|
231
204
|
}
|
|
232
205
|
// ── bundle ─────────────────────────────────────────────────────────────────────
|
|
@@ -253,11 +226,9 @@ const BUILTIN = new Set([
|
|
|
253
226
|
...builtinModules,
|
|
254
227
|
...builtinModules.map((m) => `node:${m}`),
|
|
255
228
|
]);
|
|
256
|
-
/** Resolves
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
* A package resolving to a `.d.ts` is declined — that is a type, not the implementation —
|
|
260
|
-
* which leaves node_modules to nodeResolve. */
|
|
229
|
+
/** Resolves through TYPESCRIPT under the typecheck's config, so a `paths` alias that compiles
|
|
230
|
+
* also bundles. A `.d.ts` resolution is declined (a type, not code), leaving node_modules to
|
|
231
|
+
* nodeResolve. */
|
|
261
232
|
function tsResolve(configPath) {
|
|
262
233
|
let options = {};
|
|
263
234
|
if (configPath) {
|
|
@@ -278,14 +249,12 @@ function tsResolve(configPath) {
|
|
|
278
249
|
},
|
|
279
250
|
};
|
|
280
251
|
}
|
|
281
|
-
/**
|
|
282
|
-
*
|
|
283
|
-
* Bundling is entirely the importer's job, so a definition version pins its code forever. */
|
|
252
|
+
/** A self-contained ES module whose default export is the author's own, unwrapped. Bundling here
|
|
253
|
+
* means a definition version pins its code forever. */
|
|
284
254
|
async function bundle(at) {
|
|
285
255
|
const site = at.site;
|
|
286
|
-
// Builtins are
|
|
287
|
-
//
|
|
288
|
-
// of a module that will not be there, which bundles clean and fails at runtime.
|
|
256
|
+
// Builtins are externalised; anything else unresolved is a REFUSAL, since rollup's default
|
|
257
|
+
// leaves an import that bundles clean and fails at runtime.
|
|
289
258
|
const built = await rollup({
|
|
290
259
|
input: at.file,
|
|
291
260
|
external: (id) => BUILTIN.has(id),
|
|
@@ -293,8 +262,7 @@ async function bundle(at) {
|
|
|
293
262
|
tsResolve(await nearestTsconfig(dirname(at.file), root)),
|
|
294
263
|
nodeResolve({ extensions: [".ts", ".tsx", ".mjs", ".js", ".json"] }),
|
|
295
264
|
commonjs(),
|
|
296
|
-
//
|
|
297
|
-
// did natively; without it rollup hands the JSON to the JS parser.
|
|
265
|
+
// Inlines `.json` imports; without it rollup hands JSON to the JS parser.
|
|
298
266
|
json(),
|
|
299
267
|
transpile,
|
|
300
268
|
],
|
|
@@ -344,15 +312,10 @@ const located = manifest.processes.flatMap((where) => where.sites.map((site) =>
|
|
|
344
312
|
where,
|
|
345
313
|
file: resolve(where.dir, site.argument),
|
|
346
314
|
})));
|
|
347
|
-
//
|
|
348
|
-
//
|
|
349
|
-
// `child` is the shape the scaffold uses — a call to a process that forwards to the evaluator —
|
|
350
|
-
// and `external` is the same request made directly.
|
|
315
|
+
// The `code`-field contract is this resolver's, not genctl's, so it checks the directive landed
|
|
316
|
+
// there: in a child call (the scaffold's shape) or an external task's input.
|
|
351
317
|
for (const at of located) {
|
|
352
|
-
//
|
|
353
|
-
// it the directive sits is the pointer. A child call is the shape the scaffold generates — to a
|
|
354
|
-
// process that forwards to the evaluator — and an external task is the same request made
|
|
355
|
-
// directly.
|
|
318
|
+
// The action's kind is a field; where in it the directive sits is the pointer.
|
|
356
319
|
const kind = at.site.level === "action" ? (at.site.action ?? "") : "";
|
|
357
320
|
const slot = at.site.pointer.slice(-2).join(".");
|
|
358
321
|
if ((kind !== "child" && kind !== "external") || slot !== "input.code") {
|
|
@@ -361,8 +324,7 @@ for (const at of located) {
|
|
|
361
324
|
`${kind ? `a ${kind} task's ` : ""}\`${slot}\`.`);
|
|
362
325
|
}
|
|
363
326
|
}
|
|
364
|
-
// genctl
|
|
365
|
-
// does is the one that must say when it is not there.
|
|
327
|
+
// genctl does not know the argument is a file, so this resolver reports a missing one.
|
|
366
328
|
for (const at of located) {
|
|
367
329
|
if (!existsSync(at.file)) {
|
|
368
330
|
die(`${join(at.where.dir, at.where.file)}: ${address(at.site.pointer)}: ` +
|
|
@@ -383,7 +345,7 @@ for (const at of located) {
|
|
|
383
345
|
byPath.set(at.file, at);
|
|
384
346
|
}
|
|
385
347
|
for (const at of byPath.values()) {
|
|
386
|
-
await
|
|
348
|
+
await writeFile(typesPathFor(at.file), declarations(at));
|
|
387
349
|
}
|
|
388
350
|
if (manifest.mode === "types") {
|
|
389
351
|
console.log(JSON.stringify(manifest, null, 2));
|
package/dist/realm.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
// The evaluation realm
|
|
2
|
-
//
|
|
3
|
-
// eval.ts owns the budget and does the killing; nothing here knows about time.
|
|
4
|
-
//
|
|
5
|
-
// Everything that touches the script's VALUE lives on this side of the boundary — loading,
|
|
6
|
-
// classifying, serialising — because this is the only realm the value exists in.
|
|
1
|
+
// The evaluation realm: one Worker per execution, killable mid-loop by eval.ts, which owns the
|
|
2
|
+
// budget. Everything touching the script's VALUE lives here, the only realm it exists in.
|
|
7
3
|
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
8
4
|
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
9
5
|
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
@@ -14,9 +10,8 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
14
10
|
};
|
|
15
11
|
import { registerHooks } from "node:module";
|
|
16
12
|
import { parentPort } from "node:worker_threads";
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
// the way it does everywhere else.
|
|
13
|
+
// IMPORTED under our own URL rather than compiled from a string, so frames carry the author's
|
|
14
|
+
// line numbers and builtin imports resolve normally.
|
|
20
15
|
const SCRIPT_URL = "script:main";
|
|
21
16
|
const STACK_BYTES = 2_048;
|
|
22
17
|
// The only channel a load hook has to the source. Written per request and read once — a realm
|
|
@@ -54,9 +49,8 @@ function safeText(v) {
|
|
|
54
49
|
return String(v);
|
|
55
50
|
}
|
|
56
51
|
}
|
|
57
|
-
/**
|
|
58
|
-
*
|
|
59
|
-
* which is the script throwing. */
|
|
52
|
+
/** Unparseable code or an unresolvable import is broken code; anything else the import throws is
|
|
53
|
+
* the module's top level running, i.e. the script throwing. */
|
|
60
54
|
function unloadable(err) {
|
|
61
55
|
const code = err?.code;
|
|
62
56
|
return err instanceof SyntaxError || (typeof code === "string" && code.startsWith("ERR_MODULE"));
|
|
@@ -97,10 +91,8 @@ async function run(req) {
|
|
|
97
91
|
return { ok: false, failure: describe(err, "nonserializable") };
|
|
98
92
|
}
|
|
99
93
|
}
|
|
100
|
-
//
|
|
101
|
-
//
|
|
102
|
-
// write's callback fires once the queue ahead of it has drained, which makes the reply a barrier
|
|
103
|
-
// for `console` and a direct process.stdout.write alike: both are this stream.
|
|
94
|
+
// eval.ts terminates this thread the moment the reply lands, while stdio may still be in the
|
|
95
|
+
// pipe. An empty write's callback fires once the queue drains, making the reply a barrier.
|
|
104
96
|
function flush(stream) {
|
|
105
97
|
return new Promise((resolve) => stream.write("", () => resolve()));
|
|
106
98
|
}
|