@tsplc/compiler 0.5.0 → 0.5.2
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/bun-runtime.js +1345 -0
- package/dist/bun-runtime.js.map +25 -0
- package/dist/cli.js +251 -46
- package/dist/cli.js.map +8 -6
- package/dist/codesys.js +11 -6
- package/dist/codesys.js.map +3 -3
- package/dist/elaborate-capture.js +5 -5
- package/dist/elaborate-capture.js.map +4 -4
- package/dist/index.js +3 -3
- package/dist/index.js.map +4 -4
- package/dist/project.js +45 -20
- package/dist/project.js.map +5 -4
- package/package.json +13 -9
- package/src/codesys/manifest.ts +8 -1
- package/src/frontend/elaborate/capture-protocol.ts +18 -0
- package/src/frontend/elaborate/capture.ts +3 -11
- package/src/frontend/elaborate/graph.ts +3 -2
- package/src/project/cli.ts +5 -0
- package/src/project/project-commands.ts +60 -6
- package/src/project/project.ts +4 -0
- package/src/runtime/async.ts +200 -0
- package/src/runtime/launch.ts +49 -0
- package/src/runtime/main.ts +54 -0
- package/src/runtime/process.ts +172 -0
- package/src/runtime/program.ts +142 -0
- package/src/runtime/retain.ts +100 -0
- package/src/runtime/runtime.ts +329 -0
- package/src/runtime/storage.ts +481 -0
- package/src/runtime/symbols.ts +153 -0
- package/src/runtime/telemetry.ts +123 -0
package/dist/cli.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// packages/compiler/src/project/cli.ts
|
|
5
|
-
import { existsSync as
|
|
5
|
+
import { existsSync as existsSync5 } from "fs";
|
|
6
6
|
import { parseArgs } from "util";
|
|
7
7
|
import { formatDiagnostic, hasErrors as hasErrors4 } from "@tsplc/compiler/ir";
|
|
8
8
|
import { loadTsplcConfig as loadTsplcConfig3 } from "@tsplc/config";
|
|
9
|
-
import { z as
|
|
9
|
+
import { z as z6 } from "zod";
|
|
10
10
|
|
|
11
11
|
// packages/compiler/src/project/debugger.ts
|
|
12
12
|
import { existsSync as existsSync3 } from "node:fs";
|
|
@@ -15,7 +15,7 @@ import { serverTokenEnv as serverTokenEnv2 } from "@tsplc/config";
|
|
|
15
15
|
import { tcpPort } from "@tsplc/config/build";
|
|
16
16
|
import {
|
|
17
17
|
emittedStDirectory as emittedStDirectory3,
|
|
18
|
-
generatedDirectory as
|
|
18
|
+
generatedDirectory as generatedDirectory3
|
|
19
19
|
} from "@tsplc/config/project-files";
|
|
20
20
|
import {
|
|
21
21
|
createDebugger,
|
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
createAgentClient
|
|
38
38
|
} from "@tsplc/agent/client";
|
|
39
39
|
import { LoginUnavailable, noLogin } from "@tsplc/debug";
|
|
40
|
-
import { z as
|
|
40
|
+
import { z as z4 } from "zod";
|
|
41
41
|
|
|
42
42
|
// packages/compiler/src/project/release.ts
|
|
43
43
|
import { existsSync as existsSync2 } from "node:fs";
|
|
@@ -94,6 +94,37 @@ import {
|
|
|
94
94
|
resolveIo
|
|
95
95
|
} from "@tsplc/typegen";
|
|
96
96
|
|
|
97
|
+
// packages/compiler/src/runtime/launch.ts
|
|
98
|
+
import { generatedDirectory } from "@tsplc/config/project-files";
|
|
99
|
+
import { serviceOfPath } from "@tsplc/server";
|
|
100
|
+
import { z } from "zod";
|
|
101
|
+
var runtimeDirectory = `${generatedDirectory}/runtime`;
|
|
102
|
+
var runtimeFiles = {
|
|
103
|
+
launch: "launch.json",
|
|
104
|
+
state: "state.json",
|
|
105
|
+
retain: "retain.json",
|
|
106
|
+
log: "plc.log",
|
|
107
|
+
certificates: "pki"
|
|
108
|
+
};
|
|
109
|
+
var launchSchema = z.strictObject({
|
|
110
|
+
config: z.string().nonempty(),
|
|
111
|
+
target: z.string().nonempty().nullable(),
|
|
112
|
+
services: z.record(z.string(), z.string().startsWith("/tsplc/services/"))
|
|
113
|
+
});
|
|
114
|
+
var runtimeStateSchema = z.strictObject({
|
|
115
|
+
pid: z.number().int().positive(),
|
|
116
|
+
endpoint: z.string().startsWith("opc.tcp://"),
|
|
117
|
+
startedAt: z.iso.datetime()
|
|
118
|
+
});
|
|
119
|
+
var serviceRoutes = (core) => Object.fromEntries(core.blocks.flatMap((block) => {
|
|
120
|
+
if (block.runtime?.kind !== "http") {
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
const route = URL.parse(block.runtime.url)?.pathname;
|
|
124
|
+
const procedure = route && serviceOfPath(route);
|
|
125
|
+
return route && procedure ? [[procedure, route]] : [];
|
|
126
|
+
}));
|
|
127
|
+
|
|
97
128
|
// packages/compiler/src/project/artifacts.ts
|
|
98
129
|
import { createHash } from "node:crypto";
|
|
99
130
|
import {
|
|
@@ -109,32 +140,32 @@ import { dirname, join } from "node:path";
|
|
|
109
140
|
import { sha256Digest } from "@tsplc/config/build";
|
|
110
141
|
import {
|
|
111
142
|
emittedStDirectory,
|
|
112
|
-
generatedDirectory
|
|
143
|
+
generatedDirectory as generatedDirectory2
|
|
113
144
|
} from "@tsplc/config/project-files";
|
|
114
|
-
import { z } from "zod";
|
|
145
|
+
import { z as z2 } from "zod";
|
|
115
146
|
var missing = (cause) => cause instanceof Error && ("code" in cause) && cause.code === "ENOENT";
|
|
116
147
|
var digest = (value) => createHash("sha256").update(value).digest("hex");
|
|
117
|
-
var generatedFileSchema =
|
|
118
|
-
path:
|
|
148
|
+
var generatedFileSchema = z2.object({
|
|
149
|
+
path: z2.string().regex(/^[A-Za-z0-9_ .-]+(?:\/[A-Za-z0-9_ .-]+)*$/).refine((path) => !path.split("/").some((part) => part === "." || part === "..") && !["manifest.json", "receipt.json"].includes(path)),
|
|
119
150
|
sha256: sha256Digest
|
|
120
151
|
});
|
|
121
|
-
var manifestSchema =
|
|
122
|
-
kind:
|
|
123
|
-
version:
|
|
124
|
-
configFile:
|
|
125
|
-
files:
|
|
152
|
+
var manifestSchema = z2.object({
|
|
153
|
+
kind: z2.literal("tsplc-artifacts"),
|
|
154
|
+
version: z2.literal(1),
|
|
155
|
+
configFile: z2.string(),
|
|
156
|
+
files: z2.array(z2.unknown())
|
|
126
157
|
});
|
|
127
|
-
var buildStatusSchema =
|
|
128
|
-
var receiptSchema =
|
|
129
|
-
kind:
|
|
130
|
-
version:
|
|
131
|
-
configFile:
|
|
158
|
+
var buildStatusSchema = z2.enum(["emitted", "vendor-compiled"]);
|
|
159
|
+
var receiptSchema = z2.object({
|
|
160
|
+
kind: z2.literal("tsplc-build"),
|
|
161
|
+
version: z2.literal(1),
|
|
162
|
+
configFile: z2.string(),
|
|
132
163
|
status: buildStatusSchema
|
|
133
164
|
});
|
|
134
|
-
var engineeringMarkerSchema =
|
|
135
|
-
kind:
|
|
136
|
-
version:
|
|
137
|
-
configFile:
|
|
165
|
+
var engineeringMarkerSchema = z2.object({
|
|
166
|
+
kind: z2.literal("tsplc-engineering"),
|
|
167
|
+
version: z2.literal(1),
|
|
168
|
+
configFile: z2.string()
|
|
138
169
|
});
|
|
139
170
|
function manifest(value, configFile) {
|
|
140
171
|
const parsed = manifestSchema.safeParse(value);
|
|
@@ -215,7 +246,7 @@ async function engineeringDirectory(path, configFile) {
|
|
|
215
246
|
await inspect(path);
|
|
216
247
|
}
|
|
217
248
|
async function owned(configFile, withdrawReceipt = false) {
|
|
218
|
-
const root = join(dirname(configFile),
|
|
249
|
+
const root = join(dirname(configFile), generatedDirectory2);
|
|
219
250
|
const output = join(dirname(configFile), dirname(emittedStDirectory));
|
|
220
251
|
if (!await directory(root) || !await directory(output)) {
|
|
221
252
|
return { root, output, unknown: [] };
|
|
@@ -599,6 +630,7 @@ async function buildProject(file = "tsplc.config.ts", options = {}) {
|
|
|
599
630
|
status,
|
|
600
631
|
...controllerConfig && { controllerConfig },
|
|
601
632
|
targets: coreTargets(checked.plan.core),
|
|
633
|
+
services: serviceRoutes(checked.plan.core),
|
|
602
634
|
diagnostics: [...checked.diagnostics, ...bundle.diagnostics]
|
|
603
635
|
};
|
|
604
636
|
} catch (cause) {
|
|
@@ -650,16 +682,16 @@ import { mkdir as mkdir3, mkdtemp as mkdtemp2, rename as rename2, rm as rm3 } fr
|
|
|
650
682
|
import { createRequire } from "node:module";
|
|
651
683
|
import { dirname as dirname3, join as join3, resolve as resolve2 } from "node:path";
|
|
652
684
|
import { fileURLToPath } from "node:url";
|
|
653
|
-
import { z as
|
|
685
|
+
import { z as z3 } from "zod";
|
|
654
686
|
var resolveServerModule = (root, name) => name.startsWith(".") || name.startsWith("/") || existsSync(resolve2(root, name)) ? resolve2(root, name) : createRequire(join3(root, "package.json")).resolve(name);
|
|
655
687
|
var kebabCase = (name) => name.replace(/([a-z0-9])([A-Z])|([A-Z])([A-Z][a-z])/g, "$1$3-$2$4").replace(/[^A-Za-z0-9]+/g, "-").replace(/^-|-$/g, "").toLowerCase();
|
|
656
688
|
var serverOutput = (config, root, extension) => resolve2(root, "build/server", `${kebabCase(config.name)}-services${extension}`);
|
|
657
|
-
var serverCheckRequestSchema =
|
|
658
|
-
entry:
|
|
659
|
-
root:
|
|
689
|
+
var serverCheckRequestSchema = z3.strictObject({
|
|
690
|
+
entry: z3.string(),
|
|
691
|
+
root: z3.string()
|
|
660
692
|
});
|
|
661
|
-
var serverCheckResultSchema =
|
|
662
|
-
failure:
|
|
693
|
+
var serverCheckResultSchema = z3.strictObject({
|
|
694
|
+
failure: z3.string().nullable()
|
|
663
695
|
});
|
|
664
696
|
var serverCheckScript = () => {
|
|
665
697
|
const script = ["./server-check.ts", "./server-check.js"].map((path) => fileURLToPath(new URL(path, import.meta.url))).find((path) => existsSync(path));
|
|
@@ -869,11 +901,11 @@ var timedProgress = () => {
|
|
|
869
901
|
|
|
870
902
|
// packages/compiler/src/project/plant.ts
|
|
871
903
|
var connect = (env) => {
|
|
872
|
-
const environment =
|
|
873
|
-
TSPLC_AGENT_URL:
|
|
904
|
+
const environment = z4.object({
|
|
905
|
+
TSPLC_AGENT_URL: z4.url({
|
|
874
906
|
error: "Configure the target's agent, or set TSPLC_AGENT_URL to the plant agent, such as http://plant-pc:4850"
|
|
875
907
|
}),
|
|
876
|
-
TSPLC_AGENT_TOKEN:
|
|
908
|
+
TSPLC_AGENT_TOKEN: z4.string({
|
|
877
909
|
error: "Set TSPLC_AGENT_TOKEN to the plant agent's token"
|
|
878
910
|
})
|
|
879
911
|
}).parse(env);
|
|
@@ -936,7 +968,7 @@ async function serveProjectDebugger({ config, root, env }, flags) {
|
|
|
936
968
|
probe: manifest.build.target,
|
|
937
969
|
endpoint: `the plant agent at ${agentUrl}`
|
|
938
970
|
}),
|
|
939
|
-
stateDirectory: resolve4(root,
|
|
971
|
+
stateDirectory: resolve4(root, generatedDirectory3, "debug"),
|
|
940
972
|
watch: config.debug?.watch ?? {},
|
|
941
973
|
...serverUrl && token && { server: { url: serverUrl, token } },
|
|
942
974
|
projectRoot: root,
|
|
@@ -965,7 +997,7 @@ import {
|
|
|
965
997
|
createAgentClient as createAgentClient2
|
|
966
998
|
} from "@tsplc/agent/client";
|
|
967
999
|
import { LoginUnavailable as LoginUnavailable2, noLogin as noLogin2 } from "@tsplc/debug";
|
|
968
|
-
import { z as
|
|
1000
|
+
import { z as z5 } from "zod";
|
|
969
1001
|
var plantCommands = [
|
|
970
1002
|
"deploy",
|
|
971
1003
|
"target",
|
|
@@ -983,11 +1015,11 @@ var plantCommands = [
|
|
|
983
1015
|
];
|
|
984
1016
|
var plantCommand = (name) => plantCommands.find((command) => command === name);
|
|
985
1017
|
var connect2 = (env) => {
|
|
986
|
-
const environment =
|
|
987
|
-
TSPLC_AGENT_URL:
|
|
1018
|
+
const environment = z5.object({
|
|
1019
|
+
TSPLC_AGENT_URL: z5.url({
|
|
988
1020
|
error: "Configure the target's agent, or set TSPLC_AGENT_URL to the plant agent, such as http://plant-pc:4850"
|
|
989
1021
|
}),
|
|
990
|
-
TSPLC_AGENT_TOKEN:
|
|
1022
|
+
TSPLC_AGENT_TOKEN: z5.string({
|
|
991
1023
|
error: "Set TSPLC_AGENT_TOKEN to the plant agent's token"
|
|
992
1024
|
})
|
|
993
1025
|
}).parse(env);
|
|
@@ -1217,7 +1249,7 @@ var runPlantCommand = async (agent, command, args, flags, project) => {
|
|
|
1217
1249
|
return send({ command: "stop" });
|
|
1218
1250
|
case "reset": {
|
|
1219
1251
|
expect(1, "warm|cold");
|
|
1220
|
-
const kind =
|
|
1252
|
+
const kind = z5.enum(["warm", "cold"]).parse(args[0]);
|
|
1221
1253
|
if (!await confirm(`Reset the application (${kind})? It stops and reinitializes its variables.`, flags)) {
|
|
1222
1254
|
throw new Error("Cancelled.");
|
|
1223
1255
|
}
|
|
@@ -1252,6 +1284,146 @@ import {
|
|
|
1252
1284
|
} from "@tsplc/config";
|
|
1253
1285
|
import { resolveConfig } from "@tsplc/config/build";
|
|
1254
1286
|
import { generateProject as generateProject2 } from "@tsplc/typegen";
|
|
1287
|
+
|
|
1288
|
+
// packages/compiler/src/runtime/process.ts
|
|
1289
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
1290
|
+
import { existsSync as existsSync4, openSync } from "node:fs";
|
|
1291
|
+
import { mkdir as mkdir4, readFile as readFile2, rm as rm4, writeFile as writeFile3 } from "node:fs/promises";
|
|
1292
|
+
import { join as join4, relative as relative3 } from "node:path";
|
|
1293
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
1294
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
1295
|
+
import { progressLog } from "@tsplc/build";
|
|
1296
|
+
var startTimeoutMs = 60000;
|
|
1297
|
+
var stopTimeoutMs = 15000;
|
|
1298
|
+
var runtimeScript = () => {
|
|
1299
|
+
const script = ["./main.ts", "./bun-runtime.js"].map((path) => fileURLToPath2(new URL(path, import.meta.url))).find((path) => existsSync4(path));
|
|
1300
|
+
if (!script) {
|
|
1301
|
+
throw new Error("The Bun runtime's script is missing from this build.");
|
|
1302
|
+
}
|
|
1303
|
+
return script;
|
|
1304
|
+
};
|
|
1305
|
+
var alive = (pid) => {
|
|
1306
|
+
try {
|
|
1307
|
+
process.kill(pid, 0);
|
|
1308
|
+
return true;
|
|
1309
|
+
} catch {
|
|
1310
|
+
return false;
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
var isRuntime = (pid, launchFile) => {
|
|
1314
|
+
if (!alive(pid)) {
|
|
1315
|
+
return false;
|
|
1316
|
+
}
|
|
1317
|
+
if (process.platform === "win32") {
|
|
1318
|
+
return true;
|
|
1319
|
+
}
|
|
1320
|
+
const command = spawnSync("ps", ["-o", "command=", "-p", String(pid)], {
|
|
1321
|
+
encoding: "utf8"
|
|
1322
|
+
}).stdout;
|
|
1323
|
+
return command.includes(launchFile);
|
|
1324
|
+
};
|
|
1325
|
+
var readState = async (file) => {
|
|
1326
|
+
const text = await readFile2(file, "utf8").catch(() => {
|
|
1327
|
+
return;
|
|
1328
|
+
});
|
|
1329
|
+
if (text === undefined) {
|
|
1330
|
+
return;
|
|
1331
|
+
}
|
|
1332
|
+
try {
|
|
1333
|
+
return runtimeStateSchema.parse(JSON.parse(text));
|
|
1334
|
+
} catch {
|
|
1335
|
+
return;
|
|
1336
|
+
}
|
|
1337
|
+
};
|
|
1338
|
+
var stopRunning = async (directory, log) => {
|
|
1339
|
+
const stateFile = join4(directory, runtimeFiles.state);
|
|
1340
|
+
const state = await readState(stateFile);
|
|
1341
|
+
if (!state || !isRuntime(state.pid, join4(directory, runtimeFiles.launch))) {
|
|
1342
|
+
await rm4(stateFile, { force: true });
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
log(`Stopping the Bun runtime that runs as process ${state.pid}`);
|
|
1346
|
+
process.kill(state.pid, "SIGTERM");
|
|
1347
|
+
const deadline = Date.now() + stopTimeoutMs;
|
|
1348
|
+
while (alive(state.pid)) {
|
|
1349
|
+
if (Date.now() >= deadline) {
|
|
1350
|
+
process.kill(state.pid, "SIGKILL");
|
|
1351
|
+
break;
|
|
1352
|
+
}
|
|
1353
|
+
await delay(100);
|
|
1354
|
+
}
|
|
1355
|
+
await rm4(stateFile, { force: true });
|
|
1356
|
+
};
|
|
1357
|
+
var runInBun = async (options) => {
|
|
1358
|
+
const log = progressLog(options.progress);
|
|
1359
|
+
const directory = join4(options.root, runtimeDirectory);
|
|
1360
|
+
await mkdir4(directory, { recursive: true });
|
|
1361
|
+
await stopRunning(directory, log);
|
|
1362
|
+
const launchFile = join4(directory, runtimeFiles.launch);
|
|
1363
|
+
await writeFile3(launchFile, `${JSON.stringify(options.launch, null, 2)}
|
|
1364
|
+
`);
|
|
1365
|
+
const logFile = join4(directory, runtimeFiles.log);
|
|
1366
|
+
const command = [runtimeScript(), launchFile];
|
|
1367
|
+
if (options.foreground) {
|
|
1368
|
+
log("Running the program in Bun; stop it with Ctrl-C");
|
|
1369
|
+
const child = spawn(process.execPath, command, {
|
|
1370
|
+
cwd: options.root,
|
|
1371
|
+
env: options.environment,
|
|
1372
|
+
stdio: "inherit"
|
|
1373
|
+
});
|
|
1374
|
+
const wait = () => {
|
|
1375
|
+
return;
|
|
1376
|
+
};
|
|
1377
|
+
const forward = () => child.kill("SIGTERM");
|
|
1378
|
+
process.on("SIGINT", wait);
|
|
1379
|
+
process.on("SIGTERM", forward);
|
|
1380
|
+
const code = await new Promise((resolve) => child.once("exit", resolve));
|
|
1381
|
+
process.off("SIGINT", wait);
|
|
1382
|
+
process.off("SIGTERM", forward);
|
|
1383
|
+
if (code !== 0) {
|
|
1384
|
+
throw new Error(`The Bun runtime exited with code ${code}.`);
|
|
1385
|
+
}
|
|
1386
|
+
return { stopped: true };
|
|
1387
|
+
}
|
|
1388
|
+
const output = openSync(logFile, "w");
|
|
1389
|
+
const child = spawn(process.execPath, command, {
|
|
1390
|
+
cwd: options.root,
|
|
1391
|
+
env: options.environment,
|
|
1392
|
+
detached: true,
|
|
1393
|
+
stdio: ["ignore", output, output]
|
|
1394
|
+
});
|
|
1395
|
+
const exited = {
|
|
1396
|
+
code: null,
|
|
1397
|
+
done: false
|
|
1398
|
+
};
|
|
1399
|
+
child.once("exit", (code) => {
|
|
1400
|
+
Object.assign(exited, { code, done: true });
|
|
1401
|
+
});
|
|
1402
|
+
const stateFile = join4(directory, runtimeFiles.state);
|
|
1403
|
+
const deadline = Date.now() + startTimeoutMs;
|
|
1404
|
+
while (true) {
|
|
1405
|
+
const state = await readState(stateFile);
|
|
1406
|
+
if (state && state.pid === child.pid) {
|
|
1407
|
+
child.unref();
|
|
1408
|
+
const shown = relative3(process.cwd(), logFile) || logFile;
|
|
1409
|
+
log(`The program runs in Bun as process ${state.pid}: OPC UA at ${state.endpoint}, output in ${shown}`);
|
|
1410
|
+
return { ...state, log: logFile };
|
|
1411
|
+
}
|
|
1412
|
+
if (exited.done || Date.now() >= deadline) {
|
|
1413
|
+
if (!exited.done) {
|
|
1414
|
+
child.kill("SIGTERM");
|
|
1415
|
+
}
|
|
1416
|
+
const tail = (await readFile2(logFile, "utf8").catch(() => "")).trimEnd().split(`
|
|
1417
|
+
`).slice(-30).join(`
|
|
1418
|
+
`);
|
|
1419
|
+
throw new Error(`The Bun runtime ${exited.done ? `exited with code ${exited.code}` : "did not start in time"}:
|
|
1420
|
+
${tail}`);
|
|
1421
|
+
}
|
|
1422
|
+
await delay(100);
|
|
1423
|
+
}
|
|
1424
|
+
};
|
|
1425
|
+
|
|
1426
|
+
// packages/compiler/src/project/project-commands.ts
|
|
1255
1427
|
var projectCommands = [
|
|
1256
1428
|
"install",
|
|
1257
1429
|
"typegen",
|
|
@@ -1283,6 +1455,12 @@ var checkProjectFlags = (command, flags) => {
|
|
|
1283
1455
|
if (flags.runtime && command !== "configure") {
|
|
1284
1456
|
throw new Error("--runtime applies only to configure.");
|
|
1285
1457
|
}
|
|
1458
|
+
if (flags.bun && (command !== "run" || !flags.simulate)) {
|
|
1459
|
+
throw new Error("--bun applies only to run --simulate: the Bun runtime has no fieldbus, so a plant simulator writes its inputs.");
|
|
1460
|
+
}
|
|
1461
|
+
if (flags.foreground && !flags.bun) {
|
|
1462
|
+
throw new Error("--foreground applies only to run --simulate --bun.");
|
|
1463
|
+
}
|
|
1286
1464
|
if ((flags.plc || flags.server) && command !== "build") {
|
|
1287
1465
|
throw new Error("--plc and --server apply only to build.");
|
|
1288
1466
|
}
|
|
@@ -1371,7 +1549,7 @@ var check = async (file, { loaded, hostConfigDiagnostics }, environment) => {
|
|
|
1371
1549
|
var buildPlc = async (command, file, { loaded, hostConfigDiagnostics }, flags, { progress, environment }) => {
|
|
1372
1550
|
const { config } = loaded;
|
|
1373
1551
|
if (config.compiler) {
|
|
1374
|
-
const { targets, ...built } = await buildProject(file, {
|
|
1552
|
+
const { targets, services, ...built } = await buildProject(file, {
|
|
1375
1553
|
progress,
|
|
1376
1554
|
environment,
|
|
1377
1555
|
emitOnly: flags["emit-only"],
|
|
@@ -1385,7 +1563,7 @@ var buildPlc = async (command, file, { loaded, hostConfigDiagnostics }, flags, {
|
|
|
1385
1563
|
throw new DiagnosticFailure(built);
|
|
1386
1564
|
}
|
|
1387
1565
|
await generateProject2(file, { loaded, targets });
|
|
1388
|
-
return built;
|
|
1566
|
+
return { built, services };
|
|
1389
1567
|
}
|
|
1390
1568
|
if (flags["emit-only"]) {
|
|
1391
1569
|
throw new Error("Raw Structured Text is already emitted.");
|
|
@@ -1396,7 +1574,7 @@ var buildPlc = async (command, file, { loaded, hostConfigDiagnostics }, flags, {
|
|
|
1396
1574
|
simulate: flags.simulate
|
|
1397
1575
|
}), { progress });
|
|
1398
1576
|
await generateProject2(file, { hardwareOnly: !config.typegen, loaded });
|
|
1399
|
-
return built;
|
|
1577
|
+
return { built, services: undefined };
|
|
1400
1578
|
};
|
|
1401
1579
|
var build = async (file, checked, flags, context) => {
|
|
1402
1580
|
const { config, root } = checked.loaded;
|
|
@@ -1408,21 +1586,43 @@ var build = async (file, checked, flags, context) => {
|
|
|
1408
1586
|
serverCheck?.catch(() => {
|
|
1409
1587
|
return;
|
|
1410
1588
|
});
|
|
1411
|
-
const plc = await buildPlc("build", file, checked, flags, context);
|
|
1589
|
+
const { built: plc } = await buildPlc("build", file, checked, flags, context);
|
|
1412
1590
|
if (!serverCheck) {
|
|
1413
1591
|
return plc;
|
|
1414
1592
|
}
|
|
1415
1593
|
return { ...plc, ...await buildServer(await serverCheck, config, root) };
|
|
1416
1594
|
};
|
|
1417
1595
|
var run = async (file, checked, flags, context) => {
|
|
1596
|
+
if (flags.bun) {
|
|
1597
|
+
return runInBunRuntime(file, checked, flags, context);
|
|
1598
|
+
}
|
|
1418
1599
|
const { config, configFile } = checked.loaded;
|
|
1419
|
-
const built = await buildPlc("run", file, checked, flags, context);
|
|
1600
|
+
const { built } = await buildPlc("run", file, checked, flags, context);
|
|
1420
1601
|
if (!config.build) {
|
|
1421
1602
|
throw new Error("Configure build to run this project.");
|
|
1422
1603
|
}
|
|
1423
1604
|
await runProject(resolveConfig(config.compiler ? config.build : rawBuildConfig(config), configFile), config.name, { progress: context.progress });
|
|
1424
1605
|
return built;
|
|
1425
1606
|
};
|
|
1607
|
+
var runInBunRuntime = async (file, checked, flags, context) => {
|
|
1608
|
+
const { config, configFile, root } = checked.loaded;
|
|
1609
|
+
if (!config.compiler) {
|
|
1610
|
+
throw new Error("The Bun runtime runs a TypeScript program; this project builds raw Structured Text.");
|
|
1611
|
+
}
|
|
1612
|
+
const { built, services } = await buildPlc("run", file, checked, { ...flags, "emit-only": true }, context);
|
|
1613
|
+
const runtime = await runInBun({
|
|
1614
|
+
root,
|
|
1615
|
+
launch: {
|
|
1616
|
+
config: configFile,
|
|
1617
|
+
target: flags.target ?? null,
|
|
1618
|
+
services: services ?? {}
|
|
1619
|
+
},
|
|
1620
|
+
environment: context.environment,
|
|
1621
|
+
foreground: flags.foreground ?? false,
|
|
1622
|
+
progress: context.progress
|
|
1623
|
+
});
|
|
1624
|
+
return { ...built, runtime };
|
|
1625
|
+
};
|
|
1426
1626
|
var updateProgram = async (operation, file, checked, flags, { progress, environment }) => {
|
|
1427
1627
|
const { config } = checked.loaded;
|
|
1428
1628
|
if (!config.build) {
|
|
@@ -1462,6 +1662,9 @@ var emittedControllerSettings = async (operation, file, { loaded, hostConfigDiag
|
|
|
1462
1662
|
// packages/compiler/src/project/cli.ts
|
|
1463
1663
|
var usage = `tsplc install|typegen|check|build|run|download|online-change|inspect|clean|configure [--config tsplc.config.ts] [--target name] [--plc|--server] [--simulate] [--runtime] [--emit-only] [--format json] [--read symbol]
|
|
1464
1664
|
|
|
1665
|
+
Run the TypeScript program in Bun instead of CODESYS, with OPC UA on opc.tcp://127.0.0.1:4840:
|
|
1666
|
+
tsplc run --simulate --bun [--foreground] [--target name]
|
|
1667
|
+
|
|
1465
1668
|
Plant agent (the target's agent, else TSPLC_AGENT_URL; TSPLC_AGENT_TOKEN):
|
|
1466
1669
|
tsplc deploy [--target name] [--download] [--select] [--initialize-user] [--simulate]
|
|
1467
1670
|
tsplc target | status | login | logout
|
|
@@ -1472,7 +1675,7 @@ Plant agent (the target's agent, else TSPLC_AGENT_URL; TSPLC_AGENT_TOKEN):
|
|
|
1472
1675
|
Debugger, on http://127.0.0.1, for the built .tsplc/artifacts/st/debug.json; it reads through
|
|
1473
1676
|
the plant agent's login (TSPLC_AGENT_URL, TSPLC_AGENT_TOKEN), or --opcua at config monitor:
|
|
1474
1677
|
tsplc debug [--target name] [--port 4870] [--server-url url] [--opcua]`;
|
|
1475
|
-
var formatSchema =
|
|
1678
|
+
var formatSchema = z6.enum(["json", "text"]).optional();
|
|
1476
1679
|
var requestedFormat = (argv) => {
|
|
1477
1680
|
const index = argv.findIndex((argument) => argument === "--format" || argument.startsWith("--format="));
|
|
1478
1681
|
const flag = argv[index];
|
|
@@ -1505,6 +1708,8 @@ async function main() {
|
|
|
1505
1708
|
server: { type: "boolean" },
|
|
1506
1709
|
simulate: { type: "boolean" },
|
|
1507
1710
|
runtime: { type: "boolean" },
|
|
1711
|
+
bun: { type: "boolean" },
|
|
1712
|
+
foreground: { type: "boolean" },
|
|
1508
1713
|
download: { type: "boolean" },
|
|
1509
1714
|
restore: { type: "boolean" },
|
|
1510
1715
|
select: { type: "boolean" },
|
|
@@ -1542,7 +1747,7 @@ async function main() {
|
|
|
1542
1747
|
target: values.target,
|
|
1543
1748
|
forAgent: true
|
|
1544
1749
|
});
|
|
1545
|
-
const loaded =
|
|
1750
|
+
const loaded = existsSync5(file) ? await load() : undefined;
|
|
1546
1751
|
const env = loaded?.env ?? process.env;
|
|
1547
1752
|
const failed = await runPlantCommand(connect2(env), plant, args, values, {
|
|
1548
1753
|
file,
|
|
@@ -1598,5 +1803,5 @@ try {
|
|
|
1598
1803
|
}
|
|
1599
1804
|
}
|
|
1600
1805
|
|
|
1601
|
-
//# debugId=
|
|
1806
|
+
//# debugId=FD5DF7ECE8BCB6B464756E2164756E21
|
|
1602
1807
|
//# sourceMappingURL=cli.js.map
|