@skillstech/thunderlang 1.6.1 → 1.8.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/CHANGELOG.md +121 -0
- package/README.md +10 -3
- package/dist/core.cjs +264 -47
- package/dist/index.cjs +9118 -1077
- package/dist/learn.cjs +1419 -90
- package/package.json +1 -1
- package/src/ai.mjs +2 -1
- package/src/atlas.mjs +2 -1
- package/src/behaviour.mjs +246 -0
- package/src/cli-main.mjs +3015 -0
- package/src/cli.mjs +9 -2799
- package/src/conflict.mjs +0 -0
- package/src/core/ThunderDotnet.cs +195 -0
- package/src/core/check.mjs +316 -10
- package/src/core/cli.mjs +67 -10
- package/src/core/csharp-run.mjs +29 -8
- package/src/core/diagnostics.mjs +12 -1
- package/src/core/engine-core.mjs +161 -20
- package/src/core/engine-values.mjs +1 -0
- package/src/core/engine.mjs +131 -7
- package/src/core/go-run.mjs +3 -2
- package/src/core/index.mjs +6 -2
- package/src/core/java-run.mjs +3 -3
- package/src/core/kind.mjs +45 -0
- package/src/core/lexer.mjs +16 -2
- package/src/core/parser.mjs +254 -22
- package/src/core/project-root.mjs +18 -0
- package/src/core/project.mjs +18 -18
- package/src/core/react-run.mjs +3 -3
- package/src/core/runtime-go/thunder_runtime.go +269 -1
- package/src/core/runtime-npm.mjs +79 -0
- package/src/core/runtime-python.mjs +365 -3
- package/src/core/runtime-react.mjs +2 -1
- package/src/core/runtime-typescript.mjs +155 -6
- package/src/core/rust-run.mjs +3 -2
- package/src/core/serving.mjs +12 -0
- package/src/core/store-format.mjs +110 -0
- package/src/core/target-csharp.mjs +5 -1
- package/src/core/target-go.mjs +11 -4
- package/src/core/target-python.mjs +39 -6
- package/src/core/target-rust.mjs +1 -1
- package/src/core/target-typescript.mjs +95 -7
- package/src/core/typescript-run.mjs +14 -7
- package/src/core-changes-fs.mjs +28 -0
- package/src/core-changes.d.mts +67 -0
- package/src/core-changes.mjs +603 -0
- package/src/core-rules.mjs +146 -0
- package/src/core-services.d.mts +4 -0
- package/src/core-services.mjs +49 -0
- package/src/decision.mjs +2 -1
- package/src/distributed.mjs +2 -1
- package/src/emit.mjs +2 -2
- package/src/evidence.mjs +28 -0
- package/src/examples.d.mts +21 -0
- package/src/examples.mjs +175 -0
- package/src/focus.mjs +2 -1
- package/src/index.d.ts +4 -0
- package/src/index.mjs +4 -0
- package/src/intent-atlas.mjs +4 -3
- package/src/mcp.mjs +52 -6
- package/src/passport-fs.mjs +2 -1
- package/src/passport.mjs +2 -1
- package/src/privacy.mjs +2 -1
- package/src/program.d.mts +4 -0
- package/src/program.mjs +4 -0
- package/src/read-repo-fs.mjs +2 -1
- package/src/read-repo.mjs +3 -2
- package/src/report.mjs +3 -2
- package/src/review.mjs +71 -4
- package/src/select.mjs +2 -1
- package/src/semantic-diff.mjs +7 -6
- package/src/system.mjs +3 -2
- package/src/text-order.mjs +6 -0
- package/src/thunderize.mjs +2 -1
- package/src/trace-cli.mjs +8 -3
- package/src/trace-data.mjs +3 -2
- package/src/trace-fs.mjs +29 -3
- package/src/trace.mjs +27 -10
- package/src/write-across-cli.mjs +22 -4
- package/src/write-across.mjs +2 -1
- package/syntaxes/thunder.tmLanguage.json +196 -0
package/src/core/cli.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// The Thunder Core commands: thunder new | run | build | test | check | format.
|
|
2
2
|
//
|
|
3
|
-
// When does a command mean Thunder Core (and not a mission .thunder file)? Deterministically, never by guessing
|
|
4
|
-
// from the file's contents:
|
|
3
|
+
// When does a command mean Thunder Core (and not a mission .thunder file)? Deterministically, never by guessing:
|
|
5
4
|
// - thunder new <dir> always creates a Thunder Core project (missions: thunder init <Name>)
|
|
6
5
|
// - no file given, and a thunder.toml is in this folder or above it
|
|
7
6
|
// - the file is a folder that holds a thunder.toml, or a .thunder file under one
|
|
8
7
|
// - --core is given (a single file with no project)
|
|
8
|
+
// - --mission is given: never Core
|
|
9
|
+
// - otherwise, a .thunder file whose first line cannot start a mission (fileKind in kind.mjs)
|
|
9
10
|
// Everything else falls through to the mission commands, unchanged.
|
|
10
11
|
|
|
11
12
|
import { readFileSync, writeFileSync, existsSync, statSync, readdirSync } from 'node:fs';
|
|
@@ -20,15 +21,16 @@ import { javaClassName } from './target-java.mjs';
|
|
|
20
21
|
import { formatDiagnostic } from './diagnostics.mjs';
|
|
21
22
|
import { formatCore } from './format.mjs';
|
|
22
23
|
import { paint, paintThunder, useColor } from '../term.mjs';
|
|
23
|
-
import { runWithEngine, testWithEngine, ENGINES } from './engine.mjs';
|
|
24
|
+
import { runWithEngine, testWithEngine, serveWithEngine, ENGINES, nodeStore } from './engine.mjs';
|
|
24
25
|
import { recordedRun, screenApp, screenOutline, runInProcess } from './engine-core.mjs';
|
|
25
26
|
import { hasScreens } from './target-react.mjs';
|
|
26
27
|
import { COMPILER_VERSION } from '../emit.mjs';
|
|
28
|
+
import { fileKind } from './kind.mjs';
|
|
27
29
|
|
|
28
30
|
/** The format of a Time Machine recording (thunder run --record, thunder replay). */
|
|
29
31
|
export const TIME_MACHINE_SCHEMA = 'thunder-time-machine-v1';
|
|
30
32
|
|
|
31
|
-
const CORE_COMMANDS = new Set(['new', 'run', 'build', 'test', 'check', 'format', 'fmt']);
|
|
33
|
+
export const CORE_COMMANDS = new Set(['new', 'run', 'build', 'test', 'check', 'format', 'fmt']);
|
|
32
34
|
|
|
33
35
|
function parse(argv) {
|
|
34
36
|
const a = { _: [], core: false, json: false, write: false, check: false, force: false, mission: false, engine: null, target: null };
|
|
@@ -37,6 +39,8 @@ function parse(argv) {
|
|
|
37
39
|
if (x === '--target') a.target = argv[++i] ?? '';
|
|
38
40
|
else if (x.startsWith('--target=')) a.target = x.slice('--target='.length);
|
|
39
41
|
else if (x === '--engine') a.engine = argv[++i] ?? '';
|
|
42
|
+
else if (x === '--port') a.port = argv[++i] ?? '';
|
|
43
|
+
else if (x.startsWith('--port=')) a.port = x.slice('--port='.length);
|
|
40
44
|
else if (x === '--record') a.record = argv[++i] ?? '';
|
|
41
45
|
else if (x.startsWith('--record=')) a.record = x.slice('--record='.length);
|
|
42
46
|
else if (x.startsWith('--engine=')) a.engine = x.slice('--engine='.length);
|
|
@@ -47,12 +51,23 @@ function parse(argv) {
|
|
|
47
51
|
else if (x === '--force') a.force = true;
|
|
48
52
|
else if (x === '--mission') a.mission = true;
|
|
49
53
|
else if (x === '--run') a.run = true;
|
|
50
|
-
else if (x.startsWith('--')) a.other = true;
|
|
54
|
+
else if (x.startsWith('--')) { a.other = true; a.unknown ??= x; }
|
|
51
55
|
else a._.push(x);
|
|
52
56
|
}
|
|
53
57
|
return a;
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
/** Does the program answer requests (When someone calls …)? Then thunder run keeps it running until stopped. */
|
|
61
|
+
const answersRequests = (build) => !!build.entry && (build.entry.info.endpoints ?? []).some((f) => !build.entry.info.imported?.has(f));
|
|
62
|
+
|
|
63
|
+
/** The known option closest to a mistyped one (one or two letters off), or null. */
|
|
64
|
+
function closestOption(said, known) {
|
|
65
|
+
const dist = (x, y) => { const d = Array.from({ length: y.length + 1 }, (_, j) => j); for (let i = 1; i <= x.length; i++) { let prev = d[0]; d[0] = i; for (let j = 1; j <= y.length; j++) { const t = d[j]; d[j] = Math.min(d[j] + 1, d[j - 1] + 1, prev + (x[i - 1] === y[j - 1] ? 0 : 1)); prev = t; } } return d[y.length]; };
|
|
66
|
+
let best = null, bestD = 3;
|
|
67
|
+
for (const k of known) { const dd = dist(said, k); if (dd < bestD) { bestD = dd; best = k; } }
|
|
68
|
+
return best;
|
|
69
|
+
}
|
|
70
|
+
|
|
56
71
|
/** Decide whether this invocation is a Thunder Core one: { root, file } or null. */
|
|
57
72
|
export function coreTarget(cmd, argv, cwd = process.cwd()) {
|
|
58
73
|
if (!CORE_COMMANDS.has(cmd)) return null;
|
|
@@ -70,12 +85,23 @@ export function coreTarget(cmd, argv, cwd = process.cwd()) {
|
|
|
70
85
|
if (!file.endsWith('.thunder')) return null;
|
|
71
86
|
const root = findProjectRoot(p);
|
|
72
87
|
if (root || a.core) return { root, file: p };
|
|
88
|
+
if (a.mission) return null;
|
|
89
|
+
// No project and no flag: the file itself says. A mission always starts with a mission keyword.
|
|
90
|
+
try { if (fileKind(readFileSync(p, 'utf8')).kind === 'program') return { root: null, file: p }; } catch { /* unreadable: the mission commands say so */ }
|
|
73
91
|
return null;
|
|
74
92
|
}
|
|
75
93
|
|
|
76
94
|
const say = (s = '') => process.stdout.write(`${paint(s)}\n`);
|
|
77
95
|
const warn = (s = '') => process.stderr.write(`${s}\n`);
|
|
78
96
|
|
|
97
|
+
/** Holes (TC120) are not mistakes: a draft is counted and named apart from the problems to fix. */
|
|
98
|
+
const holeCount = (build) => build.results.reduce((k, r) => k + r.diagnostics.filter((d) => d.code === 'TC120').length, 0);
|
|
99
|
+
function problemWords(n, holes) {
|
|
100
|
+
const fix = n - holes;
|
|
101
|
+
const p = `${fix} problem${fix === 1 ? '' : 's'}`;
|
|
102
|
+
return holes ? `${p} and ${holes} hole${holes === 1 ? '' : 's'}` : p;
|
|
103
|
+
}
|
|
104
|
+
|
|
79
105
|
function report(build, cwd) {
|
|
80
106
|
let n = 0;
|
|
81
107
|
for (const r of build.results) for (const d of r.diagnostics) { warn(formatDiagnostic(d, relative(cwd, r.path) || r.rel)); n++; }
|
|
@@ -87,6 +113,21 @@ export function coreMain(cmd, argv, cwd = process.cwd()) {
|
|
|
87
113
|
const t = coreTarget(cmd, argv, cwd);
|
|
88
114
|
if (!t) return null;
|
|
89
115
|
const a = parse(argv);
|
|
116
|
+
// An option Thunder doesn't know is refused, never ignored: "--core --target go" written as one word would otherwise
|
|
117
|
+
// run the default target and look like it worked.
|
|
118
|
+
if (a.unknown && cmd !== 'new') {
|
|
119
|
+
const known = ['--core', '--engine', '--target', '--port', '--record', '--json', '--write', '--check', '--force'];
|
|
120
|
+
const said = a.unknown.split(/\s+/)[0].split('=')[0];
|
|
121
|
+
const near = known.find((k) => k === said) ? null : closestOption(said, known);
|
|
122
|
+
warn(`thunder ${cmd}: I don't know the option "${a.unknown}".${a.unknown.includes(' ') ? ' Options are separate words: --core --target go.' : near ? ` Did you mean ${near}?` : ''} Options for Thunder programs: ${known.join(', ')}.`);
|
|
123
|
+
return 2;
|
|
124
|
+
}
|
|
125
|
+
// --port: where a program with endpoints answers (every engine and target reads THUNDER_PORT).
|
|
126
|
+
if (a.port != null) {
|
|
127
|
+
if (cmd !== 'run') { warn(`thunder ${cmd}: --port is for thunder run, for a program that answers requests.`); return 2; }
|
|
128
|
+
if (!/^\d+$/.test(a.port) || Number(a.port) < 1 || Number(a.port) > 65535) { warn(`thunder run: --port takes a number from 1 to 65535, for example --port 8080.`); return 2; }
|
|
129
|
+
process.env.THUNDER_PORT = a.port;
|
|
130
|
+
}
|
|
90
131
|
try {
|
|
91
132
|
if (cmd === 'new') {
|
|
92
133
|
const root = newProject(resolve(cwd, t.new), { force: a.force });
|
|
@@ -117,11 +158,19 @@ export function coreMain(cmd, argv, cwd = process.cwd()) {
|
|
|
117
158
|
if (cmd === 'check') {
|
|
118
159
|
if (a.json) { say(JSON.stringify({ ok: build.ok, files: build.results.map((r) => ({ file: relative(cwd, r.path), diagnostics: r.diagnostics })) }, null, 2)); return build.ok ? 0 : 1; }
|
|
119
160
|
const n = report(build, cwd);
|
|
120
|
-
|
|
161
|
+
const holes = holeCount(build);
|
|
162
|
+
if (n && holes === n) { warn(`thunder check: a draft with ${holes} hole${holes === 1 ? '' : 's'} to fill in, and nothing else to fix.`); return 1; }
|
|
163
|
+
if (n) { warn(`thunder check: ${problemWords(n, holes)} in ${build.results.filter((r) => !r.ok).length} of ${build.results.length} file${build.results.length === 1 ? '' : 's'}.`); return 1; }
|
|
121
164
|
say(`thunder check: no problems in ${build.results.length} Thunder Core file${build.results.length === 1 ? '' : 's'}.`);
|
|
122
165
|
return 0;
|
|
123
166
|
}
|
|
124
|
-
if (!build.ok) {
|
|
167
|
+
if (!build.ok) {
|
|
168
|
+
const n = report(build, cwd);
|
|
169
|
+
const holes = holeCount(build);
|
|
170
|
+
const done = `nothing was ${cmd === 'build' ? 'built' : 'run'}`;
|
|
171
|
+
warn(n === holes ? `thunder ${cmd}: this is a draft with ${holes} hole${holes === 1 ? '' : 's'} to fill in; ${done}.` : `thunder ${cmd}: ${problemWords(n, holes)}; ${done}.`);
|
|
172
|
+
return 1;
|
|
173
|
+
}
|
|
125
174
|
const out = relative(cwd, build.outDir) || '.';
|
|
126
175
|
if (cmd === 'run' && a.record == null && build.entry && hasScreens(build.entry.info)) return showScreens(build, warn);
|
|
127
176
|
if (cmd === 'build' && build.target === 'react') {
|
|
@@ -185,7 +234,7 @@ export function coreMain(cmd, argv, cwd = process.cwd()) {
|
|
|
185
234
|
if (python.error) { warn(`thunder ${cmd}: ${python.error}${['run', 'test'].includes(cmd) ? `\nOr run it without Python, on the Thunder engine: thunder ${cmd} ${argv.filter((x) => !x.startsWith('--engine')).join(' ')}${argv.length ? ' ' : ''}--engine thunder`.replace(/ +/g, ' ') : ''}`); return 2; }
|
|
186
235
|
if (cmd === 'run') {
|
|
187
236
|
if (!build.entryModule) { warn('thunder run: there is no program to run (no .thunder files in src/).'); return 1; }
|
|
188
|
-
const r = runPython(python, build.outDir, `${build.entryModule}.py`, build.base);
|
|
237
|
+
const r = runPython(python, build.outDir, `${build.entryModule}.py`, build.base, { serving: answersRequests(build) });
|
|
189
238
|
return r.status ?? 1;
|
|
190
239
|
}
|
|
191
240
|
if (cmd === 'test') {
|
|
@@ -225,7 +274,7 @@ function showScreens(build, warn) {
|
|
|
225
274
|
function runCompiledTypeScript(cmd, build, warn, say) {
|
|
226
275
|
if (cmd === 'run' && !build.entryModule) { warn('thunder run: there is no program to run (no .thunder files in src/).'); return 1; }
|
|
227
276
|
if (cmd === 'test' && !build.results.reduce((n, r) => n + r.info.tests.length, 0)) { say('thunder test: no Test blocks found. Write one: Test "what it checks": then Expect … lines.'); return 0; }
|
|
228
|
-
const r = runTypeScript(build.outDir, cmd === 'run' ? `${build.entryModule}.ts` : 'run_tests.ts', { cwd: build.base, stdio: 'inherit' });
|
|
277
|
+
const r = runTypeScript(build.outDir, cmd === 'run' ? `${build.entryModule}.ts` : 'run_tests.ts', { cwd: build.base, stdio: 'inherit', serving: cmd === 'run' && answersRequests(build) });
|
|
229
278
|
if (r.error && typeof r.error === 'string') { warn(`thunder ${cmd}: ${r.error}`); return 2; }
|
|
230
279
|
return r.status ?? 1;
|
|
231
280
|
}
|
|
@@ -233,7 +282,7 @@ function runCompiledTypeScript(cmd, build, warn, say) {
|
|
|
233
282
|
/** thunder run --record <file>: run on the Thunder engine and save a step-by-step recording (the Time Machine). */
|
|
234
283
|
function recordRun(build, file, cwd, warn) {
|
|
235
284
|
if (!build.entry) { warn('thunder run: there is no program to run (no .thunder files in src/).'); return 1; }
|
|
236
|
-
const r = recordedRun({ entry: build.entry, cwd: build.base, readText: (p, dir) => readFileSync(resolve(dir, p), 'utf8') });
|
|
285
|
+
const r = recordedRun({ entry: build.entry, cwd: build.base, readText: (p, dir) => readFileSync(resolve(dir, p), 'utf8'), store: nodeStore(build.base) });
|
|
237
286
|
if (r.refused) { warn(`thunder run: ${r.stderr.trim()}`); return 2; }
|
|
238
287
|
if (r.stdout) process.stdout.write(r.stdout);
|
|
239
288
|
if (r.stderr) process.stderr.write(r.stderr);
|
|
@@ -288,6 +337,14 @@ const readdirDeep = (root, dir) => { try { return readdirSync(join(root, dir)).f
|
|
|
288
337
|
function runOnEngine(cmd, build, warn, say) {
|
|
289
338
|
if (cmd === 'run') {
|
|
290
339
|
if (!build.entry) { warn('thunder run: there is no program to run (no .thunder files in src/).'); return 1; }
|
|
340
|
+
if (answersRequests(build)) {
|
|
341
|
+
// A program with endpoints keeps answering requests until stopped; it reports here only if it can't start.
|
|
342
|
+
const r = serveWithEngine({ entry: build.entry, cwd: build.base });
|
|
343
|
+
if (!r) return 0; // answering requests now; the process stays alive until Ctrl+C
|
|
344
|
+
if (r.stdout) process.stdout.write(r.stdout);
|
|
345
|
+
if (r.stderr) process.stderr.write(r.stderr);
|
|
346
|
+
return r.status;
|
|
347
|
+
}
|
|
291
348
|
const r = runWithEngine({ entry: build.entry, cwd: build.base });
|
|
292
349
|
if (r.stdout) process.stdout.write(r.stdout);
|
|
293
350
|
if (r.stderr) process.stderr.write(r.stderr.startsWith('This program uses') ? `thunder run: ${r.stderr}` : r.stderr);
|
package/src/core/csharp-run.mjs
CHANGED
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
// Program.cs that runs the program (`dotnet ThunderProgram.dll`) or its tests (`dotnet ThunderProgram.dll test`).
|
|
5
5
|
// Several programs can share one build (one namespace each, picked by number), which is how the conformance tests
|
|
6
6
|
// keep .NET's build time down.
|
|
7
|
-
import { writeFileSync, mkdirSync, readFileSync, existsSync } from 'node:fs';
|
|
7
|
+
import { writeFileSync, mkdirSync, readFileSync, existsSync, rmSync } from 'node:fs';
|
|
8
8
|
import { join } from 'node:path';
|
|
9
9
|
import { spawnSync } from 'node:child_process';
|
|
10
10
|
import { toCSharp, pythonOnlyUses, classOf, cs } from './target-csharp.mjs';
|
|
11
|
+
import { npmRefusals, storeRefusals, httpRefusals } from './target-typescript.mjs';
|
|
11
12
|
import { diag } from './diagnostics.mjs';
|
|
12
13
|
|
|
13
14
|
export const CS_RUNTIME = readFileSync(new URL('./ThunderRuntime.cs', import.meta.url), 'utf8');
|
|
@@ -15,9 +16,9 @@ export const ASSEMBLY = 'ThunderProgram';
|
|
|
15
16
|
|
|
16
17
|
/** TC405 for every Use in a file: Python modules exist only for the Python target. */
|
|
17
18
|
export function csharpDiagnostics(result) {
|
|
18
|
-
return pythonOnlyUses(result.info).map((u) => diag('TC405', u.line,
|
|
19
|
+
return [...npmRefusals(result.info, 'C#', diag), ...storeRefusals(result.info, 'C#', diag), ...httpRefusals(result.info, 'C#', diag), ...pythonOnlyUses(result.info).map((u) => diag('TC405', u.line,
|
|
19
20
|
`"${u.module}" is a Python module, and this program is compiled to C#, which cannot use it.`,
|
|
20
|
-
'Build for Python (target = "python") to use Python modules. Thunder never swaps in a different library.'));
|
|
21
|
+
'Build for Python (target = "python") to use Python modules. Thunder never swaps in a different library.'))];
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
/** The .NET SDK here: { cmd, version, major } or { error }. */
|
|
@@ -31,7 +32,23 @@ export function findDotnet() {
|
|
|
31
32
|
return { cmd, version, major };
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
/** The .NET boundary (Use "<type>" from .NET or NuGet), written next to the program only when it uses one. */
|
|
36
|
+
export const CS_DOTNET = readFileSync(new URL('./ThunderDotnet.cs', import.meta.url), 'utf8');
|
|
37
|
+
|
|
38
|
+
/** The NuGet packages a program's files name: [{ package, version, line, file }]. */
|
|
39
|
+
export function nugetPackages(results) {
|
|
40
|
+
return results.flatMap((r) => (r.info.modules ?? []).filter((m) => !r.info.imported?.has(m) && m.ecosystem === 'nuget').map((m) => ({ package: m.package, version: m.version, line: m.line, file: r.file })));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const usesDotnet = (results) => results.some((r) => (r.info.modules ?? []).some((m) => !r.info.imported?.has(m) && (m.ecosystem === 'dotnet' || m.ecosystem === 'nuget')));
|
|
44
|
+
|
|
45
|
+
const packageRefs = (packages) => {
|
|
46
|
+
const seen = new Map();
|
|
47
|
+
for (const p of packages) if (!seen.has(p.package)) seen.set(p.package, p.version);
|
|
48
|
+
return seen.size ? ` <ItemGroup>\n${[...seen].map(([n, v]) => ` <PackageReference Include="${n}" Version="${v}" />`).join('\n')}\n </ItemGroup>\n` : '';
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const csproj = (major, packages = [], invariant = true) => `<Project Sdk="Microsoft.NET.Sdk">
|
|
35
52
|
<!-- Generated by the Thunder compiler. Build: dotnet build; run: dotnet bin/${ASSEMBLY}.dll (add "test" to run the tests). -->
|
|
36
53
|
<PropertyGroup>
|
|
37
54
|
<OutputType>Exe</OutputType>
|
|
@@ -40,7 +57,7 @@ const csproj = (major) => `<Project Sdk="Microsoft.NET.Sdk">
|
|
|
40
57
|
<RootNamespace>${ASSEMBLY}</RootNamespace>
|
|
41
58
|
<Nullable>disable</Nullable>
|
|
42
59
|
<ImplicitUsings>disable</ImplicitUsings>
|
|
43
|
-
<InvariantGlobalization
|
|
60
|
+
<InvariantGlobalization>${invariant}</InvariantGlobalization>
|
|
44
61
|
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
|
45
62
|
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
|
46
63
|
<NoWarn>CS0162;CS0168;CS0219;CS0472;CS1717;CS8321;CS0414</NoWarn>
|
|
@@ -49,7 +66,7 @@ const csproj = (major) => `<Project Sdk="Microsoft.NET.Sdk">
|
|
|
49
66
|
<ItemGroup>
|
|
50
67
|
<Compile Remove="bin/**;obj/**" />
|
|
51
68
|
</ItemGroup>
|
|
52
|
-
</Project>
|
|
69
|
+
${packageRefs(packages)}</Project>
|
|
53
70
|
`;
|
|
54
71
|
|
|
55
72
|
/** The C# for one program's results (src files, then test files) in `namespace`: { [module]: text }. */
|
|
@@ -84,6 +101,8 @@ export function writeCSharp(results, outDir, { entry = results.find((r) => r.kin
|
|
|
84
101
|
const files = compileCSharp(results);
|
|
85
102
|
for (const [m, text] of Object.entries(files)) writeFileSync(join(outDir, `${m}.cs`), text);
|
|
86
103
|
writeFileSync(join(outDir, 'ThunderRuntime.cs'), CS_RUNTIME);
|
|
104
|
+
if (usesDotnet(results)) writeFileSync(join(outDir, 'ThunderDotnet.cs'), CS_DOTNET);
|
|
105
|
+
else rmSync(join(outDir, 'ThunderDotnet.cs'), { force: true });
|
|
87
106
|
const code = runCode(results, entry, ASSEMBLY, 16);
|
|
88
107
|
writeFileSync(join(outDir, 'Program.cs'), `// Generated by the Thunder compiler: runs the program, or every Test block with "test".
|
|
89
108
|
using Thunder;
|
|
@@ -110,7 +129,7 @@ ${code.run}
|
|
|
110
129
|
}
|
|
111
130
|
}
|
|
112
131
|
`);
|
|
113
|
-
writeFileSync(join(outDir, `${ASSEMBLY}.csproj`), csproj(major));
|
|
132
|
+
writeFileSync(join(outDir, `${ASSEMBLY}.csproj`), csproj(major, nugetPackages(results), !usesDotnet(results)));
|
|
114
133
|
return Object.keys(files);
|
|
115
134
|
}
|
|
116
135
|
|
|
@@ -128,6 +147,8 @@ export function writeCSharpBatch(programs, outDir, { major = findDotnet().major
|
|
|
128
147
|
cases.push(` case ${i}:\n if (tests)\n {\n${code.tests}\n }\n else\n {\n${code.run}\n }\n break;`);
|
|
129
148
|
});
|
|
130
149
|
writeFileSync(join(outDir, 'ThunderRuntime.cs'), CS_RUNTIME);
|
|
150
|
+
const all = programs.flatMap((p) => p.results);
|
|
151
|
+
if (usesDotnet(all)) writeFileSync(join(outDir, 'ThunderDotnet.cs'), CS_DOTNET);
|
|
131
152
|
writeFileSync(join(outDir, 'Program.cs'), `// Generated by the Thunder compiler: many programs in one build, chosen by number.
|
|
132
153
|
using Thunder;
|
|
133
154
|
|
|
@@ -150,7 +171,7 @@ ${cases.join('\n')}
|
|
|
150
171
|
}
|
|
151
172
|
}
|
|
152
173
|
`);
|
|
153
|
-
writeFileSync(join(outDir, `${ASSEMBLY}.csproj`), csproj(major));
|
|
174
|
+
writeFileSync(join(outDir, `${ASSEMBLY}.csproj`), csproj(major, nugetPackages(all), !usesDotnet(all)));
|
|
154
175
|
}
|
|
155
176
|
|
|
156
177
|
/** dotnet build the project in `outDir` into outDir/bin. { ok, output } or { error } when there is no .NET SDK. */
|
package/src/core/diagnostics.mjs
CHANGED
|
@@ -24,6 +24,7 @@ export const CODES = {
|
|
|
24
24
|
TC117: 'Lines like "name: value" with no record or function call to give them to',
|
|
25
25
|
TC118: 'A line inside a Screen is not something a screen can show',
|
|
26
26
|
TC119: '"Receive" or "Remember" is not at the top of a Screen',
|
|
27
|
+
TC120: 'A hole (?, ?number) in a draft: the program does not run until it is filled in',
|
|
27
28
|
TC201: 'Unknown name',
|
|
28
29
|
TC202: 'A name uses a word that belongs to Thunder',
|
|
29
30
|
TC203: 'A name is defined twice',
|
|
@@ -38,6 +39,11 @@ export const CODES = {
|
|
|
38
39
|
TC212: 'Unknown screen',
|
|
39
40
|
TC213: 'An input of a screen is changed',
|
|
40
41
|
TC214: 'A screen is given an input it does not have, or is missing one it needs',
|
|
42
|
+
TC215: '"Depending on" leaves out an alternative of the data type (and has no "Otherwise")',
|
|
43
|
+
TC216: 'A field only some alternatives have, read where the alternative is not known',
|
|
44
|
+
TC217: 'An alternative a data type does not have, or a value built without saying which alternative it is',
|
|
45
|
+
TC218: 'An HTTP status (Give … with status, Stop … and status) outside an endpoint',
|
|
46
|
+
TC219: 'Inside where or sorted by, a name that is both a field of each item and a value of yours (the field wins, so your value is hidden)',
|
|
41
47
|
TC301: 'Money and a plain number are mixed',
|
|
42
48
|
TC302: 'Values of different kinds are compared',
|
|
43
49
|
TC303: 'A name changes kind',
|
|
@@ -51,6 +57,10 @@ export const CODES = {
|
|
|
51
57
|
TC405: 'A Python module ("Use") can be used only when compiling to Python',
|
|
52
58
|
TC406: 'A Screen is built only for React (--target react)',
|
|
53
59
|
TC407: 'A step that cannot run when a button is pressed',
|
|
60
|
+
TC408: 'An npm package ("Use … from npm") can be used only when compiling to TypeScript',
|
|
61
|
+
TC409: 'A .NET library ("Use … from .NET" or "from NuGet") can be used only when compiling to C#',
|
|
62
|
+
TC410: 'A stored list ("Store … as a list of …") runs on Python, TypeScript, Go, and the Thunder engine only, for now',
|
|
63
|
+
TC411: 'An endpoint or a call to another service in a program compiled to a target without HTTP yet',
|
|
54
64
|
TC501: 'Divided by zero (runtime)',
|
|
55
65
|
TC502: 'Nothing used where a value was needed (runtime)',
|
|
56
66
|
TC503: 'A field or entry is missing (runtime)',
|
|
@@ -58,8 +68,9 @@ export const CODES = {
|
|
|
58
68
|
TC505: 'An Expect check failed (runtime)',
|
|
59
69
|
TC506: 'Values of different kinds were mixed (runtime)',
|
|
60
70
|
TC507: 'The program stopped with a message (runtime)',
|
|
61
|
-
TC508: '
|
|
71
|
+
TC508: 'Library code used through "Use" failed (runtime)',
|
|
62
72
|
TC509: 'A value could not be converted (runtime)',
|
|
73
|
+
TC510: 'A call to another service failed: it could not be reached, or it answered with a problem (runtime)',
|
|
63
74
|
};
|
|
64
75
|
|
|
65
76
|
export class CoreError extends Error {
|